CharacterRandom.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Utilities;
  5. using Sirenix.OdinInspector;
  6. using KairoEngine.Core;
  7. using KairoEngine.Inventory;
  8. namespace KairoEngine.CharacterSystem
  9. {
  10. [CreateAssetMenu(fileName = "RandomCharacter", menuName = "KairoEngine/RandomCharacter", order = 7)]
  11. public class CharacterRandom : SerializedScriptableObject
  12. {
  13. [Title("Identification")]
  14. public Race race;
  15. public Faction faction;
  16. [Title("Details")]
  17. public Gender gender;
  18. [Range(18, 85)] public int minAge = 24;
  19. [Range(18, 85)] public int maxAge = 38;
  20. [HorizontalGroup("Hitpoints"), SuffixLabel("HP", true)] public int hitpoints;
  21. [HorizontalGroup("Hitpoints", 0.3f), HideLabel, SuffixLabel("Max HP", true)] public int maxHitpoints;
  22. public int armor;
  23. [Title("Visuals")]
  24. public List<ModelData> bodyModelList;
  25. public List<GameObject> headAttachmentPrefabList;
  26. public List<GameObject> faceAttachmentPrefabList;
  27. [Title("Items")]
  28. [MinMaxSlider(0, 5, true)] public Vector2 extraClips = new Vector2(1,2);
  29. public List<ItemBaseFirearm> randomFirearm;
  30. public List<ItemBaseHandWeapon> randomMeleeWeapon;
  31. public List<RandomItem> randomItems = new List<RandomItem>();
  32. public CharacterData Generate(string id = "")
  33. {
  34. CharacterData data = ScriptableObject.CreateInstance<CharacterData>();
  35. if(id == "") id = KairoEngine.Core.Utilities.RandomString(12);
  36. data.characterName = "";
  37. data.id = id;
  38. data.race = race;
  39. data.faction = faction;
  40. data.gender = gender;
  41. data.age = Random.Range(minAge, maxAge + 1);
  42. data.hitpoints = hitpoints;
  43. data.maxHitpoints = maxHitpoints;
  44. data.armor = armor;
  45. data.bodyModelData = bodyModelList[Random.Range(0, bodyModelList.Count)];
  46. data.bodyMaterialNumber = Random.Range(0, data.bodyModelData.materials.Count);
  47. if(headAttachmentPrefabList.Count > 0)
  48. {
  49. GameObject headAttachment = headAttachmentPrefabList[Random.Range(0, headAttachmentPrefabList.Count)];
  50. if(headAttachment != null) data.headAttachmentPrefab = headAttachment;
  51. }
  52. if(faceAttachmentPrefabList.Count > 0)
  53. {
  54. GameObject faceAttachment = faceAttachmentPrefabList[Random.Range(0, faceAttachmentPrefabList.Count)];
  55. if(faceAttachment != null) data.faceAttachmentPrefab = faceAttachment;
  56. }
  57. if(randomFirearm.Count > 0)
  58. {
  59. ItemBaseFirearm firearm = randomFirearm[Random.Range(0, randomFirearm.Count)];
  60. ItemFirearmRef firearmRef = new ItemFirearmRef(firearm, 1, firearm.ammoType, firearm.ammoCapacity);
  61. data.itemList.Add(firearmRef);
  62. ItemRef ammoRef = new ItemRef(firearm.ammoType, firearm.ammoCapacity * (int)Random.Range(extraClips.x, extraClips.y));
  63. data.itemList.Add(ammoRef);
  64. }
  65. if(randomMeleeWeapon.Count > 0)
  66. {
  67. ItemBaseHandWeapon handWeapon = randomMeleeWeapon[Random.Range(0, randomMeleeWeapon.Count)];
  68. ItemRef itemRef = new ItemRef(handWeapon, 1);
  69. data.itemList.Add(itemRef);
  70. }
  71. if(randomItems.Count > 0)
  72. {
  73. for (int i = 0; i < randomItems.Count; i++)
  74. {
  75. RandomItem item = randomItems[i];
  76. float dice = Random.Range(0, 101);
  77. if(dice <= item.probability)
  78. {
  79. int quantity = Random.Range((int)item.quantity.x, ((int)item.quantity.y) + 1);
  80. if(item.item.category == ItemType.firearm)
  81. {
  82. ItemBaseFirearm itemBaseFirearm = (ItemBaseFirearm)item.item;
  83. ItemBaseAmmo itemBaseAmmo = (ItemBaseAmmo)itemBaseFirearm.ammoType;
  84. int ammo = itemBaseFirearm.ammoCapacity;
  85. ItemFirearmRef firearmRef = new ItemFirearmRef(itemBaseFirearm, quantity, itemBaseAmmo, ammo);
  86. data.itemList.Add(firearmRef);
  87. }
  88. else
  89. {
  90. ItemRef itemRef = new ItemRef(item.item, quantity, 10000);
  91. data.itemList.Add(itemRef);
  92. }
  93. }
  94. }
  95. }
  96. return data;
  97. }
  98. }
  99. }