From e85460fd2207eef0d25790dfd5f63238eb2ec080 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 23 Oct 2021 18:29:18 +0200 Subject: [PATCH] Adds Assurance effect --- Moves.json | 5 +- Scripts/Interfaces/AttackUseHistory.astypedef | 7 +++ Scripts/Interfaces/Battle.astypedef | 1 + Scripts/Interfaces/BattleHistory.astypedef | 5 ++ Scripts/Interfaces/DamageHistory.astypedef | 9 ++++ Scripts/Interfaces/HistoryElement.astypedef | 4 ++ .../Interfaces/HistoryElementKind.astypedef | 4 ++ Scripts/Moves/Assurance.as | 47 +++++++++++++++++++ 8 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Scripts/Interfaces/AttackUseHistory.astypedef create mode 100644 Scripts/Interfaces/BattleHistory.astypedef create mode 100644 Scripts/Interfaces/DamageHistory.astypedef create mode 100644 Scripts/Interfaces/HistoryElement.astypedef create mode 100644 Scripts/Interfaces/HistoryElementKind.astypedef create mode 100644 Scripts/Moves/Assurance.as diff --git a/Moves.json b/Moves.json index 5230200..551c976 100644 --- a/Moves.json +++ b/Moves.json @@ -406,7 +406,10 @@ "priority": 0, "target": "Any", "category": "physical", - "flags": ["contact", "protect", "mirror"] + "flags": ["contact", "protect", "mirror"], + "effect": { + "name": "Assurance" + } }, { "name": "astonish", diff --git a/Scripts/Interfaces/AttackUseHistory.astypedef b/Scripts/Interfaces/AttackUseHistory.astypedef new file mode 100644 index 0000000..de27e87 --- /dev/null +++ b/Scripts/Interfaces/AttackUseHistory.astypedef @@ -0,0 +1,7 @@ +type AttackUseHistory { + const HistoryElement@ Previous { get const; }; + HistoryElementKind Kind { get const; }; + uint TurnNumber { get const; }; + const HistoryElement@ opImplCast() const; + const ExecutingMove@ Move { get const; }; +} diff --git a/Scripts/Interfaces/Battle.astypedef b/Scripts/Interfaces/Battle.astypedef index 25c0bf1..0aed2cf 100644 --- a/Scripts/Interfaces/Battle.astypedef +++ b/Scripts/Interfaces/Battle.astypedef @@ -6,6 +6,7 @@ type Battle { ChoiceQueue@ TurnQueue { get const; }; narray@ Sides { get const; }; narray@ Parties { get const; }; + BattleHistory@ History { get const; }; bool CanUse(BaseTurnChoice@ choice); ref@ AddVolatile(const constString &in name); void RemoveVolatile(const constString &in name) const; diff --git a/Scripts/Interfaces/BattleHistory.astypedef b/Scripts/Interfaces/BattleHistory.astypedef new file mode 100644 index 0000000..02bdf4c --- /dev/null +++ b/Scripts/Interfaces/BattleHistory.astypedef @@ -0,0 +1,5 @@ +type BattleHistory { + const HistoryElement@ TopElement { get const; }; + const AttackUseHistory@ GetLastUsedAttack() const; + const DamageHistory@ GetLastDamageOnTarget(Pokemon@ target) const; +} diff --git a/Scripts/Interfaces/DamageHistory.astypedef b/Scripts/Interfaces/DamageHistory.astypedef new file mode 100644 index 0000000..a2ca7ad --- /dev/null +++ b/Scripts/Interfaces/DamageHistory.astypedef @@ -0,0 +1,9 @@ +type DamageHistory { + const HistoryElement@ Previous { get const; }; + HistoryElementKind Kind { get const; }; + uint TurnNumber { get const; }; + const HistoryElement@ opImplCast() const; + Pokemon@ Target { get const; }; + uint Amount { get const; }; + DamageSource Source { get const; }; +} diff --git a/Scripts/Interfaces/HistoryElement.astypedef b/Scripts/Interfaces/HistoryElement.astypedef new file mode 100644 index 0000000..311e124 --- /dev/null +++ b/Scripts/Interfaces/HistoryElement.astypedef @@ -0,0 +1,4 @@ +type HistoryElement { + const DamageHistory@ opCast() const; + const AttackUseHistory@ opCast() const; +} diff --git a/Scripts/Interfaces/HistoryElementKind.astypedef b/Scripts/Interfaces/HistoryElementKind.astypedef new file mode 100644 index 0000000..8d74c60 --- /dev/null +++ b/Scripts/Interfaces/HistoryElementKind.astypedef @@ -0,0 +1,4 @@ +enum HistoryElementKind { + AttackUse = 0, + Damage = 1, +} diff --git a/Scripts/Moves/Assurance.as b/Scripts/Moves/Assurance.as new file mode 100644 index 0000000..62bb49e --- /dev/null +++ b/Scripts/Moves/Assurance.as @@ -0,0 +1,47 @@ +namespace Gen7{ + [Move effect=Assurance] + class Assurance : PkmnScript { + void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint &inout damage) override { + auto damageEvent = target.Battle.History.GetLastDamageOnTarget(target); + if (damageEvent is null){ + return; + } + if (damageEvent.TurnNumber == target.Battle.CurrentTurn){ + damage *= 2; + } + }; + } +} + +#if TESTS +[Test name="Assurance: damage without damage on the same turn"] +void Assurance_DamageWithoutEvent(){ + auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100); + auto mon1 = battle.GetBattleSide(0).GetPokemon(0); + auto mon2 = battle.GetBattleSide(1).GetPokemon(0); + + auto script = cast(CreateMoveScript("Assurance")); + Require(script !is null); + uint damage = 100; + auto executingMove = CreateExecutingMove("Assurance", mon1, mon2); + script.OverrideDamage(executingMove, mon2, 0x0, damage); + RequireEquals(100, damage); +} + +[Test name="Assurance: damage with damage on the same turn"] +void Assurance_DamageWithEvent(){ + auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100); + auto mon1 = battle.GetBattleSide(0).GetPokemon(0); + auto mon2 = battle.GetBattleSide(1).GetPokemon(0); + + mon2.Damage(10, DamageSource::AttackDamage); + + auto script = cast(CreateMoveScript("Assurance")); + Require(script !is null); + uint damage = 100; + auto executingMove = CreateExecutingMove("Assurance", mon1, mon2); + script.OverrideDamage(executingMove, mon2, 0x0, damage); + RequireEquals(200, damage); +} + +#endif \ No newline at end of file