DayZ 1.26
DayZ Explorer by KGB
Загрузка...
Поиск...
Не найдено
Класс PlayerSpawnHandler

Закрытые статические члены

static bool LoadData ()
 
static bool IsInitialized ()
 
static PlayerSpawnPreset GetRandomCharacterPreset ()
 
static bool ProcessEquipmentData (PlayerBase player, PlayerSpawnPreset data)
 equips character with the chosen preset
 
static void ProcessSlotsEquipment (PlayerBase player, PlayerSpawnPreset data)
 iterates over each object and spawns alternatives
 
static bool SelectAndSpawnSlotEquipment (PlayerBase player, PlayerSpawnPresetSlotData slotData)
 selects weighted slot equipment variant
 
static void ProcessCargoEquipment (PlayerBase player, PlayerSpawnPreset data)
 chooses one object from the array
 
static bool SelectAndSpawnCargoSet (PlayerBase player, PlayerSpawnPreset data)
 
static bool SpawnDiscreteCargoItemSet (PlayerBase player, PlayerSpawnPresetDiscreteCargoSetData csd)
 
static bool SpawnDiscreteSlotItemSet (PlayerBase player, PlayerSpawnPresetDiscreteItemSetSlotData dis, int slotID)
 
static bool SpawnComplexChildrenItems (EntityAI parent, notnull PlayerSpawnPresetItemSetBase data)
 could spawn other items recursively. Parent item is guaranteed here.
 
static bool SpawnSimpleChildrenItems (EntityAI parent, PlayerSpawnPresetItemSetBase data)
 
static void HandleNewItem (notnull ItemBase item, PlayerSpawnPresetItemSetBase data)
 
static EntityAI CreateChildItem (EntityAI parent, string type)
 
static void ApplyAttributes (ItemBase item, PlayerSpawnAttributesData attributes)
 
static bool IsWeaponAndMagazineType (EntityAI parent, string type)
 Used for exceptions in the system.
 

Закрытые статические данные

static bool m_Initialized
 
static ref PlayerSpawnJsonData m_Data = new PlayerSpawnJsonData()
 

Подробное описание

Методы

◆ ApplyAttributes()

static void ApplyAttributes ( ItemBase item,
PlayerSpawnAttributesData attributes )
inlinestaticprivate
306 {
307 if (!attributes)
308 return;
309
310 float health01 = Math.RandomFloatInclusive(attributes.healthMin,attributes.healthMax);
311 item.SetHealth01("","Health",health01);
312
313 float quantity01 = Math.RandomFloatInclusive(attributes.quantityMin,attributes.quantityMax);
314 if (item.IsMagazine())
315 {
316 Magazine mag = Magazine.Cast(item);
317 /*if (attributes.magazineAmmoOrdered && attributes.magazineAmmoOrdered.Count() > 0)
318 {
319 mag.ServerSetAmmoCount(0);
320 foreach (string bulletType : attributes.magazineAmmoOrdered)
321 {
322 mag.ServerStoreCartridge(health01,bulletType);
323 }
324 mag.SetSynchDirty();
325 }
326 else*/
327 {
328 int ammoQuantity = (int)Math.Lerp(0,mag.GetAmmoMax(),quantity01);
329 mag.ServerSetAmmoCount(ammoQuantity);
330 }
331 }
332 else //'varQuantityDestroyOnMin' quantity safeguard
333 {
334 float quantityAbsolute = Math.Lerp(item.GetQuantityMin(),item.GetQuantityMax(),quantity01);
335 quantityAbsolute = Math.Round(quantityAbsolute); //avoids weird floats
336 if (quantityAbsolute <= item.GetQuantityMin() && item.ConfigGetBool("varQuantityDestroyOnMin"))
338 item.SetQuantity(quantityAbsolute);
339 }
340 }
Param3 int
Definition EnMath.c:7
Definition EntityAI.c:95
static proto float Round(float f)
Returns mathematical round of value.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.

Перекрестные ссылки Math::Lerp(), Math::RandomFloatInclusive() и Math::Round().

Используется в HandleNewItem() и SpawnSimpleChildrenItems().

◆ CreateChildItem()

static EntityAI CreateChildItem ( EntityAI parent,
string type )
inlinestaticprivate
272 {
275 if (Class.CastTo(player,parent)) //special behavior
276 {
277 if (Class.CastTo(newItem,player.GetInventory().CreateInInventory(type)))
278 return newItem;
279
280 Debug.Log("FAILED spawning item: " + type + ", it fits in no cargo or attachment on any worn item","n/a","n/a","CreateChildItem");
281 return null;
282 }
283
284 //weapon magazine exception
285 if (GetGame().ConfigIsExisting(CFG_MAGAZINESPATH + " " + type) && parent.IsWeapon())
286 {
288 if (Class.CastTo(wep,parent) && wep.SpawnAmmo(type) && !wep.HasInternalMagazine(-1)) //assuming weps with internal magazine don't attach external magazines
289 {
291 int muzzleCount = wep.GetMuzzleCount();
292 for (int i = 0; i < muzzleCount; i++)
293 {
294 if (Class.CastTo(mag,wep.GetMagazine(i)) && mag.GetType() == type)
295 return mag;
296 }
297 }
298
299 return null;
300 }
301
302 return parent.GetInventory().CreateInInventory(type);
303 }
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:136
Definition InventoryItem.c:731
Definition PlayerBaseClient.c:2
shorthand
Definition BoltActionRifle_Base.c:6
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const string CFG_MAGAZINESPATH
Definition constants.c:219

Перекрестные ссылки Class::CastTo(), CFG_MAGAZINESPATH, GetGame() и Debug::Log().

Используется в SpawnComplexChildrenItems() и SpawnSimpleChildrenItems().

◆ GetRandomCharacterPreset()

static PlayerSpawnPreset GetRandomCharacterPreset ( )
inlinestaticprivate
41 {
43 int count = m_Data.presets.Count();
45 for (int i = 0; i < count; i++)
46 {
47 p = m_Data.presets[i];
48 if (p.IsValid())
49 {
50 for (int j = 0; j < p.spawnWeight; j++)
51 {
53 }
54 }
55 }
56
57 return m_Data.presets.Get(weightedPresetIndexes.GetRandomElement());
58 }
static ref PlayerSpawnJsonData m_Data
Definition CfgPlayerSpawnHandler.c:4
Definition CfgPlayerSpawnDataJson.c:17

Перекрестные ссылки m_Data.

Используется в MissionBase::OnClientNewEvent().

◆ HandleNewItem()

static void HandleNewItem ( notnull ItemBase item,
PlayerSpawnPresetItemSetBase data )
inlinestaticprivate
260 {
261 ApplyAttributes(item,data.attributes);
262
264 if (Class.CastTo(player,item.GetHierarchyRootPlayer()) && data.GetQuickbarIdx() > -1)
265 player.SetQuickBarEntityShortcut(item,data.GetQuickbarIdx());
266
269 }
static bool SpawnComplexChildrenItems(EntityAI parent, notnull PlayerSpawnPresetItemSetBase data)
could spawn other items recursively. Parent item is guaranteed here.
Definition CfgPlayerSpawnHandler.c:190
static bool SpawnSimpleChildrenItems(EntityAI parent, PlayerSpawnPresetItemSetBase data)
Definition CfgPlayerSpawnHandler.c:223
static void ApplyAttributes(ItemBase item, PlayerSpawnAttributesData attributes)
Definition CfgPlayerSpawnHandler.c:305

Перекрестные ссылки ApplyAttributes(), Class::CastTo(), SpawnComplexChildrenItems() и SpawnSimpleChildrenItems().

Используется в SpawnComplexChildrenItems() и SpawnDiscreteSlotItemSet().

◆ IsInitialized()

static bool IsInitialized ( )
inlinestaticprivate
36 {
37 return m_Initialized;
38 }
static bool m_Initialized
Definition CfgPlayerSpawnHandler.c:3

Перекрестные ссылки m_Initialized.

Используется в MissionBase::OnClientNewEvent().

◆ IsWeaponAndMagazineType()

static bool IsWeaponAndMagazineType ( EntityAI parent,
string type )
inlinestaticprivate

Used for exceptions in the system.

344 {
345 return (GetGame().ConfigIsExisting(CFG_MAGAZINESPATH + " " + type) && parent.IsWeapon());
346 }

Перекрестные ссылки CFG_MAGAZINESPATH и GetGame().

Используется в SpawnComplexChildrenItems() и SpawnSimpleChildrenItems().

◆ LoadData()

static bool LoadData ( )
inlinestaticprivate
7 {
9 if (!spawnGearPresetFiles || (spawnGearPresetFiles && spawnGearPresetFiles.Count() == 0))
10 return false;
11
12 m_Data.presets = {};
13
14 foreach (string spawnPresetFile : spawnGearPresetFiles)
15 {
17 string path = "$mission:" + spawnPresetFile;
18
19 string errorMessage;
21 {
23 return false;
24 }
25
26 if (preset != null)
27 m_Data.presets.Insert(preset);
28 }
29
30 m_Initialized = m_Data.presets.Count() > 0;
31
32 return true;
33 }
string path
Definition OptionSelectorMultistate.c:142
Definition CfgGameplayHandler.c:2
static TStringArray GetPlayerSpawnGearPresetFiles()
Definition CfgGameplayHandler.c:438
enum ShapeType ErrorEx

Перекрестные ссылки ErrorEx, CfgGameplayHandler::GetPlayerSpawnGearPresetFiles(), m_Data, m_Initialized и path.

Используется в MissionBase::OnInit().

◆ ProcessCargoEquipment()

static void ProcessCargoEquipment ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

chooses one object from the array

121 {
122 if (!data.HasDiscreteUnsortedItemSetsDefined())
123 {
124 Debug.Log("No non-empty 'discreteUnsortedItemSets' array found. Skipping cargo spawns","n/a","n/a","ProcessCargoEquipment");
125 return;
126 }
127
129 }
static bool SelectAndSpawnCargoSet(PlayerBase player, PlayerSpawnPreset data)
Definition CfgPlayerSpawnHandler.c:131

Перекрестные ссылки Debug::Log() и SelectAndSpawnCargoSet().

Используется в ProcessEquipmentData().

◆ ProcessEquipmentData()

static bool ProcessEquipmentData ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

equips character with the chosen preset

62 {
63 if (data.IsValid())
64 {
67 }
68
69 return true;
70 }
static void ProcessCargoEquipment(PlayerBase player, PlayerSpawnPreset data)
chooses one object from the array
Definition CfgPlayerSpawnHandler.c:120
static void ProcessSlotsEquipment(PlayerBase player, PlayerSpawnPreset data)
iterates over each object and spawns alternatives
Definition CfgPlayerSpawnHandler.c:73

Перекрестные ссылки ProcessCargoEquipment() и ProcessSlotsEquipment().

Используется в MissionBase::OnClientNewEvent().

◆ ProcessSlotsEquipment()

static void ProcessSlotsEquipment ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

iterates over each object and spawns alternatives

74 {
75 if (!data.HasAttachmentSlotSetsDefined())
76 {
77 Debug.Log("No non-empty 'attachmentSlotItemSets' array found. Skipping slot spawns","n/a","n/a","ProcessSlotsEquipment");
78 return;
79 }
80
81 foreach (PlayerSpawnPresetSlotData slotData : data.attachmentSlotItemSets)
82 {
84 }
85 }
static bool SelectAndSpawnSlotEquipment(PlayerBase player, PlayerSpawnPresetSlotData slotData)
selects weighted slot equipment variant
Definition CfgPlayerSpawnHandler.c:88

Перекрестные ссылки Debug::Log() и SelectAndSpawnSlotEquipment().

Используется в ProcessEquipmentData().

◆ SelectAndSpawnCargoSet()

static bool SelectAndSpawnCargoSet ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate
132 {
134 int count = data.discreteUnsortedItemSets.Count();
136 for (int i = 0; i < count; i++)
137 {
138 csd = data.discreteUnsortedItemSets[i];
139
140 if (csd.IsValid()) //only when the spawnWeight is set
141 {
142 for (int j = 0; j < csd.spawnWeight; j++)
143 {
145 }
146 }
147 }
148
149 csd = null;
150 if (weightedDiscreteSetIndexes.Count() > 0)
151 csd = data.discreteUnsortedItemSets.Get(weightedDiscreteSetIndexes.GetRandomElement());
153 }
static bool SpawnDiscreteCargoItemSet(PlayerBase player, PlayerSpawnPresetDiscreteCargoSetData csd)
Definition CfgPlayerSpawnHandler.c:155

Перекрестные ссылки SpawnDiscreteCargoItemSet().

Используется в ProcessCargoEquipment().

◆ SelectAndSpawnSlotEquipment()

static bool SelectAndSpawnSlotEquipment ( PlayerBase player,
PlayerSpawnPresetSlotData slotData )
inlinestaticprivate

selects weighted slot equipment variant

89 {
90 int slotID;
91 if (!slotData.TranslateAndValidateSlot(player,slotID))
92 return false;
93
94 if (!slotData.IsValid())
95 return false;
96
98 int count = slotData.discreteItemSets.Count();
100 for (int i = 0; i < count; i++)
101 {
102 dis = slotData.discreteItemSets[i];
103
104 if (dis.IsValid()) //only when the type exists and spawnWeight is set
105 {
106 for (int j = 0; j < dis.spawnWeight; j++)
107 {
109 }
110 }
111 }
112
113 dis = null;
114 if (weightedDiscreteSetIndexes.Count() > 0)
115 dis = slotData.discreteItemSets.Get(weightedDiscreteSetIndexes.GetRandomElement());
117 }
static bool SpawnDiscreteSlotItemSet(PlayerBase player, PlayerSpawnPresetDiscreteItemSetSlotData dis, int slotID)
Definition CfgPlayerSpawnHandler.c:162
one item set for slot
Definition CfgPlayerSpawnDataJson.c:150

Перекрестные ссылки SpawnDiscreteSlotItemSet().

Используется в ProcessSlotsEquipment().

◆ SpawnComplexChildrenItems()

static bool SpawnComplexChildrenItems ( EntityAI parent,
notnull PlayerSpawnPresetItemSetBase data )
inlinestaticprivate

could spawn other items recursively. Parent item is guaranteed here.

191 {
192 if (!data.complexChildrenTypes || data.complexChildrenTypes.Count() < 1) //no children defined, still valid!
193 {
194 return false;
195 }
196
197 foreach (PlayerSpawnPresetComplexChildrenType cct : data.complexChildrenTypes)
198 {
199 if (cct.itemType == string.Empty)
200 {
201 Debug.Log("Empty item type found in 'complexChildrenTypes' of parent : " + parent,"n/a","n/a","SpawnSimpleChildrenItems");
202 continue;
203 }
204
206 Class.CastTo(item,CreateChildItem(parent,cct.itemType));
207
208 if (item)
209 {
211 }
212 else
213 {
215 if (!Class.CastTo(wep,parent) || !IsWeaponAndMagazineType(parent,cct.itemType) || !wep.HasInternalMagazine(-1))
216 Debug.Log("FAILED spawning item: " + cct.itemType + " of parent: " + parent,"n/a","n/a","SpawnComplexChildrenItems");
217 }
218 }
219
220 return true;
221 }
static EntityAI CreateChildItem(EntityAI parent, string type)
Definition CfgPlayerSpawnHandler.c:271
static void HandleNewItem(notnull ItemBase item, PlayerSpawnPresetItemSetBase data)
Definition CfgPlayerSpawnHandler.c:259
static bool IsWeaponAndMagazineType(EntityAI parent, string type)
Used for exceptions in the system.
Definition CfgPlayerSpawnHandler.c:343
used for specific hierarchical child spawning
Definition CfgPlayerSpawnDataJson.c:186

Перекрестные ссылки Class::CastTo(), CreateChildItem(), HandleNewItem(), IsWeaponAndMagazineType() и Debug::Log().

Используется в HandleNewItem() и SpawnDiscreteCargoItemSet().

◆ SpawnDiscreteCargoItemSet()

static bool SpawnDiscreteCargoItemSet ( PlayerBase player,
PlayerSpawnPresetDiscreteCargoSetData csd )
inlinestaticprivate
156 {
159 return true;
160 }

Перекрестные ссылки SpawnComplexChildrenItems() и SpawnSimpleChildrenItems().

Используется в SelectAndSpawnCargoSet().

◆ SpawnDiscreteSlotItemSet()

static bool SpawnDiscreteSlotItemSet ( PlayerBase player,
PlayerSpawnPresetDiscreteItemSetSlotData dis,
int slotID )
inlinestaticprivate
163 {
164 if (!dis)
165 {
166 Debug.Log("No PlayerSpawnPresetDiscreteItemSet found. Skipping spawn for slot: " + InventorySlots.GetSlotName(slotID),"n/a","n/a","SpawnDiscreteSlotItemSet");
167 return false;
168 }
169
171 if (slotID == InventorySlots.HANDS) //hands exception
172 item = ItemBase.Cast(player.GetHumanInventory().CreateInHands(dis.itemType));
173 else
174 item = ItemBase.Cast(player.GetInventory().CreateAttachmentEx(dis.itemType,slotID));
175
176 if (item)
177 {
179 }
180 else if (dis.itemType != string.Empty)
181 {
182 Debug.Log("FAILED spawning item type: " + dis.itemType + " into slot: " + InventorySlots.GetSlotName(slotID) + " of parent: " + player,"n/a","n/a","SpawnDiscreteSlotItemSet");
183 return false;
184 }
185
186 return item != null;
187 }
provides access to slot configuration
Definition InventorySlots.c:6
static proto native owned string GetSlotName(int id)
converts slot_id to string

Перекрестные ссылки InventorySlots::GetSlotName(), HandleNewItem() и Debug::Log().

Используется в SelectAndSpawnSlotEquipment().

◆ SpawnSimpleChildrenItems()

static bool SpawnSimpleChildrenItems ( EntityAI parent,
PlayerSpawnPresetItemSetBase data )
inlinestaticprivate
224 {
225 if (!data || !data.simpleChildrenTypes || data.simpleChildrenTypes.Count() < 1) //no children defined, still valid!
226 {
227 return false;
228 }
229
230 int count = data.simpleChildrenTypes.Count();
231 string itemType;
232 for (int i = 0; i < count; i++)
233 {
234 itemType = data.simpleChildrenTypes[i];
235 if (itemType == string.Empty)
236 {
237 Debug.Log("Empty item type found at idx: " + i.ToString() + " of 'simpleChildrenTypes' array. Skipping","n/a","n/a","SpawnSimpleChildrenItems");
238 continue;
239 }
240
242 Class.CastTo(item,CreateChildItem(parent,itemType));
243
244 if (item)
245 {
246 if (!data.simpleChildrenUseDefaultAttributes)
247 ApplyAttributes(item,data.attributes);
248 }
249 else
250 {
252 if (!Class.CastTo(wep,parent) || !IsWeaponAndMagazineType(parent,itemType) || !wep.HasInternalMagazine(-1))
253 Debug.Log("FAILED spawning item type: " + itemType + " to parent: " + parent,"n/a","n/a","SpawnSimpleChildrenItems");
254 }
255 }
256 return true;
257 }
Empty
Definition Hand_States.c:14

Перекрестные ссылки ApplyAttributes(), Class::CastTo(), CreateChildItem(), Empty, IsWeaponAndMagazineType() и Debug::Log().

Используется в HandleNewItem() и SpawnDiscreteCargoItemSet().

Поля

◆ m_Data

ref PlayerSpawnJsonData m_Data = new PlayerSpawnJsonData()
staticprivate

Используется в GetRandomCharacterPreset() и LoadData().

◆ m_Initialized

bool m_Initialized
staticprivate

Используется в IsInitialized() и LoadData().


Объявления и описания членов класса находятся в файле: