You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.5 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Base class all logic blocks are derived from
  6. /// </summary>
  7. [System.Serializable]
  8. public abstract class LogicBlock : ScriptableObject
  9. {
  10. #region Inspector Fields
  11. [SerializeField]
  12. [Header("UI Settings")]
  13. [Tooltip("Color which will identify this element")]
  14. public Color Color;
  15. [SerializeField]
  16. [Tooltip("Name which will appear in the UI")]
  17. protected string _DisplayName;
  18. [SerializeField]
  19. [Header("Base Settings")]
  20. [Tooltip("Wait until this block is resolved before moving to next")]
  21. public bool WaitUntilFinished = false;
  22. [SerializeField]
  23. [Tooltip("Amount of times to run this Block before moving to next")]
  24. protected int RepeatAmount = 1;
  25. #endregion Inspector Fields
  26. #region ReadOnly Variables
  27. public string DisplayName { get {return (string.IsNullOrEmpty(_DisplayName)) ? name : _DisplayName; } }
  28. #endregion
  29. #region private variables
  30. /// <summary>
  31. /// Amount of times this block has run
  32. /// </summary>
  33. protected int RepeatCount = 0;
  34. #endregion private variables
  35. #region Class Functions
  36. /// <summary>
  37. /// Runs the block
  38. /// </summary>
  39. /// <param name="player">Player which will be affected by the block</param>
  40. /// <returns>returns true if block is finished</returns>
  41. public virtual bool Run(Character player)
  42. {
  43. RepeatCount++;
  44. BlockLogic(player);
  45. return isFinished();
  46. }
  47. /// <summary>
  48. /// Returns the amount of space this logic block takes up
  49. /// </summary>
  50. /// <returns>Int which controlls how much space this takes up</returns>
  51. public virtual int Size()
  52. {
  53. return 1;
  54. }
  55. /// <summary>
  56. /// Where derived callses should implement the logic for their classes
  57. /// </summary>
  58. /// <param name="player">Player which will be affected by the block</param>
  59. /// <returns>returns true if block is finished</returns>
  60. protected abstract void BlockLogic(Character player);
  61. /// <summary>
  62. /// Resets the block to be ready to used again
  63. /// </summary>
  64. public virtual void Reset()
  65. {
  66. RepeatCount = 0;
  67. }
  68. /// <summary>
  69. /// False if this block needs to be run again
  70. /// </summary>
  71. /// <returns>bool false if block needs to be run again</returns>
  72. public virtual bool isFinished()
  73. {
  74. return (RepeatCount == RepeatAmount);
  75. }
  76. #endregion Class Functions
  77. }