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.

81 lines
2.1 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("Base Settings")]
  13. [Tooltip("Wait until this block is resolved before moving to next")]
  14. public bool WaitUntilFinished = false;
  15. [SerializeField]
  16. [Tooltip("Amount of times to run this Block before moving to next")]
  17. protected int RepeatAmount = 1;
  18. #endregion Inspector Fields
  19. #region private variables
  20. /// <summary>
  21. /// Amount of times this block has run
  22. /// </summary>
  23. protected int RepeatCount = 0;
  24. #endregion private variables
  25. #region Class Functions
  26. /// <summary>
  27. /// Runs the block
  28. /// </summary>
  29. /// <param name="player">Player which will be affected by the block</param>
  30. /// <returns>returns true if block is finished</returns>
  31. public virtual bool Run(Character player)
  32. {
  33. RepeatCount++;
  34. BlockLogic(player);
  35. return isFinished();
  36. }
  37. /// <summary>
  38. /// Returns the amount of space this logic block takes up
  39. /// </summary>
  40. /// <returns>Int which controlls how much space this takes up</returns>
  41. public virtual int Size()
  42. {
  43. return 1;
  44. }
  45. /// <summary>
  46. /// Where derived callses should implement the logic for their classes
  47. /// </summary>
  48. /// <param name="player">Player which will be affected by the block</param>
  49. /// <returns>returns true if block is finished</returns>
  50. protected abstract void BlockLogic(Character player);
  51. /// <summary>
  52. /// Resets the block to be ready to used again
  53. /// </summary>
  54. public virtual void Reset()
  55. {
  56. RepeatCount = 0;
  57. }
  58. /// <summary>
  59. /// False if this block needs to be run again
  60. /// </summary>
  61. /// <returns>bool false if block needs to be run again</returns>
  62. public virtual bool isFinished()
  63. {
  64. return (RepeatCount == RepeatAmount);
  65. }
  66. #endregion Class Functions
  67. }