using System; using System.Collections; using System.Linq; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using KairoEngine.Core.GameActions; using KairoEngine.Stockpiles; namespace KairoEngine.Stockpile.GameActions { [System.Serializable, HideReferenceObjectPicker] public class StockpileChangeValueGameAction : GameActionBase { #region DefaultVariables public override string name { get => $"Change {stockpileOwner}'s \'{(stockpileName)}\'stockpile by {ammount}/{capacity}"; } public override GameActionsController controller { get => _controller; set { _controller = value; typeName = "StockpileChangeValueGameAction"; } } public override string GetTypeName() => "StockpileChangeValueGameAction"; public override string GetActionName() => "Stockpile Change Value"; #endregion #region ActionVariables [FoldoutGroup("@name")] public string stockpileOwner; [FoldoutGroup("@name")] public string stockpileName; [FoldoutGroup("@name")] public int ammount = 0; [FoldoutGroup("@name")] public int capacity = 0; #endregion #region ActionFunctions public StockpileChangeValueGameAction(GameActionsController controller) : base(controller) { this.controller = controller; className = this.GetType().AssemblyQualifiedName; } #endregion #region Flow public override void Start() { if(string.IsNullOrEmpty(stockpileName)) { Debug.LogError("No StockpileName set in StockpileGameAction"); } else if(StockpileManager.instance != null) { StockpileManager.instance.AddToStockpileCapacity(stockpileOwner, stockpileName, capacity); StockpileManager.instance.AddToStockpileAmmout(stockpileOwner, stockpileName, ammount); } else Debug.LogError("StockpileManager.instance could not be found"); _done = true; _started = true; } public override void Update() { } public override void Restart() { _done = false; _started = false; } #endregion #region utilities private StockpileChangeValueGameAction Duplicate(GameActionsController controller = null) { StockpileChangeValueGameAction action = new StockpileChangeValueGameAction(controller == null ? this.controller : controller); action.controller = controller; return action; } #endregion #region Serialization public static StockpileChangeValueGameAction JSONToStockpileChangeValueGameAction(string data) { return JsonUtility.FromJson(data); } public override void OnBeforeSerialize(GameActionObjectSerializer serializer, int n, int depth) { } public override void OnBeforeDeserialize(GameActionObjectSerializer serializer, int n, int depth) { } #endregion } }