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());
77 Debug.
Log(
"No non-empty 'attachmentSlotItemSets' array found. Skipping slot spawns",
"n/a",
"n/a",
"ProcessSlotsEquipment");
91 if (!slotData.TranslateAndValidateSlot(player,slotID))
94 if (!slotData.IsValid())
98 int count = slotData.discreteItemSets.Count();
100 for (
int i = 0; i < count; i++)
102 dis = slotData.discreteItemSets[i];
106 for (
int j = 0; j < dis.spawnWeight; j++)
108 weightedDiscreteSetIndexes.Insert(i);
114 if (weightedDiscreteSetIndexes.Count() > 0)
115 dis = slotData.discreteItemSets.Get(weightedDiscreteSetIndexes.GetRandomElement());
124 Debug.
Log(
"No non-empty 'discreteUnsortedItemSets' array found. Skipping cargo spawns",
"n/a",
"n/a",
"ProcessCargoEquipment");
135 PlayerSpawnPresetDiscreteCargoSetData csd;
136 for (
int i = 0; i < count; i++)
142 for (
int j = 0; j < csd.spawnWeight; j++)
144 weightedDiscreteSetIndexes.Insert(i);
150 if (weightedDiscreteSetIndexes.Count() > 0)
172 item =
ItemBase.Cast(player.GetHumanInventory().CreateInHands(dis.
itemType));
174 item =
ItemBase.Cast(player.GetInventory().CreateAttachmentEx(dis.
itemType,slotID));
192 if (!data.complexChildrenTypes || data.complexChildrenTypes.Count() < 1)
201 Debug.
Log(
"Empty item type found in 'complexChildrenTypes' of parent : " + parent,
"n/a",
"n/a",
"SpawnSimpleChildrenItems");
216 Debug.
Log(
"FAILED spawning item: " + cct.
itemType +
" of parent: " + parent,
"n/a",
"n/a",
"SpawnComplexChildrenItems");
232 for (
int i = 0; i < count; i++)
235 if (itemType ==
string.
Empty)
237 Debug.
Log(
"Empty item type found at idx: " + i.ToString() +
" of 'simpleChildrenTypes' array. Skipping",
"n/a",
"n/a",
"SpawnSimpleChildrenItems");
253 Debug.
Log(
"FAILED spawning item type: " + itemType +
" to parent: " + parent,
"n/a",
"n/a",
"SpawnSimpleChildrenItems");
277 if (
Class.
CastTo(newItem,player.GetInventory().CreateInInventory(type)))
280 Debug.
Log(
"FAILED spawning item: " + type +
", it fits in no cargo or attachment on any worn item",
"n/a",
"n/a",
"CreateChildItem");
288 if (
Class.
CastTo(wep,parent) && wep.SpawnAmmo(type) && !wep.HasInternalMagazine(-1))
291 int muzzleCount = wep.GetMuzzleCount();
292 for (
int i = 0; i < muzzleCount; i++)
294 if (
Class.
CastTo(mag,wep.GetMagazine(i)) && mag.GetType() == type)
302 return parent.GetInventory().CreateInInventory(type);
311 item.SetHealth01(
"",
"Health",health01);
314 if (item.IsMagazine())
316 Magazine mag = Magazine.Cast(item);
328 int ammoQuantity = (
int)
Math.
Lerp(0,mag.GetAmmoMax(),quantity01);
329 mag.ServerSetAmmoCount(ammoQuantity);
334 float quantityAbsolute =
Math.
Lerp(item.GetQuantityMin(),item.GetQuantityMax(),quantity01);
335 quantityAbsolute =
Math.
Round(quantityAbsolute);
336 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.
static proto native owned string GetSlotName(int id)
converts slot_id to string
provides access to slot configuration
override bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
static bool IsInitialized()
static bool SpawnDiscreteSlotItemSet(PlayerBase player, PlayerSpawnPresetDiscreteItemSetSlotData dis, int slotID)
static void ProcessSlotsEquipment(PlayerBase player, PlayerSpawnPreset data)
iterates over each object and spawns alternatives
static void ApplyAttributes(ItemBase item, PlayerSpawnAttributesData attributes)
static ref PlayerSpawnJsonData m_Data
static bool SpawnSimpleChildrenItems(EntityAI parent, PlayerSpawnPresetItemSetBase data)
static bool SpawnDiscreteCargoItemSet(PlayerBase player, PlayerSpawnPresetDiscreteCargoSetData csd)
static bool SpawnComplexChildrenItems(EntityAI parent, notnull PlayerSpawnPresetItemSetBase data)
could spawn other items recursively. Parent item is guaranteed here.
static bool SelectAndSpawnSlotEquipment(PlayerBase player, PlayerSpawnPresetSlotData slotData)
selects weighted slot equipment variant
static bool ProcessEquipmentData(PlayerBase player, PlayerSpawnPreset data)
equips character with the chosen preset
static bool SelectAndSpawnCargoSet(PlayerBase player, PlayerSpawnPreset data)
static void ProcessCargoEquipment(PlayerBase player, PlayerSpawnPreset data)
chooses one object from the array
static bool m_Initialized
static void HandleNewItem(notnull ItemBase item, PlayerSpawnPresetItemSetBase data)
static PlayerSpawnPreset GetRandomCharacterPreset()
static bool IsWeaponAndMagazineType(EntityAI parent, string type)
Used for exceptions in the system.
static EntityAI CreateChildItem(EntityAI parent, string type)
ref array< ref PlayerSpawnPresetDiscreteCargoSetData > discreteUnsortedItemSets
ref array< ref PlayerSpawnPresetSlotData > attachmentSlotItemSets
bool HasDiscreteUnsortedItemSetsDefined()
preset might be valid even with no unsorted item sets configured, checked separately
bool HasAttachmentSlotSetsDefined()
preset might be valid even with no attachmentSlotItemSets configured, checked separately
used for specific hierarchical child spawning
int GetQuickbarIdx()
overriden later
bool simpleChildrenUseDefaultAttributes
ref array< string > simpleChildrenTypes
ref PlayerSpawnAttributesData attributes
ref array< ref PlayerSpawnPresetComplexChildrenType > complexChildrenTypes
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
static proto float Round(float f)
Returns mathematical round of value.
static const string Empty