Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
transfervalues.c
Go to the documentation of this file.
1class TransferValues extends Managed
2{
3 const int TYPE_HEALTH = 1;
4 const int TYPE_BLOOD = 2;
5
6 const float VALUE_CHECK_INTERVAL = 5;
7 const float SENSITIVTY_PERCENTAGE = 1;//how much the value needs to change up/down from previous update to trigger a new update(in percent)
8
9 const int BLOOD_THRESHOLD_LOW = 3000;
12
14 float m_LastBloodUpdate;
15
16 //float m_CumulatedHealthDiff;
17 //float m_CumulatedBloodDiff;
18
19 float m_HealthMaxValue;
20 float m_BloodMaxValue;
21
22 float m_BloodClient;
23 float m_HealthClient;
24
25 protected bool m_InitialSyncSent;
26
28 {
29 m_Player = player;
30 m_InitialSyncSent = false;
31 Init();
32 }
33
34 void Init()
35 {
37 m_LastBloodUpdate = 0;
38 m_HealthMaxValue = m_Player.GetMaxHealth("", "Health");
39 m_BloodMaxValue = m_Player.GetMaxHealth("", "Blood");
40 m_BloodClient = 0;
41 m_HealthClient = 0;
42 }
43
44 void OnScheduledTick(float deltatime)
45 {
46 #ifdef DIAG_DEVELOPER
47 #ifndef SERVER
48 ShowDebugValues(DiagMenu.GetBool(DiagMenuIDs.TRANSFER_VALUES_SHOW));
49 #endif
50 #endif
51
52 if ( GetGame().IsClient() ) return;
53
54 m_TimeSinceLastTick += deltatime;
55
56 if (!m_InitialSyncSent)
57 {
59 }
61 {
62 /*
63 Print(m_TimeSinceLastTick.ToString());
64 Print(VALUE_CHECK_INTERVAL.ToString());
65 Print("--------------");
66 */
69
70 // send sync junctures if necessary
71 // TODO: !!!! event is sent too often, please fix it
72 /*
73 float damage = 1 - m_Player.GetHealth("", "") / 100;
74 DayZPlayerSyncJunctures.SendInjury(m_Player, true, damage);
75 */
76 }
77 }
78
80 {
82 CheckBlood();
83 }
84
85 float GetBlood()
86 {
87 return m_BloodClient;
88
89 }
90
91 float GetHealth()
92 {
93 return m_HealthClient;
94 }
95
97 {
98 float health_current = m_Player.GetHealth("","Health");
99 float health_normalized = health_current / m_HealthMaxValue;
100 float difference_normalized = health_normalized - m_LastHealthUpdate;
101 float diff_abs = Math.AbsFloat(difference_normalized);
102
103 if ( diff_abs > ( SENSITIVTY_PERCENTAGE / 100 ) )
104 {
105 SendValue(TYPE_HEALTH, health_normalized);
106 m_LastHealthUpdate = health_normalized;
107 }
108 }
109
111 {
112 float blood_current = m_Player.GetHealth("","Blood");
113 //float blood_normalized = blood_current / m_BloodMaxValue;
114 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
115 blood_normalized = Math.Clamp(blood_normalized,0,1);
116 float difference_normalized = blood_normalized - m_LastBloodUpdate;
117 float diff_abs = Math.AbsFloat(difference_normalized);
118
119 if ( diff_abs > ( SENSITIVTY_PERCENTAGE /100 ) )
120 {
121 SendValue(TYPE_BLOOD, blood_normalized);
122 m_LastBloodUpdate = blood_normalized;
123 }
124 }
125
128 {
129 m_InitialSyncSent = true;
130
131 //HP
132 float health_current = m_Player.GetHealth("","Health");
133 float health_normalized = health_current / m_HealthMaxValue;
134 SendValue(TYPE_HEALTH, health_normalized);
135 m_LastHealthUpdate = health_normalized;
136
137 //Blood
138 float blood_current = m_Player.GetHealth("","Blood");
139 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
140 blood_normalized = Math.Clamp(blood_normalized,0,1);
141 SendValue(TYPE_BLOOD, blood_normalized);
142 m_LastBloodUpdate = blood_normalized;
143 }
144
145 void SendValue(int value_type, float value)
146 {
147 CachedObjectsParams.PARAM2_INT_FLOAT.param1 = value_type;
148 CachedObjectsParams.PARAM2_INT_FLOAT.param2 = value;
149
150 GetGame().RPCSingleParam(m_Player, ERPCs.RPC_DAMAGE_VALUE_SYNC, CachedObjectsParams.PARAM2_INT_FLOAT, true, m_Player.GetIdentity());
151 }
152
153 void ReceiveValue(int value_type, float value)
154 {
155 if ( value_type == TYPE_HEALTH )
156 {
157 m_HealthClient = value;
158 }
159 else if ( value_type == TYPE_BLOOD )
160 {
161 m_BloodClient = value;
162 }
163 }
164
166 {
167 ctx.Read(CachedObjectsParams.PARAM2_INT_FLOAT);
168
169 int value_type = CachedObjectsParams.PARAM2_INT_FLOAT.param1;
170 float value = CachedObjectsParams.PARAM2_INT_FLOAT.param2;
171
172 ReceiveValue(value_type, value);
173 }
174
175 void ShowDebugValues(bool show)
176 {
177 #ifdef DIAG_DEVELOPER
178 if ( show )
179 {
180 DbgUI.BeginCleanupScope();
181 DbgUI.Begin("Values", 50, 50);
182
183 DbgUI.Text("Blood: " + m_BloodClient.ToString());
184 DbgUI.Text("Health: " + m_HealthClient.ToString());
185
186 DbgUI.End();
187 DbgUI.EndCleanupScope();
188 }
189 else
190 {
191 DbgUI.BeginCleanupScope();
192 DbgUI.Begin("Values", 50, 50);
193 DbgUI.End();
194 DbgUI.EndCleanupScope();
195 }
196 #endif
197 }
198}
Definition dbgui.c:60
TODO doc.
Definition enscript.c:118
void OnRPC(ParamsReadContext ctx)
void ShowDebugValues(bool show)
float GetBlood()
void ReceiveValue(int value_type, float value)
void CheckHealth()
void Init()
float GetHealth()
void CheckValues()
void SendValue(int value_type, float value)
void OnScheduledTick(float deltatime)
void CheckBlood()
void SendInitValues()
Sends values on object creation.
bool m_InitialSyncSent
void TransferValues(PlayerBase player)
Definition enmath.c:7
Serialization general interface. Serializer API works with:
Definition serializer.c:56
override Widget Init()
Definition dayzgame.c:127
DiagMenuIDs
Definition ediagmenuids.c:2
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
DayZPlayer m_Player
Definition hand_events.c:42
eInjuryHandlerLevels m_LastHealthUpdate
float m_HealthMaxValue
const float SENSITIVTY_PERCENTAGE
enum eInjuryHandlerLevels VALUE_CHECK_INTERVAL
float m_TimeSinceLastTick