Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
introscenecharacter.c
Go to the documentation of this file.
1 class IntroSceneCharacter extends Managed
2 {
3  protected int m_CharacterId;
4  protected string m_CharacterType;
5  protected MenuData m_CharacterDta;
6  protected PlayerBase m_CharacterObj;
7  protected vector m_CharacterPos;
8  protected vector m_CharacterRot;
9 
10  protected ref TStringArray m_CharGenderList = new TStringArray;
11  protected ref TStringArray m_CharShirtList = new TStringArray; //legacy
12  protected ref TStringArray m_CharPantsList = new TStringArray; //legacy
13  protected ref TStringArray m_CharShoesList = new TStringArray; //legacy
14 
16 
17  protected ECharGender m_CharGender;
18 
19  void IntroSceneCharacter()
20  {
21  m_CharacterId = GameConstants.DEFAULT_CHARACTER_MENU_ID;
22  }
23 
24  void ~IntroSceneCharacter()
25  {
26  CharacterUnload();
27  }
28 
29  bool IsDefaultCharacter()
30  {
31  return m_CharacterId == GameConstants.DEFAULT_CHARACTER_MENU_ID;
32  }
33 
34  void SetToDefaultCharacter()
35  {
36  m_CharacterId = GameConstants.DEFAULT_CHARACTER_MENU_ID;
37  }
38  //==============================================
39  // SetcharacterID
40  //==============================================
41  void SetCharacterID(int char_id)
42  {
43  m_CharacterId = char_id;
44  }
45 
46  //==============================================
47  // GetCharacterID
48  //==============================================
49  int GetCharacterID()
50  {
51  return m_CharacterId;
52  }
53 
54  //==============================================
55  // GetCharacterObj
56  //==============================================
57  PlayerBase GetCharacterObj()
58  {
59  return m_CharacterObj;
60  }
61 
62  //==============================================
63  // GetCharGenderList
64  //==============================================
65  TStringArray GetCharGenderList()
66  {
67  return m_CharGenderList;
68  }
69 
70  //==============================================
71  // GetCharGenderList
72  //==============================================
73  TStringArray GetCharList(ECharGender gender)
74  {
75  return m_Characters[gender];
76  }
77 
78  //==============================================
79  // GetCharShirtsList
80  //==============================================
81  TStringArray GetCharShirtsList()
82  {
83  return m_CharShirtList;
84  }
85 
86  //==============================================
87  // GetCharPantsList
88  //==============================================
89  TStringArray GetCharPantsList()
90  {
91  return m_CharPantsList;
92  }
93 
94  //==============================================
95  // GetCharShoesList
96  //==============================================
97  TStringArray GetCharShoesList()
98  {
99  return m_CharShoesList;
100  }
101 
102  //==============================================
103  // SetCharacterGender
104  //==============================================
105  void SetCharacterGender(ECharGender gender)
106  {
107  m_CharGender = gender;
108  }
109 
110  //==============================================
111  // IsCharacterFemale
112  //==============================================
113  bool IsCharacterFemale()
114  {
115  return ( m_CharGender == ECharGender.Female );
116  }
117 
118  //==============================================
119  // SetCharacterGender
120  //==============================================
121  ECharGender GetCharacterGender()
122  {
123  return m_CharGender;
124  }
125 
126  //==============================================
127  // GetPosition
128  //==============================================
130  {
131  return m_CharacterObj.GetPosition();
132  }
133 
134  //==============================================
135  // GetNextCharacterID
136  //==============================================
137  int GetNextCharacterID()
138  {
139  int count = m_CharacterDta.GetCharactersCount();
140 
141  if ( count == 0 )
142  {
143  return -1;
144  }
145 
146  if ( m_CharacterId + 1 < count )
147  {
148  return m_CharacterId + 1;
149  }
150  else
151  {
152  return -1;
153  }
154  }
155 
156  //==============================================
157  // GetPrevCharacterID
158  //==============================================
159  int GetPrevCharacterID()
160  {
161  int count = m_CharacterDta.GetCharactersCount();
162 
163  if ( count == 0 )
164  {
165  return -1;
166  }
167 
168  if ( m_CharacterId > -1 )
169  {
170  return m_CharacterId - 1;
171  }
172 
173  return count - 1;
174  }
175 
176  //==============================================
177  // CreateNewCharacterRandom
178  //==============================================
179  void CreateNewCharacterRandom()
180  {
181  // Select random gender
182  SetCharacterGender( Math.RandomInt(0, 2) );
183 
184  // Select random character skin (class name)
185  string char_name_random = m_Characters[GetCharacterGender()].GetRandomElement();
186 
187  // Create new character
188  CreateNewCharacterByName( char_name_random );
189  }
190 
191  //==============================================
192  // CreateNewCharacterById
193  //==============================================
194  void CreateNewCharacterById( int character_id )
195  {
196  if ( character_id == GameConstants.DEFAULT_CHARACTER_MENU_ID )
197  {
198  CreateDefaultCharacter();
199  }
200  else
201  {
202  CharacterLoad( character_id, m_CharacterPos, m_CharacterRot );
203  }
204  }
205 
206  //==============================================
207  // CreateNewCharacterByName
208  //==============================================
209  void CreateNewCharacterByName( string character_name, bool randomize_equip = true )
210  {
211  m_CharacterType = character_name;
212  GetGame().GetMenuDefaultCharacterData().SetCharacterType(m_CharacterType);
213  if (randomize_equip)
214  GetGame().GetMenuDefaultCharacterData().GenerateRandomEquip();
215 
216  CreateNewCharacter();
217  }
218 
219  void CreateDefaultCharacter()
220  {
221  CharacterUnload();
222  //m_CharacterDta.RequestGetDefaultCharacterData();
223  m_CharacterType = GetGame().GetMenuDefaultCharacterData().GetCharacterType();
224  if (m_CharacterType != "")
225  {
226  CreateNewCharacter();
227  }
228 
229  if(m_CharacterObj)
230  {
231  m_CharacterObj.PlaceOnSurface();
232  m_CharacterObj.SetPosition(m_CharacterPos);
233  m_CharacterObj.SetOrientation(m_CharacterRot);
234  }
235  else
236  {
237  string default_name = Widget.TranslateString( GameConstants.DEFAULT_CHARACTER_NAME );
238  CreateNewCharacterRandom();
239  //m_CharacterDta.SetCharacterName(GameConstants.DEFAULT_CHARACTER_MENU_ID, default_name);
240  GetGame().GetMenuDefaultCharacterData().SetCharacterName(GameConstants.DEFAULT_CHARACTER_NAME);
241  }
242  }
243 
244  void GetLastPlayedServer(int characterID, out string address, out string name, out int port)
245  {
246  m_CharacterDta.GetLastServerAddress(characterID,address);
247  port = m_CharacterDta.GetLastServerPort(characterID);
248  m_CharacterDta.GetLastServerName(characterID,name);
249  }
250  //==============================================
251  // CreateNewCharacter
252  //==============================================
253  void CreateNewCharacter()
254  {
255  // Unload old character (if exist)
256  CharacterUnload();
257 
258  // Create Character
259  m_CharacterObj = PlayerBase.Cast(g_Game.CreateObjectEx(m_CharacterType, m_CharacterPos, ECE_PLACE_ON_SURFACE));
260 
261  if (m_CharacterObj)
262  {
263  m_CharacterObj.PlaceOnSurface();
264  m_CharacterObj.SetOrientation(m_CharacterRot);
265  GetGame().GetMenuDefaultCharacterData().EquipDefaultCharacter(m_CharacterObj);
266  }
267 
268  //Create New Random Character
269  SetupPlayerName( true );
270  }
271 
273  /*void EquipNewCharacter()
274  {
275  int slot_ID;
276  string attachment_type;
277  for (int i = 0; i < DefaultCharacterCreationMethods.GetAttachmentSlotsArray().Count(); i++)
278  {
279  slot_ID = DefaultCharacterCreationMethods.GetAttachmentSlotsArray().Get(i);
280  if (DefaultCharacterCreationMethods.GetConfigArrayCountFromSlotID(slot_ID) > 0)
281  {
282  attachment_type = DefaultCharacterCreationMethods.GetConfigAttachmentTypes(slot_ID).GetRandomElement();
283  if (attachment_type != "")
284  SetAttachment(attachment_type,slot_ID);
285  }
286  }
287  }*/
288 
289  //==============================================
290  // LoadCharacterData
291  //==============================================
292  void LoadCharacterData(vector char_pos, vector char_rot, bool default_char = false)
293  {
294  m_CharacterDta = g_Game.GetMenuData();
295  m_CharacterPos = char_pos;
296  m_CharacterRot = char_rot;
297 
298  if (!default_char && m_CharacterDta.GetLastPlayedCharacter() > -1 )
299  {
300  m_CharacterId = m_CharacterDta.GetLastPlayedCharacter();
301  m_CharacterDta.GetCharacterName(m_CharacterId, g_Game.GetPlayerGameName());
302  }
303 
304  // Load all avalible options for character creation; mostly legacy stuff
305  g_Game.ConfigGetTextArray("cfgCharacterCreation" + " gender", m_CharGenderList);
306  g_Game.ConfigGetTextArray("cfgCharacterCreation" + " top", m_CharShirtList);
307  g_Game.ConfigGetTextArray("cfgCharacterCreation" + " bottom", m_CharPantsList);
308  g_Game.ConfigGetTextArray("cfgCharacterCreation" + " shoe", m_CharShoesList);
309 
310  // Init character table
311  m_Characters.Clear();
312  m_Characters.Insert( ECharGender.Male, new array<string> );
313  m_Characters.Insert( ECharGender.Female, new array<string> );
314 
315  // Sort character by Gender
316  TStringArray characters = GetGame().ListAvailableCharacters();
317  for (int i = 0; i < characters.Count(); i++)
318  {
319  string char_cfg_name = characters.Get(i);
320  if ( GetGame().IsKindOf(char_cfg_name, "SurvivorMale_Base") )
321  {
322  m_Characters[ECharGender.Male].Insert( char_cfg_name );
323  }
324  else
325  {
326  m_Characters[ECharGender.Female].Insert( char_cfg_name );
327  }
328  }
329 
330  CreateNewCharacterById(m_CharacterId/*, m_CharacterPos, m_CharacterRot*/);
331 
332  if (GetCharacterObj() )
333  {
334  if ( GetCharacterObj().IsMale() )
335  SetCharacterGender(ECharGender.Male);
336  else
337  SetCharacterGender(ECharGender.Female);
338  }
339  }
340 
341  //-------------------------
342  // CharacterUnload
343  //-------------------------
344  protected void CharacterUnload()
345  {
346  if ( m_CharacterObj )
347  {
348  g_Game.ObjectDelete(m_CharacterObj);
349  m_CharacterObj = NULL;
350  }
351  }
352 
353  //-------------------------
354  // CharacterLoad
355  //-------------------------
356  protected void CharacterLoad( int character_id, vector char_pos, vector char_rot )
357  {
358  if ( character_id == -1 )
359  {
360  Error("IntroSceneCharacter->CharacterLoad: character_id = "+ character_id +" Cant Load Character!!!");
361  return;
362  }
363 
364  CharacterUnload();
365 
366  SetCharacterID( character_id );
367 
368  m_CharacterObj = PlayerBase.Cast( m_CharacterDta.CreateCharacterPerson( character_id ) );
369 
370  if ( m_CharacterObj )
371  {
372 
373  m_CharacterObj.PlaceOnSurface();
374  m_CharacterObj.SetPosition(char_pos);
375  m_CharacterObj.SetOrientation(char_rot);
376  }
377  }
378 
379  //-------------------------
380  // SetupPlayerName
381  //-------------------------
382  protected void SetupPlayerName( bool new_name )
383  {
384  string name = GameConstants.DEFAULT_CHARACTER_NAME;
385 
386 #ifdef PLATFORM_CONSOLE
387  BiosUserManager user_manager = GetGame().GetUserManager();
388  if( user_manager )
389  {
390  BiosUser user = user_manager.GetSelectedUser();
391  if( user )
392  {
393  name = user.GetName();
394  }
395  }
396 #else
397  if ( !new_name )
398  {
399  m_CharacterDta.GetCharacterName(m_CharacterId, name);
400  }
401 #endif
402 
403  g_Game.SetPlayerGameName(name);
404  }
405 
406  //==============================================
407  // SetAttachment
408  //==============================================
409  void SetAttachment(string type, int slot)
410  {
411  if ( !m_CharacterObj )
412  {
413  return;
414  }
415 
416  g_Game.ObjectDelete(m_CharacterObj.GetInventory().FindAttachment(slot));
417 
418  EntityAI entity = EntityAI.Cast( g_Game.CreateObjectEx(type, m_CharacterObj.GetPosition(), ECE_PLACE_ON_SURFACE) );
419 
420  if (entity)
421  {
422  m_CharacterObj.LocalTakeEntityAsAttachmentEx(entity, slot);
423  }
424  }
425 
426  string GetCharacterNameById(int char_id )
427  {
428  string character_name;
429  if (char_id == GameConstants.DEFAULT_CHARACTER_MENU_ID)
430  {
431  character_name = GetGame().GetMenuDefaultCharacterData().GetCharacterName();
432  }
433  else
434  {
435  m_CharacterDta.GetCharacterName(char_id, character_name);
436  }
437  return character_name;
438  }
439 
440  string GetCharacterName()
441  {
442  string character_name;
443  if (IsDefaultCharacter())
444  {
445  character_name = GetGame().GetMenuDefaultCharacterData().GetCharacterName();
446  }
447  else
448  {
449  m_CharacterDta.GetCharacterName(m_CharacterId, character_name);
450  }
451  return character_name;
452  }
453 
454  //==============================================
455  // SaveCharName
456  //==============================================
457  void SaveCharName( string name )
458  {
459  if (IsDefaultCharacter())
460  {
461  GetGame().GetMenuDefaultCharacterData().SetCharacterName(name);
462  }
463  else
464  {
465  m_CharacterDta.SetCharacterName(m_CharacterId, name);
466  }
467  m_CharacterDta.SaveCharactersLocal();
468  }
469 
470  //==============================================
471  // SaveDefaultCharacter
472  //==============================================
473  void SaveDefaultCharacter()
474  {
475  //if (m_CharacterObj)
476  {
477  m_CharacterDta.RequestSetDefaultCharacterData();
478  }
479  }
480 }
GetGame
proto native CGame GetGame()
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
TStringArray
array< string > TStringArray
Definition: enscript.c:685
Managed
TODO doc.
Definition: enscript.c:117
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
ECharGender
ECharGender
Definition: echargender.c:1
BiosUserManager
Definition: biosusermanager.c:16
array< string >
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
MenuData
Definition: gameplay.c:895
GameConstants
Definition: constants.c:612
BiosUser
Definition: biosusermanager.c:8
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5