2021-05-13 12:32:56 +00:00
|
|
|
namespace Gen7 {
|
|
|
|
[Move effect=Assist]
|
|
|
|
class Assist : PkmnScript {
|
|
|
|
void ChangeAttack(MoveTurnChoice@ move, constString &inout moveName) override {
|
|
|
|
auto user = move.User;
|
|
|
|
auto battle = user.Battle;
|
|
|
|
auto party = battle.FindPartyForPokemon(user).Party;
|
|
|
|
array<const MoveData@> possibleMoves;
|
2021-10-23 12:20:18 +00:00
|
|
|
for (uint64 i = 0; i < party.Length; i++){
|
2021-05-13 12:32:56 +00:00
|
|
|
auto mon = party.GetAtIndex(i);
|
|
|
|
if (mon is null){ continue; }
|
2021-08-29 15:49:29 +00:00
|
|
|
if (mon is user){ continue; }
|
2021-10-23 12:20:18 +00:00
|
|
|
auto moves = mon.Moves;
|
|
|
|
for (uint64 j = 0; j < moves.Length; j++){
|
2021-05-13 12:32:56 +00:00
|
|
|
auto m = moves[j];
|
|
|
|
if (m is null){ continue; }
|
2021-08-29 09:51:04 +00:00
|
|
|
if (CopyableMoves::CanCopyMove(m.MoveData)){
|
2021-05-13 12:32:56 +00:00
|
|
|
possibleMoves.insertLast(m.MoveData);
|
|
|
|
}
|
|
|
|
}
|
2021-10-23 12:20:18 +00:00
|
|
|
}
|
2021-05-13 12:32:56 +00:00
|
|
|
if (possibleMoves.length == 0){
|
|
|
|
// TODO: Log failure.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto i = battle.Random.Get(possibleMoves.length);
|
|
|
|
moveName = possibleMoves[i].Name;
|
|
|
|
}
|
|
|
|
}
|
2021-08-29 09:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if TESTS
|
|
|
|
[Test name="Assist: Switch move to known move from party member"]
|
|
|
|
void Assist_ChangesMove(){
|
|
|
|
auto p1 = CreateSimpleParty({"charizard", "blastoise"}, 100);
|
|
|
|
auto p2 = CreateSimpleParty({"venusaur", "pikachu"}, 100);
|
|
|
|
|
|
|
|
auto battle = CreateSimpleBattle(684, p1, p2);
|
2021-08-29 15:49:29 +00:00
|
|
|
p1.GetAtIndex(1).LearnMove("bubble_beam");
|
|
|
|
auto choice = CreateMoveTurnChoice("assist", p1.GetAtIndex(0), 1, 0);
|
|
|
|
constString moveName = "assist";
|
|
|
|
auto script = cast<Gen7::Assist>(CreateMoveScript("Assist"));
|
|
|
|
script.ChangeAttack(choice, moveName);
|
|
|
|
RequireEquals("bubble_beam", moveName);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test name="Assist: Doesn't switch when move can't be copied"]
|
|
|
|
void Assist_CantSwitchIntoNonCopyable(){
|
|
|
|
auto p1 = CreateSimpleParty({"charizard", "blastoise"}, 100);
|
|
|
|
auto p2 = CreateSimpleParty({"venusaur", "pikachu"}, 100);
|
|
|
|
|
|
|
|
auto battle = CreateSimpleBattle(684, p1, p2);
|
|
|
|
p1.GetAtIndex(1).LearnMove("dig");
|
|
|
|
auto choice = CreateMoveTurnChoice("assist", p1.GetAtIndex(0), 1, 0);
|
|
|
|
constString moveName = "assist";
|
|
|
|
auto script = cast<Gen7::Assist>(CreateMoveScript("Assist"));
|
|
|
|
script.ChangeAttack(choice, moveName);
|
|
|
|
RequireEquals("assist", moveName);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test name="Assist: Doesn't switch if no move"]
|
|
|
|
void Assist_CantSwitchWhenNoOptions(){
|
|
|
|
auto p1 = CreateSimpleParty({"charizard", "blastoise"}, 100);
|
|
|
|
auto p2 = CreateSimpleParty({"venusaur", "pikachu"}, 100);
|
|
|
|
|
|
|
|
auto battle = CreateSimpleBattle(684, p1, p2);
|
|
|
|
auto choice = CreateMoveTurnChoice("assist", p1.GetAtIndex(0), 1, 0);
|
|
|
|
constString moveName = "assist";
|
|
|
|
auto script = cast<Gen7::Assist>(CreateMoveScript("Assist"));
|
|
|
|
script.ChangeAttack(choice, moveName);
|
|
|
|
RequireEquals("assist", moveName);
|
2021-08-29 09:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|