Dayz Explorer 1.28.160049
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 (GetGame().ConfigIsExisting(path))
126 {
127 if (GetGame().ConfigIsExisting(path + " resultQuantityBaseMod"))
128 m_QualityBaseMod += GetGame().ConfigGetFloat(path + " resultQuantityBaseMod");
129 if (GetGame().ConfigIsExisting(path + " resultQuantityDispersionMin"))
130 m_QualityDispersionMinMod += GetGame().ConfigGetFloat(path + " resultQuantityDispersionMin");
131 if (GetGame().ConfigIsExisting(path + " resultQuantityDispersionMax"))
132 m_QualityDispersionMaxMod += GetGame().ConfigGetFloat(path + " resultQuantityDispersionMax");
133 if (GetGame().ConfigIsExisting(path + " hookLossChanceMod"))
134 m_HookLossChanceMod += GetGame().ConfigGetFloat(path + " hookLossChanceMod");
135 if (GetGame().ConfigIsExisting(path + " baitLossChanceMod"))
136 m_BaitLossChanceMod += GetGame().ConfigGetFloat(path + " baitLossChanceMod");
137
138 if (GetGame().ConfigIsExisting(path + " signalDurationMin"))
139 {
140 if (m_SignalDurationMin == -1)
142 m_SignalDurationMin += GetGame().ConfigGetFloat(path + " signalDurationMin");
143 }
144 if (GetGame().ConfigIsExisting(path + " signalDurationMax"))
145 {
146 if (m_SignalDurationMax == -1)
148 m_SignalDurationMax += GetGame().ConfigGetFloat(path + " signalDurationMax");
149 }
150
151 if (GetGame().ConfigIsExisting(path + " signalCycleTargetAdjustment"))
152 m_SignalCycleTargetAdjustment += GetGame().ConfigGetFloat(path + " signalCycleTargetAdjustment");
153 if (GetGame().ConfigIsExisting(path + " signalCycleTargetEndAdjustment"))
154 m_SignalCycleTargetEndAdjustment += GetGame().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 if (IsCLIParam("fishingLogs"))
190 {
191 Debug.Log("---ModifySignalProbability---","Fishing");
192 Debug.Log("m_SignalCurrent: " + m_SignalCurrent,"Fishing");
193 Debug.Log("easingTime: " + easingTime,"Fishing");
194 Debug.Log("probability: " + probability,"Fishing");
195 }
196 #endif
197
198 return true;
199 }
200
202 {
203 return UAFishingConstants.SIGNAL_FISHING_CHANCE_COEF;
204 }
205
206 override bool RollCatch()
207 {
208 bool ret = super.RollCatch();
210 return ret;
211 }
212
213 protected void ResetSignalCounter()
214 {
215 m_SignalCurrent = 0.0;
216 }
217
219 override void GenerateResult()
220 {
221 YieldItemBase yItem;
222 int idx = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,0,m_ProbabilityArray.Count() - 1);
223 Class.CastTo(yItem,m_YieldsMapAll.Get(m_ProbabilityArray[idx]));
224 m_Result.SetYieldItem(yItem);
225 }
226
228 {
229 if (m_Result)
231
232 return ParticleList.INVALID;
233 }
234
235 override protected void RecalculateProcessingData()
236 {
238 }
239
241 {
242 return Math.Clamp(m_HookLossChanceMod,0.001,1);
243 }
244
246 {
247 return Math.Clamp(m_BaitLossChanceMod,0,1);
248 }
249
251 {
252 return CarchingResultFishingAction.Cast(m_Result).GetCurrentCycleTime(this);
253 }
254
256 {
257 float res = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,m_SignalDurationMin,m_SignalDurationMax);
258 #ifdef DEVELOPER
259 if (IsCLIParam("fishingLogs"))
260 {
261 Debug.Log("---RandomizeSignalDuration---","Fishing");
262 Debug.Log("next signal duration: " + res,"Fishing");
263 }
264 #endif
265
266 return res;
267 }
268
270 {
271 float res = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,m_SignalStartTimeMin,m_SignalStartTimeMax);
272 #ifdef DEVELOPER
273 if (IsCLIParam("fishingLogs"))
274 {
275 Debug.Log("---RandomizeSignalStartTime---","Fishing");
276 Debug.Log("next signal start time: " + res,"Fishing");
277 }
278 #endif
279 return res;
280 }
281
282 protected void TryHookLoss()
283 {
284 if (m_Hook && !m_Hook.IsSetForDeletion())
285 {
286 float lossChance = GetHookLossChanceModifierClamped();
287 if (lossChance <= 0)
288 return;
289
290 float roll = m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSAnimalCatching);
291
292 if (lossChance >= 1 || roll < lossChance)
293 {
295 }
296 }
297 }
298
299 protected void RemoveItemSafe(EntityAI item)
300 {
301 if (item && !m_Player.IsQuickFishing())
302 {
303 item.SetPrepareToDelete(); //should probably flag the bait too, but the action terminates anyway
304 item.DeleteSafe();
305 }
306 }
307
308 protected void TryBaitLoss()
309 {
310 if (m_Bait && !m_Bait.IsSetForDeletion())
311 {
312 float lossChance = GetBaitLossChanceModifierClamped();
313 if (lossChance <= 0)
314 return;
315
316 float roll = m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSAnimalCatching);
317
318 if (lossChance >= 1 || roll < lossChance)
319 {
321 }
322 }
323 }
324
325 protected void TryDamageItems()
326 {
327 if (!GetGame().IsMultiplayer() || GetGame().IsDedicatedServer())
328 {
329 if (m_Hook && !m_Hook.IsSetForDeletion())
330 m_Hook.AddHealth("","Health",-UAFishingConstants.DAMAGE_HOOK);
331 }
332 }
333
334 override EntityAI SpawnAndSetupCatch(out int yItemIdx, vector v = vector.Zero)
335 {
336 //hook check on catch
337 if (m_Hook && !m_Hook.IsSetForDeletion())
338 return super.SpawnAndSetupCatch(yItemIdx,v);
339 return null;
340 }
341
342 //events
344 {
345 TryHookLoss();
346 }
347
353
356 {
357 TryHookLoss();
358 TryBaitLoss();
359 }
360
367
369 //Fish pen of deprecated code//
371 protected float m_SignalPoissonMean = AnimalCatchingConstants.POISSON_CYCLE_MEAN_DEFAULT;
374}
void UpdateCatchingItemData()
float m_QualityBaseMod
class BaitData m_MainItem
Definition actionbase.c:36
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
void UpdateCatchChance(CatchingContextBase ctx)
void SetYieldItem(YieldItemBase yItem)
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
const int MAX
Definition enconvert.c:27
proto native CGame GetGame()
const string CFG_VEHICLESPATH
Definition constants.c:220
proto native bool IsCLIParam(string param)
Returns if command line argument is present.