From f19c60c4c147d1e4e49d1ee0c980178ff1ef747a Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 20 Nov 2021 11:00:48 +0100 Subject: [PATCH] Adds anticipation ability --- Scripts/Abilities/Anticipation.as | 51 ++++++++++++++++++++++++ Scripts/Interfaces/BattleSide.astypedef | 1 + Scripts/Interfaces/Pokemon.astypedef | 2 + Scripts/Interfaces/TypeLibrary.astypedef | 1 + 4 files changed, 55 insertions(+) create mode 100644 Scripts/Abilities/Anticipation.as diff --git a/Scripts/Abilities/Anticipation.as b/Scripts/Abilities/Anticipation.as new file mode 100644 index 0000000..00c1ce3 --- /dev/null +++ b/Scripts/Abilities/Anticipation.as @@ -0,0 +1,51 @@ +namespace Gen7 { + [Ability effect=Anticipation] + class Anticipation : PkmnScript { + void OnSwitchIn(Pokemon@ pokemon){ + if (DoesOpponentHaveSuperEffectiveMove(pokemon.Battle, pokemon)){ + // TODO: Shudder + } + } + + bool DoesOpponentHaveSuperEffectiveMove(Battle@ battle, Pokemon@ pokemon){ + bool hasSuperEffectiveMove = false; + auto typeLib = battle.Library.StaticLibrary.TypeLibrary; + for (uint64 i = 0; i < battle.Sides.Length; i++){ + if (hasSuperEffectiveMove){ + break; + } + auto side = battle.Sides[i]; + if (side is pokemon.BattleSide){ + continue; + } + for (uint64 j = 0; j < side.Pokemon.Length; j++){ + if (hasSuperEffectiveMove){ + break; + } + auto opponent = side.Pokemon[j]; + if (opponent is null){ + continue; + } + if (opponent.IsFainted){ + continue; + } + for (uint64 k = 0; k < opponent.Moves.Length; k++){ + if (hasSuperEffectiveMove){ + break; + } + auto move = opponent.Moves[k]; + if (move is null){ + continue; + } + if (typeLib.GetEffectiveness(move.MoveData.Type, pokemon) > 1){ + hasSuperEffectiveMove = true; + break; + } + } + } + } + + return hasSuperEffectiveMove; + } + } +} \ No newline at end of file diff --git a/Scripts/Interfaces/BattleSide.astypedef b/Scripts/Interfaces/BattleSide.astypedef index 08e3539..b7f6417 100644 --- a/Scripts/Interfaces/BattleSide.astypedef +++ b/Scripts/Interfaces/BattleSide.astypedef @@ -4,6 +4,7 @@ type BattleSide { bool IsDefeated { get const; }; bool HasFled { get const; }; Battle@ Battle { get const; }; + narray@ Pokemon { get const; }; uint8 GetPokemonIndex(const Pokemon@ pokemon) const; Pokemon@ GetPokemon(uint8 index) const; ref@ AddVolatile(const constString &in name); diff --git a/Scripts/Interfaces/Pokemon.astypedef b/Scripts/Interfaces/Pokemon.astypedef index d69710c..28fbc58 100644 --- a/Scripts/Interfaces/Pokemon.astypedef +++ b/Scripts/Interfaces/Pokemon.astypedef @@ -19,6 +19,8 @@ type Pokemon { float Weight { get const; set; }; float Height { get const; set; }; const constString& ActiveAbility { get const; }; + uint64 TypesLength { get const; }; + uint8 GetType(uint64 index) const; bool HasHeldItem(const constString &in name) const; void SetHeldItem(const constString &in name); void SetHeldItem(const Item@ item); diff --git a/Scripts/Interfaces/TypeLibrary.astypedef b/Scripts/Interfaces/TypeLibrary.astypedef index 5c41e26..4ae1e85 100644 --- a/Scripts/Interfaces/TypeLibrary.astypedef +++ b/Scripts/Interfaces/TypeLibrary.astypedef @@ -1,4 +1,5 @@ type TypeLibrary { uint8 GetTypeId(const constString &in name) const; float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const; + float GetEffectiveness(uint8 attackingType, Pokemon@ defender) const; }