Skip to content

Commit

Permalink
Handle Disable ending message
Browse files Browse the repository at this point in the history
  • Loading branch information
davidstone committed Nov 2, 2024
1 parent 0bf20f1 commit 6a32696
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/tm/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ struct Battle {
});
}

auto end_disable(bool ai_is_user) & -> void {
apply_to_teams(ai_is_user, [&](auto & user_team, auto const &) {
user_team.pokemon().end_disable();
});
}

auto end_turn(bool const ai_went_first, EndOfTurnFlags const first_flags, EndOfTurnFlags const last_flags) & -> void {
apply_to_teams(ai_went_first, [&](auto & first, auto & last) {
end_of_turn(first, first_flags, last, last_flags, m_environment);
Expand Down
1 change: 1 addition & 0 deletions source/tm/clients/client_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export struct ClientBattle {
virtual auto use_move(bool ai_is_user, MoveResult, bool user_status_was_cleared) & -> void = 0;
virtual auto use_switch(bool ai_is_user, Switch) & -> void = 0;
virtual auto hit_self_in_confusion(bool ai_is_user, VisibleHP const damage) & -> void = 0;
virtual auto end_disable(bool ai_is_user) & -> void = 0;

// TODO: Delete this function
virtual auto cures_target_status(bool is_ai, MoveName) const -> bool = 0;
Expand Down
4 changes: 4 additions & 0 deletions source/tm/clients/make_client_battle_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ struct ClientBattleImpl final : ClientBattle {
m_battle.hit_self_in_confusion(ai_is_user, damage);
}

auto end_disable(bool ai_is_user) & -> void final {
m_battle.end_disable(ai_is_user);
}

auto end_turn(bool const ai_went_first, EndOfTurnFlags const first_flags, EndOfTurnFlags const last_flags) & -> void final {
m_battle.end_turn(ai_went_first, first_flags, last_flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ auto BattleMessageHandler::handle_message(std::span<ParsedMessage const> const b
);
// TODO: Implement Generation 1 Disable
},
[&](DisableEndedMessage const message) {
m_client_battle->end_disable(message.party == m_party);
},
[&](RechargingMessage const message) {
use_previous_action();
auto & move_builder = make_move_builder();
Expand Down
3 changes: 3 additions & 0 deletions source/tm/clients/pokemon_showdown/event_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ constexpr auto parse_message(InMessage message) -> tv::optional<ParsedMessage> {
[&](FromConfusion) -> tv::optional<ParsedMessage> {
return ConfusionEndedMessage(party);
},
[&](FromDisable) -> tv::optional<ParsedMessage> {
return DisableEndedMessage(party);
},
[](FromMiscellaneous) -> tv::optional<ParsedMessage> {
return tv::none;
},
Expand Down
6 changes: 6 additions & 0 deletions source/tm/clients/pokemon_showdown/parsed_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export struct DisableMessage {
friend auto operator==(DisableMessage, DisableMessage) -> bool = default;
};

export struct DisableEndedMessage {
Party party;
friend auto operator==(DisableEndedMessage, DisableEndedMessage) -> bool = default;
};

export struct RechargingMessage {
Party party;
friend auto operator==(RechargingMessage, RechargingMessage) -> bool = default;
Expand Down Expand Up @@ -244,6 +249,7 @@ export using ParsedMessage = tv::variant<
PartiallyTrappedMessage,
StillAsleepMessage,
DisableMessage,
DisableEndedMessage,
RechargingMessage,
CriticalHitMessage,
StatusClearMessage,
Expand Down
3 changes: 3 additions & 0 deletions source/tm/pokemon/active_pokemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ struct AnyMutableActivePokemon : ActivePokemonImpl<PokemonType> {
constexpr auto advance_disable() const {
this->m_flags.disable.advance_one_turn();
}
constexpr auto end_disable() const -> void {
this->m_flags.disable = {};
}
constexpr auto activate_embargo() const {
this->m_flags.embargo.activate();
}
Expand Down

0 comments on commit 6a32696

Please sign in to comment.