More abilities, implemented support for form inheritance
All checks were successful
Build / Build (push) Successful in 49s
All checks were successful
Build / Build (push) Successful in 49s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
@@ -111,11 +112,40 @@ public class SerializedForm
|
||||
/// </summary>
|
||||
public bool IsBattleOnly { get; set; }
|
||||
|
||||
public string? InheritFrom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Additional data that is not part of the standard form data.
|
||||
/// </summary>
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? ExtensionData { get; set; }
|
||||
|
||||
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract"),
|
||||
SuppressMessage("ReSharper", "NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract")]
|
||||
internal void MakeInheritFrom(SerializedForm other)
|
||||
{
|
||||
Abilities ??= other.Abilities.ToArray();
|
||||
HiddenAbilities ??= other.HiddenAbilities.ToArray();
|
||||
BaseStats ??= other.BaseStats.Copy();
|
||||
EVReward ??= other.EVReward.Copy();
|
||||
Types ??= other.Types.ToArray();
|
||||
if (Height == 0)
|
||||
Height = other.Height;
|
||||
if (Weight == 0)
|
||||
Weight = other.Weight;
|
||||
if (BaseExp == 0)
|
||||
BaseExp = other.BaseExp;
|
||||
Moves ??= new SerializedMoves();
|
||||
if (Moves.LevelMoves == null || Moves.LevelMoves.Length == 0)
|
||||
Moves.LevelMoves = other.Moves.LevelMoves?.ToArray();
|
||||
if (Moves.EggMoves == null || Moves.EggMoves.Length == 0)
|
||||
Moves.EggMoves = other.Moves.EggMoves?.ToArray();
|
||||
if (Moves.TutorMoves == null || Moves.TutorMoves.Length == 0)
|
||||
Moves.TutorMoves = other.Moves.TutorMoves?.ToArray();
|
||||
if (Moves.Machine == null || Moves.Machine.Length == 0)
|
||||
Moves.Machine = other.Moves.Machine?.ToArray();
|
||||
Flags ??= other.Flags.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -159,6 +189,17 @@ public record SerializedStats
|
||||
|
||||
/// <inheritdoc cref="PkmnLib.Static.ImmutableStatisticSet{T}.Speed"/>
|
||||
public ushort Speed { get; set; }
|
||||
|
||||
public SerializedStats Copy() =>
|
||||
new()
|
||||
{
|
||||
Hp = Hp,
|
||||
Attack = Attack,
|
||||
Defense = Defense,
|
||||
SpecialAttack = SpecialAttack,
|
||||
SpecialDefense = SpecialDefense,
|
||||
Speed = Speed,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -76,6 +76,20 @@ public static class SpeciesDataLoader
|
||||
$"Egg cycles for species {id} is invalid: {serialized.EggCycles}. Must be greater than or equal to 0.");
|
||||
}
|
||||
|
||||
foreach (var form in serialized.Formes)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(form.Value.InheritFrom))
|
||||
{
|
||||
var inheritedForm = serialized.Formes.GetValueOrDefault(form.Value.InheritFrom);
|
||||
if (inheritedForm == null)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
$"Form {form.Key} inherits from {form.Value.InheritFrom}, but that form does not exist.");
|
||||
}
|
||||
form.Value.MakeInheritFrom(inheritedForm);
|
||||
}
|
||||
}
|
||||
|
||||
var forms = serialized.Formes.ToDictionary(x => (StringKey)x.Key,
|
||||
x => DeserializeForm(x.Key, x.Value, typeLibrary));
|
||||
var evolutions = serialized.Evolutions.Select(DeserializeEvolution).ToList();
|
||||
|
||||
@@ -784,6 +784,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
{
|
||||
var previous = HeldItem;
|
||||
HeldItem = item;
|
||||
this.RunScriptHook(x => x.OnAfterHeldItemChange(this, previous, item));
|
||||
return previous;
|
||||
}
|
||||
|
||||
@@ -799,6 +800,7 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
}
|
||||
var previous = HeldItem;
|
||||
HeldItem = null;
|
||||
this.RunScriptHook(x => x.OnAfterHeldItemChange(this, previous, null));
|
||||
return previous;
|
||||
}
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ public abstract class Script : IDeepCloneable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function triggers when an opponent on the field faints.
|
||||
/// This function triggers when an opponent on the field faints due to the move that is being executed.
|
||||
/// </summary>
|
||||
public virtual void OnOpponentFaints(IExecutingMove move, IPokemon target, byte hit)
|
||||
{
|
||||
@@ -794,4 +794,11 @@ public abstract class Script : IDeepCloneable
|
||||
ref bool isContact)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function allows a script to run after a held item has changed.
|
||||
/// </summary>
|
||||
public virtual void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user