| enum eModifiersTickType//bitmask |
| { |
| TICK = 1, |
| ACTIVATE_CHECK = 2, |
| DEACTIVATE_CHECK = 4, |
| } |
|
|
|
|
| class ModifierBase |
| { |
| int m_ID = 0; |
| ModifiersManager m_Manager; |
| string m_System = "Modifiers"; |
| float m_ActivatedTime; |
| bool m_TrackActivatedTime; |
| bool m_IsPersistent; |
| PlayerBase m_Player; |
| float m_TickIntervalInactive = 5; |
| float m_TickIntervalActive = 3; |
| bool m_IsActive; |
| bool m_ShouldBeActive; |
| float m_AccumulatedTimeActive; |
| float m_AccumulatedTimeInactive; |
| float m_LastTickedActive; |
| int m_TickType = (eModifiersTickType.TICK | eModifiersTickType.ACTIVATE_CHECK | eModifiersTickType.DEACTIVATE_CHECK); |
| float m_LastTickedInactive; |
| bool m_IsLocked = false; |
| EActivationType m_ActivationType; |
| eModifierSyncIDs m_SyncID; |
| PluginPlayerStatus m_ModulePlayerStatus; |
|
|
| void ModifierBase() |
| { |
| Class.CastTo(m_ModulePlayerStatus, GetPlugin(PluginPlayerStatus)); |
| } |
| |
| void InitBase(PlayerBase player, ModifiersManager manager) |
| { |
| m_Manager = manager; |
| m_Player = player; |
| Init(); |
| } |
| |
| void Init(){} |
|
|
|
|
| PlayerBase GetPlayer() |
| { |
| return m_Player; |
| } |
| |
| bool IsPersistent() |
| { |
| return m_IsPersistent; |
| } |
|
|
| void MakeParamObjectPersistent(Param object) |
| { |
| m_Manager.m_ParamList.Insert(object); |
| } |
|
|
|
|
| void ResetLastTickTime() |
| { |
| m_LastTickedActive = 0; |
| } |
|
|
| string GetDebugText() |
| { |
| return ""; |
| } |
| |
| string GetDebugTextSimple() |
| { |
| return ""; |
| } |
| |
| void DisableActivateCheck() |
| { |
| m_TickType = (m_TickType & ~eModifiersTickType.ACTIVATE_CHECK); |
| } |
| |
| void DisableDeactivateCheck() |
| { |
| m_TickType = (m_TickType & ~eModifiersTickType.DEACTIVATE_CHECK); |
| } |
|
|
| void Tick(float delta_time) |
| { |
|
|
| if( !m_IsActive && m_ShouldBeActive ) |
| { |
| Activate(); |
| } |
|
|
| if( m_IsActive ) |
| { |
| m_AccumulatedTimeActive += delta_time; |
| if( m_AccumulatedTimeActive > m_TickIntervalActive ) |
| { |
| if( m_TickType & eModifiersTickType.DEACTIVATE_CHECK && DeactivateCondition(m_Player) && !IsLocked() ) |
| { |
| Deactivate(); |
| } |
| else |
| { |
| m_ActivatedTime += m_AccumulatedTimeActive; |
| OnTick(m_Player, m_AccumulatedTimeActive); |
| } |
| m_AccumulatedTimeActive = 0; |
| } |
| } |
| else if(m_TickType & eModifiersTickType.ACTIVATE_CHECK) |
| { |
| m_AccumulatedTimeInactive += delta_time; |
| if( m_AccumulatedTimeInactive > m_TickIntervalInactive ) |
| { |
| if( ActivateCondition(m_Player) ) |
| { |
| if( !IsLocked() ) |
| { |
| ActivateRequest(EActivationType.TRIGGER_EVENT_ON_ACTIVATION); |
| } |
| } |
| m_AccumulatedTimeInactive = 0; |
| } |
| } |
| } |
| |
| bool IsActive() |
| { |
| return m_IsActive; |
| } |
| |
| void SetLock(bool state) |
| { |
| m_IsLocked = state; |
| } |
|
|
| bool IsLocked() |
| { |
| return m_IsLocked; |
| } |
| |
| bool IsTrackAttachedTime() |
| { |
| return m_TrackActivatedTime; |
| } |
| |
| float GetAttachedTime() |
| { |
| return m_ActivatedTime; |
| } |
| |
| void SetAttachedTime(float time) |
| { |
| m_ActivatedTime = time; |
| } |
| |
| int GetModifierID() |
| { |
| return m_ID; |
| } |
| |
| string GetName() |
| { |
| string name = ClassName(); |
| int index_start = name.Length() - 4; |
| int index_end = name.Length(); |
| name = name.SubstringInverted(name, index_start, index_end); |
| return name; |
| } |
|
|
| bool ActivateCondition(PlayerBase player) |
| { |
| return false; |
| } |
|
|
| bool DeactivateCondition(PlayerBase player) |
| { |
| return false; |
| } |
|
|
| |
| void OnActivate(PlayerBase player) |
| { |
|
|
| } |
| |
| |
| void OnReconnect(PlayerBase player) |
| { |
|
|
| } |
|
|
| void OnDeactivate(PlayerBase player) |
| { |
|
|
| } |
| |
| void Activate() |
| { |
| m_IsActive = true; |
| m_Player.m_SyncedModifiers = (m_Player.m_SyncedModifiers | m_SyncID); |
| if( m_ActivationType == EActivationType.TRIGGER_EVENT_ON_ACTIVATION ) OnActivate(m_Player); |
| else if(m_ActivationType == EActivationType.TRIGGER_EVENT_ON_CONNECT ) OnReconnect(m_Player); |
| m_Player.SetSynchDirty(); |
| } |
| |
| void ActivateRequest(EActivationType trigger) |
| { |
| m_ShouldBeActive = true; |
| m_ActivationType = trigger; |
| } |
|
|
| void Deactivate(bool trigger = true) |
| { |
| if(!m_IsActive) |
| return; |
| m_Player.m_SyncedModifiers = (m_Player.m_SyncedModifiers & ~m_SyncID); |
| m_ShouldBeActive = false; |
| m_IsActive = false; |
| m_ActivatedTime = 0; |
| if(trigger) |
| OnDeactivate(m_Player); |
| } |
|
|
|
|
| void OnStoreSave( ParamsWriteContext ctx ) |
| { |
| } |
|
|
|
|
| private void OnTick(PlayerBase player, float deltaT) |
| { |
| |
| } |
| } |
|
|