File size: 5,062 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 |
class PlayerSpawnJsonDataBase : Managed
{
//! sets default values throughout the freshly created structure as required
bool IsValid()
{
return true;
}
}
class PlayerSpawnJsonData : PlayerSpawnJsonDataBase
{
ref array<ref PlayerSpawnPreset> presets;
}
class PlayerSpawnPreset : PlayerSpawnJsonDataBase
{
int spawnWeight; //spawn probability weight
string name; //optional
ref array<string> characterTypes;
ref array<ref PlayerSpawnPresetSlotData> attachmentSlotItemSets;
ref array<ref PlayerSpawnPresetDiscreteCargoSetData> discreteUnsortedItemSets;
string GetRandomCharacterType()
{
if (characterTypes && characterTypes.Count() > 0)
return characterTypes.GetRandomElement();
Debug.Log("No characterTypes defined. Falling back to 'default' character type, or random, if undefined","n/a","n/a","PlayerSpawnPreset");
return string.Empty;
}
override bool IsValid()
{
if (!super.IsValid())
return false;
if (spawnWeight < 1)
{
Debug.Log("Invalid spawn weight, skipping preset: " + name,"n/a","Validation","PlayerSpawnPreset");
return false;
}
return true;
}
//! preset might be valid even with no attachmentSlotItemSets configured, checked separately
bool HasAttachmentSlotSetsDefined()
{
return attachmentSlotItemSets && attachmentSlotItemSets.Count() > 0;
}
//! preset might be valid even with no unsorted item sets configured, checked separately
bool HasDiscreteUnsortedItemSetsDefined()
{
return discreteUnsortedItemSets && discreteUnsortedItemSets.Count() > 0;
}
}
class PlayerSpawnPresetSlotData : PlayerSpawnJsonDataBase
{
string slotName;
ref array<ref PlayerSpawnPresetDiscreteItemSetSlotData> discreteItemSets;
//! Translates slot name to match something from both 'CfgSlots' and 'attachments[]' in entity's config
bool TranslateAndValidateSlot(EntityAI parent, inout int slotID)
{
string tmp = slotName;
if (slotName == "shoulderL")
{
tmp = "Shoulder";
}
else if (slotName == "shoulderR")
{
tmp = "Melee";
}
slotID = InventorySlots.GetSlotIdFromString(tmp);
if (!InventorySlots.IsSlotIdValid(slotID))
{
Debug.Log("Wrong slot name used: " + slotName,"n/a","Validation","PlayerSpawnPresetSlotData");
return false;
}
if (!parent)
{
Debug.Log("No parent entity found when trying to populate slot: " + slotName,"n/a","Validation","PlayerSpawnPresetSlotData");
return false;
}
if (!parent.GetInventory().HasAttachmentSlot(slotID))
{
Debug.Log("Slot: " + slotName + " undefined on entity: " + parent.GetType(),"n/a","Validation","PlayerSpawnPresetSlotData");
return false;
}
return true;
}
//! slot name validity checked separately
override bool IsValid()
{
if (!super.IsValid())
return false;
if (discreteItemSets == null || discreteItemSets.Count() < 1)
{
Debug.Log("discreteItemSets for slot: " + slotName + " undefined","n/a","Validation","PlayerSpawnPresetSlotData");
return false;
}
return true;
}
}
//! base for any item set
class PlayerSpawnPresetItemSetBase : PlayerSpawnJsonDataBase
{
bool simpleChildrenUseDefaultAttributes;
ref PlayerSpawnAttributesData attributes;
ref array<ref PlayerSpawnPresetComplexChildrenType> complexChildrenTypes;
ref array<string> simpleChildrenTypes;
//! overriden later
int GetQuickbarIdx()
{
return -1;
}
}
//base for DISCRETE item sets
class PlayerSpawnPresetDiscreteItemSetBase : PlayerSpawnPresetItemSetBase
{
int spawnWeight;
override bool IsValid()
{
if (!super.IsValid())
return false;
if (spawnWeight < 1)
{
Debug.Log("Invalid spawnWeight set for a discrete item set!","n/a","Validation","PlayerSpawnPresetDiscreteItemSetBase");
return false;
}
return true;
}
}
//! one item set for slot
class PlayerSpawnPresetDiscreteItemSetSlotData : PlayerSpawnPresetDiscreteItemSetBase
{
string itemType;
int quickBarSlot;
override bool IsValid()
{
if (!super.IsValid())
return false;
//empty 'itemType' is valid alternative here
if (!attributes)
{
Debug.Log("No attributes defined for a discrete item set!","n/a","Validation","PlayerSpawnPresetDiscreteItemSetSlotData");
return false;
}
//unable to verify any of the other integers, since they always default to '0'. Needs to be configured carefully!
return true;
}
override int GetQuickbarIdx()
{
return quickBarSlot;
}
}
//! one set for cargo
class PlayerSpawnPresetDiscreteCargoSetData : PlayerSpawnPresetDiscreteItemSetBase
{
string name;
}
//! used for specific hierarchical child spawning
class PlayerSpawnPresetComplexChildrenType : PlayerSpawnPresetItemSetBase
{
string itemType;
int quickBarSlot;
override bool IsValid()
{
if (!super.IsValid())
return false;
return itemType != string.Empty; //needs item type to function
}
override int GetQuickbarIdx()
{
return quickBarSlot;
}
}
class PlayerSpawnAttributesData : PlayerSpawnJsonDataBase
{
float healthMin;
float healthMax;
float quantityMin;
float quantityMax;
//ref array<string> magazineAmmoOrdered;
}
|