4 static ref PlayerSpawnJsonData
m_Data =
new PlayerSpawnJsonData();
9 if (!spawnGearPresetFiles || (spawnGearPresetFiles && spawnGearPresetFiles.Count() == 0))
14 foreach (
string spawnPresetFile : spawnGearPresetFiles)
17 string path =
"$mission:" + spawnPresetFile;
20 if (!JsonFileLoader<PlayerSpawnPreset>.LoadFile(
path, preset, errorMessage))
27 m_Data.presets.Insert(preset);
43 int count =
m_Data.presets.Count();
45 for (
int i = 0; i < count; i++)
52 weightedPresetIndexes.Insert(i);
57 return m_Data.presets.Get(weightedPresetIndexes.GetRandomElement());
88 Debug.
Log(
"No non-empty 'attachmentSlotItemSets' array found. Skipping slot spawns",
"n/a",
"n/a",
"ProcessSlotsEquipment");
102 if (!slotData.TranslateAndValidateSlot(player,slotID))
105 if (!slotData.IsValid())
109 int count = slotData.discreteItemSets.Count();
111 for (
int i = 0; i < count; i++)
113 dis = slotData.discreteItemSets[i];
117 for (
int j = 0; j < dis.spawnWeight; j++)
119 weightedDiscreteSetIndexes.Insert(i);
125 if (weightedDiscreteSetIndexes.Count() > 0)
126 dis = slotData.discreteItemSets.Get(weightedDiscreteSetIndexes.GetRandomElement());
135 Debug.
Log(
"No non-empty 'discreteUnsortedItemSets' array found. Skipping cargo spawns",
"n/a",
"n/a",
"ProcessCargoEquipment");
146 PlayerSpawnPresetDiscreteCargoSetData csd;
147 for (
int i = 0; i < count; i++)
153 for (
int j = 0; j < csd.spawnWeight; j++)
155 weightedDiscreteSetIndexes.Insert(i);
161 if (weightedDiscreteSetIndexes.Count() > 0)
183 item =
ItemBase.Cast(player.GetHumanInventory().CreateInHands(dis.
itemType));
185 item =
ItemBase.Cast(player.GetInventory().CreateAttachmentEx(dis.
itemType,slotID));
203 if (!data.complexChildrenTypes || data.complexChildrenTypes.Count() < 1)
212 Debug.
Log(
"Empty item type found in 'complexChildrenTypes' of parent : " + parent,
"n/a",
"n/a",
"SpawnSimpleChildrenItems");
227 Debug.
Log(
"FAILED spawning item: " + cct.
itemType +
" of parent: " + parent,
"n/a",
"n/a",
"SpawnComplexChildrenItems");
243 for (
int i = 0; i < count; i++)
246 if (itemType ==
string.
Empty)
248 Debug.
Log(
"Empty item type found at idx: " + i.ToString() +
" of 'simpleChildrenTypes' array. Skipping",
"n/a",
"n/a",
"SpawnSimpleChildrenItems");
264 Debug.
Log(
"FAILED spawning item type: " + itemType +
" to parent: " + parent,
"n/a",
"n/a",
"SpawnSimpleChildrenItems");
288 if (
Class.
CastTo(newItem,player.GetInventory().CreateInInventory(type)))
291 Debug.
Log(
"FAILED spawning item: " + type +
", it fits in no cargo or attachment on any worn item",
"n/a",
"n/a",
"CreateChildItem");
299 if (
Class.
CastTo(wep,parent) && wep.SpawnAmmo(type) && !wep.HasInternalMagazine(-1))
302 int muzzleCount = wep.GetMuzzleCount();
303 for (
int i = 0; i < muzzleCount; i++)
305 if (
Class.
CastTo(mag,wep.GetMagazine(i)) && mag.GetType() == type)
313 return parent.GetInventory().CreateInInventory(type);
322 item.SetHealth01(
"",
"Health",health01);
325 if (item.IsMagazine())
327 Magazine mag = Magazine.Cast(item);
339 int ammoQuantity = (
int)
Math.
Lerp(0,mag.GetAmmoMax(),quantity01);
340 mag.ServerSetAmmoCount(ammoQuantity);
345 float quantityAbsolute =
Math.
Lerp(item.GetQuantityMin(),item.GetQuantityMax(),quantity01);
346 quantityAbsolute =
Math.
Round(quantityAbsolute);
347 if (quantityAbsolute <= item.GetQuantityMin() && item.ConfigGetBool(
"varQuantityDestroyOnMin"))
static TStringArray GetPlayerSpawnGearPresetFiles()
Super root of all classes in Enforce script.
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.
provides access to slot configuration
static proto native owned string GetSlotName(int id)
override bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
static PlayerSpawnPreset GetRandomCharacterPreset()
static bool SpawnDiscreteCargoItemSet(PlayerBase player, PlayerSpawnPresetDiscreteCargoSetData csd)
static EntityAI CreateChildItem(EntityAI parent, string type)
static void ProcessCargoEquipment(PlayerBase player, PlayerSpawnPreset data)
chooses one object from the array
static PlayerSpawnPreset GetCharacterPresetByName(string presetName)
static bool ProcessEquipmentData(PlayerBase player, PlayerSpawnPreset data)
equips character with the chosen preset
static bool SpawnComplexChildrenItems(EntityAI parent, notnull PlayerSpawnPresetItemSetBase data)
could spawn other items recursively. Parent item is guaranteed here.
static bool SpawnDiscreteSlotItemSet(PlayerBase player, PlayerSpawnPresetDiscreteItemSetSlotData dis, int slotID)
static bool m_Initialized
static void HandleNewItem(notnull ItemBase item, PlayerSpawnPresetItemSetBase data)
static ref PlayerSpawnJsonData m_Data
static bool SpawnSimpleChildrenItems(EntityAI parent, PlayerSpawnPresetItemSetBase data)
static bool SelectAndSpawnSlotEquipment(PlayerBase player, PlayerSpawnPresetSlotData slotData)
selects weighted slot equipment variant
static bool IsInitialized()
static void ProcessSlotsEquipment(PlayerBase player, PlayerSpawnPreset data)
iterates over each object and spawns alternatives
static bool SelectAndSpawnCargoSet(PlayerBase player, PlayerSpawnPreset data)
static void ApplyAttributes(ItemBase item, PlayerSpawnAttributesData attributes)
static bool IsWeaponAndMagazineType(EntityAI parent, string type)
Used for exceptions in the system.
used for specific hierarchical child spawning
bool HasAttachmentSlotSetsDefined()
preset might be valid even with no attachmentSlotItemSets configured, checked separately
ref array< ref PlayerSpawnPresetSlotData > attachmentSlotItemSets
ref array< ref PlayerSpawnPresetDiscreteCargoSetData > discreteUnsortedItemSets
bool HasDiscreteUnsortedItemSetsDefined()
preset might be valid even with no unsorted item sets configured, checked separately
ref array< string > simpleChildrenTypes
int GetQuickbarIdx()
overriden later
ref PlayerSpawnAttributesData attributes
bool simpleChildrenUseDefaultAttributes
ref array< ref PlayerSpawnPresetComplexChildrenType > complexChildrenTypes
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
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].
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static const string Empty