Bunch more moves, changes in how additional information for items works.

This commit is contained in:
2025-04-14 15:29:26 +02:00
parent 2adbb12367
commit 7c2845502d
60 changed files with 4275 additions and 963 deletions

View File

@@ -109,7 +109,9 @@ public interface IItem : INamedValue
ISecondaryEffect? Effect { get; }
ISecondaryEffect? BattleEffect { get; }
byte FlingPower { get; }
IReadOnlyDictionary<StringKey, object?> AdditionalData { get; }
bool TryGetAdditionalData<T>(StringKey key, out T? value);
/// <summary>
/// Checks whether the item has a specific flag.
@@ -124,7 +126,8 @@ public class ItemImpl : IItem
{
/// <inheritdoc cref="ItemImpl"/>
public ItemImpl(StringKey name, ItemCategory category, BattleItemCategory battleCategory, int price,
IEnumerable<StringKey> flags, ISecondaryEffect? effect, ISecondaryEffect? battleTriggerEffect, byte flingPower)
IEnumerable<StringKey> flags, ISecondaryEffect? effect, ISecondaryEffect? battleTriggerEffect,
Dictionary<StringKey, object?> additionalData)
{
Name = name;
Category = category;
@@ -132,7 +135,7 @@ public class ItemImpl : IItem
Price = price;
Effect = effect;
BattleEffect = battleTriggerEffect;
FlingPower = flingPower;
AdditionalData = additionalData;
Flags = [..flags];
}
@@ -158,7 +161,35 @@ public class ItemImpl : IItem
public ISecondaryEffect? BattleEffect { get; }
/// <inheritdoc />
public byte FlingPower { get; }
public IReadOnlyDictionary<StringKey, object?> AdditionalData { get; }
/// <inheritdoc />
public bool TryGetAdditionalData<T>(StringKey key, out T? value)
{
if (AdditionalData.TryGetValue(key, out var obj))
{
switch (obj)
{
case T t:
value = t;
return true;
case IConvertible convertible:
try
{
value = (T)convertible.ToType(typeof(T), null);
return true;
}
catch (InvalidCastException)
{
// Ignore
}
break;
}
}
value = default;
return false;
}
/// <inheritdoc />
public bool HasFlag(string key) => Flags.Contains(key);