scriptanalytics.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // class binded to engine
  2. class StatsEventMeasuresData
  3. {
  4. string m_CharacterId; //!< character ID
  5. int m_TimeInterval; //!< amount of real time in seconds covered by this event
  6. int m_DaytimeHour; //!< current daytime in gameplay (hour in 24h format)
  7. vector m_PositionStart; //!< player world position at the start of interval
  8. vector m_PositionEnd; //!< player world position at the end of interval
  9. float m_DistanceOnFoot; //!< traveled distance on foot (meters) during interval
  10. float m_DistanceVehicle; //!< traveled distance (meters) in vehicle during interval
  11. float m_TimeVONIn; //!< amount of time in seconds with inbound VON during interval
  12. float m_TimeVONOut; //!< amount of time in seconds with outbound VON during interval
  13. int m_CntLootAny; //!< count of any loot collected during interval
  14. int m_CntLootFood; //!< count of any food or consumables collected during interval
  15. int m_CntLootCloth; //!< count of cloth collected during interval
  16. int m_CntLootFirearm; //!< count of firearms collected during interval
  17. int m_CntLootAmmo; //!< count of ammo collected during interval
  18. int m_CntKillInfected; //!< count of infected kills during interval
  19. int m_CntConsumedFood; //!< count of consumed food during interval
  20. int m_CntConsumedWater; //!< count of consumed water during interval
  21. int m_HealthRestored; //!< number of health point restored during interval
  22. int m_CntFiredAmmo; //!< firearm rounds fired during interval
  23. int m_CntCraftedItem; //!< number of items crafted during interval
  24. // listStatus // state metric of health, hunger, thirst, etc... when event is created/send
  25. int m_HealthStatus; //!< state of health (current state)
  26. int m_BloodStatus; //!< state of blood (current state)
  27. int m_SicknessStatus; //!< state of sickness (current state)
  28. int m_TemperatureStatus; //!< state of temperature (current state)
  29. int m_FoodStatus; //!< state of food (hunger) (current state)
  30. int m_HydrationStatus; //!< state of hydration (thirst) (current state)
  31. };
  32. // class binded to engine
  33. class StatsEventDeathData
  34. {
  35. string m_CharacterId; //!< character ID
  36. int m_CharacterLifetime; //!< lifetime of character in seconds
  37. string m_Cause; //!< cause of death (hunger, sickness, player-killed, zombie-killed...)
  38. string m_WeaponName; //!< name of weapon which caused death
  39. float m_Distance; //!< distance in meters (rounded) from spawn position to death position
  40. vector m_Position; //!< position of player when died
  41. int m_ListDamages[5]; //!< list of damages (5 values) during last n sec. For example: {20, 80, 0, 0, 0}
  42. };
  43. // class binded to engine
  44. class StatsEventScoredKillData
  45. {
  46. string m_CharacterId; //!< character ID
  47. string m_WeaponName; //!< name of weapon which killed player (victim)
  48. int m_KillDistance; //!< distance in meters (rounded) between killer and victim
  49. vector m_PositionKiller; //!< position of killer
  50. vector m_PositionVictim; //!< position of victim
  51. };
  52. // class binded to engine
  53. class StatsEventDisconnectedData
  54. {
  55. string m_CharacterId; //!< character ID
  56. string m_Reason; //!< reason of disconnect (quit, kick, ban, sign-out...)
  57. };
  58. // class binded to engine
  59. class StatsEventSpawnedData
  60. {
  61. string m_CharacterId; //!< character ID
  62. int m_Lifetime; //!< lifetime of character in seconds
  63. vector m_Position; //!< position of spawn
  64. int m_Population; //!< population of current gameplay (server)
  65. int m_DaytimeHour; //!< current time in hour (hour in 24h)
  66. };
  67. // class binded to engine
  68. class StatsEventData
  69. {
  70. void StatsEventData(string eventName)
  71. {
  72. m_eventName = eventName;
  73. m_valuesBool = new map<string, int>();
  74. m_valuesInt = new map<string, int>();
  75. m_valuesFloat = new map<string, float>();
  76. m_valuesString = new map<string, string>();
  77. m_valuesVector = new map<string, vector>();
  78. }
  79. void AddBool(string key, bool value)
  80. {
  81. m_valuesBool.Insert(key, (int)value);
  82. }
  83. void AddInt(string key, int value)
  84. {
  85. m_valuesInt.Insert(key, value);
  86. }
  87. void AddFloat(string key, float value)
  88. {
  89. m_valuesFloat.Insert(key, value);
  90. }
  91. void AddString(string key, string value)
  92. {
  93. m_valuesString.Insert(key, value);
  94. }
  95. void AddVector(string key, vector value)
  96. {
  97. m_valuesVector.Insert(key, value);
  98. }
  99. private string m_eventName;
  100. private autoptr map<string, int> m_valuesBool;//TODO: use bool instead of int (problem with engine type binding)
  101. private autoptr map<string, int> m_valuesInt;
  102. private autoptr map<string, float> m_valuesFloat;
  103. private autoptr map<string, string> m_valuesString;
  104. private autoptr map<string, vector> m_valuesVector;
  105. }
  106. class ScriptAnalytics
  107. {
  108. //! send event about death to statistic DB
  109. static proto native void SendPlayerDeath(StatsEventDeathData data);
  110. //! send event about kill to statistic DB
  111. static proto native void SendPlayerScoredKill(StatsEventScoredKillData data);
  112. //! send event to statistic DB
  113. static proto native void SendPlayerDisconnected(StatsEventDisconnectedData data);
  114. //! send event about player status to statistic DB
  115. static proto native void SendPlayerMeasures(StatsEventMeasuresData data);
  116. //! send event about spawning to statistic DB
  117. static proto native void SendPlayerSpawned(StatsEventSpawnedData data);
  118. //! universal analytics event
  119. static proto native void SendEvent(StatsEventData data);
  120. };
  121. class Analytics
  122. {
  123. // send stats data with log
  124. static void PlayerDeath(StatsEventDeathData data)
  125. {
  126. ScriptAnalytics.SendPlayerDeath(data);
  127. }
  128. // send stats data with log
  129. static void PlayerScoredKill(StatsEventScoredKillData data)
  130. {
  131. ScriptAnalytics.SendPlayerScoredKill(data);
  132. }
  133. // send stats data with log
  134. static void PlayerDisconnected(StatsEventDisconnectedData data)
  135. {
  136. ScriptAnalytics.SendPlayerDisconnected(data);
  137. }
  138. // send stats data with log
  139. static void PlayerMeasures(StatsEventMeasuresData data)
  140. {
  141. ScriptAnalytics.SendPlayerMeasures(data);
  142. }
  143. // send stats data with log
  144. static void PlayerSpawned(StatsEventSpawnedData data)
  145. {
  146. ScriptAnalytics.SendPlayerSpawned(data);
  147. }
  148. }