File size: 6,013 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//this is instantiated on the client for both the controlled character, as well as the remote characters
class BleedingSourcesManagerRemote extends BleedingSourcesManagerBase
{
	int m_BleedingBits;
	bool m_ShowDiag;
	bool m_ShowingDiag;
	bool m_ShowingDiagDraw;
	Shape m_Point;
	bool m_EnableHitIndication = false;
	
	override protected void Init()
	{
		super.Init();
		
		if (GetGame().GetMission().GetEffectWidgets()/* && m_Player.IsControlledPlayer()*/)
		{
			Param3<bool,int,float> par = new Param3<bool,int,float>(true,0,0);
			GetGame().GetMission().GetEffectWidgets().RegisterGameplayEffectData(EffectWidgetsTypes.BLEEDING_LAYER,par);
		}
	}
	
	override protected void RegisterBleedingZoneEx(string name, int max_time, string bone = "", vector orientation = "0 0 0", vector offset = "0 0 0", float flow_modifier = 1, string particle_name = "BleedingSourceEffect", int inv_location = 0)
	{
		super.RegisterBleedingZoneEx(name,max_time,bone,orientation,offset,flow_modifier,particle_name,inv_location);
		
		if (GetGame().GetMission().GetEffectWidgets()/* && m_Player.IsControlledPlayer()*/)
		{
			Param3<bool,int,float> par = new Param3<bool,int,float>(false,m_Bit,flow_modifier);
			GetGame().GetMission().GetEffectWidgets().RegisterGameplayEffectData(EffectWidgetsTypes.BLEEDING_LAYER,par);
		}
	}
	
	void OnVariablesSynchronized(int current_bits)
	{
		if (current_bits != m_BleedingBits)
		{
			if (m_BleedingBits == 0)
			{
				m_Player.OnBleedingBegin();
			}
			OnBleedingBitsUpdate(m_BleedingBits, current_bits);
			m_BleedingBits = current_bits;
			if (m_BleedingBits == 0)
			{
				m_Player.OnBleedingEnd();
			}
		}
	}
	
	void Reload()
	{
		m_BleedingSourceZone.Clear();
		m_BitOffset = 0;
		Init();
		int bit_offset = 0;
		
		for (int i = 0; i < BIT_INT_SIZE; i++)
		{
			int bit = 1 << bit_offset;
			bit_offset++;
			if ( (bit & m_BleedingBits) != 0 )
			{
				RemoveBleedingSource(bit);
				AddBleedingSource(bit);
			}
		}
	}
	
	
	override protected void AddBleedingSource(int bit)
	{
		super.AddBleedingSource(bit);
		if (GetGame().IsMultiplayer())
			m_Player.OnBleedingSourceAdded();
	}
	
	override protected bool RemoveBleedingSource(int bit)
	{
		if (super.RemoveBleedingSource(bit))
		{
			if (GetGame().IsMultiplayer())
				m_Player.OnBleedingSourceRemovedEx(m_Item);
			return true;
		}
		return false;
	}

	void OnBleedingBitsUpdate(int old_mask, int new_mask)
	{
		for (int i = 0; i < 32; i++)
		{
			int compare_bit = 1 << i;
			int new_compare_result_bit = compare_bit & new_mask;
			int old_compare_result_bit = compare_bit & old_mask;
			
			if ( new_compare_result_bit )
			{
				if ( !(new_compare_result_bit & old_mask))
				{
					//a different active bit in the new mask
					AddBleedingSource(new_compare_result_bit);
				}
			}
			else
			{
				if ( new_compare_result_bit != old_compare_result_bit )
				{
					RemoveBleedingSource(old_compare_result_bit);
				}
			}
		}
	}
	
	int GetBleedingSourceCountRemote()
	{
		int bleeding_source_count = 0;
		int pow = 0;
		
		for (int i = 0; i < BIT_INT_SIZE ; i++)
		{
			int bit = Math.Pow(2, pow);
			pow++;
			if ( (m_BleedingBits & bit) != 0)
			{
				bleeding_source_count++;
			}
		}
		
		return bleeding_source_count;
	}
	
	void SetDiag(bool value)
	{
		m_ShowDiag = value;
		return;
		
		int boneIdx = m_Player.GetBoneIndexByName("RightArmExtra");

		if ( boneIdx != -1 )
		{
		  Object linkedObject = GetGame().CreateObject("Ammo_ArrowBolt", "0 0 0");
		
		//linkedObject.SetPosition("0 1 0");
		//linkedObject.SetOrientation("0 90 0");
		  /*
		
		  Set local space transform for linked object
		
		  */
			
			BleedingSourceEffect eff = new BleedingSourceEffect();
			eff.SetAutodestroy(true);
			SEffectManager.PlayInWorld( eff, "0 0 0" );
			Particle p = eff.GetParticle();
			//p.SetOrientation("0 90 0");
			m_Player.AddChild(p, boneIdx);
		
		 	 m_Player.AddChild(linkedObject, boneIdx);
		}
	
	}
	
	void OnUpdate()
	{
		#ifndef NO_GUI
		if (m_ShowDiag)
		{
			DisplayDebug();
			DisplayVisualDebug();
		}
		else if ( m_ShowingDiag || m_ShowingDiagDraw )
		{
			if (m_ShowingDiag)
				CleanDebug();
			if (m_ShowingDiagDraw)
				CleanVisualDebug();
		}
		#endif
	}
	
	void DisplayDebug()
	{	
		m_ShowingDiag = true;
		
		DbgUI.BeginCleanupScope();
        DbgUI.Begin("Bleeding Sources", 50, 50);
		
		int pow = 0;
		
		bool anyBleedingSourceActive = false;
		
		for (int i = 0; i < BIT_INT_SIZE ; i++)
		{
			int bit = Math.Pow(2, pow);
			pow++;
			if ( (m_BleedingBits & bit) != 0)
			{
				BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
				
				string name = GetSelectionNameFromBit(bit);
				string slot_name =  InventorySlots.GetSlotName(bsz.GetInvLocation());
				DbgUI.Text(name + "| slot name: "+ slot_name);
				anyBleedingSourceActive = true;
			}
		}
		
		if (!anyBleedingSourceActive)
		{
			DbgUI.Text("Currently no bleeding sources are active.");
		}
		
        DbgUI.End();
        DbgUI.EndCleanupScope();
	}
	
	void CleanDebug()
	{
		m_ShowingDiag = false;
		
		DbgUI.BeginCleanupScope();
		DbgUI.Begin("Bleeding Sources", 50, 50);
		DbgUI.End();
		DbgUI.EndCleanupScope();
	}
	
	void DisplayVisualDebug()
	{
		/*
		if(m_Point) 
		{
			Debug.RemoveShape(m_Point);
		}
		
		int boneIdx = m_Player.GetBoneIndexByName("LeftKneeExtra");
		int pointIdx = m_Player.GetMemoryPointIndex("lknee");
		
		vector posLS = DayZPlayerUtils.GetMemoryPointPositionBoneRelative(m_Player, boneIdx, pointIdx);
		
		vector pTm[4];
		m_Player.GetBoneTransformMS(boneIdx, pTm);
		vector posMS = posLS.Multiply4(pTm);
		
		vector pos = m_Player.ModelToWorld(posMS);
		m_Point = Debug.DrawSphere(pos, 0.1, COLOR_RED);
		*/
		
		m_ShowingDiagDraw = true;
		
		int bsCount = m_BleedingSources.Count();
		for (int i = 0; i < bsCount; ++i)
		{
			m_BleedingSources.GetElement(i).DrawDebugShape();
		}
	}
	
	void CleanVisualDebug()
	{
		m_ShowingDiagDraw = false;
		
		int bsCount = m_BleedingSources.Count();
		for (int i = 0; i < bsCount; ++i)
		{
			m_BleedingSources.GetElement(i).RemoveDebugShape();
		}
	}
}