File size: 4,814 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
class AnalyticsManagerClient
{
	static const int GEAR_COUNT = 3; 
	static string m_FullGear[GEAR_COUNT] = {"Shoulder","Melee","Back"};
	
	void RegisterEvents()
	{
		ClientData.SyncEvent_OnEntityKilled.Insert(Event_OnEntityKilled);
		ClientData.SyncEvent_OnPlayerIgnitedFireplace.Insert(Event_OnPlayerIgnitedFireplace);
	}
	
	void UnregisterEvents()
	{
		ClientData.SyncEvent_OnEntityKilled.Remove(Event_OnEntityKilled);
		ClientData.SyncEvent_OnPlayerIgnitedFireplace.Remove(Event_OnPlayerIgnitedFireplace);
	}
	
	//===================================
	// OnActionEat
	//===================================
	void OnActionEat()
	{
		Achievements.OnActionEat();
	}
	
	//===================================
	// OnActionDrink
	//===================================
	void OnActionDrink()
	{
		Achievements.OnActionDrink();
	}
	
	//===================================
	// OnActionCookedSteak - not implemented
	//===================================
	void OnActionCookedSteak()
	{
		Achievements.OnCookedSteak();
	}
	
	//===================================
	// OnActionFinishedShaveSelf
	//===================================
	void OnActionFinishedShaveSelf()
	{
		Achievements.OnActionShave();
	}
	
	//===================================
	// OnActionFinishedGutDeer
	//===================================
	void OnActionFinishedGutDeer()
	{
		Achievements.OnActionGutDeer();
	}
	
	//===================================
	// OnActionRestrain
	//===================================
	void OnActionRestrain()
	{		
		Achievements.OnActionHandcuff();
	}
	
	//===================================
	// OnActionBandageTarget
	//===================================
	void OnActionBandageTarget()
	{	
		Achievements.OnActionMedsSurvivor();
	}
	
	//===================================
	// OnItemAttachedAtPlayer
	//===================================
	void OnItemAttachedAtPlayer(EntityAI item, string slot_name)
	{
		bool weapon_present;
		bool melee_present;
		bool backpack_present;
		HumanInventory inventory;

		if ( GetDayZGame().GetGameState() != DayZGameState.IN_GAME )
		{
			return;
		}
		
		Man player = GetGame().GetPlayer();
		if (!player)
		{
			return;
		}
		
		inventory = player.GetHumanInventory();
			
		if ( player && inventory )
		{
			for ( int i = 0; i < GEAR_COUNT; ++i )
			{
				int slot_id = InventorySlots.GetSlotIdFromString(m_FullGear[i]);
				EntityAI att_item = inventory.FindAttachment( slot_id ); // Boris V [27.2.2019]: Consider using player.GetItemOnSlot(m_FullGear[i]) instead.
					
				if ( !att_item )
				{
					//Print("index: "+ i +" slot_id: "+ slot_id +" = "+ att_item + " EMPTY");
					continue;
				}
				
				//checks for firearm
				if (att_item.IsWeapon())
					weapon_present = true;
				//checks for melee weapon
				else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Melee")))
					melee_present = true;
				//checks for backpack
				else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Back")))
					backpack_present = true;
				//Print("index: "+ i +" slot_id: "+ slot_id +" = "+ att_item + " ATTACHED");
			}
				
			//separate check for hand slot; TODO remove duplicates
			att_item = inventory.GetEntityInHands();
			if ( att_item )
			{
				//checks for firearm
				if (att_item.IsWeapon())
					weapon_present = true;
				//checks for melee weapon
				else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Melee")) )
					melee_present = true;
				//checks for backpack
				else if (!att_item.IsWeapon() && att_item.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString("Back")))
					backpack_present = true;
			}
				
			if (weapon_present && melee_present && backpack_present)
			{
				//Print("---EAchievementActionId.ACTION_EQUIP_GEAR");
				Achievements.OnEquippedFullGear();
			}
		}
	}
	
	//===================================
	// Event_OnPlayerIgnitedFireplace
	//===================================
	void Event_OnPlayerIgnitedFireplace( EFireIgniteType ignite_type )
	{
		switch ( ignite_type )
		{
			case EFireIgniteType.Matchbox:
			{
				Achievements.OnActionIgniteMatchbox();
				break;
			}
			case EFireIgniteType.Roadflare:
			{
				Achievements.OnActionIgniteRoadflare();
				break;
			}
			case EFireIgniteType.HandDrill:
			{
				Achievements.OnActionIgniteDrill();
				break;
			}
		}
	}
	
	//===================================
	// Event_OnEntityKilled
	//===================================
	void Event_OnEntityKilled(EntityAI victim, EntityAI killer, EntityAI source, bool is_headshot)
	{
		if ( killer != null && killer.IsPlayer() && killer.GetID() == GetGame().GetPlayer().GetID() )
		{
			Achievements.OnPlayerKilled(victim, killer, source, is_headshot);
		}
	}
}