Dayz Explorer 1.28.160049
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
31 protected ref Timer m_SynchTimer;
32
34 {
35 m_Player = player;
36 m_IsCoolDown = false;
37 m_IsLinear = false;
38 m_IsActive = true;
39 m_IsDebugMode = false;
40 }
41
42 void InitSpecialty( float specialty_level )
43 {
44 SetSpecialtyLevel( specialty_level );
46 }
47
49 {
50 delete m_CoolDownTimer;
51 }
52
53 // ----------------------------------------------------------------------------------------
54 float AddLinearPrecise( float specialty_weight )
55 {
56 m_SpecialtyLevel += specialty_weight;
57 SetLastUAValue( specialty_weight );
59
60 return m_SpecialtyLevel;
61 }
62
63 // ----------------------------------------------------------------------------------------
64 float AddLinearRough( float specialty_weight )
65 {
66 m_SpecialtyLevel += specialty_weight;
67 SetLastUAValue( specialty_weight );
69
70 return m_SpecialtyLevel;
71 }
72
73 // ----------------------------------------------------------------------------------------
74 float AddExponentialPrecise( float specialty_weight )
75 {
77
78 if( m_UserActionsCounter == 0)
79 {
82 }
83
84 float adjusted_weight = specialty_weight / Math.Sqrt( Math.AbsInt( m_UserActionsCounter ) );
85
86 SetLastUAValue( adjusted_weight );
87
88 m_SpecialtyLevel += adjusted_weight;
90
91 return m_SpecialtyLevel;
92 }
93
94 // ----------------------------------------------------------------------------------------
95 float AddExponentialRough( float specialty_weight )
96 {
98
99 if( m_UserActionsCounter == 0)
100 {
103 }
104
105 float adjusted_weight = specialty_weight / Math.Sqrt( Math.AbsInt( m_UserActionsCounter ) );
106
107 SetLastUAValue( adjusted_weight );
108
109 m_SpecialtyLevel += adjusted_weight;
111
112 return m_SpecialtyLevel;
113 }
114
115 // ----------------------------------------------------------------------------------------
116 void AddSpecialty( float specialty_weight )
117 {
118 if( GetSoftSkillsState() )
119 {
120 if( !IsCoolDown() )
121 {
122 if( specialty_weight < 0 )
123 {
124 if( IsLinear() )
125 {
126 SetSpecialtyLevel( AddLinearPrecise( specialty_weight ) );
127 }
128 else
129 {
130 SetSpecialtyLevel( AddExponentialPrecise( specialty_weight ) );
131 }
132
133 m_Player.GetStatSpecialty().Set( m_SpecialtyLevel );
134 StartCoolDownTimer( Math.AbsFloat( ( specialty_weight * 100 ) ) * COOLDOWN_TIMER );
136 }
137 else if( specialty_weight > 0 )
138 {
139 if( IsLinear() )
140 {
141 SetSpecialtyLevel( AddLinearRough( specialty_weight ) );
142 }
143 else
144 {
145 SetSpecialtyLevel( AddExponentialRough( specialty_weight ) );
146 }
147
148 m_Player.GetStatSpecialty().Set( m_SpecialtyLevel );
149 StartCoolDownTimer( Math.AbsFloat( ( specialty_weight * 100 ) ) * COOLDOWN_TIMER );
151 }
152 else
153 {
154 //if the specialty weight for a recipe or UA is set to 0, it will increase neither specialty, nor UA counter
155 return;
156 }
157 }
158 else
159 {
160 StartCoolDownTimer( Math.AbsFloat( ( specialty_weight * 100 ) ) * COOLDOWN_TIMER );
161 }
162 }
163 }
164
165 // ----------------------------------------------------------------------------------------
166 // Use AddSpecialtyBonus if you want to increase a value, based on the specialty level of the player. e.g. more harvested material
167 // 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
168 float AddSpecialtyBonus( float base_value, float specialty_weight, bool is_cacomponent = false, float limit_efficiency = 2 )
169 {
170 if ( specialty_weight == 0 )
171 {
172 return base_value;
173 }
174
175 SetBonusBefore( is_cacomponent, base_value);
176
177 float adjusted_value;
178
180
181 if ( limit_efficiency != 0 )
182 {
183 if ( specialty_weight < 0 )
184 {
185 adjusted_value = base_value + ( ( base_value * m_PreciseLevel ) / limit_efficiency );
186 }
187 else
188 {
189 adjusted_value = base_value + ( ( base_value * m_RoughLevel ) / limit_efficiency );
190 }
191 }
192 else
193 {
194 if ( specialty_weight < 0 )
195 {
196 adjusted_value = base_value + ( ( base_value * m_PreciseLevel ) );
197 }
198 else
199 {
200 adjusted_value = base_value + ( ( base_value * m_RoughLevel ) );
201 }
202 }
203
204 SetBonusAfter( is_cacomponent, adjusted_value );
205
206 return adjusted_value;
207 }
208
209 // ----------------------------------------------------------------------------------------
210 // Use SubtractSpecialtyBonus if you want to decrease a value, based on the specialty level of the player. e.g. faster harvesting time
211 // 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
212 float SubtractSpecialtyBonus( float base_value, float specialty_weight, bool is_cacomponent = false, float limit_efficiency = 2 )
213 {
214 if ( specialty_weight == 0 )
215 {
216 return base_value;
217 }
218
219 SetBonusBefore( is_cacomponent, base_value);
220
221 float adjusted_value;
222
224
225 if ( limit_efficiency != 0 )
226 {
227 if ( specialty_weight < 0 )
228 {
229 adjusted_value = base_value - ( ( base_value * m_PreciseLevel ) / limit_efficiency );
230 }
231 else
232 {
233 adjusted_value = base_value - ( ( base_value * m_RoughLevel ) / limit_efficiency );
234 }
235 }
236 else
237 {
238 if ( specialty_weight < 0 )
239 {
240 adjusted_value = base_value - ( ( base_value * m_PreciseLevel ) );
241 }
242 else
243 {
244 adjusted_value = base_value - ( ( base_value * m_RoughLevel ) );
245 }
246 }
247
248 SetBonusAfter( is_cacomponent, adjusted_value );
249
250 return adjusted_value;
251 }
252
253 // ----------------------------------------------------------------------------------------
254 // Use AdjustCraftingTime if you want to decrease time for recipe crafting
255 // 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
256 float AdjustCraftingTime( float base_time, float specialty_weight, float limit_efficiency = 2 )
257 {
258 if ( specialty_weight == 0 )
259 {
260 return base_time;
261 }
262
263 SetBonusBefore( false, base_time);
264
265 float adjusted_time;
266
268
269 if ( specialty_weight < 0 )
270 {
271 adjusted_time = base_time - ( ( base_time * m_PreciseLevel ) / limit_efficiency );
272 }
273 else
274 {
275 adjusted_time = base_time - ( ( base_time * m_RoughLevel ) / limit_efficiency );
276 }
277
278 SetBonusAfter( false, adjusted_time );
279
280 return adjusted_time;
281 }
282
283 // ----------------------------------------------------------------------------------------
285 {
286 return m_Player;
287 }
288
289 // ----------------------------------------------------------------------------------------
290 void SetSpecialtyLevel( float specialty_level )
291 {
292 m_SpecialtyLevel = specialty_level;
293 }
294
295 // ----------------------------------------------------------------------------------------
297 {
298 return m_SpecialtyLevel;
299 }
300
301 // ----------------------------------------------------------------------------------------
303 {
304 #ifdef SERVER
305 Param1<float> specialty_level = new Param1<float>( m_SpecialtyLevel );
306 GetGame().RPCSingleParam( m_Player, ERPCs.RPC_SOFT_SKILLS_SPECIALTY_SYNC, specialty_level, true, m_Player.GetIdentity() );
307 #endif
308 }
309
310 // ----------------------------------------------------------------------------------------
311 void SetSoftSkillsState( bool state )
312 {
313 m_IsActive = state;
314 }
315
316 // ----------------------------------------------------------------------------------------
318 {
319 return m_IsActive;
320 }
321
322 // ----------------------------------------------------------------------------------------
323 void SetLinearState( bool model )
324 {
325 m_IsLinear = model;
326 }
327
328 // ----------------------------------------------------------------------------------------
329 bool IsLinear()
330 {
331 return m_IsLinear;
332 }
333
334 // ----------------------------------------------------------------------------------------
336 {
337 if ( m_SpecialtyLevel > 0)
338 {
341 }
342 else if ( m_SpecialtyLevel < 0)
343 {
346 }
347 else
348 {
351 }
352 }
353
354 // ----------------------------------------------------------------------------------------
355 void StartCoolDownTimer( float cooldown_value )
356 {
357 SetCoolDown( true );
358 SetCoolDownValue( cooldown_value );
359 m_CoolDownTimer.Run( cooldown_value, this, "SetCoolDown", new Param1<bool>( false ) );
360 }
361
362 // ----------------------------------------------------------------------------------------
364 {
365 return m_IsCoolDown;
366 }
367
368 // ----------------------------------------------------------------------------------------
369 void SetCoolDown( bool cool_down )
370 {
371 m_IsCoolDown = cool_down;
372 }
373
374// ----------------------------------------------------------------------------------------
375// SoftSkillManagerDebug support
376// ----------------------------------------------------------------------------------------
377 void CreateDebugWindow( bool create )
378 {
379 if ( create )
380 {
382 SetIsDebug( create );
383 }
384 else
385 {
387 SetIsDebug( create );
388 delete m_DebugWindow;
389 }
390 }
391
392 // ----------------------------------------------------------------------------------------
394 {
395 if ( GetGame().IsServer() && GetGame().IsMultiplayer() )
396 {
397 Param5<float, float, float, float, bool> debug_stats = new Param5<float, float, float, float, bool>( m_GeneralBonusBefore, m_GeneralBonusAfter, m_LastUAValue, m_CoolDownValue, m_IsCoolDown );
398 GetGame().RPCSingleParam( m_Player, ERPCs.RPC_SOFT_SKILLS_STATS_SYNC, debug_stats, true, m_Player.GetIdentity() );
399 }
400 }
401
402 // ----------------------------------------------------------------------------------------
403 void SetIsDebug( bool is_debug )
404 {
405 m_IsDebugMode = is_debug;
406 }
407
408 // ----------------------------------------------------------------------------------------
409 bool IsDebug()
410 {
411 return m_IsDebugMode;
412 }
413
414 // ----------------------------------------------------------------------------------------
415 void SetCoolDownValue( float cooldown_value )
416 {
417 m_CoolDownValue = cooldown_value;
418 }
419
420 // ----------------------------------------------------------------------------------------
422 {
423 return m_CoolDownValue;
424 }
425
426 // ----------------------------------------------------------------------------------------
428 {
429 return m_LastUAValue;
430 }
431
432 // ----------------------------------------------------------------------------------------
433 void SetLastUAValue( float last_ua_value )
434 {
435 m_LastUAValue = last_ua_value;
436 }
437
438 // ----------------------------------------------------------------------------------------
439 void SetBonusBefore( bool is_cacomponent, float base_value)
440 {
441 if ( IsDebug() )
442 {
443 if ( is_cacomponent )
444 {
445 SetComponentBonusBefore(base_value);
446 }
447 else
448 {
449 SetGeneralBonusBefore(base_value);
450 }
451 }
452 }
453
454 // ----------------------------------------------------------------------------------------
455 void SetBonusAfter( bool is_cacomponent, float adjusted_value )
456 {
457 if ( IsDebug() )
458 {
459 if ( is_cacomponent )
460 {
461 SetComponentBonusAfter(adjusted_value);
462 }
463 else
464 {
465 SetGeneralBonusAfter(adjusted_value);
466 }
467 }
468 }
469
470 // ----------------------------------------------------------------------------------------
472 {
474 }
475
476 // ----------------------------------------------------------------------------------------
477 void SetComponentBonusBefore( float component_bonus_before )
478 {
479 m_ComponentBonusBefore = component_bonus_before;
480 }
481
482 // ----------------------------------------------------------------------------------------
484 {
486 }
487
488 // ----------------------------------------------------------------------------------------
489 void SetComponentBonusAfter( float component_bonus_after )
490 {
491 m_ComponentBonusAfter = component_bonus_after;
492 }
493
494 // ----------------------------------------------------------------------------------------
496 {
498 }
499
500 // ----------------------------------------------------------------------------------------
501 void SetGeneralBonusBefore( float general_bonus_before )
502 {
503 m_GeneralBonusBefore = general_bonus_before;
504 }
505
506 // ----------------------------------------------------------------------------------------
508 {
509 return m_GeneralBonusAfter;
510 }
511
512 // ----------------------------------------------------------------------------------------
513 void SetGeneralBonusAfter( float general_bonus_after )
514 {
515 m_GeneralBonusAfter = general_bonus_after;
516 }
517
518 // ----------------------------------------------------------------------------------------
520 {
521 SetIsDebug( true );
522 m_SynchTimer = new Timer;
523 m_SynchTimer.Run( 2, this, "SynchDebugStats", NULL, true );
524 }
525
526 // ----------------------------------------------------------------------------------------
528 {
529 SetIsDebug( false );
530
531 if ( m_SynchTimer )
532 {
533 m_SynchTimer.Stop();
534 delete m_SynchTimer;
535 }
536 }
537
538 // ----------------------------------------------------------------------------------------
551}
552
553// ----------------------------------------------------------------------------------------
554// SoftSkillManagerDebug
555// ----------------------------------------------------------------------------------------
556
558{
561 TextWidget SpecialtyTotal;
562 TextWidget SpecialtyChange;
567 TextWidget CoolDown;
568 TextWidget IsCoolDown;
569
570 void SoftSkillManagerDebug( SoftSkillsManager softskill_manager )
571 {
572 m_SoftSkillManager = softskill_manager;
573 m_PanelSoftSkills = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_hud_debug_softskills.layout");
574
575 GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Insert(this.OnUpdate);
576
577 Class.CastTo(SpecialtyTotal, m_PanelSoftSkills.FindWidget("SpecialtyTotal"));
578 Class.CastTo(SpecialtyChange, m_PanelSoftSkills.FindWidget("SpecialtyChange"));
579 Class.CastTo(ComponentBonusBefore, m_PanelSoftSkills.FindWidget("ComponentBonusBefore"));
580 Class.CastTo(ComponentBonusAfter, m_PanelSoftSkills.FindWidget("ComponentBonusAfter"));
581 Class.CastTo(GeneralBonusBefore, m_PanelSoftSkills.FindWidget("GeneralBonusBefore"));
582 Class.CastTo(GeneralBonusAfter, m_PanelSoftSkills.FindWidget("GeneralBonusAfter"));
583 Class.CastTo(CoolDown, m_PanelSoftSkills.FindWidget("CoolDown"));
584 Class.CastTo(IsCoolDown, m_PanelSoftSkills.FindWidget("IsCoolDown"));
585
586 m_PanelSoftSkills.Show( true );
587 SpecialtyTotal.Show( true );
588 SpecialtyChange.Show( true );
589 ComponentBonusBefore.Show( true );
590 ComponentBonusAfter.Show( true );
591 GeneralBonusBefore.Show( true );
592 GeneralBonusAfter.Show( true );
593 CoolDown.Show( true );
594 IsCoolDown.Show( true );
595 }
596
598 {
599 if ( GetGame() )
600 {
601 GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnUpdate);
602 }
603
604 delete m_PanelSoftSkills;
605 }
606
611
612 void OnUpdate()
613 {
614 if ( GetActiveSoftSkillManager().GetSoftSkillsPlayer().IsAlive() )
615 {
616 float speciality = GetActiveSoftSkillManager().GetSpecialtyLevel();
617 speciality = speciality * 100;
618 speciality = Math.Round( speciality );
619 speciality = speciality * 0.01;
620
621 SpecialtyTotal.SetText( "Specialty level: " + speciality.ToString() );
622 SpecialtyChange.SetText( "Specialty change: " + GetActiveSoftSkillManager().GetLastUAValue() );
623 ComponentBonusBefore.SetText( "Component/craft default: " + GetActiveSoftSkillManager().GetComponentBonusBefore() );
624 ComponentBonusAfter.SetText( "Component/craft with bonus: " + GetActiveSoftSkillManager().GetComponentBonusAfter() );
625 GeneralBonusBefore.SetText( "General default: " + GetActiveSoftSkillManager().GetGeneralBonusBefore() );
626 GeneralBonusAfter.SetText( "General with bonus: " + GetActiveSoftSkillManager().GetGeneralBonusAfter() );
627 CoolDown.SetText( "CoolDown value: " + GetActiveSoftSkillManager().GetCoolDownValue() );
628 IsCoolDown.SetText( "Cooldown active: " + GetActiveSoftSkillManager().IsCoolDown() );
629 }
630 else
631 {
632 delete this;
633 }
634 }
635
636}
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)
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
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