123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- enum EFireworksState
- {
- DEFAULT,
- PLACED,
- IGNITED,
- FIRING,
- FINISHED
- }
- class FireworksBase: Inventory_Base
- {
- protected EFireworksState m_State;
- protected EFireworksState m_StatePrev;
- protected ref Timer m_TimerEvent;
- protected int m_RandomSeed;
- void FireworksBase()
- {
- Init();
- }
-
- override void EEOnCECreate()
- {
- StandUp();
- }
-
- protected void Init();
-
-
- override protected void SetActions()
- {
- super.SetActions();
-
- AddAction(ActionTogglePlaceObject);
- AddAction(ActionDeployObject);
- AddAction(ActionLightItemOnFire);
- }
-
- override bool HasFlammableMaterial()
- {
- return true;
- }
-
- protected float GetMaxAllowedWetness()
- {
- return 0.1;
- }
-
- protected EFireworksState GetState()
- {
- return m_State;
- }
-
- protected void SetState(EFireworksState state)
- {
- if (state != m_StatePrev && GetGame().IsServer())
- {
- m_State = state;
- SetSynchDirty();
- OnStateChangedServer(state);
- m_StatePrev = state;
- }
- }
-
- protected void OnStateChangedServer(EFireworksState currentState);
- protected void OnStateChangedClient(EFireworksState currentState);
-
- override protected void OnInventoryEnter(Man player)
- {
- if (GetState() == EFireworksState.PLACED)
- {
- SetState(EFireworksState.DEFAULT);
- }
- }
-
- override protected void OnInventoryExit(Man player)
- {
- super.OnInventoryExit(player);
-
- if (!IsBeingPlaced())
- StandUp();
- }
-
- protected void StandUp()
- {
- if (!IsRuined())
- {
- SetOrientation(vector.Zero);
- }
- }
-
- //! Executed on Server when some item ignited this one
- override void OnIgnitedThis( EntityAI fire_source)
- {
- SetState(EFireworksState.IGNITED);
- }
-
- // Checkes if Torch can be ignited
- override protected bool CanBeIgnitedBy(EntityAI igniter = NULL)
- {
- if (GetWet() >= GetMaxAllowedWetness())
- {
- return false;
- }
-
- if (MiscGameplayFunctions.IsUnderRoofEx(this, 60))
- {
- return false;
- }
-
- if ((GetState() <= EFireworksState.PLACED) && vector.Dot(vector.Up,GetDirectionUp()) > 0.95)
- {
- return true;
- }
- return false;
- }
-
- //!Called periodically after the entity gets ignited
- protected void OnEventServer(int type);
-
- protected float GetEventDelay()
- {
- return 0;
- }
-
- override protected void OnVariablesSynchronized()
- {
- //Print("new state client: " + m_State);
- super.OnVariablesSynchronized();
- if (m_State != m_StatePrev)
- {
- OnStateChangedClient(m_State);
- m_StatePrev = m_State;
- }
- }
-
- #ifdef DEVELOPER
-
- override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
- {
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Ignite", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
-
- super.GetDebugActions(outputList);
- }
-
- override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
- {
- if (super.OnAction(action_id, player, ctx))
- return true;
- if (GetGame().IsServer() || !GetGame().IsMultiplayer())
- {
- if (action_id == EActions.ACTIVATE_ENTITY)
- {
- OnIgnitedThis(null);
- }
-
- }
- return false;
- }
- #endif
- }
|