Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
undergroundtrigger.c
Go to the documentation of this file.
1 class UndergroundTriggerCarrier extends UndergroundTriggerCarrierBase
4 {
6  UndergroundTrigger m_Trigger;
7 
8  void UndergroundTriggerCarrier()
9  {
10  RegisterNetSyncVariableInt("m_TriggerIndex", -1, 255);
11  }
12 
13  void ~UndergroundTriggerCarrier()
14  {
15  if (m_Trigger && !m_Trigger.IsSetForDeletion() && GetGame())
16  {
17  //RemoveChild(m_Trigger);
18  m_Trigger.Delete();
19  }
20  }
21 
22  override void OnVariablesSynchronized()
23  {
24  super.OnVariablesSynchronized();
25  if (!m_Trigger)
26  {
27  SpawnTrigger();
28  }
29  }
30 
31  bool CanSpawnTrigger()
32  {
33  return UndergroundAreaLoader.m_JsonData && m_TriggerIndex != -1;
34  }
35 
36  void RequestDelayedTriggerSpawn()
37  {
38  //Print("RequestDelayedTriggerSpawn() " + this);
39  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(SpawnTrigger, 100);
40  }
41 
42  void SpawnTrigger()
43  {
44 
45  if (!CanSpawnTrigger())
46  {
47  RequestDelayedTriggerSpawn();
48  return;
49  }
50 
51  if (UndergroundAreaLoader.m_JsonData.Triggers && UndergroundAreaLoader.m_JsonData.Triggers.IsValidIndex(m_TriggerIndex))
52  {
53  JsonUndergroundAreaTriggerData data = UndergroundAreaLoader.m_JsonData.Triggers[m_TriggerIndex];
54  UndergroundTrigger trigger = UndergroundTrigger.Cast(GetGame().CreateObjectEx( "UndergroundTrigger", GetPosition(), ECE_LOCAL ));
55  if (trigger)
56  {
57  #ifdef DIAG_DEVELOPER
58  trigger.m_Local = true;
59  #endif
60  trigger.SetPosition(vector.Zero);
61  AddChild(trigger,-1);
62  trigger.Init(data);
63 
64  m_Trigger = trigger;
65  }
66  }
67  }
68 
69 }
70 
71 enum EUndergroundTriggerType
72 {
73  UNDEFINED,
75  OUTER,
76  INNER
77 }
78 
79 class UndergroundTrigger : ManTrigger
80 {
82 
83  EUndergroundTriggerType m_Type;
86 
88  {
89  m_Data = data;
90  //Print("Spawning trigger " + this + "at pos: " + GetPosition());
91  vector extMax = data.GetSize() * 0.5;
92  vector extMin = -extMax;
93  SetExtents(extMin, extMax);
94  m_Accommodation = data.EyeAccommodation;
95  m_InterpolationSpeed = data.InterpolationSpeed;
96 
97  if (data.Breadcrumbs && data.Breadcrumbs.Count() > 0) //TODO: simpler check
98  {
99  if (data.Breadcrumbs.Count() > 32)
100  {
101  ErrorEx("max 'Breadcrumb' count is 32, found: " + data.Breadcrumbs.Count());
102  }
103  m_Type = EUndergroundTriggerType.TRANSITIONING;
104  }
105  else
106  {
107  if (m_Accommodation == 1)
108  {
109  m_Type = EUndergroundTriggerType.OUTER;
110  }
111  else
112  {
113  m_Type = EUndergroundTriggerType.INNER;
114  }
115  }
116  }
117 
118  override protected bool CanAddObjectAsInsider(Object object)
119  {
120  if (!super.CanAddObjectAsInsider(object))
121  {
122  return false;
123  }
124 
125  PlayerBase player = PlayerBase.Cast(object);
126  return player.IsControlledPlayer();
127  }
128 
129 
130  override void EOnInit(IEntity other, int extra)
131  {
132  //disable parent behaviour
133  }
134 
135 
136 
137 
138  #ifdef DEVELOPER
139  override protected void OnEnterServerEvent(TriggerInsider insider)
140  {
141  #ifndef SERVER//to make it work in single during development
142  OnEnterClientEvent(insider);
143  #endif
144  }
145  override protected void OnLeaveServerEvent(TriggerInsider insider)
146  {
147  #ifndef SERVER//to make it work in single during development
148  OnLeaveClientEvent(insider);
149  #endif
150  }
151  #endif
152 
153  override protected void OnEnterClientEvent(TriggerInsider insider)
154  {
155  //Print("OnEnterClientEvent " + this);
156  //return;
157  PlayerBase player = PlayerBase.Cast(insider.GetObject());
158  if (player)
159  {
160  UndergroundHandlerClient handler = player.GetUndergroundHandler();
161  if (handler)
162  {
163  handler.OnTriggerEnter(this);
164  }
165  }
166  }
167 
168  override protected void OnLeaveClientEvent(TriggerInsider insider)
169  {
170  //Print("OnLeaveClientEvent " + this);
171  //return;
172  PlayerBase player = PlayerBase.Cast(insider.GetObject());
173  if (player)
174  {
175  UndergroundHandlerClient handler = player.GetUndergroundHandler();
176  if (handler)
177  {
178  handler.OnTriggerLeave(this);
179  }
180  }
181  }
182 
183 };
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
TriggerInsider
The object which is in a trigger and its metadata.
Definition: trigger.c:2
OnEnterServerEvent
class TriggerInsider OnEnterServerEvent
Definition: traptrigger.c:29
UndergroundHandlerClient
void UndergroundHandlerClient(PlayerBase player)
Definition: undergroundhandlerclient.c:35
SetExtents
void SetExtents(vector mins, vector maxs)
Definition: areadamagemanager.c:233
JsonUndergroundAreaTriggerData
Definition: undergroundarealoader.c:20
m_Accommodation
float m_Accommodation
Definition: undergroundtrigger.c:84
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: anniversarymusicsource.c:42
TRANSITIONING
class UndergroundTriggerCarrier extends UndergroundTriggerCarrierBase TRANSITIONING
OUTER
class UndergroundTriggerCarrier extends UndergroundTriggerCarrierBase OUTER
ErrorEx
enum ShapeType ErrorEx
IEntity
Definition: enentity.c:164
OnEnterClientEvent
override protected void OnEnterClientEvent(TriggerInsider insider)
Definition: undergroundtrigger.c:153
m_Data
class UndergroundTriggerCarrier extends UndergroundTriggerCarrierBase m_Data
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
m_InterpolationSpeed
float m_InterpolationSpeed
Definition: undergroundtrigger.c:85
OnLeaveClientEvent
override protected void OnLeaveClientEvent(TriggerInsider insider)
Definition: undergroundtrigger.c:168
CanAddObjectAsInsider
override protected bool CanAddObjectAsInsider(Object object)
Definition: undergroundtrigger.c:118
ManTrigger
Trigger only accepting Object which IsMan()
Definition: mantrigger.c:2
UndergroundAreaLoader
Definition: undergroundarealoader.c:47
Object
Definition: objecttyped.c:1
m_Type
EUndergroundTriggerType m_Type
Definition: undergroundtrigger.c:83
UndergroundTriggerCarrierBase
Definition: undergroundtrigger.c:3
AddChild
proto native void AddChild(Widget child, bool immedUpdate=true)
OnLeaveServerEvent
override void OnLeaveServerEvent(TriggerInsider insider)
Definition: areadamagemanager.c:179
ECE_LOCAL
const int ECE_LOCAL
Definition: centraleconomy.c:24
Init
void Init(JsonUndergroundAreaTriggerData data)
Definition: undergroundtrigger.c:87
UNDEFINED
class UndergroundTriggerCarrier extends UndergroundTriggerCarrierBase UNDEFINED
EOnInit
override void EOnInit(IEntity other, int extra)
Definition: undergroundtrigger.c:130