LAFCS4AAOMBOBURWXRZEDUI4J5QGBP7CJQXIPLKXEDXNBCVE7SLQC
FNS4LRFQNFM4BCB23CYHOWA2N4MG2DEUMNK6D55BQ26TX6OJLIBQC
I33Z5QD6JHPO7W7G3EHGBIXQABW6ZOC2W4NJP6L5ENDPFRORUFNAC
HUULCHM5GFGZ7GKLCULFHC333LQ3LBI62VKII3YL5O4C5CDGCT4AC
IDXWT3DH3C3X7PP4VVKUZTCGDALW6NH7KREI4E2VFQVMCBJKDMTAC
YI7M5RWLKUG256YXK6CGZKUPDCNHREU2PGV344L2IV24FF5PHG3AC
FQZF2IY4T2F7KEVSHMFID35WNAU55CRRDF6XEXZB7PYZH26UGYPQC
CD5FF75KTOBTMVMTMCKMR6F5DFKOF26I5K43ITNHGBI3ZAZHA4RAC
HXTSBPAP75A7EC4RKWYQMVPPHPNZFPHUORBZWDHGEB6MPAGI7G7AC
fileFormatVersion: 2
guid: 7bb214e6518a2aa4cae0c5a2d997643e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace TagFighter.Resources
{
public interface IStatModifier<TUnitType> where TUnitType : IUnitType
{
public Unit<TUnitType> Amount { get; set; }
}
public class PermanentStatModifier<TUnitType> : IStatModifier<TUnitType> where TUnitType : IUnitType
{
public Unit<TUnitType> Amount { get; set; }
}
public class TransientStatModifier<TUnitType> : IStatModifier<TUnitType> where TUnitType : IUnitType
{
public double ExpiryTime;
public TransientStatModifier(double expiryTime) {
ExpiryTime = expiryTime;
}
public Unit<TUnitType> Amount { get; set; }
}
public interface IStat { }
[Serializable]
public class Stat<TUnitType> : IStat where TUnitType : IUnitType
{
[SerializeField] Unit<TUnitType> _base;
List<TransientStatModifier<TUnitType>> _modifiers = new();
HashSet<double> Expiry = new();
public Unit<TUnitType> Base {
get {
return _base;
}
private set {
_base = value;
}
}
public Unit<TUnitType> Modified => _modifiers.Aggregate((Unit<TUnitType>)0, (acc, modifier) => acc + modifier.Amount);
public Unit<TUnitType> Value => Base + Modified;
/// <Summary>
/// Adds a new permanent modifier to the stat. Taken into account in <paramref name="Base"/> property.
/// </Summary>
public void AddPermanentModifier(PermanentStatModifier<TUnitType> modifier) {
Base += modifier.Amount;
}
/// <Summary>
/// Adds a new transient modifier to the stat. Taken into account in <paramref name="Modified"/> and <paramref name="Value"/> properties.
/// </Summary>
/// <returns>
/// True when a transient modifier with a new expiry time is inserted.
/// False when a transient modifier with the same expiry time is already present.
/// </returns>
public bool AddTransientModifier(TransientStatModifier<TUnitType> modifier) {
_modifiers.Add(modifier);
return Expiry.Add(modifier.ExpiryTime);
}
public void Retire(double expiryTime) {
_modifiers = _modifiers.Where(modifier => modifier.ExpiryTime > expiryTime).ToList();
Expiry.Remove(expiryTime);
}
}
}
fileFormatVersion: 2
guid: 7bb214e6518a2aa4cae0c5a2d997643e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace TagFighter.Resources
{
public interface IStatModifier<TUnitType> where TUnitType : IUnitType
{
public Unit<TUnitType> Amount { get; set; }
}
public class PermanentStatModifier<TUnitType> : IStatModifier<TUnitType> where TUnitType : IUnitType
{
public Unit<TUnitType> Amount { get; set; }
}
public class TransientStatModifier<TUnitType> : IStatModifier<TUnitType> where TUnitType : IUnitType
{
public double ExpiryTime;
public TransientStatModifier(double expiryTime) {
ExpiryTime = expiryTime;
}
public Unit<TUnitType> Amount { get; set; }
}
}
var stat = _capacity;
if (stat.AddTransientModifier(modifier)) {
StartCoroutine(ExpireModifiers(modifier.ExpiryTime, stat, OnCapacityChanged));
}
Debug.Log($"{nameof(AddTransientCapacityModifier)}");
OnCapacityChanged?.Invoke(this, (OnChangeArgs)this);
AddTransientModifier(modifier, _capacity);
return new(
(int)resource.GetCurrent(),
(int)resource.GetCapacity(),
0,
0);
return new( (int)resource.GetCurrent(), (int)resource.GetCapacity());
}
public interface IStatType { }
private class Current : IStatType { }
private class Capacity : IStatType { }
[Serializable]
public class Stat<TStatType> where TStatType : IStatType
{
[SerializeField] Unit<TUnitType> _base;
List<TransientStatModifier<TUnitType>> _modifiers = new();
HashSet<double> Expiry = new();
public Unit<TUnitType> Base {
get {
return _base;
}
private set {
_base = value;
}
}
public Unit<TUnitType> Modified => _modifiers.Aggregate((Unit<TUnitType>)0, (acc, modifier) => acc + modifier.Amount);
public Unit<TUnitType> Value => Base + Modified;
/// <Summary>
/// Adds a new permanent modifier to the stat. Taken into account in <paramref name="Base"/> property.
/// </Summary>
public void AddPermanentModifier(PermanentStatModifier<TUnitType> modifier) {
Base += modifier.Amount;
}
/// <Summary>
/// Adds a new transient modifier to the stat. Taken into account in <paramref name="Modified"/> and <paramref name="Value"/> properties.
/// </Summary>
/// <returns>
/// True when a transient modifier with a new expiry time is inserted.
/// False when a transient modifier with the same expiry time is already present.
/// </returns>
public bool AddTransientModifier(TransientStatModifier<TUnitType> modifier) {
_modifiers.Add(modifier);
return Expiry.Add(modifier.ExpiryTime);
}
public void Retire(double expiryTime) {
_modifiers = _modifiers.Where(modifier => modifier.ExpiryTime > expiryTime).ToList();
Expiry.Remove(expiryTime);
}