fireworksbase.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. enum EFireworksState
  2. {
  3. DEFAULT,
  4. PLACED,
  5. IGNITED,
  6. FIRING,
  7. FINISHED
  8. }
  9. class FireworksBase: Inventory_Base
  10. {
  11. protected EFireworksState m_State;
  12. protected EFireworksState m_StatePrev;
  13. protected ref Timer m_TimerEvent;
  14. protected int m_RandomSeed;
  15. void FireworksBase()
  16. {
  17. Init();
  18. }
  19. override void EEOnCECreate()
  20. {
  21. StandUp();
  22. }
  23. protected void Init();
  24. override protected void SetActions()
  25. {
  26. super.SetActions();
  27. AddAction(ActionTogglePlaceObject);
  28. AddAction(ActionDeployObject);
  29. AddAction(ActionLightItemOnFire);
  30. }
  31. override bool HasFlammableMaterial()
  32. {
  33. return true;
  34. }
  35. protected float GetMaxAllowedWetness()
  36. {
  37. return 0.1;
  38. }
  39. protected EFireworksState GetState()
  40. {
  41. return m_State;
  42. }
  43. protected void SetState(EFireworksState state)
  44. {
  45. if (state != m_StatePrev && GetGame().IsServer())
  46. {
  47. m_State = state;
  48. SetSynchDirty();
  49. OnStateChangedServer(state);
  50. m_StatePrev = state;
  51. }
  52. }
  53. protected void OnStateChangedServer(EFireworksState currentState);
  54. protected void OnStateChangedClient(EFireworksState currentState);
  55. override protected void OnInventoryEnter(Man player)
  56. {
  57. if (GetState() == EFireworksState.PLACED)
  58. {
  59. SetState(EFireworksState.DEFAULT);
  60. }
  61. }
  62. override protected void OnInventoryExit(Man player)
  63. {
  64. super.OnInventoryExit(player);
  65. if (!IsBeingPlaced())
  66. StandUp();
  67. }
  68. protected void StandUp()
  69. {
  70. if (!IsRuined())
  71. {
  72. SetOrientation(vector.Zero);
  73. }
  74. }
  75. //! Executed on Server when some item ignited this one
  76. override void OnIgnitedThis( EntityAI fire_source)
  77. {
  78. SetState(EFireworksState.IGNITED);
  79. }
  80. // Checkes if Torch can be ignited
  81. override protected bool CanBeIgnitedBy(EntityAI igniter = NULL)
  82. {
  83. if (GetWet() >= GetMaxAllowedWetness())
  84. {
  85. return false;
  86. }
  87. if (MiscGameplayFunctions.IsUnderRoofEx(this, 60))
  88. {
  89. return false;
  90. }
  91. if ((GetState() <= EFireworksState.PLACED) && vector.Dot(vector.Up,GetDirectionUp()) > 0.95)
  92. {
  93. return true;
  94. }
  95. return false;
  96. }
  97. //!Called periodically after the entity gets ignited
  98. protected void OnEventServer(int type);
  99. protected float GetEventDelay()
  100. {
  101. return 0;
  102. }
  103. override protected void OnVariablesSynchronized()
  104. {
  105. //Print("new state client: " + m_State);
  106. super.OnVariablesSynchronized();
  107. if (m_State != m_StatePrev)
  108. {
  109. OnStateChangedClient(m_State);
  110. m_StatePrev = m_State;
  111. }
  112. }
  113. #ifdef DEVELOPER
  114. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  115. {
  116. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Ignite", FadeColors.LIGHT_GREY));
  117. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
  118. super.GetDebugActions(outputList);
  119. }
  120. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  121. {
  122. if (super.OnAction(action_id, player, ctx))
  123. return true;
  124. if (GetGame().IsServer() || !GetGame().IsMultiplayer())
  125. {
  126. if (action_id == EActions.ACTIVATE_ENTITY)
  127. {
  128. OnIgnitedThis(null);
  129. }
  130. }
  131. return false;
  132. }
  133. #endif
  134. }