Skip to content

Commit

Permalink
Support "Disable" as a Pokemon Showdown effect source
Browse files Browse the repository at this point in the history
  • Loading branch information
davidstone committed Oct 21, 2024
1 parent b7279a4 commit b90298e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ auto BattleMessageHandler::handle_message(std::span<ParsedMessage const> const b
auto & move_builder = make_move_builder();
move_builder.still_asleep(message.party);
},
[&](DisableMessage const message) {
m_client_battle->active_has(
message.party == m_party,
message.move
);
// TODO: Implement Generation 1 Disable
},
[&](RechargingMessage const message) {
use_previous_action();
auto & move_builder = make_move_builder();
Expand Down
13 changes: 13 additions & 0 deletions source/tm/clients/pokemon_showdown/event_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ constexpr auto parse_message(InMessage message) -> tv::optional<ParsedMessage> {
// TODO: Should I send this as a message?
return tv::none;
},
[](FromDisable) -> tv::optional<ParsedMessage> {
throw std::runtime_error("Unexpected -activate source FromDisable");
},
[](FromEntryHazards) -> tv::optional<ParsedMessage> {
throw std::runtime_error("Unexpected -activate source FromEntryHazards");
},
Expand Down Expand Up @@ -205,6 +208,9 @@ constexpr auto parse_message(InMessage message) -> tv::optional<ParsedMessage> {
[&](FromConfusion) -> tv::optional<ParsedMessage> {
return HitSelfMessage(parsed.party, parsed.status, parsed.hp);
},
[](FromDisable) -> tv::optional<ParsedMessage> {
throw std::runtime_error("Invalid -damage source of FromDisable");
},
[&](FromEntryHazards) -> tv::optional<ParsedMessage> {
return HPMessage(parsed.party, parsed.status, parsed.hp);
},
Expand Down Expand Up @@ -435,6 +441,10 @@ constexpr auto parse_message(InMessage message) -> tv::optional<ParsedMessage> {
[](MainEffect) -> tv::optional<ParsedMessage> {
throw std::runtime_error("Unexpected -start source MainEffect");
},
[&](FromDisable) -> tv::optional<ParsedMessage> {
auto const move_str = message.pop();
return DisableMessage(party, from_string<MoveName>(move_str));
},
[](FromRecoil) -> tv::optional<ParsedMessage> {
throw std::runtime_error("Unexpected -start source FromRecoil");
},
Expand All @@ -460,6 +470,9 @@ constexpr auto parse_message(InMessage message) -> tv::optional<ParsedMessage> {
[&](MainEffect) -> tv::optional<ParsedMessage> {
return MoveStatus(party, status);
},
[](FromDisable) -> tv::optional<ParsedMessage> {
throw std::runtime_error("Disable cannot cause a status");
},
[](FromEntryHazards) -> tv::optional<ParsedMessage> {
return tv::none;
},
Expand Down
15 changes: 14 additions & 1 deletion source/tm/clients/pokemon_showdown/parse_effect_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ using namespace std::string_view_literals;
export struct MainEffect {};
export struct FromMove {};
export struct FromConfusion {};
export struct FromDisable {};
export struct FromEntryHazards {};
export struct FromMiscellaneous {};
export struct FromRecoil {};
export struct FromSubstitute {};

export using EffectSource = tv::variant<MainEffect, Item, Ability, FromMove, FromConfusion, FromEntryHazards, FromMiscellaneous, FromRecoil, FromSubstitute>;
export using EffectSource = tv::variant<
MainEffect,
Item,
Ability,
FromMove,
FromConfusion,
FromDisable,
FromEntryHazards,
FromMiscellaneous,
FromRecoil,
FromSubstitute
>;

export constexpr auto parse_effect_source(std::string_view const type, std::string_view const source) -> EffectSource {
return
Expand All @@ -41,6 +53,7 @@ export constexpr auto parse_effect_source(std::string_view const type, std::stri
(type == "ability") ? EffectSource(from_string<Ability>(source)) :
(type == "move") ? EffectSource(FromMove()) :
(type == "confusion") ? EffectSource(FromConfusion()) :
(type == "Disable") ? EffectSource(FromDisable()) :
(type == "Recoil") ? EffectSource(FromRecoil()) :
(type == "Spikes") ? EffectSource(FromEntryHazards()) :
(type == "Stealth Rock") ? EffectSource(FromEntryHazards()) :
Expand Down
7 changes: 7 additions & 0 deletions source/tm/clients/pokemon_showdown/parsed_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export struct StillAsleepMessage {
friend auto operator==(StillAsleepMessage, StillAsleepMessage) -> bool = default;
};

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

export struct RechargingMessage {
Party party;
friend auto operator==(RechargingMessage, RechargingMessage) -> bool = default;
Expand Down Expand Up @@ -237,6 +243,7 @@ export using ParsedMessage = tv::variant<
FullyParalyzedMessage,
PartiallyTrappedMessage,
StillAsleepMessage,
DisableMessage,
RechargingMessage,
CriticalHitMessage,
StatusClearMessage,
Expand Down

0 comments on commit b90298e

Please sign in to comment.