This commit is contained in:
@@ -354,12 +354,12 @@ public interface IPokemon : IScriptSource, IDeepCloneable
|
||||
/// <summary>
|
||||
/// Adds a non-volatile status to the Pokemon.
|
||||
/// </summary>
|
||||
bool SetStatus(StringKey status);
|
||||
bool SetStatus(StringKey status, EventBatchId batchId = default);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the current non-volatile status from the Pokemon.
|
||||
/// </summary>
|
||||
void ClearStatus();
|
||||
void ClearStatus(EventBatchId batchId = default);
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the level by a certain amount
|
||||
@@ -382,6 +382,11 @@ public interface IPokemon : IScriptSource, IDeepCloneable
|
||||
/// <param name="position"></param>
|
||||
void SetBattleSidePosition(byte position);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the battle data of the Pokémon. This is called when the battle ends.
|
||||
/// </summary>
|
||||
void ClearBattleData();
|
||||
|
||||
/// <summary>
|
||||
/// Marks a Pokemon as seen in the battle.
|
||||
/// </summary>
|
||||
@@ -475,6 +480,16 @@ public interface IPokemonBattleData : IDeepCloneable
|
||||
/// The side the Pokémon is on.
|
||||
/// </summary>
|
||||
IBattleSide BattleSide { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The species of the Pokémon at the time it was sent out.
|
||||
/// </summary>
|
||||
ISpecies OriginalSpecies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The form of the Pokémon at the time it was sent out.
|
||||
/// </summary>
|
||||
IForm OriginalForm { get; }
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IPokemon"/>
|
||||
@@ -928,7 +943,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ChangeForm(IForm form, EventBatchId batchId)
|
||||
public void ChangeForm(IForm form, EventBatchId batchId = default)
|
||||
{
|
||||
if (form == Form)
|
||||
return;
|
||||
@@ -1120,13 +1135,14 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
public bool HasStatus(StringKey status) => StatusScript.Script?.Name == status;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SetStatus(StringKey status)
|
||||
public bool SetStatus(StringKey status, EventBatchId batchId = default)
|
||||
{
|
||||
if (!Library.ScriptResolver.TryResolve(ScriptCategory.Status, status, null, out var statusScript))
|
||||
throw new KeyNotFoundException($"Status script {status} not found");
|
||||
|
||||
if (!StatusScript.IsEmpty)
|
||||
return false;
|
||||
var oldStatus = StatusScript.Script?.Name;
|
||||
|
||||
var preventStatus = false;
|
||||
this.RunScriptHook(script => script.PreventStatusChange(this, status, ref preventStatus));
|
||||
@@ -1135,11 +1151,22 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
|
||||
StatusScript.Set(statusScript);
|
||||
statusScript.OnAddedToParent(this);
|
||||
BattleData?.Battle.EventHook.Invoke(new StatusChangeEvent(this, oldStatus, status)
|
||||
{
|
||||
BatchId = batchId,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearStatus() => StatusScript.Clear();
|
||||
public void ClearStatus(EventBatchId batchId = default)
|
||||
{
|
||||
StatusScript.Clear();
|
||||
BattleData?.Battle.EventHook.Invoke(new StatusChangeEvent(this, StatusScript.Script?.Name, null)
|
||||
{
|
||||
BatchId = batchId,
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ChangeLevelBy(int change)
|
||||
@@ -1160,7 +1187,17 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
else
|
||||
{
|
||||
BattleData = new PokemonBattleDataImpl(battle, sideIndex, battle.CurrentTurnNumber);
|
||||
BattleData = new PokemonBattleDataImpl(battle, sideIndex, battle.CurrentTurnNumber, Species, Form);
|
||||
}
|
||||
if (ActiveAbility != null && Library.ScriptResolver.TryResolve(ScriptCategory.Ability, ActiveAbility.Name,
|
||||
ActiveAbility.Parameters, out var abilityScript))
|
||||
{
|
||||
AbilityScript.Set(abilityScript);
|
||||
abilityScript.OnAddedToParent(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
AbilityScript.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1192,6 +1229,24 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearBattleData()
|
||||
{
|
||||
var battleData = BattleData;
|
||||
BattleData = null;
|
||||
Volatile.Clear();
|
||||
WeightInKg = Form.Weight;
|
||||
HeightInMeters = Form.Height;
|
||||
Types = Form.Types;
|
||||
OverrideAbility = null;
|
||||
AbilitySuppressed = false;
|
||||
StatBoost.Reset();
|
||||
if (battleData != null && Form.IsBattleOnlyForm)
|
||||
{
|
||||
ChangeForm(battleData.OriginalSpecies == Species ? battleData.OriginalForm : Species.GetDefaultForm());
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void MarkOpponentAsSeen(IPokemon pokemon) => BattleData?.MarkOpponentAsSeen(pokemon);
|
||||
|
||||
@@ -1295,11 +1350,14 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
public class PokemonBattleDataImpl : IPokemonBattleData
|
||||
{
|
||||
/// <inheritdoc cref="PokemonBattleDataImpl"/>
|
||||
public PokemonBattleDataImpl(IBattle battle, byte sideIndex, uint switchInTurn)
|
||||
public PokemonBattleDataImpl(IBattle battle, byte sideIndex, uint switchInTurn, ISpecies originalSpecies,
|
||||
IForm originalForm)
|
||||
{
|
||||
Battle = battle;
|
||||
SideIndex = sideIndex;
|
||||
SwitchInTurn = switchInTurn;
|
||||
OriginalSpecies = originalSpecies;
|
||||
OriginalForm = originalForm;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -1342,4 +1400,10 @@ public class PokemonBattleDataImpl : IPokemonBattleData
|
||||
|
||||
/// <inheritdoc />
|
||||
public IBattleSide BattleSide => Battle.Sides[SideIndex];
|
||||
|
||||
/// <inheritdoc />
|
||||
public ISpecies OriginalSpecies { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IForm OriginalForm { get; }
|
||||
}
|
||||
Reference in New Issue
Block a user