DayZ 1.24
Loading...
Searching...
No Matches
TriggerEffectManager.c
Go to the documentation of this file.
1// Used for Effect based triggers ( such as Contaminated areas )
2// Allows us to unify these triggers and treat Enter / Exit events as if all triggers were one
4{
6
7 // Player map will only be handled client side as it is most relevant
8 ref map<string, ref map<PlayerBase, int>> m_PlayerInsiderMap; // Used to keep track of which players are in which effects
9
14
15 static void DestroyInstance()
16 {
17 m_This = null;
18 }
19
20 // This is a SINGLETON so, if we can't get the instance, we create it
22 {
23 if (!m_This)
25
26 return m_This;
27 }
28
30 {
31 if (!m_PlayerInsiderMap.Contains(effectTrigger.GetType()))
32 {
35
36 //Debug.Log( "We have : " + m_PlayerInsiderMap.Count() + " triggers");
37 }
38 }
39
40 // When a player enters a trigger using this class, we add player to map or increase its trigger count
42 {
43 string trigger_type = trigger.GetType();
44
47 {
48 if (playerMap)
49 {
50 if (playerMap.Contains(player))
51 {
52 int newTriggerCount = playerMap.Get(player) + 1;
54 //Debug.Log("We increase the amount of triggers a player is in");
55 }
56 else
57 {
58 // First time this player enters this type of trigger, we set the trigger count to 1
59 playerMap.Insert(player, 1);
60 if (trigger.GetEffectArea())
61 trigger.GetEffectArea().OnPlayerEnterServer(player, trigger);
62 //Debug.Log("We insert a player");
63 }
64
65 //m_PlayerInsiderMap.Set( trigger_type, playerMap );
66 }
67 else
68 {
69 // We didn't have the map yet, we create it and register this player in it
71 playerMap.Insert(player, 1);
72 if (trigger.GetEffectArea())
73 trigger.GetEffectArea().OnPlayerEnterServer(player, trigger);
75 }
76 }
77 }
78
81
82 // Same as OnPlayerEnter, but we decrease trigger count on each trigger leave and remove player from map when count is 0
84 {
85 string trigger_type = trigger.GetType();
86
89 {
90 if (playerMap.Contains(player))
91 {
92 if (playerMap.Get(player) > 1)
93 {
94 //Debug.Log("We reduced the amount of triggers the player is in");
95 playerMap.Set(player, playerMap.Get(player) - 1);
96 }
97 else
98 {
99 // The player left the last trigger of this type they were in
100 playerMap.Remove(player);
101 if (trigger.GetEffectArea())
102 trigger.GetEffectArea().OnPlayerExitServer(player, trigger);
103 player.RemoveCurrentEffectTrigger();
104 //Debug.Log("We removed this player from this trigger type");
105 }
106 }
107 //m_PlayerInsiderMap.Set( trigger_type, playerMap );
108
109 }
110 }
111
113 {
115 if (m_PlayerInsiderMap.Find(trigger.GetType(), playerMap))
116 return playerMap != null && playerMap.Contains(player);
117 return false;
118 }
119}
void RegisterTriggerType(EffectTrigger effectTrigger)
ref map< string, ref map< PlayerBase, int > > m_PlayerInsiderMap
bool IsPlayerInTriggerType(notnull PlayerBase player, notnull EffectTrigger trigger)
void OnPlayerExit(notnull PlayerBase player, notnull EffectTrigger trigger)
void OnPlayerInsideEffectAreaExit(PlayerBase player)
static ref TriggerEffectManager m_This
static TriggerEffectManager GetInstance()
void OnPlayerEnter(notnull PlayerBase player, notnull EffectTrigger trigger)
void OnPlayerInsideEffectAreaEnter(PlayerBase player)