This commit is contained in:
21
PkmnLib.Dynamic/Events/DisplaySpeciesChangeEvent.cs
Normal file
21
PkmnLib.Dynamic/Events/DisplaySpeciesChangeEvent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using PkmnLib.Dynamic.Events;
|
||||
using PkmnLib.Static.Species;
|
||||
|
||||
namespace PkmnLib.Dynamic.Models;
|
||||
|
||||
public class DisplaySpeciesChangeEvent : IEventData
|
||||
{
|
||||
public IPokemon Pokemon { get; }
|
||||
public ISpecies? Species { get; }
|
||||
public IForm? Form { get; }
|
||||
|
||||
public DisplaySpeciesChangeEvent(IPokemon pokemon, ISpecies? species, IForm? form)
|
||||
{
|
||||
Pokemon = pokemon;
|
||||
Species = species;
|
||||
Form = form;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EventBatchId BatchId { get; init; }
|
||||
}
|
||||
@@ -41,6 +41,11 @@ public interface IPokemon : IScriptSource, IDeepCloneable
|
||||
/// </summary>
|
||||
IForm? DisplayForm { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the display species and form of the Pokemon. This is used for abilities like Illusion.
|
||||
/// </summary>
|
||||
void SetDisplaySpecies(ISpecies? species, IForm? form);
|
||||
|
||||
/// <summary>
|
||||
/// The current level of the Pokemon.
|
||||
/// </summary>
|
||||
@@ -90,14 +95,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable
|
||||
/// <summary>
|
||||
/// The weight of the Pokemon in kilograms.
|
||||
/// </summary>
|
||||
float WeightInKg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the weight of the Pokémon in kilograms. Returns whether the weight was changed.
|
||||
/// </summary>
|
||||
/// <param name="weightInKg">The new weight in kilograms</param>
|
||||
/// <returns></returns>
|
||||
public bool ChangeWeightInKgBy(float weightInKg);
|
||||
float WeightInKg { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The height of the Pokémon in meters.
|
||||
@@ -511,7 +509,6 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
Types = form.Types.ToList();
|
||||
|
||||
Experience = library.StaticLibrary.GrowthRates.CalculateExperience(species.GrowthRate, level);
|
||||
WeightInKg = form.Weight;
|
||||
HeightInMeters = form.Height;
|
||||
Happiness = species.BaseHappiness;
|
||||
Volatile = new ScriptSet(this);
|
||||
@@ -546,7 +543,6 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
|
||||
CurrentHealth = serializedPokemon.CurrentHealth;
|
||||
WeightInKg = form.Weight;
|
||||
HeightInMeters = form.Height;
|
||||
Happiness = serializedPokemon.Happiness;
|
||||
IndividualValues = serializedPokemon.IndividualValues.ToIndividualValueStatisticSet();
|
||||
@@ -599,6 +595,18 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
/// <inheritdoc />
|
||||
public IForm? DisplayForm { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetDisplaySpecies(ISpecies? species, IForm? form)
|
||||
{
|
||||
DisplaySpecies = species;
|
||||
DisplayForm = form;
|
||||
|
||||
BattleData?.Battle.EventHook.Invoke(new DisplaySpeciesChangeEvent(this, species, form)
|
||||
{
|
||||
BatchId = new EventBatchId(),
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public LevelInt Level { get; private set; }
|
||||
|
||||
@@ -660,18 +668,18 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
public uint CurrentHealth { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public float WeightInKg { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ChangeWeightInKgBy(float weightInKg)
|
||||
public float WeightInKg
|
||||
{
|
||||
if (WeightInKg <= 0.1f)
|
||||
return false;
|
||||
var newWeight = WeightInKg + weightInKg;
|
||||
if (newWeight <= 0.1f)
|
||||
newWeight = 0.1f;
|
||||
WeightInKg = newWeight;
|
||||
return true;
|
||||
get
|
||||
{
|
||||
var weight = Form.Weight;
|
||||
if (BattleData is not null)
|
||||
// ReSharper disable once AccessToModifiedClosure
|
||||
this.RunScriptHook(script => script.ModifyWeight(ref weight));
|
||||
if (weight < 0.1f)
|
||||
weight = 0.1f;
|
||||
return weight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -958,7 +966,6 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
|
||||
Form = form;
|
||||
Types = form.Types.ToList();
|
||||
WeightInKg = form.Weight;
|
||||
HeightInMeters = form.Height;
|
||||
var newAbility = Form.GetAbility(AbilityIndex);
|
||||
|
||||
@@ -1216,7 +1223,6 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
if (!onBattleField)
|
||||
{
|
||||
Volatile.Clear();
|
||||
WeightInKg = Form.Weight;
|
||||
HeightInMeters = Form.Height;
|
||||
Types = Form.Types;
|
||||
OverrideAbility = null;
|
||||
@@ -1241,7 +1247,6 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
var battleData = BattleData;
|
||||
BattleData = null;
|
||||
Volatile.Clear();
|
||||
WeightInKg = Form.Weight;
|
||||
HeightInMeters = Form.Height;
|
||||
Types = Form.Types;
|
||||
OverrideAbility = null;
|
||||
|
||||
@@ -761,4 +761,12 @@ public abstract class Script : IDeepCloneable
|
||||
public virtual void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the weight of a Pokemon.
|
||||
/// </summary>
|
||||
/// <param name="weight">The weight in kilograms</param>
|
||||
public virtual void ModifyWeight(ref float weight)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user