Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
corpsedata.c
Go to the documentation of this file.
1 class CorpseData
2 {
3  const int GET_LIFETIME_TRIES_MAX = 3;
4 
5  bool m_bUpdate;
6  int m_iLastUpdateTime;
7  int m_iTimeOfDeath;
8  int m_iMaxLifetime;
9  int m_iCorpseState;
10  int m_iTriesToGetLifetime;
11  PlayerBase m_Player;
12 
13  void CorpseData(notnull PlayerBase player,int time_of_death)
14  {
15  m_bUpdate = true;
16  m_iLastUpdateTime = time_of_death;
17  m_iTimeOfDeath = time_of_death;
18  m_iMaxLifetime = -1;
19  //m_iMaxLifetime = player.GetLifetime(); //player.GetEconomyProfile().GetLifetime();
20  m_iCorpseState = PlayerConstants.CORPSE_STATE_FRESH;
21  m_Player = player;
22  m_iTriesToGetLifetime = 0;
23 
24  /*Print("CorpseData init value | player.GetLifetime(): " + player.GetLifetime() );
25  Print("CorpseData init value | player.GetEconomyProfile().GetLifetime(): " + player.GetEconomyProfile().GetLifetime() );
26  Print("---------------------");*/
27  }
28 
29  void UpdateCorpseState(bool force_check = false)
30  {
31  /*Print("CorpseData update value | player.GetLifetime(): " + m_Player.GetLifetime() );
32  Print("CorpseData update value | player.GetEconomyProfile().GetLifetime(): " + m_Player.GetEconomyProfile().GetLifetime() );
33  Print("---------------------");*/
34 
35  if (m_iMaxLifetime <= 0 )
36  {
37  if ( m_iCorpseState == PlayerConstants.CORPSE_STATE_DECAYED && !force_check )
38  {
39  m_bUpdate = false;
40  return;
41  }
42  else
43  {
44  m_iMaxLifetime = m_Player.GetLifetime();
45  if (m_iMaxLifetime <= 0) //cleanup time not initialized yet!
46  {
47  m_iTriesToGetLifetime++;
48  m_iMaxLifetime = -1;
49  if (m_iTriesToGetLifetime >= GET_LIFETIME_TRIES_MAX)
50  {
51  m_bUpdate = false;
52  }
53 
54  return;
55  }
56  m_iMaxLifetime -= 30 * m_iTriesToGetLifetime; //adjusts for failed init attempts
57  m_Player.SetLifetime(m_iMaxLifetime);
58  }
59  }
60 
61  int ioriginal_state = m_iCorpseState;
62  float fremaining_lifetime = m_Player.GetLifetime();
63  float fdecay_percentage = fremaining_lifetime/m_iMaxLifetime;
64 
65  #ifdef DIAG_DEVELOPER
66  float timeAccel = 1;
67  if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.FOOD_DECAY))
68  {
69  timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
70  float percetElapsed = 1-fdecay_percentage;
71  fdecay_percentage = Math.Clamp(1 - percetElapsed * timeAccel,0,1);
72  }
73  #endif
74 
75  //int current_time = GetGame().GetTime();
76  //float fdecay_percentage_by_game_time = 1 - ((current_time - m_iTimeOfDeath) / 1000 )/m_iMaxLifetime;
77  //Print("fdecay_percentage_by_game_time - " + fdecay_percentage_by_game_time);
78 
79  if (fdecay_percentage > PlayerConstants.CORPSE_THRESHOLD_MEDIUM)
80  {
81  m_iCorpseState = PlayerConstants.CORPSE_STATE_FRESH;
82  }
83  else if (fdecay_percentage <= PlayerConstants.CORPSE_THRESHOLD_MEDIUM && fdecay_percentage > PlayerConstants.CORPSE_THRESHOLD_DECAYED)
84  {
85  m_iCorpseState = PlayerConstants.CORPSE_STATE_MEDIUM;
86  }
87  else
88  {
89  m_iCorpseState = PlayerConstants.CORPSE_STATE_DECAYED;
90  m_bUpdate = false;
91  }
92 
93  if (ioriginal_state != m_iCorpseState)
94  {
95  m_Player.m_CorpseState = m_iCorpseState;
96  m_Player.SetSynchDirty();
97 /*
98  Print("Corpse Syncing | player - " + m_Player);
99  Print("Corpse Syncing | state - " + m_iCorpseState);
100 */
101  }
102  }
103 }
CorpseData
Definition: corpsedata.c:1
PlayerBase
Definition: playerbaseclient.c:1
PlayerConstants
Definition: playerconstants.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
Math
Definition: enmath.c:6