DayZ 1.24
Loading...
Searching...
No Matches
SoftSkillsManager.c
Go to the documentation of this file.
2{
4 protected float m_SpecialtyLevel;
5 protected float m_RoughLevel;
6 protected float m_PreciseLevel;
7
8 protected bool m_IsLinear;
9 protected bool m_IsActive;
10 protected bool m_IsCoolDown;
11
12 protected int m_UserActionsCounter;
13
14 static protected const int DEFAULT_EFFICIENCY = 0;
15 static protected const float PRECISE_WEIGHT_LIMIT = -1;
16 static protected const float ROUGH_WEIGHT_LIMIT = 1;
17 static protected const float COOLDOWN_TIMER = 5; //default 5,
18
19 protected ref Timer m_CoolDownTimer = new Timer();
20
21 protected bool m_IsDebugMode;
22 protected float m_CoolDownValue;
23 protected float m_LastUAValue;
24 protected float m_ComponentBonusBefore;
25 protected float m_ComponentBonusAfter;
26 protected float m_GeneralBonusBefore;
27 protected float m_GeneralBonusAfter;
28
30
32
34 {
36 m_IsCoolDown = false;
37 m_IsLinear = false;
38 m_IsActive = true;
39 m_IsDebugMode = false;
40 }
41
47
49 {
50 delete m_CoolDownTimer;
51 }
52
53 // ----------------------------------------------------------------------------------------
62
63 // ----------------------------------------------------------------------------------------
72
73 // ----------------------------------------------------------------------------------------
93
94 // ----------------------------------------------------------------------------------------
114
115 // ----------------------------------------------------------------------------------------
117 {
118 if (GetSoftSkillsState())
119 {
120 if (!IsCoolDown())
121 {
122 if (specialty_weight < 0)
123 {
124 if (IsLinear())
126 else
128
129 m_Player.GetStatSpecialty().Set(m_SpecialtyLevel);
132 }
133 else if (specialty_weight > 0)
134 {
135 if (IsLinear())
137 else
139
140 m_Player.GetStatSpecialty().Set(m_SpecialtyLevel);
143 }
144 else
145 {
146 //if the specialty weight for a recipe or UA is set to 0, it will increase neither specialty, nor UA counter
147 return;
148 }
149 }
150 else
152 }
153 }
154
155 // ----------------------------------------------------------------------------------------
156 // Use AddSpecialtyBonus if you want to increase a value, based on the specialty level of the player. e.g. more harvested material
157 // limit_efficiency sets the max amount of bonus, the soft skill can provide: limit_efficiency = 2 is 50% bonus, limit_efficiency = 3 is 33% bonus etc
159 {
160 if (specialty_weight == 0)
161 return base_value;
162
164
165 float adjusted_value;
166
168
169 if (limit_efficiency != 0)
170 {
171 if (specialty_weight < 0)
173 else
175 }
176 else
177 {
178 if (specialty_weight < 0)
180 else
182 }
183
185
186 return adjusted_value;
187 }
188
189 // ----------------------------------------------------------------------------------------
190 // Use SubtractSpecialtyBonus if you want to decrease a value, based on the specialty level of the player. e.g. faster harvesting time
191 // limit_efficiency sets the max amount of bonus, the soft skill can provide: limit_efficiency = 2 is 50% bonus, limit_efficiency = 3 is 33% bonus etc
193 {
194 if (specialty_weight == 0)
195 return base_value;
196
198
199 float adjusted_value;
200
202
203 if (limit_efficiency != 0)
204 {
205 if (specialty_weight < 0)
207 else
209 }
210 else
211 {
212 if (specialty_weight < 0)
214 else
216 }
217
219
220 return adjusted_value;
221 }
222
223 // ----------------------------------------------------------------------------------------
224 // Use AdjustCraftingTime if you want to decrease time for recipe crafting
225 // limit_efficiency sets the max amount of bonus, the soft skill can provide: limit_efficiency = 2 is 50% bonus, limit_efficiency = 3 is 33% bonus etc
227 {
228 if (specialty_weight == 0)
229 return base_time;
230
232
233 float adjusted_time;
234
236
237 if (specialty_weight < 0)
239 else
241
243
244 return adjusted_time;
245 }
246
247 // ----------------------------------------------------------------------------------------
249 {
250 return m_Player;
251 }
252
253 // ----------------------------------------------------------------------------------------
258
259 // ----------------------------------------------------------------------------------------
261 {
262 return m_SpecialtyLevel;
263 }
264
265 // ----------------------------------------------------------------------------------------
267 {
268#ifdef SERVER
270 GetGame().RPCSingleParam(m_Player, ERPCs.RPC_SOFT_SKILLS_SPECIALTY_SYNC, specialty_level, true, m_Player.GetIdentity());
271#endif
272 }
273
274 // ----------------------------------------------------------------------------------------
276 {
278 }
279
280 // ----------------------------------------------------------------------------------------
282 {
283 return m_IsActive;
284 }
285
286 // ----------------------------------------------------------------------------------------
288 {
290 }
291
292 // ----------------------------------------------------------------------------------------
293 bool IsLinear()
294 {
295 return m_IsLinear;
296 }
297
298 // ----------------------------------------------------------------------------------------
317
318 // ----------------------------------------------------------------------------------------
320 {
321 SetCoolDown(true);
323 m_CoolDownTimer.Run(cooldown_value, this, "SetCoolDown", new Param1<bool>(false));
324 }
325
326 // ----------------------------------------------------------------------------------------
328 {
329 return m_IsCoolDown;
330 }
331
332 // ----------------------------------------------------------------------------------------
334 {
336 }
337
338 // ----------------------------------------------------------------------------------------
339 // SoftSkillManagerDebug support
340 // ----------------------------------------------------------------------------------------
342 {
343 if (create)
344 {
347 }
348 else
349 {
352 delete m_DebugWindow;
353 }
354 }
355
356 // ----------------------------------------------------------------------------------------
358 {
359 if (GetGame().IsServer() && GetGame().IsMultiplayer())
360 {
362 GetGame().RPCSingleParam(m_Player, ERPCs.RPC_SOFT_SKILLS_STATS_SYNC, debug_stats, true, m_Player.GetIdentity());
363 }
364 }
365
366 // ----------------------------------------------------------------------------------------
368 {
370 }
371
372 // ----------------------------------------------------------------------------------------
373 bool IsDebug()
374 {
375 return m_IsDebugMode;
376 }
377
378 // ----------------------------------------------------------------------------------------
383
384 // ----------------------------------------------------------------------------------------
386 {
387 return m_CoolDownValue;
388 }
389
390 // ----------------------------------------------------------------------------------------
392 {
393 return m_LastUAValue;
394 }
395
396 // ----------------------------------------------------------------------------------------
401
402 // ----------------------------------------------------------------------------------------
404 {
405 if (IsDebug())
406 {
407 if (is_cacomponent)
409 else
411 }
412 }
413
414 // ----------------------------------------------------------------------------------------
416 {
417 if (IsDebug())
418 {
419 if (is_cacomponent)
421 else
423 }
424 }
425
426 // ----------------------------------------------------------------------------------------
428 {
430 }
431
432 // ----------------------------------------------------------------------------------------
437
438 // ----------------------------------------------------------------------------------------
440 {
442 }
443
444 // ----------------------------------------------------------------------------------------
449
450 // ----------------------------------------------------------------------------------------
452 {
454 }
455
456 // ----------------------------------------------------------------------------------------
461
462 // ----------------------------------------------------------------------------------------
464 {
465 return m_GeneralBonusAfter;
466 }
467
468 // ----------------------------------------------------------------------------------------
473
474 // ----------------------------------------------------------------------------------------
476 {
477 SetIsDebug(true);
478 m_SynchTimer = new Timer;
479 m_SynchTimer.Run(2, this, "SynchDebugStats", NULL, true);
480 }
481
482 // ----------------------------------------------------------------------------------------
484 {
485 SetIsDebug(false);
486
487 if (m_SynchTimer)
488 {
489 m_SynchTimer.Stop();
490 delete m_SynchTimer;
491 }
492 }
493
494 // ----------------------------------------------------------------------------------------
507}
508
509// ----------------------------------------------------------------------------------------
510// SoftSkillManagerDebug
511// ----------------------------------------------------------------------------------------
512
514{
525
527 {
529 m_PanelSoftSkills = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_hud_debug_softskills.layout");
530
531 GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Insert(this.OnUpdate);
532
533 Class.CastTo(SpecialtyTotal, m_PanelSoftSkills.FindWidget("SpecialtyTotal"));
534 Class.CastTo(SpecialtyChange, m_PanelSoftSkills.FindWidget("SpecialtyChange"));
535 Class.CastTo(ComponentBonusBefore, m_PanelSoftSkills.FindWidget("ComponentBonusBefore"));
536 Class.CastTo(ComponentBonusAfter, m_PanelSoftSkills.FindWidget("ComponentBonusAfter"));
537 Class.CastTo(GeneralBonusBefore, m_PanelSoftSkills.FindWidget("GeneralBonusBefore"));
538 Class.CastTo(GeneralBonusAfter, m_PanelSoftSkills.FindWidget("GeneralBonusAfter"));
539 Class.CastTo(CoolDown, m_PanelSoftSkills.FindWidget("CoolDown"));
540 Class.CastTo(IsCoolDown, m_PanelSoftSkills.FindWidget("IsCoolDown"));
541
542 m_PanelSoftSkills.Show(true);
543 SpecialtyTotal.Show(true);
544 SpecialtyChange.Show(true);
545 ComponentBonusBefore.Show(true);
546 ComponentBonusAfter.Show(true);
547 GeneralBonusBefore.Show(true);
548 GeneralBonusAfter.Show(true);
549 CoolDown.Show(true);
550 IsCoolDown.Show(true);
551 }
552
554 {
555 if (GetGame())
556 GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnUpdate);
557
558 delete m_PanelSoftSkills;
559 }
560
565
566 void OnUpdate()
567 {
568 if (GetActiveSoftSkillManager().GetSoftSkillsPlayer().IsAlive())
569 {
571 speciality = speciality * 100;
573 speciality = speciality * 0.01;
574
575 SpecialtyTotal.SetText("Specialty level: " + speciality.ToString());
576 SpecialtyChange.SetText("Specialty change: " + GetActiveSoftSkillManager().GetLastUAValue());
577 ComponentBonusBefore.SetText("Component/craft default: " + GetActiveSoftSkillManager().GetComponentBonusBefore());
578 ComponentBonusAfter.SetText("Component/craft with bonus: " + GetActiveSoftSkillManager().GetComponentBonusAfter());
579 GeneralBonusBefore.SetText("General default: " + GetActiveSoftSkillManager().GetGeneralBonusBefore());
580 GeneralBonusAfter.SetText("General with bonus: " + GetActiveSoftSkillManager().GetGeneralBonusAfter());
581 CoolDown.SetText("CoolDown value: " + GetActiveSoftSkillManager().GetCoolDownValue());
582 IsCoolDown.SetText("Cooldown active: " + GetActiveSoftSkillManager().IsCoolDown());
583 }
584 else
585 delete this;
586 }
587
588}
ERPCs
Definition ERPCs.c:2
void SoftSkillManagerDebug(SoftSkillsManager softskill_manager)
void ~SoftSkillManagerDebug()
TextWidget SpecialtyTotal
TextWidget SpecialtyChange
TextWidget GeneralBonusAfter
TextWidget CoolDown
SoftSkillsManager GetActiveSoftSkillManager()
TextWidget ComponentBonusAfter
TextWidget IsCoolDown
TextWidget GeneralBonusBefore
TextWidget ComponentBonusBefore
ref Widget m_PanelSoftSkills
class SoftSkillsManager m_SoftSkillManager
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
ref SoftSkillManagerDebug m_DebugWindow
void AddSpecialty(float specialty_weight)
float AddSpecialtyBonus(float base_value, float specialty_weight, bool is_cacomponent=false, float limit_efficiency=2)
PlayerBase GetSoftSkillsPlayer()
void SetCoolDown(bool cool_down)
void SetComponentBonusAfter(float component_bonus_after)
void SetLastUAValue(float last_ua_value)
const float COOLDOWN_TIMER
void SetGeneralBonusBefore(float general_bonus_before)
float SubtractSpecialtyBonus(float base_value, float specialty_weight, bool is_cacomponent=false, float limit_efficiency=2)
const float PRECISE_WEIGHT_LIMIT
void SetIsDebug(bool is_debug)
void SetLinearState(bool model)
void SetCoolDownValue(float cooldown_value)
float AddLinearRough(float specialty_weight)
float AddExponentialPrecise(float specialty_weight)
void SetGeneralBonusAfter(float general_bonus_after)
float AddLinearPrecise(float specialty_weight)
void SetBonusAfter(bool is_cacomponent, float adjusted_value)
void SoftSkillsManager(PlayerBase player)
void SetSoftSkillsState(bool state)
void SetComponentBonusBefore(float component_bonus_before)
float AddExponentialRough(float specialty_weight)
void SetBonusBefore(bool is_cacomponent, float base_value)
const float ROUGH_WEIGHT_LIMIT
void StartCoolDownTimer(float cooldown_value)
void InitSpecialty(float specialty_level)
void SetSpecialtyLevel(float specialty_level)
float AdjustCraftingTime(float base_time, float specialty_weight, float limit_efficiency=2)
void CreateDebugWindow(bool create)
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Sqrt(float val)
Returns square root.
static proto int AbsInt(int i)
Returns absolute value.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float AbsFloat(float f)
Returns absolute value.
proto native void OnUpdate()
Definition tools.c:333
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8