Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
catchingcontextfishingrodaction.c
Go to the documentation of this file.
2{
4 //chances + modifiers
5 protected float m_BaitLossChanceMod;
6 protected float m_HookLossChanceMod;
7 //times
8 protected float m_SignalDurationMin; //seconds
9 protected float m_SignalDurationMax; //seconds
10 protected float m_SignalStartTimeMin; //seconds
11 protected float m_SignalStartTimeMax; //seconds
12 //signal targets
13 protected float m_SignalCycleTarget;
14 protected float m_SignalCycleEndTarget;
17 //signal targets - constant
20 //misc
21 protected int m_SignalCurrent;
22
23 //important items
24 protected EntityAI m_Hook;
25 protected EntityAI m_Bait;
26 protected EntityAI m_Rod;
27
28 override protected void Init(Param par)
29 {
30 super.Init(par);
31
32 m_Rod = m_MainItem; //only stable one, rest initialized on 'InitItemValues' periodically
33 m_Player = PlayerBase.Cast(m_MainItem.GetHierarchyRootPlayer());
34 }
35
36 override protected void InitCatchMethodMask()
37 {
38 m_MethodMask = AnimalCatchingConstants.MASK_METHOD_ROD;
39 }
40
41 override protected void InitCatchEnviroMask()
42 {
43 if (m_IsSea)
44 m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_SEA;
45 else
46 m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_POND;
47 }
48
49 override protected void CreateResultDataStructure()
50 {
52
53 super.CreateResultDataStructure();
54 }
55
57 override protected void ClearCatchingItemData()
58 {
59 super.ClearCatchingItemData();
60
68 m_SignalCycleTarget = UAFishingConstants.SIGNAL_CYCLE_MEAN_DEFAULT - 1; //lowered by '1', configured value is count
69 m_SignalCycleEndTarget = UAFishingConstants.SIGNAL_CYCLE_HARD_TARGET_DEFAULT - 1; //lowered by '1', configured value is count
70 m_SignalTargetProbability = UAFishingConstants.SIGNAL_MEAN_CHANCE_DEFAULT;
71 m_SignalTargetEndProbability = UAFishingConstants.SIGNAL_HARD_TARGET_CHANCE_DEFAULT;
74 }
75
76 override void InitCatchingItemData()
77 {
78 super.InitCatchingItemData();
79
80 //sanitize fishing values
81 if (m_SignalDurationMin == -1) //if not set by any item
82 m_SignalDurationMin = UAFishingConstants.SIGNAL_DURATION_MIN_BASE;
83 else
84 m_SignalDurationMin = Math.Clamp(m_SignalDurationMin,UAFishingConstants.SIGNAL_DURATION_MIN_BASE,UAFishingConstants.SIGNAL_DURATION_MAX_BASE);
85
86 if (m_SignalDurationMax == -1) //if not set by any item
87 m_SignalDurationMax = UAFishingConstants.SIGNAL_DURATION_MAX_BASE;
88 else
89 m_SignalDurationMax = Math.Clamp(m_SignalDurationMax,UAFishingConstants.SIGNAL_DURATION_MIN_BASE,UAFishingConstants.SIGNAL_DURATION_MAX_BASE);
90
91 if (m_SignalStartTimeMin == -1) //if not set by any item (else already clamped)
92 m_SignalStartTimeMin = UAFishingConstants.SIGNAL_START_TIME_MIN_BASE;
93
94 if (m_SignalStartTimeMax == -1) //if not set by any item (else already clamped)
95 m_SignalStartTimeMax = UAFishingConstants.SIGNAL_START_TIME_MAX_BASE;
96
99
100 #ifdef DEVELOPER
101 if (IsCLIParam("fishingLogs"))
102 {
103 Debug.Log("---InitCatchingItemData---","Fishing");
104 Debug.Log("m_SignalCycleTarget (adjusted): " + m_SignalCycleTarget,"Fishing");
105 Debug.Log("m_SignalCycleTargetAdjustment: " + m_SignalCycleTargetAdjustment,"Fishing");
106 Debug.Log("m_SignalTargetProbability: " + m_SignalTargetProbability,"Fishing");
107 Debug.Log("m_SignalCycleEndTarget (adjusted): " + m_SignalCycleEndTarget,"Fishing");
108 Debug.Log("m_SignalCycleTargetEndAdjustment: " + m_SignalCycleTargetEndAdjustment,"Fishing");
109 Debug.Log("m_SignalTargetEndProbability: " + m_SignalTargetEndProbability,"Fishing");
110 Debug.Log("m_SignalDurationMin: " + m_SignalDurationMin,"Fishing");
111 Debug.Log("m_SignalDurationMax: " + m_SignalDurationMax,"Fishing");
112 Debug.Log("m_SignalStartTimeMin: " + m_SignalStartTimeMin,"Fishing");
113 Debug.Log("m_SignalStartTimeMax: " + m_SignalStartTimeMax,"Fishing");
114 }
115 #endif
116 }
117
118 override protected void InitItemValues(EntityAI item)
119 {
120 //skip ruined or deleted items entirely
121 if (item.IsRuined() || item.IsSetForDeletion())
122 return;
123
124 string path = "" + CFG_VEHICLESPATH + " " + item.GetType() + " Fishing";
125 if (g_Game.ConfigIsExisting(path))
126 {
127 if (g_Game.ConfigIsExisting(path + " resultQuantityBaseMod"))
128 m_QualityBaseMod += g_Game.ConfigGetFloat(path + " resultQuantityBaseMod");
129 if (g_Game.ConfigIsExisting(path + " resultQuantityDispersionMin"))
130 m_QualityDispersionMinMod += g_Game.ConfigGetFloat(path + " resultQuantityDispersionMin");
131 if (g_Game.ConfigIsExisting(path + " resultQuantityDispersionMax"))
132 m_QualityDispersionMaxMod += g_Game.ConfigGetFloat(path + " resultQuantityDispersionMax");
133 if (g_Game.ConfigIsExisting(path + " hookLossChanceMod"))
134 m_HookLossChanceMod += g_Game.ConfigGetFloat(path + " hookLossChanceMod");
135 if (g_Game.ConfigIsExisting(path + " baitLossChanceMod"))
136 m_BaitLossChanceMod += g_Game.ConfigGetFloat(path + " baitLossChanceMod");
137
138 if (g_Game.ConfigIsExisting(path + " signalDurationMin"))
139 {
140 if (m_SignalDurationMin == -1)
142 m_SignalDurationMin += g_Game.ConfigGetFloat(path + " signalDurationMin");
143 }
144 if (g_Game.ConfigIsExisting(path + " signalDurationMax"))
145 {
146 if (m_SignalDurationMax == -1)
148 m_SignalDurationMax += g_Game.ConfigGetFloat(path + " signalDurationMax");
149 }
150
151 if (g_Game.ConfigIsExisting(path + " signalCycleTargetAdjustment"))
152 m_SignalCycleTargetAdjustment += g_Game.ConfigGetFloat(path + " signalCycleTargetAdjustment");
153 if (g_Game.ConfigIsExisting(path + " signalCycleTargetEndAdjustment"))
154 m_SignalCycleTargetEndAdjustment += g_Game.ConfigGetFloat(path + " signalCycleTargetEndAdjustment");
155
156 int slotID;
157 string slotName;
158 if (item.GetInventory().GetCurrentAttachmentSlotInfo(slotID,slotName))
159 {
160 switch (slotName)
161 {
162 case "Bait":
163 m_Bait = item;
164 break;
165
166 case "Hook":
167 m_Hook = item;
168 break;
169 }
170 }
171 }
172 }
173
174 override bool ModifySignalProbability(inout float probability)
175 {
176 float easingTime;
178 {
179 easingTime = Math.InverseLerp(0,m_SignalCycleTarget,(float)m_SignalCurrent);
180 probability = Easing.EaseInExpo(easingTime) * m_SignalTargetProbability * GetChanceCoef();
181 }
182 else
183 {
184 easingTime = Math.InverseLerp(m_SignalCycleTarget,m_SignalCycleEndTarget,(float)m_SignalCurrent);
186 }
187
188 #ifdef DEVELOPER
189 // Needs to be revisited, won't work when the autotests run inside of workbench
190 if (IsCLIParam("autotest"))
191 probability = UAFishingConstants.DEBUG_FISHING_CHANCE_PROBABILITY;
192
193 if (IsCLIParam("fishingLogs"))
194 {
195 Debug.Log("---ModifySignalProbability---","Fishing");
196 Debug.Log("m_SignalCurrent: " + m_SignalCurrent,"Fishing");
197 Debug.Log("easingTime: " + easingTime,"Fishing");
198 Debug.Log("probability: " + probability,"Fishing");
199 }
200 #endif
201
202 return true;
203 }
204
206 {
207 return UAFishingConstants.SIGNAL_FISHING_CHANCE_COEF;
208 }
209
210 override bool RollCatch()
211 {
212 bool ret = super.RollCatch();
214 return ret;
215 }
216
217 protected void ResetSignalCounter()
218 {
219 m_SignalCurrent = 0.0;
220 }
221
223 override void GenerateResult()
224 {
225 YieldItemBase yItem;
226 int idx = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,0,m_ProbabilityArray.Count() - 1);
227 Class.CastTo(yItem,m_YieldsMapAll.Get(m_ProbabilityArray[idx]));
228 m_Result.SetYieldItem(yItem);
229 }
230
232 {
233 if (m_Result)
234 return m_Result.GetYieldItemParticleId();
235
236 return ParticleList.INVALID;
237 }
238
239 override protected void RecalculateProcessingData()
240 {
241 m_Result.UpdateCatchChance(this);
242 }
243
245 {
246 return Math.Clamp(m_HookLossChanceMod,0.001,1);
247 }
248
250 {
251 return Math.Clamp(m_BaitLossChanceMod,0,1);
252 }
253
255 {
256 return CarchingResultFishingAction.Cast(m_Result).GetCurrentCycleTime(this);
257 }
258
260 {
261 float res = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,m_SignalDurationMin,m_SignalDurationMax);
262 #ifdef DEVELOPER
263 if (IsCLIParam("fishingLogs"))
264 {
265 Debug.Log("---RandomizeSignalDuration---","Fishing");
266 Debug.Log("next signal duration: " + res,"Fishing");
267 }
268 #endif
269
270 return res;
271 }
272
274 {
275 float res = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,m_SignalStartTimeMin,m_SignalStartTimeMax);
276 #ifdef DEVELOPER
277 if (IsCLIParam("fishingLogs"))
278 {
279 Debug.Log("---RandomizeSignalStartTime---","Fishing");
280 Debug.Log("next signal start time: " + res,"Fishing");
281 }
282 #endif
283 return res;
284 }
285
286 protected void TryHookLoss()
287 {
288 if (m_Hook && !m_Hook.IsSetForDeletion())
289 {
290 float lossChance = GetHookLossChanceModifierClamped();
291 if (lossChance <= 0)
292 return;
293
294 float roll = m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSAnimalCatching);
295
296 if (lossChance >= 1 || roll < lossChance)
297 {
299 }
300 }
301 }
302
303 protected void RemoveItemSafe(EntityAI item)
304 {
305 if (item && !m_Player.IsQuickFishing())
306 {
307 item.SetPrepareToDelete(); //should probably flag the bait too, but the action terminates anyway
308 item.DeleteSafe();
309 }
310 }
311
312 protected void TryBaitLoss()
313 {
314 if (m_Bait && !m_Bait.IsSetForDeletion())
315 {
316 float lossChance = GetBaitLossChanceModifierClamped();
317 if (lossChance <= 0)
318 return;
319
320 float roll = m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSAnimalCatching);
321
322 if (lossChance >= 1 || roll < lossChance)
323 {
325 }
326 }
327 }
328
329 protected void TryDamageItems()
330 {
331 if (!g_Game.IsMultiplayer() || g_Game.IsDedicatedServer())
332 {
333 if (m_Hook && !m_Hook.IsSetForDeletion())
334 m_Hook.AddHealth("","Health",-UAFishingConstants.DAMAGE_HOOK);
335 }
336 }
337
338 override EntityAI SpawnAndSetupCatch(out int yItemIdx, vector v = vector.Zero)
339 {
340 //hook check on catch
341 if (m_Hook && !m_Hook.IsSetForDeletion())
342 return super.SpawnAndSetupCatch(yItemIdx,v);
343 return null;
344 }
345
346 //events
348 {
349 TryHookLoss();
350 }
351
357
360 {
361 TryHookLoss();
362 TryBaitLoss();
363 }
364
371
373 //Fish pen of deprecated code//
375 protected float m_SignalPoissonMean = AnimalCatchingConstants.POISSON_CYCLE_MEAN_DEFAULT;
378}
void UpdateCatchingItemData()
float m_QualityBaseMod
class BaitData m_MainItem
Definition actionbase.c:42
ref CatchingResultBasic m_Result
int m_MethodMask
float m_QualityDispersionMinMod
ref array< int > m_ProbabilityArray
float m_QualityDispersionMaxMod
YieldsMap m_YieldsMapAll
int m_EnviroMask
PlayerSpawnPreset slotName
override bool ModifySignalProbability(inout float probability)
float GetSignalPoissonMean()
Deprecated, left here due to inheritance change.
void ClearCatchingItemData()
only clear stuff you need to update
int GetSignalMax()
Deprecated, left here due to inheritance change.
override EntityAI SpawnAndSetupCatch(out int yItemIdx, vector v=vector.Zero)
override void GenerateResult()
done locally on both sides, needs a synced random
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition debug.c:2
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition easing.c:3
Definition enmath.c:7
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
DayZGame g_Game
Definition dayzgame.c:3942
const int MAX
Definition enconvert.c:27
const string CFG_VEHICLESPATH
Definition constants.c:220
proto native bool IsCLIParam(string param)
Returns if command line argument is present.