File size: 4,887 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
enum eModifiersTickType//bitmask
{
	TICK 					= 1,
	ACTIVATE_CHECK 			= 2,
	DEACTIVATE_CHECK 		= 4,
}


class ModifierBase
{
	int					m_ID = 0;
	ModifiersManager 	m_Manager;//the manager instance
	string 				m_System = "Modifiers";
	float 				m_ActivatedTime;//overall time this modifier was active
	bool				m_TrackActivatedTime;//should this modifier track overall time it was active ?
	bool				m_IsPersistent;//is this modifier saved to the DB ?
	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);//some modifiers do not need to check activate condition, as they get activated by request 
	float				m_LastTickedInactive;
	bool				m_IsLocked = false;
	EActivationType		m_ActivationType;
	eModifierSyncIDs	m_SyncID;//max 32 synced modifiers supported, 0 == no sync
	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//if(m_TickType & eModifiersTickType.TICK)
				{
					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;
	}

	//! is called when an inactive modifier gets activated during gameplay, is NOT called on activation upon player server connection(see OnReconnect)
	void OnActivate(PlayerBase player)
	{

	}
	
	//! is called when a modifier is being re-activated upon player server connection, use to activate systems which are not persistent and need to run alongside active modifiers
	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)
	{
		
	}
}