Bunch more moves, changes in how additional information for items works.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -33,4 +33,13 @@ public static class EnumerableHelpers
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void RemoveAll<T>(this IList<T> list, Func<T, bool> predicate)
|
||||
{
|
||||
for (var i = list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (predicate(list[i]))
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,10 @@ public static class NumericHelpers
|
||||
var result = (ulong)value * multiplier;
|
||||
return result > uint.MaxValue ? uint.MaxValue : (uint)result;
|
||||
}
|
||||
|
||||
public static uint MultiplyOrMax(this uint value, float multiplier)
|
||||
{
|
||||
var result = value * multiplier;
|
||||
return result > uint.MaxValue ? uint.MaxValue : (uint)result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user