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.

90 lines
2.3 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. public 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 private variables
  27. /// <summary>
  28. /// Amount of times this block has run
  29. /// </summary>
  30. protected int RepeatCount = 0;
  31. #endregion private variables
  32. #region Class Functions
  33. /// <summary>
  34. /// Runs the block
  35. /// </summary>
  36. /// <param name="player">Player which will be affected by the block</param>
  37. /// <returns>returns true if block is finished</returns>
  38. public virtual bool Run(Character player)
  39. {
  40. RepeatCount++;
  41. BlockLogic(player);
  42. return isFinished();
  43. }
  44. /// <summary>
  45. /// Returns the amount of space this logic block takes up
  46. /// </summary>
  47. /// <returns>Int which controlls how much space this takes up</returns>
  48. public virtual int Size()
  49. {
  50. return 1;
  51. }
  52. /// <summary>
  53. /// Where derived callses should implement the logic for their classes
  54. /// </summary>
  55. /// <param name="player">Player which will be affected by the block</param>
  56. /// <returns>returns true if block is finished</returns>
  57. protected abstract void BlockLogic(Character player);
  58. /// <summary>
  59. /// Resets the block to be ready to used again
  60. /// </summary>
  61. public virtual void Reset()
  62. {
  63. RepeatCount = 0;
  64. }
  65. /// <summary>
  66. /// False if this block needs to be run again
  67. /// </summary>
  68. /// <returns>bool false if block needs to be run again</returns>
  69. public virtual bool isFinished()
  70. {
  71. return (RepeatCount == RepeatAmount);
  72. }
  73. #endregion Class Functions
  74. }