Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 {
5  static ref TriggerEffectManager m_This;
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 
11  {
12  m_PlayerInsiderMap = new map<string, ref map<PlayerBase, int>>;
13  }
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
21  static TriggerEffectManager GetInstance()
22  {
23  if ( !m_This )
24  m_This = new TriggerEffectManager();
25 
26  return m_This;
27  }
28 
29  void RegisterTriggerType( EffectTrigger effectTrigger )
30  {
31  if ( !m_PlayerInsiderMap.Contains( effectTrigger.GetType() ) )
32  {
34  m_PlayerInsiderMap.Insert( effectTrigger.GetType(), playerMap );
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
41  void OnPlayerEnter( notnull PlayerBase player, notnull EffectTrigger trigger )
42  {
43  string trigger_type = trigger.GetType();
44 
45  map<PlayerBase, int> playerMap;
46  if ( m_PlayerInsiderMap.Find( trigger_type, playerMap) )
47  {
48  if ( playerMap )
49  {
50  if ( playerMap.Contains( player ) )
51  {
52  int newTriggerCount = playerMap.Get( player ) + 1;
53  playerMap.Set( player, newTriggerCount );
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
70  playerMap = new map<PlayerBase, int>;
71  playerMap.Insert( player, 1 );
72  if (trigger.GetEffectArea())
73  trigger.GetEffectArea().OnPlayerEnterServer(player, trigger);
74  m_PlayerInsiderMap.Insert( trigger_type, playerMap );
75  }
76  }
77  }
78 
79  void OnPlayerInsideEffectAreaEnter(PlayerBase player);
80  void OnPlayerInsideEffectAreaExit(PlayerBase player);
81 
82  // Same as OnPlayerEnter, but we decrease trigger count on each trigger leave and remove player from map when count is 0
83  void OnPlayerExit( notnull PlayerBase player, notnull EffectTrigger trigger )
84  {
85  string trigger_type = trigger.GetType();
86 
87  map<PlayerBase, int> playerMap;
88  if ( m_PlayerInsiderMap.Find( trigger_type, playerMap ) && playerMap )
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 
112  bool IsPlayerInTriggerType( notnull PlayerBase player, notnull EffectTrigger trigger )
113  {
114  map<PlayerBase, int> playerMap;
115  if ( m_PlayerInsiderMap.Find( trigger.GetType(), playerMap ) )
116  {
117  return playerMap != null && playerMap.Contains( player );
118  }
119  return false;
120  }
121 }
TriggerEffectManager
Definition: triggereffectmanager.c:3
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
EffectTrigger
Definition: contaminatedtrigger.c:2