analyticsmanagerclient.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. class AnalyticsManagerClient
  2. {
  3. static const int GEAR_COUNT = 3;
  4. static string m_FullGear[GEAR_COUNT] = {"Shoulder","Melee","Back"};
  5. void RegisterEvents()
  6. {
  7. ClientData.SyncEvent_OnEntityKilled.Insert(Event_OnEntityKilled);
  8. ClientData.SyncEvent_OnPlayerIgnitedFireplace.Insert(Event_OnPlayerIgnitedFireplace);
  9. }
  10. void UnregisterEvents()
  11. {
  12. ClientData.SyncEvent_OnEntityKilled.Remove(Event_OnEntityKilled);
  13. ClientData.SyncEvent_OnPlayerIgnitedFireplace.Remove(Event_OnPlayerIgnitedFireplace);
  14. }
  15. //===================================
  16. // OnActionEat
  17. //===================================
  18. void OnActionEat()
  19. {
  20. Achievements.OnActionEat();
  21. }
  22. //===================================
  23. // OnActionDrink
  24. //===================================
  25. void OnActionDrink()
  26. {
  27. Achievements.OnActionDrink();
  28. }
  29. //===================================
  30. // OnActionCookedSteak - not implemented
  31. //===================================
  32. void OnActionCookedSteak()
  33. {
  34. Achievements.OnCookedSteak();
  35. }
  36. //===================================
  37. // OnActionFinishedShaveSelf
  38. //===================================
  39. void OnActionFinishedShaveSelf()
  40. {
  41. Achievements.OnActionShave();
  42. }
  43. //===================================
  44. // OnActionFinishedGutDeer
  45. //===================================
  46. void OnActionFinishedGutDeer()
  47. {
  48. Achievements.OnActionGutDeer();
  49. }
  50. //===================================
  51. // OnActionRestrain
  52. //===================================
  53. void OnActionRestrain()
  54. {
  55. Achievements.OnActionHandcuff();
  56. }
  57. //===================================
  58. // OnActionBandageTarget
  59. //===================================
  60. void OnActionBandageTarget()
  61. {
  62. Achievements.OnActionMedsSurvivor();
  63. }
  64. //===================================
  65. // OnItemAttachedAtPlayer
  66. //===================================
  67. void OnItemAttachedAtPlayer(EntityAI item, string slot_name)
  68. {
  69. bool weapon_present;
  70. bool melee_present;
  71. bool backpack_present;
  72. HumanInventory inventory;
  73. if ( GetDayZGame().GetGameState() != DayZGameState.IN_GAME )
  74. {
  75. return;
  76. }
  77. Man player = GetGame().GetPlayer();
  78. if (!player)
  79. {
  80. return;
  81. }
  82. inventory = player.GetHumanInventory();
  83. if ( player && inventory )
  84. {
  85. for ( int i = 0; i < GEAR_COUNT; ++i )
  86. {
  87. int slot_id = InventorySlots.GetSlotIdFromString(m_FullGear[i]);
  88. EntityAI att_item = inventory.FindAttachment( slot_id ); // Boris V [27.2.2019]: Consider using player.GetItemOnSlot(m_FullGear[i]) instead.
  89. if ( !att_item )
  90. {
  91. //Print("index: "+ i +" slot_id: "+ slot_id +" = "+ att_item + " EMPTY");
  92. continue;
  93. }
  94. //checks for firearm
  95. if (att_item.IsWeapon())
  96. weapon_present = true;
  97. //checks for melee weapon
  98. else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Melee")))
  99. melee_present = true;
  100. //checks for backpack
  101. else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Back")))
  102. backpack_present = true;
  103. //Print("index: "+ i +" slot_id: "+ slot_id +" = "+ att_item + " ATTACHED");
  104. }
  105. //separate check for hand slot; TODO remove duplicates
  106. att_item = inventory.GetEntityInHands();
  107. if ( att_item )
  108. {
  109. //checks for firearm
  110. if (att_item.IsWeapon())
  111. weapon_present = true;
  112. //checks for melee weapon
  113. else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Melee")) )
  114. melee_present = true;
  115. //checks for backpack
  116. else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Back")))
  117. backpack_present = true;
  118. }
  119. if (weapon_present && melee_present && backpack_present)
  120. {
  121. //Print("---EAchievementActionId.ACTION_EQUIP_GEAR");
  122. Achievements.OnEquippedFullGear();
  123. }
  124. }
  125. }
  126. //===================================
  127. // Event_OnPlayerIgnitedFireplace
  128. //===================================
  129. void Event_OnPlayerIgnitedFireplace( EFireIgniteType ignite_type )
  130. {
  131. switch ( ignite_type )
  132. {
  133. case EFireIgniteType.Matchbox:
  134. {
  135. Achievements.OnActionIgniteMatchbox();
  136. break;
  137. }
  138. case EFireIgniteType.Roadflare:
  139. {
  140. Achievements.OnActionIgniteRoadflare();
  141. break;
  142. }
  143. case EFireIgniteType.HandDrill:
  144. {
  145. Achievements.OnActionIgniteDrill();
  146. break;
  147. }
  148. }
  149. }
  150. //===================================
  151. // Event_OnEntityKilled
  152. //===================================
  153. void Event_OnEntityKilled(EntityAI victim, EntityAI killer, EntityAI source, bool is_headshot)
  154. {
  155. if ( killer != null && killer.IsPlayer() && killer.GetID() == GetGame().GetPlayer().GetID() )
  156. {
  157. Achievements.OnPlayerKilled(victim, killer, source, is_headshot);
  158. }
  159. }
  160. }