cfgplayerspawndatajson.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. class PlayerSpawnJsonDataBase : Managed
  2. {
  3. //! sets default values throughout the freshly created structure as required
  4. bool IsValid()
  5. {
  6. return true;
  7. }
  8. }
  9. class PlayerSpawnJsonData : PlayerSpawnJsonDataBase
  10. {
  11. ref array<ref PlayerSpawnPreset> presets;
  12. }
  13. class PlayerSpawnPreset : PlayerSpawnJsonDataBase
  14. {
  15. int spawnWeight; //spawn probability weight
  16. string name; //optional
  17. ref array<string> characterTypes;
  18. ref array<ref PlayerSpawnPresetSlotData> attachmentSlotItemSets;
  19. ref array<ref PlayerSpawnPresetDiscreteCargoSetData> discreteUnsortedItemSets;
  20. string GetRandomCharacterType()
  21. {
  22. if (characterTypes && characterTypes.Count() > 0)
  23. return characterTypes.GetRandomElement();
  24. Debug.Log("No characterTypes defined. Falling back to 'default' character type, or random, if undefined","n/a","n/a","PlayerSpawnPreset");
  25. return string.Empty;
  26. }
  27. override bool IsValid()
  28. {
  29. if (!super.IsValid())
  30. return false;
  31. if (spawnWeight < 1)
  32. {
  33. Debug.Log("Invalid spawn weight, skipping preset: " + name,"n/a","Validation","PlayerSpawnPreset");
  34. return false;
  35. }
  36. return true;
  37. }
  38. //! preset might be valid even with no attachmentSlotItemSets configured, checked separately
  39. bool HasAttachmentSlotSetsDefined()
  40. {
  41. return attachmentSlotItemSets && attachmentSlotItemSets.Count() > 0;
  42. }
  43. //! preset might be valid even with no unsorted item sets configured, checked separately
  44. bool HasDiscreteUnsortedItemSetsDefined()
  45. {
  46. return discreteUnsortedItemSets && discreteUnsortedItemSets.Count() > 0;
  47. }
  48. }
  49. class PlayerSpawnPresetSlotData : PlayerSpawnJsonDataBase
  50. {
  51. string slotName;
  52. ref array<ref PlayerSpawnPresetDiscreteItemSetSlotData> discreteItemSets;
  53. //! Translates slot name to match something from both 'CfgSlots' and 'attachments[]' in entity's config
  54. bool TranslateAndValidateSlot(EntityAI parent, inout int slotID)
  55. {
  56. string tmp = slotName;
  57. if (slotName == "shoulderL")
  58. {
  59. tmp = "Shoulder";
  60. }
  61. else if (slotName == "shoulderR")
  62. {
  63. tmp = "Melee";
  64. }
  65. slotID = InventorySlots.GetSlotIdFromString(tmp);
  66. if (!InventorySlots.IsSlotIdValid(slotID))
  67. {
  68. Debug.Log("Wrong slot name used: " + slotName,"n/a","Validation","PlayerSpawnPresetSlotData");
  69. return false;
  70. }
  71. if (!parent)
  72. {
  73. Debug.Log("No parent entity found when trying to populate slot: " + slotName,"n/a","Validation","PlayerSpawnPresetSlotData");
  74. return false;
  75. }
  76. if (!parent.GetInventory().HasAttachmentSlot(slotID))
  77. {
  78. Debug.Log("Slot: " + slotName + " undefined on entity: " + parent.GetType(),"n/a","Validation","PlayerSpawnPresetSlotData");
  79. return false;
  80. }
  81. return true;
  82. }
  83. //! slot name validity checked separately
  84. override bool IsValid()
  85. {
  86. if (!super.IsValid())
  87. return false;
  88. if (discreteItemSets == null || discreteItemSets.Count() < 1)
  89. {
  90. Debug.Log("discreteItemSets for slot: " + slotName + " undefined","n/a","Validation","PlayerSpawnPresetSlotData");
  91. return false;
  92. }
  93. return true;
  94. }
  95. }
  96. //! base for any item set
  97. class PlayerSpawnPresetItemSetBase : PlayerSpawnJsonDataBase
  98. {
  99. bool simpleChildrenUseDefaultAttributes;
  100. ref PlayerSpawnAttributesData attributes;
  101. ref array<ref PlayerSpawnPresetComplexChildrenType> complexChildrenTypes;
  102. ref array<string> simpleChildrenTypes;
  103. //! overriden later
  104. int GetQuickbarIdx()
  105. {
  106. return -1;
  107. }
  108. }
  109. //base for DISCRETE item sets
  110. class PlayerSpawnPresetDiscreteItemSetBase : PlayerSpawnPresetItemSetBase
  111. {
  112. int spawnWeight;
  113. override bool IsValid()
  114. {
  115. if (!super.IsValid())
  116. return false;
  117. if (spawnWeight < 1)
  118. {
  119. Debug.Log("Invalid spawnWeight set for a discrete item set!","n/a","Validation","PlayerSpawnPresetDiscreteItemSetBase");
  120. return false;
  121. }
  122. return true;
  123. }
  124. }
  125. //! one item set for slot
  126. class PlayerSpawnPresetDiscreteItemSetSlotData : PlayerSpawnPresetDiscreteItemSetBase
  127. {
  128. string itemType;
  129. int quickBarSlot;
  130. override bool IsValid()
  131. {
  132. if (!super.IsValid())
  133. return false;
  134. //empty 'itemType' is valid alternative here
  135. if (!attributes)
  136. {
  137. Debug.Log("No attributes defined for a discrete item set!","n/a","Validation","PlayerSpawnPresetDiscreteItemSetSlotData");
  138. return false;
  139. }
  140. //unable to verify any of the other integers, since they always default to '0'. Needs to be configured carefully!
  141. return true;
  142. }
  143. override int GetQuickbarIdx()
  144. {
  145. return quickBarSlot;
  146. }
  147. }
  148. //! one set for cargo
  149. class PlayerSpawnPresetDiscreteCargoSetData : PlayerSpawnPresetDiscreteItemSetBase
  150. {
  151. string name;
  152. }
  153. //! used for specific hierarchical child spawning
  154. class PlayerSpawnPresetComplexChildrenType : PlayerSpawnPresetItemSetBase
  155. {
  156. string itemType;
  157. int quickBarSlot;
  158. override bool IsValid()
  159. {
  160. if (!super.IsValid())
  161. return false;
  162. return itemType != string.Empty; //needs item type to function
  163. }
  164. override int GetQuickbarIdx()
  165. {
  166. return quickBarSlot;
  167. }
  168. }
  169. class PlayerSpawnAttributesData : PlayerSpawnJsonDataBase
  170. {
  171. float healthMin;
  172. float healthMax;
  173. float quantityMin;
  174. float quantityMax;
  175. //ref array<string> magazineAmmoOrdered;
  176. }