StockpileChangeValueGameAction.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using Sirenix.OdinInspector;
  7. using KairoEngine.Core.GameActions;
  8. using KairoEngine.Stockpiles;
  9. namespace KairoEngine.Stockpile.GameActions
  10. {
  11. [System.Serializable, HideReferenceObjectPicker]
  12. public class StockpileChangeValueGameAction : GameActionBase
  13. {
  14. #region DefaultVariables
  15. public override string name { get => $"Change {stockpileOwner}'s \'{(stockpileName)}\'stockpile by {ammount}/{capacity}"; }
  16. public override GameActionsController controller {
  17. get => _controller;
  18. set
  19. {
  20. _controller = value;
  21. typeName = "StockpileChangeValueGameAction";
  22. }
  23. }
  24. public override string GetTypeName() => "StockpileChangeValueGameAction";
  25. public override string GetActionName() => "Stockpile Change Value";
  26. #endregion
  27. #region ActionVariables
  28. [FoldoutGroup("@name")] public string stockpileOwner;
  29. [FoldoutGroup("@name")] public string stockpileName;
  30. [FoldoutGroup("@name")] public int ammount = 0;
  31. [FoldoutGroup("@name")] public int capacity = 0;
  32. #endregion
  33. #region ActionFunctions
  34. public StockpileChangeValueGameAction(GameActionsController controller) : base(controller)
  35. {
  36. this.controller = controller;
  37. className = this.GetType().AssemblyQualifiedName;
  38. }
  39. #endregion
  40. #region Flow
  41. public override void Start()
  42. {
  43. if(string.IsNullOrEmpty(stockpileName))
  44. {
  45. Debug.LogError("No StockpileName set in StockpileGameAction");
  46. }
  47. else if(StockpileManager.instance != null)
  48. {
  49. StockpileManager.instance.AddToStockpileCapacity(stockpileOwner, stockpileName, capacity);
  50. StockpileManager.instance.AddToStockpileAmmout(stockpileOwner, stockpileName, ammount);
  51. }
  52. else Debug.LogError("StockpileManager.instance could not be found");
  53. _done = true;
  54. _started = true;
  55. }
  56. public override void Update() { }
  57. public override void Restart()
  58. {
  59. _done = false;
  60. _started = false;
  61. }
  62. #endregion
  63. #region utilities
  64. private StockpileChangeValueGameAction Duplicate(GameActionsController controller = null)
  65. {
  66. StockpileChangeValueGameAction action = new StockpileChangeValueGameAction(controller == null ? this.controller : controller);
  67. action.controller = controller;
  68. return action;
  69. }
  70. #endregion
  71. #region Serialization
  72. public static StockpileChangeValueGameAction JSONToStockpileChangeValueGameAction(string data)
  73. {
  74. return JsonUtility.FromJson<StockpileChangeValueGameAction>(data);
  75. }
  76. public override void OnBeforeSerialize(GameActionObjectSerializer serializer, int n, int depth) { }
  77. public override void OnBeforeDeserialize(GameActionObjectSerializer serializer, int n, int depth) { }
  78. #endregion
  79. }
  80. }