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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
class IntroSceneCharacter extends Managed
{
	protected int			m_CharacterId;
	protected string		m_CharacterType;
	protected MenuData		m_CharacterDta;
	protected PlayerBase	m_CharacterObj;
	protected vector		m_CharacterPos;
	protected vector		m_CharacterRot;
		
	protected ref TStringArray 	m_CharGenderList				= new TStringArray;
	protected ref TStringArray	m_CharShirtList					= new TStringArray; //legacy
	protected ref TStringArray 	m_CharPantsList					= new TStringArray; //legacy
	protected ref TStringArray	m_CharShoesList					= new TStringArray; //legacy
	
	protected ref map<ECharGender, ref array<string>> m_Characters = new map<ECharGender, ref array<string>>;
	
	protected ECharGender		m_CharGender;
	
	void IntroSceneCharacter()
	{
		m_CharacterId = GameConstants.DEFAULT_CHARACTER_MENU_ID;
	}
	
	void ~IntroSceneCharacter()
	{
		CharacterUnload();
	}
	
	bool IsDefaultCharacter()
	{
		return m_CharacterId == GameConstants.DEFAULT_CHARACTER_MENU_ID;
	}
	
	void SetToDefaultCharacter()
	{
		m_CharacterId = GameConstants.DEFAULT_CHARACTER_MENU_ID;
	}
	//==============================================
	// SetcharacterID
	//==============================================
	void SetCharacterID(int char_id)
	{
		m_CharacterId = char_id;
	}
	
	//==============================================
	// GetCharacterID
	//==============================================
	int GetCharacterID()
	{
		return m_CharacterId;
	}
	
	//==============================================
	// GetCharacterObj
	//==============================================
	PlayerBase GetCharacterObj()
	{
		return m_CharacterObj;
	}
	
	//==============================================
	// GetCharGenderList	
	//==============================================
	TStringArray GetCharGenderList()
	{
		return m_CharGenderList;
	}
	
	//==============================================
	// GetCharGenderList	
	//==============================================
	TStringArray GetCharList(ECharGender gender)
	{
		return m_Characters[gender];
	}
	
	//==============================================
	// GetCharShirtsList
	//==============================================
	TStringArray GetCharShirtsList()
	{
		return m_CharShirtList;
	}
	
	//==============================================
	// GetCharPantsList
	//==============================================
	TStringArray GetCharPantsList()
	{
		return m_CharPantsList;
	}
	
	//==============================================
	// GetCharShoesList
	//==============================================
	TStringArray GetCharShoesList()
	{
		return m_CharShoesList;
	}
	
	//==============================================
	// SetCharacterGender
	//==============================================
	void SetCharacterGender(ECharGender gender)
	{
		m_CharGender = gender;
	}
	
	//==============================================
	// IsCharacterFemale
	//==============================================
	bool IsCharacterFemale()
	{
		return ( m_CharGender == ECharGender.Female );
	}
	
	//==============================================
	// SetCharacterGender
	//==============================================
	ECharGender GetCharacterGender()
	{
		return m_CharGender;
	}
	
	//==============================================
	// GetPosition
	//==============================================
	vector GetPosition()
	{
		return m_CharacterObj.GetPosition();
	}
	
	//==============================================
	// GetNextCharacterID
	//==============================================
	int GetNextCharacterID()
	{
		int count = m_CharacterDta.GetCharactersCount();
		
		if ( count == 0 )
		{	
			return -1;
		}
		
		if ( m_CharacterId + 1 < count )
		{
			return m_CharacterId + 1;
		}
		else
		{
			return -1;
		}
	}
	
	//==============================================
	// GetPrevCharacterID
	//==============================================
	int GetPrevCharacterID()
	{
		int count = m_CharacterDta.GetCharactersCount();
		
		if ( count == 0 )
		{
			return -1;
		}
		
		if ( m_CharacterId > -1 )
		{
			return m_CharacterId - 1;
		}
		
		return count - 1;
	}
	
	//==============================================
	// CreateNewCharacterRandom
	//==============================================
	void CreateNewCharacterRandom()
	{
		// Select random gender
		SetCharacterGender( Math.RandomInt(0, 2) );
		
		// Select random character skin (class name)
		string char_name_random = m_Characters[GetCharacterGender()].GetRandomElement();
		
		// Create new character
		CreateNewCharacterByName( char_name_random );
	}
	
	//==============================================
	// CreateNewCharacterById
	//==============================================
	void CreateNewCharacterById( int character_id )
	{
		if ( character_id == GameConstants.DEFAULT_CHARACTER_MENU_ID )
		{
			CreateDefaultCharacter();
		}
		else
		{
			CharacterLoad( character_id, m_CharacterPos, m_CharacterRot );
		}
	}
	
	//==============================================
	// CreateNewCharacterByName
	//==============================================
	void CreateNewCharacterByName( string character_name, bool randomize_equip = true )
	{
		m_CharacterType = character_name;
		GetGame().GetMenuDefaultCharacterData().SetCharacterType(m_CharacterType);
		if (randomize_equip)
			GetGame().GetMenuDefaultCharacterData().GenerateRandomEquip();
		
		CreateNewCharacter();
	}
	
	void CreateDefaultCharacter()
	{
		CharacterUnload();
		//m_CharacterDta.RequestGetDefaultCharacterData();
		m_CharacterType = GetGame().GetMenuDefaultCharacterData().GetCharacterType();
		if (m_CharacterType != "")
		{
			CreateNewCharacter();
		}
		
		if(m_CharacterObj)
		{
			m_CharacterObj.PlaceOnSurface();
			m_CharacterObj.SetPosition(m_CharacterPos);
			m_CharacterObj.SetOrientation(m_CharacterRot);
		}
		else
		{
			string default_name = Widget.TranslateString( GameConstants.DEFAULT_CHARACTER_NAME );
			CreateNewCharacterRandom();
			//m_CharacterDta.SetCharacterName(GameConstants.DEFAULT_CHARACTER_MENU_ID, default_name);
			GetGame().GetMenuDefaultCharacterData().SetCharacterName(GameConstants.DEFAULT_CHARACTER_NAME);
		}
	}
	
	void GetLastPlayedServer(int characterID, out string address, out string name, out int port)
	{
		m_CharacterDta.GetLastServerAddress(characterID,address);
		port = m_CharacterDta.GetLastServerPort(characterID);
		m_CharacterDta.GetLastServerName(characterID,name);
	}
	//==============================================
	// CreateNewCharacter
	//==============================================
	void CreateNewCharacter()
	{
		// Unload old character (if exist)
		CharacterUnload();
		
		// Create Character
		m_CharacterObj = PlayerBase.Cast(g_Game.CreateObjectEx(m_CharacterType, m_CharacterPos, ECE_PLACE_ON_SURFACE));
		
		if (m_CharacterObj)
		{
			m_CharacterObj.PlaceOnSurface();
			m_CharacterObj.SetOrientation(m_CharacterRot);
			GetGame().GetMenuDefaultCharacterData().EquipDefaultCharacter(m_CharacterObj);
		}
		
		//Create New Random Character
		SetupPlayerName( true );
	}
	
	//! Generates random equip for the new IntroSceneCharacter, whatever is defined in 'cfgCharacterCreation'
	/*void EquipNewCharacter()
	{
		int slot_ID;
		string attachment_type;
		for (int i = 0; i < DefaultCharacterCreationMethods.GetAttachmentSlotsArray().Count(); i++)
		{
			slot_ID = DefaultCharacterCreationMethods.GetAttachmentSlotsArray().Get(i);
			if (DefaultCharacterCreationMethods.GetConfigArrayCountFromSlotID(slot_ID) > 0)
			{
				attachment_type = DefaultCharacterCreationMethods.GetConfigAttachmentTypes(slot_ID).GetRandomElement();
				if (attachment_type != "")
					SetAttachment(attachment_type,slot_ID);
			}
		}
	}*/
	
	//==============================================
	// LoadCharacterData
	//==============================================
	void LoadCharacterData(vector char_pos, vector char_rot, bool default_char = false)
	{
		m_CharacterDta = g_Game.GetMenuData();
		m_CharacterPos = char_pos;
		m_CharacterRot = char_rot;
		
		if (!default_char && m_CharacterDta.GetLastPlayedCharacter() > -1 )
		{
			m_CharacterId = m_CharacterDta.GetLastPlayedCharacter();
			m_CharacterDta.GetCharacterName(m_CharacterId, g_Game.GetPlayerGameName());
		}
		
		// Load all avalible options for character creation; mostly legacy stuff
		g_Game.ConfigGetTextArray("cfgCharacterCreation" + " gender",	m_CharGenderList);
		g_Game.ConfigGetTextArray("cfgCharacterCreation" + " top",		m_CharShirtList);
		g_Game.ConfigGetTextArray("cfgCharacterCreation" + " bottom",	m_CharPantsList);
		g_Game.ConfigGetTextArray("cfgCharacterCreation" + " shoe",		m_CharShoesList);

		// Init character table
		m_Characters.Clear();
		m_Characters.Insert( ECharGender.Male,		new array<string> );
		m_Characters.Insert( ECharGender.Female,	new array<string> );
		
		// Sort character by Gender
		TStringArray characters = GetGame().ListAvailableCharacters();
		for (int i = 0; i < characters.Count(); i++)
		{
			string char_cfg_name = characters.Get(i);
			if ( GetGame().IsKindOf(char_cfg_name, "SurvivorMale_Base") )
			{
				m_Characters[ECharGender.Male].Insert( char_cfg_name );
			}
			else
			{
				m_Characters[ECharGender.Female].Insert( char_cfg_name );
			}
		}
		
		CreateNewCharacterById(m_CharacterId/*, m_CharacterPos, m_CharacterRot*/);
		
		if (GetCharacterObj() )
		{
			if ( GetCharacterObj().IsMale() )
				SetCharacterGender(ECharGender.Male);
			else
				SetCharacterGender(ECharGender.Female);
		}
	}
	
	//-------------------------
	// CharacterUnload
	//-------------------------
	protected void CharacterUnload()
	{
		if ( m_CharacterObj )
		{
			g_Game.ObjectDelete(m_CharacterObj);
			m_CharacterObj = NULL;
		}
	}

	//-------------------------
	// CharacterLoad
	//-------------------------
	protected void CharacterLoad( int character_id, vector char_pos, vector char_rot )
	{
		if ( character_id == -1 )
		{
			Error("IntroSceneCharacter->CharacterLoad: character_id = "+ character_id +" Cant Load Character!!!");
			return;
		}
		
		CharacterUnload();
		
		SetCharacterID( character_id );
				
		m_CharacterObj = PlayerBase.Cast( m_CharacterDta.CreateCharacterPerson( character_id ) );
		
		if ( m_CharacterObj )
		{
			
			m_CharacterObj.PlaceOnSurface();
			m_CharacterObj.SetPosition(char_pos);
			m_CharacterObj.SetOrientation(char_rot);	
		}	
	}
	
	//-------------------------
	// SetupPlayerName
	//-------------------------
	protected void SetupPlayerName( bool new_name )
	{
		string name = GameConstants.DEFAULT_CHARACTER_NAME;		
		
#ifdef PLATFORM_CONSOLE
		BiosUserManager user_manager = GetGame().GetUserManager();
		if( user_manager )
		{
			BiosUser user = user_manager.GetSelectedUser();
			if( user )
			{
				name = user.GetName();
			}
		}
#else
		if ( !new_name )
		{
			m_CharacterDta.GetCharacterName(m_CharacterId, name);
		}
#endif
		
		g_Game.SetPlayerGameName(name);
	}
	
	//==============================================
	// SetAttachment
	//==============================================
	void SetAttachment(string type, int slot)
	{
		if ( !m_CharacterObj )
		{
			return;
		}
		
		g_Game.ObjectDelete(m_CharacterObj.GetInventory().FindAttachment(slot));
		
		EntityAI entity = EntityAI.Cast( g_Game.CreateObjectEx(type, m_CharacterObj.GetPosition(), ECE_PLACE_ON_SURFACE) );
		
		if (entity)
		{
			m_CharacterObj.LocalTakeEntityAsAttachmentEx(entity, slot);
		}
	}
	
	string GetCharacterNameById(int char_id )
	{
		string character_name;
		if (char_id == GameConstants.DEFAULT_CHARACTER_MENU_ID)
		{
			character_name = GetGame().GetMenuDefaultCharacterData().GetCharacterName();
		}
		else
		{
			m_CharacterDta.GetCharacterName(char_id, character_name);
		}
		return character_name;
	}
	
	string GetCharacterName()
	{
		string character_name;
		if (IsDefaultCharacter())
		{
			character_name = GetGame().GetMenuDefaultCharacterData().GetCharacterName();
		}
		else
		{
			m_CharacterDta.GetCharacterName(m_CharacterId, character_name);
		}
		return character_name;
	}
	
	//==============================================
	// SaveCharName
	//==============================================
	void SaveCharName( string name )
	{
		if (IsDefaultCharacter())
		{
			GetGame().GetMenuDefaultCharacterData().SetCharacterName(name);
		}
		else
		{
			m_CharacterDta.SetCharacterName(m_CharacterId, name);
		}
		m_CharacterDta.SaveCharactersLocal();
	}
	
	//==============================================
	// SaveDefaultCharacter
	//==============================================
	void SaveDefaultCharacter()
	{
		//if (m_CharacterObj)
		{
			m_CharacterDta.RequestSetDefaultCharacterData();
		}
	}
}