More moves implemented

This commit is contained in:
2025-02-03 11:40:26 +01:00
parent 0c5ca487d7
commit 51dfc4d07e
40 changed files with 639 additions and 65 deletions

View File

@@ -373,6 +373,8 @@ public interface IPokemon : IScriptSource, IDeepCloneable
/// Replace the types of the Pokémon with the provided types.
/// </summary>
void SetTypes(IReadOnlyList<TypeIdentifier> types);
void ChangeAbility(IAbility ability);
/// <summary>
/// Converts the data structure to a serializable format.
@@ -409,7 +411,7 @@ public interface IPokemonBattleData : IDeepCloneable
/// <summary>
/// Whether the Pokémon is on the battlefield.
/// </summary>
bool IsOnBattlefield { get; set; }
bool IsOnBattlefield { get; internal set; }
/// <summary>
/// Adds an opponent to the list of seen opponents.
@@ -425,6 +427,8 @@ public interface IPokemonBattleData : IDeepCloneable
/// Marks an item as consumed.
/// </summary>
void MarkItemAsConsumed(IItem itemName);
uint SwitchInTurn { get; internal set; }
}
/// <inheritdoc cref="IPokemon"/>
@@ -720,6 +724,15 @@ public class PokemonImpl : ScriptSource, IPokemon
return false;
if (!Library.ScriptResolver.TryResolveBattleItemScript(HeldItem, out _))
return false;
if (BattleData != null)
{
var prevented = false;
this.RunScriptHook(script => script.PreventHeldItemConsume(this, HeldItem, ref prevented));
if (prevented)
return false;
}
// TODO: actually consume the item
throw new NotImplementedException();
}
@@ -885,6 +898,13 @@ public class PokemonImpl : ScriptSource, IPokemon
// If the Pokémon is already fainted, we don't need to do anything.
if (IsFainted)
return;
if (BattleData is not null)
{
var dmg = damage;
this.RunScriptHook(script => script.ChangeIncomingDamage(this, source, ref dmg));
damage = dmg;
}
// If the damage is more than the current health, we cap it at the current health, to prevent
// underflow.
if (damage >= CurrentHealth)
@@ -1013,10 +1033,11 @@ public class PokemonImpl : ScriptSource, IPokemon
{
BattleData.Battle = battle;
BattleData.SideIndex = sideIndex;
BattleData.SwitchInTurn = battle.CurrentTurnNumber;
}
else
{
BattleData = new PokemonBattleDataImpl(battle, sideIndex);
BattleData = new PokemonBattleDataImpl(battle, sideIndex, battle.CurrentTurnNumber);
}
}
@@ -1068,6 +1089,12 @@ public class PokemonImpl : ScriptSource, IPokemon
_types = types.ToList();
}
/// <inheritdoc />
public void ChangeAbility(IAbility ability)
{
OverrideAbility = ability;
}
/// <inheritdoc />
public SerializedPokemon Serialize() => new(this);
@@ -1112,10 +1139,11 @@ public class PokemonImpl : ScriptSource, IPokemon
public class PokemonBattleDataImpl : IPokemonBattleData
{
/// <inheritdoc cref="PokemonBattleDataImpl"/>
public PokemonBattleDataImpl(IBattle battle, byte sideIndex)
public PokemonBattleDataImpl(IBattle battle, byte sideIndex, uint switchInTurn)
{
Battle = battle;
SideIndex = sideIndex;
SwitchInTurn = switchInTurn;
}
/// <inheritdoc />
@@ -1151,4 +1179,7 @@ public class PokemonBattleDataImpl : IPokemonBattleData
{
_consumedItems.Add(itemName);
}
/// <inheritdoc />
public uint SwitchInTurn { get; set; }
}