Adds effects for after you, assist, and attract

This commit is contained in:
2024-11-01 14:21:01 +01:00
parent eb9a30bd41
commit 6f2bd678a5
6 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
namespace PkmnLib.Plugin.Gen7.Moves;
/// <summary>
/// The user helps the target and makes it use its move right after the user.
/// </summary>
/// <remarks>
/// The target will move next on the current turn, ignoring priority. After You bypasses accuracy checks to always hit,
/// unless the target is in the semi-invulnerable turn of a move such as Dig or Fly. It fails if the target has already
/// moved on the same turn. After You ignores the effects of Quash.
/// After You fails if the order remains the same after using After You.
/// </remarks>
[Script(ScriptCategory.Move, "after_you")]
public class AfterYou : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var queue = move.User.BattleData!.Battle.ChoiceQueue;
if (queue == null)
return;
// If the queue doesn't change, the move fails
if (!queue.MovePokemonChoiceNext(target))
{
move.GetHitData(target, hit).Fail();
}
}
}

View File

@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Plugin.Gen7.Scripts.Utils;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Moves;
/// <summary>
/// The user hurriedly and randomly uses a move among those known by ally Pokémon.
/// </summary>
/// <remarks>
/// The Assist user executes a move that is randomly selected from all the eligible moves known by other Pokémon in the
/// same party. If the same move is known by multiple Pokémon, each of them counts and therefore the move is more likely
/// to be called. Assist can call a move that currently has no PP or is known by a fainted Pokémon. It is also able to
/// call moves that are currently inaccessible to their original users due to Disable, Heal Block, Taunt, or Torment.
/// If the other Pokémon in the user's party do not know any eligible moves, Assist fails.
/// </remarks>
[Script(ScriptCategory.Move, "assist")]
public class Assist : Script
{
/// <inheritdoc />
public override void ChangeMove(IMoveChoice choice, ref StringKey moveName)
{
var user = choice.User;
if (user.BattleData == null)
return;
var battle = user.BattleData.Battle;
var party = battle.Parties.FirstOrDefault(p => p.Party.Contains(user));
if (party == null)
{
choice.Fail();
return;
}
var moves = GetPartyMoves(party.Party, user).ToList();
if (moves.Count == 0)
{
choice.Fail();
return;
}
var random = battle.Random.GetInt(moves.Count);
moveName = moves[random].Name;
}
private static IEnumerable<IMoveData> GetPartyMoves(IPokemonParty party, IPokemon user)
{
foreach (var pokemon in party.WhereNotNull())
{
if (pokemon == user)
continue;
var moves = pokemon.Moves.WhereNotNull().Where(m => m.MoveData.CanCopyMove());
foreach (var move in moves)
{
yield return move.MoveData;
}
}
}
}

View File

@@ -0,0 +1,48 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static.Species;
namespace PkmnLib.Plugin.Gen7.Moves;
/// <summary>
/// If it is the opposite gender of the user, the target becomes infatuated and less likely to attack.
/// </summary>
/// <remarks>
/// The target becomes infatuated with the user if they have opposite genders. Attract works regardless of type immunity.
/// Unlike most status moves, Attract is able to bypass a substitute.
/// Attract has no effect if the user and target have the same gender, or if either of them is a gender-unknown Pokémon
/// (such as Magnemite). It also fails when used on a Pokémon that is already infatuated.
/// Pokémon with the Ability Oblivious or under the protection of Aroma Veil are immune to the effects of Attract. If
/// a Pokémon is infatuated by Attract while holding a Mental Herb or an Eggant Berry, the item will be consumed and the
/// infatuation will end. Even if the Pokémon has Oblivious, the item will still be consumed.
/// If the target Pokémon becomes infatuated while holding a Destiny Knot, the user will also become infatuated with the
/// target.
/// </remarks>
[Script(ScriptCategory.Move, "attract")]
public class Attract : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (target.Gender == move.User.Gender)
{
move.GetHitData(target, hit).Fail();
return;
}
if (target.Gender == Gender.Genderless || move.User.Gender == Gender.Genderless)
{
move.GetHitData(target, hit).Fail();
return;
}
if (target.Volatile.Contains("infatuated"))
{
move.GetHitData(target, hit).Fail();
return;
}
target.Volatile.Add(new Infatuated());
}
}