Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
areaexposure.c
Go to the documentation of this file.
2 {
3  const int EVENT_1_INTERVAL_MIN = 3;
4  const int EVENT_1_INTERVAL_MAX = 5;
5 
6  const float AGENTS_PER_SEC = 5;
7  protected float m_NextEvent1;
8  protected float m_Time1;
9 
10  const int EVENT_2_INTERVAL_MIN = 13;
11  const int EVENT_2_INTERVAL_MAX = 18;
12 
13 
14  const float AGENT_DOSE_PER_BS_SEC = 0.33;//how many agents will be injected in one sec per a single bleeding source
15 
16  protected float m_NextEvent2;
17  protected float m_Time2;
18 
19 
20 
21  override void Init()
22  {
23  m_TrackActivatedTime = false;
24  m_ID = eModifiers.MDF_AREAEXPOSURE;
27  m_SyncID = eModifierSyncIDs.MODIFIER_SYNC_ZONE_EXPOSURE;
30 
31  }
32 
33  override bool ActivateCondition(PlayerBase player)
34  {
35  return false;
36  }
37 
38  override void OnActivate(PlayerBase player)
39  {
40 
42  if (data)
43  {
44  MiscGameplayFunctions.TeleportCheck(player, data.SafePositions);
45  }
46 
47  //make the player cough immediately
48  float transmitted = TransmitAgents(player, 1);
49  if(transmitted)
50  player.GetSymptomManager().QueueUpPrimarySymptom(SymptomIDs.SYMPTOM_COUGH);
51 
52  m_NextEvent1 = Math.RandomFloatInclusive( EVENT_1_INTERVAL_MIN, EVENT_1_INTERVAL_MAX );
53  }
54 
55  override void OnDeactivate(PlayerBase player)
56  {
57  }
58 
59  override bool DeactivateCondition(PlayerBase player)
60  {
61  return false;
62  }
63 
64  override void OnTick(PlayerBase player, float deltaT)
65  {
66  #ifdef DEVELOPER
67  if(!player.GetCanBeDestroyed())
68  return;
69  #endif
70 
71  float transmitted = TransmitAgents(player, AGENTS_PER_SEC * deltaT);
72 
73  m_Time2 += deltaT;
74 
75  if (transmitted)
76  {
77  m_Time1 += deltaT;
78  if (m_Time1 >= m_NextEvent1 )
79  {
80  player.GetSymptomManager().QueueUpPrimarySymptom(SymptomIDs.SYMPTOM_COUGH);
81 
82  if(Math.RandomFloat01() < 0.25)//creates a cough cooldown once in a while
83  {
84  m_NextEvent1 = Math.RandomFloatInclusive( EVENT_1_INTERVAL_MIN * 2, EVENT_1_INTERVAL_MAX * 2 );
85  }
86  else
87  {
88  m_NextEvent1 = Math.RandomFloatInclusive( EVENT_1_INTERVAL_MIN, EVENT_1_INTERVAL_MAX );
89  }
90 
91  m_Time1 = 0;
92  }
93  }
94 
95  if ( m_Time2 >= m_NextEvent2 )
96  {
97  BleedingSourceCreateCheck(player);
98  m_Time2 = 0;
99  m_NextEvent2 = Math.RandomFloatInclusive( EVENT_2_INTERVAL_MIN, EVENT_2_INTERVAL_MAX );
100  }
101 
102  ApplyAgentsToBleedingSources(player, deltaT);
103 
104  }
105 
106  void ApplyAgentsToBleedingSources(PlayerBase player, float deltaT)
107  {
108 
109  int count = player.GetBleedingSourceCount();
110  float agent_dose = count * AGENT_DOSE_PER_BS_SEC * deltaT;
111  player.InsertAgent(eAgents.CHEMICAL_POISON, agent_dose);
112 
113  }
114 
115  void BleedingSourceCreateCheck(PlayerBase player)
116  {
117  int free_bs_locations = 0;//bitmask where each bit set to 1 represents available bleeding source location
118  set<int> list = player.GetBleedingManagerServer().GetBleedingSourcesLocations();
119 
120  foreach(int location: list)
121  {
122  float prot_level = PluginTransmissionAgents.GetProtectionLevelEx(DEF_CHEMICAL, location, player, true);
123  float dice_throw = Math.RandomFloat01();
124  if(dice_throw > prot_level)
125  {
126  free_bs_locations = player.GetBleedingManagerServer().GetFreeBleedingSourceBitsByInvLocation(location) | free_bs_locations;
127  }
128  }
129 
130  int num_of_free_bs = Math.GetNumberOfSetBits(free_bs_locations);//gets us the number of bits set to 1, where each represents a free bleeding source location
131 
132  if ( num_of_free_bs > 0 )
133  {
134  int random_bs_index = Math.RandomIntInclusive(0, num_of_free_bs - 1 );// - 1 on the max to convert count to index
135  int random_bs_bit = Math.Pow(2, Math.GetNthBitSet(free_bs_locations,random_bs_index));
136  player.GetBleedingManagerServer().AttemptAddBleedingSourceDirectly(random_bs_bit, eBleedingSourceType.CONTAMINATED);
137  }
138  }
139 
140  float TransmitAgents(PlayerBase player, float count)
141  {
142  PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
143  return plugin.TransmitAgentsEx(null, player, AGT_AIRBOURNE_CHEMICAL, count, eAgents.CHEMICAL_POISON);
144  }
145 
146 
147 };
JsonDataContaminatedAreas
Definition: jsondatacontaminatedarea.c:2
m_SyncID
eModifierSyncIDs m_SyncID
Definition: modifierbase.c:29
m_TickIntervalActive
float m_TickIntervalActive
Definition: modifierbase.c:19
eBleedingSourceType
eBleedingSourceType
Definition: bleedingsource.c:1
m_TrackActivatedTime
bool m_TrackActivatedTime
Definition: modifierbase.c:15
DEFAULT_TICK_TIME_INACTIVE_LONG
const int DEFAULT_TICK_TIME_INACTIVE_LONG
Definition: modifiersmanager.c:34
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
DisableDeactivateCheck
void DisableDeactivateCheck()
Definition: modifierbase.c:83
EffectAreaLoader
Definition: contaminatedarealoader.c:2
AGT_AIRBOURNE_CHEMICAL
const int AGT_AIRBOURNE_CHEMICAL
Definition: constants.c:476
PlayerBase
Definition: playerbaseclient.c:1
eAgents
eAgents
Definition: eagents.c:2
AreaExposureMdfr
Definition: areaexposure.c:1
DEFAULT_TICK_TIME_ACTIVE_SHORT
const int DEFAULT_TICK_TIME_ACTIVE_SHORT
Definition: modifiersmanager.c:32
m_TickIntervalInactive
float m_TickIntervalInactive
Definition: modifierbase.c:18
eModifiers
eModifiers
Definition: emodifiers.c:1
ModifierBase
Definition: breathvapourmdfr.c:3
eModifierSyncIDs
eModifierSyncIDs
Definition: modifiersmanager.c:2
DisableActivateCheck
void DisableActivateCheck()
Definition: modifierbase.c:78
DEF_CHEMICAL
const int DEF_CHEMICAL
Definition: constants.c:479
Math
Definition: enmath.c:6
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49