rainprocurementcomponent.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. class RainProcurementComponentBase : Managed
  2. {
  3. protected ItemBase m_ProcuringItem;
  4. protected RainProcurementHandler m_Handler;
  5. protected bool m_IsUnderRoof;
  6. protected bool m_IsActive;
  7. protected int m_UpdateCounter;
  8. protected const int UPDATE_ROOFCHECK_COUNT = 3; //do roofcheck every n updates
  9. void RainProcurementComponentBase(ItemBase procuringItem)
  10. {
  11. m_ProcuringItem = procuringItem;
  12. Reset();
  13. m_Handler = MissionBaseWorld.Cast(GetGame().GetMission()).GetRainProcurementHandler();
  14. }
  15. //! Called on server to queue rain procurement (on next cycle end)
  16. void StartRainProcurement()
  17. {
  18. #ifdef SERVER
  19. Reset();
  20. SetActive(true);
  21. m_Handler.QueueStart(this);
  22. #endif
  23. }
  24. //! Called on server to queue rain procurement removal (on next cycle end)
  25. void StopRainProcurement()
  26. {
  27. #ifdef SERVER
  28. if (IsActive())
  29. {
  30. SetActive(false);
  31. m_Handler.QueueStop(this);
  32. }
  33. #endif
  34. }
  35. void OnUpdate(float deltaTime, float amount)
  36. {
  37. m_UpdateCounter++;
  38. if (m_UpdateCounter == 0 || m_UpdateCounter == UPDATE_ROOFCHECK_COUNT)
  39. {
  40. m_UpdateCounter = 0;
  41. UpdateIsUnderRoof();
  42. }
  43. ProcureLiquid(amount);
  44. }
  45. protected void Reset()
  46. {
  47. m_UpdateCounter = -1;
  48. }
  49. protected void ProcureLiquid(float amountBase, int liquidType = LIQUID_CLEANWATER)
  50. {
  51. if (!m_IsUnderRoof)
  52. {
  53. float actualAmount = amountBase * GetBaseLiquidAmount();
  54. Liquid.FillContainerEnviro(m_ProcuringItem, liquidType, actualAmount);
  55. }
  56. }
  57. protected void UpdateIsUnderRoof()
  58. {
  59. m_IsUnderRoof = MiscGameplayFunctions.IsUnderRoof(m_ProcuringItem);
  60. }
  61. //! override this to get different amount per ProcureLiquid cycle
  62. float GetBaseLiquidAmount()
  63. {
  64. return GameConstants.LIQUID_RAIN_AMOUNT_COEF_BASE;
  65. }
  66. bool IsActive()
  67. {
  68. return m_IsActive;
  69. }
  70. void SetActive(bool run)
  71. {
  72. //resets times on start
  73. if (run)
  74. Reset();
  75. m_IsActive = run;
  76. }
  77. };
  78. class RainProcurementComponentBarrel : RainProcurementComponentBase {};