123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Utilities;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- using KairoEngine.Inventory;
- namespace KairoEngine.CharacterSystem
- {
- [CreateAssetMenu(fileName = "RandomCharacter", menuName = "KairoEngine/RandomCharacter", order = 7)]
- public class CharacterRandom : SerializedScriptableObject
- {
- [Title("Identification")]
- public Race race;
- public Faction faction;
- [Title("Details")]
- public Gender gender;
- [Range(18, 85)] public int minAge = 24;
- [Range(18, 85)] public int maxAge = 38;
- [HorizontalGroup("Hitpoints"), SuffixLabel("HP", true)] public int hitpoints;
- [HorizontalGroup("Hitpoints", 0.3f), HideLabel, SuffixLabel("Max HP", true)] public int maxHitpoints;
- public int armor;
- [Title("Visuals")]
- public List<ModelData> bodyModelList;
- public List<GameObject> headAttachmentPrefabList;
- public List<GameObject> faceAttachmentPrefabList;
- [Title("Items")]
- [MinMaxSlider(0, 5, true)] public Vector2 extraClips = new Vector2(1,2);
- public List<ItemBaseFirearm> randomFirearm;
- public List<ItemBaseHandWeapon> randomMeleeWeapon;
- public List<RandomItem> randomItems = new List<RandomItem>();
- public CharacterData Generate(string id = "")
- {
- CharacterData data = ScriptableObject.CreateInstance<CharacterData>();
- if(id == "") id = KairoEngine.Core.Utilities.RandomString(12);
- data.characterName = "";
- data.id = id;
- data.race = race;
- data.faction = faction;
- data.gender = gender;
- data.age = Random.Range(minAge, maxAge + 1);
- data.hitpoints = hitpoints;
- data.maxHitpoints = maxHitpoints;
- data.armor = armor;
- data.bodyModelData = bodyModelList[Random.Range(0, bodyModelList.Count)];
- data.bodyMaterialNumber = Random.Range(0, data.bodyModelData.materials.Count);
- if(headAttachmentPrefabList.Count > 0)
- {
- GameObject headAttachment = headAttachmentPrefabList[Random.Range(0, headAttachmentPrefabList.Count)];
- if(headAttachment != null) data.headAttachmentPrefab = headAttachment;
- }
- if(faceAttachmentPrefabList.Count > 0)
- {
- GameObject faceAttachment = faceAttachmentPrefabList[Random.Range(0, faceAttachmentPrefabList.Count)];
- if(faceAttachment != null) data.faceAttachmentPrefab = faceAttachment;
- }
- if(randomFirearm.Count > 0)
- {
- ItemBaseFirearm firearm = randomFirearm[Random.Range(0, randomFirearm.Count)];
- ItemFirearmRef firearmRef = new ItemFirearmRef(firearm, 1, firearm.ammoType, firearm.ammoCapacity);
- data.itemList.Add(firearmRef);
- ItemRef ammoRef = new ItemRef(firearm.ammoType, firearm.ammoCapacity * (int)Random.Range(extraClips.x, extraClips.y));
- data.itemList.Add(ammoRef);
- }
- if(randomMeleeWeapon.Count > 0)
- {
- ItemBaseHandWeapon handWeapon = randomMeleeWeapon[Random.Range(0, randomMeleeWeapon.Count)];
- ItemRef itemRef = new ItemRef(handWeapon, 1);
- data.itemList.Add(itemRef);
- }
- if(randomItems.Count > 0)
- {
- for (int i = 0; i < randomItems.Count; i++)
- {
- RandomItem item = randomItems[i];
- float dice = Random.Range(0, 101);
- if(dice <= item.probability)
- {
- int quantity = Random.Range((int)item.quantity.x, ((int)item.quantity.y) + 1);
- if(item.item.category == ItemType.firearm)
- {
- ItemBaseFirearm itemBaseFirearm = (ItemBaseFirearm)item.item;
- ItemBaseAmmo itemBaseAmmo = (ItemBaseAmmo)itemBaseFirearm.ammoType;
- int ammo = itemBaseFirearm.ammoCapacity;
- ItemFirearmRef firearmRef = new ItemFirearmRef(itemBaseFirearm, quantity, itemBaseAmmo, ammo);
- data.itemList.Add(firearmRef);
- }
- else
- {
- ItemRef itemRef = new ItemRef(item.item, quantity, 10000);
- data.itemList.Add(itemRef);
- }
- }
- }
- }
- return data;
- }
- }
- }
|