public List <Item> GetItemsByTechAndType(Item.ItemTechnology tech, Item.ItemType type) { List <Item> returnItems = new List <Item>(); foreach (Item item in itemList) { if (item.Technology == tech && item.Type == type) { returnItems.Add(item); } } return(returnItems); }
public List <Item> FindItemsWithCondition(Item.ItemType type, Item.ItemTechnology tech) { List <Item> items = new List <Item>(); foreach (Item item in itemList) { if (item.Type == type && item.Technology == tech) { items.Add(item); } } return(items); }
public List <Item> GetItemsByTechAndEquipType(Item.ItemTechnology tech, Equipment.EquipmentType equipmentType) { List <Item> returnItems = new List <Item>(); foreach (Item item in itemList) { if (item.Technology == tech && item.Type == Item.ItemType.Equipment) { Equipment equipment = (Equipment)item; if (equipment.EquipType == equipmentType) { returnItems.Add(item); } } } return(returnItems); }
/// <summary> /// 解析模板角色信息 /// </summary> void ParseCharacterJson() { charPropList = new List <CharacterProperty>(); TextAsset charText = Resources.Load <TextAsset>("Characters"); string charJson = charText.text; JSONObject charObjects = new JSONObject(charJson); foreach (JSONObject temp in charObjects.list) { int id = (int)temp["id"].n; string name = temp["name"].str; CharacterProperty.CharacterFaction faction = (CharacterProperty.CharacterFaction)System.Enum.Parse(typeof(CharacterProperty.CharacterFaction), temp["faction"].str); CharacterProperty.CharacterType type = (CharacterProperty.CharacterType)System.Enum.Parse(typeof(CharacterProperty.CharacterType), temp["characterType"].str); int consititution = (int)temp["constitution"].n; int strength = (int)temp["strength"].n; int agility = (int)temp["agility"].n; int dexterous = (int)temp["dexterous"].n; int concentration = (int)temp["concentration"].n; string sprite = temp["sprite"].str; int allExperience = (int)temp["allExperience"].n; int headID = 0; Item.ItemTechnology headTech = Item.ItemTechnology.T0; int clothID = 0; Item.ItemTechnology clothTech = Item.ItemTechnology.T0; int pantsID = 0; Item.ItemTechnology pantsTech = Item.ItemTechnology.T0; int beltID = 0; Item.ItemTechnology beltTech = Item.ItemTechnology.T0; int weaponID = 0; Item.ItemTechnology weaponTech = Item.ItemTechnology.T0; if (temp["head"].IsNumber) { headID = (int)temp["head"].n; } if (temp["head"].IsString) { headTech = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["head"].str); } if (temp["cloth"].IsNumber) { clothID = (int)temp["cloth"].n; } if (temp["cloth"].IsString) { clothTech = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["cloth"].str); } if (temp["pants"].IsNumber) { pantsID = (int)temp["pants"].n; } if (temp["pants"].IsString) { pantsTech = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["pants"].str); } if (temp["belt"].IsNumber) { beltID = (int)temp["belt"].n; } if (temp["belt"].IsString) { beltTech = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["belt"].str); } if (temp["weapon"].IsNumber) { weaponID = (int)temp["weapon"].n; } if (temp["weapon"].IsString) { weaponTech = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["weapon"].str); } if (headTech != Item.ItemTechnology.T0) { List <Item> allRightItems = InventoryManager.Instance.GetItemsByTechAndEquipType(headTech, Equipment.EquipmentType.Head); int i = Random.Range(0, allRightItems.Count); headID = allRightItems[i].ID; } if (clothTech != Item.ItemTechnology.T0) { List <Item> allRightItems = InventoryManager.Instance.GetItemsByTechAndEquipType(clothTech, Equipment.EquipmentType.Cloth); int i = Random.Range(0, allRightItems.Count); clothID = allRightItems[i].ID; } if (pantsTech != Item.ItemTechnology.T0) { List <Item> allRightItems = InventoryManager.Instance.GetItemsByTechAndEquipType(pantsTech, Equipment.EquipmentType.Pants); int i = Random.Range(0, allRightItems.Count); pantsID = allRightItems[i].ID; } if (beltTech != Item.ItemTechnology.T0) { List <Item> allRightItems = InventoryManager.Instance.GetItemsByTechAndEquipType(beltTech, Equipment.EquipmentType.Belt); int i = Random.Range(0, allRightItems.Count); beltID = allRightItems[i].ID; } if (weaponTech != Item.ItemTechnology.T0) { Item.ItemType weaponType = Random.Range(0, 2) == 0 ? Item.ItemType.MeleeWeapon : Item.ItemType.ShootWeapon; List <Item> allRightItems = InventoryManager.Instance.GetItemsByTechAndType(weaponTech, weaponType); int i = Random.Range(0, allRightItems.Count); weaponID = allRightItems[i].ID; } int[] skills = new int[20]; for (int i = 0; i < 20; i++) { skills[0] = 0; } //TODO 特异值(主体质) CharacterProperty.CharacterKind kind = (CharacterProperty.CharacterKind)System.Enum.Parse(typeof(CharacterProperty.CharacterKind), temp["characterKind"].str); CharacterProperty charProp = new CharacterProperty(id, name, faction, type, sprite, kind, consititution, strength, agility, dexterous, concentration, InventoryManager.Instance.GetItemByID(weaponID), allExperience, 0, skills, 0, headID, clothID, pantsID, beltID); charPropList.Add(charProp); } }
/// <summary> /// 解析物品信息 /// </summary> void ParseItemJson() { itemList = new List <Item>(); TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemJson = itemText.text; JSONObject itemObjects = new JSONObject(itemJson); foreach (JSONObject temp in itemObjects.list) { Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), temp["type"].str); int id = (int)temp["id"].n; string name = temp["name"].str; string description = temp["description"].str; Item.ItemTechnology technology = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["technology"].str); int value = (int)temp["value"].n; string sprite = temp["sprite"].str; int maxStark = (int)temp["maxStark"].n; Item item = null; switch (type) { #region 解析消耗品 case Item.ItemType.Consumable: int hp = temp.HasField("hp") ? (int)temp["hp"].n : 0; int eg = temp.HasField("eg") ? (int)temp["eg"].n : 0; int hl = temp.HasField("hl") ? (int)temp["hl"].n : 0; int tempConstitution = temp.HasField("tempConstitution") ? (int)temp["tempConstitution"].n : 0; int tempStrength = temp.HasField("tempStrength") ? (int)temp["tempStrength"].n : 0; int tempAgility = temp.HasField("tempAgility") ? (int)temp["tempAgility"].n : 0; int tempDexterous = temp.HasField("tempDexterous") ? (int)temp["tempDexterous"].n : 0; int tempConcentration = temp.HasField("tempConcentration") ? (int)temp["tempConcentration"].n : 0; int continuedTime = temp.HasField("continuedTime") ? (int)temp["continuedTime"].n : 0; int con_buffID = temp.HasField("buffID") ? (int)temp["buffID"].n : 0; item = new Consumable(id, name, description, type, technology, value, maxStark, sprite, hp, eg, hl, tempConstitution, tempStrength, tempAgility, tempDexterous, tempConcentration, continuedTime, con_buffID); break; #endregion #region 解析包裹 case Item.ItemType.Package: bool isGetOne = temp["isGetOne"].n == 1 ? true : false; int[] itemIDs = temp.HasField("itemIDs") ? new int[temp["itemIDs"].list.Count] : null; if (itemIDs != null) { for (int i = 0; i < temp["itemIDs"].list.Count; i++) { itemIDs[i] = int.Parse(temp["itemIDs"].list[i].str); } } Item.ItemType[] itemTypes = temp.HasField("itemTypes") ? new Item.ItemType[temp["itemTypes"].list.Count] : null; if (itemTypes != null) { for (int i = 0; i < temp["itemTypes"].list.Count; i++) { itemTypes[i] = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), temp["itemTypes"].list[i].str); } } Item.ItemTechnology[] itemTechnologies = temp.HasField("itemTechnologies") ? new Item.ItemTechnology[temp["itemTechnologies"].list.Count] : null; if (itemTechnologies != null) { for (int i = 0; i < temp["itemTechnologies"].list.Count; i++) { itemTechnologies[i] = (Item.ItemTechnology)System.Enum.Parse(typeof(Item.ItemTechnology), temp["itemTechnologies"].list[i].str); } } int[] itemCount = new int[temp["itemCount"].list.Count]; for (int i = 0; i < temp["itemCount"].list.Count; i++) { itemCount[i] = int.Parse(temp["itemCount"].list[i].str); } float[] itemProbabilities = new float[temp["itemProbabilities"].list.Count]; for (int i = 0; i < temp["itemProbabilities"].list.Count; i++) { itemProbabilities[i] = float.Parse(temp["itemProbabilities"].list[i].str); } item = new Package(id, name, description, type, technology, value, maxStark, sprite, isGetOne, itemIDs, itemTypes, itemTechnologies, itemCount, itemProbabilities); break; #endregion #region 解析装备 case Item.ItemType.Equipment: int equipmentID = (int)temp["equipmentID"].n; Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipmentType"].str); int resistance = (int)temp["resistance"].n; int constitution = (int)temp["constitution"].n; int strength = (int)temp["strength"].n; int agility = (int)temp["agility"].n; int dexterous = (int)temp["dexterous"].n; int concentration = (int)temp["concentration"].n; item = new Equipment(id, name, description, type, technology, value, maxStark, sprite, equipmentID, equipmentType, resistance, constitution, strength, agility, dexterous, concentration); break; #endregion #region 解析武器 case Item.ItemType.MeleeWeapon: int meleeWeaponID = (int)temp["meleeWeaponID"].n; int meleeDamage = (int)temp["meleeDamage"].n; int throwDamage = (int)temp["throwDamage"].n; float attackInterval = temp["attackInterval"].n; MeleeWeapon.MeleeWeaponType mwType = (MeleeWeapon.MeleeWeaponType)System.Enum.Parse(typeof(MeleeWeapon.MeleeWeaponType), temp["mwType"].str); item = new MeleeWeapon(id, name, description, type, technology, value, maxStark, sprite, meleeWeaponID, meleeDamage, throwDamage, attackInterval, mwType); break; case Item.ItemType.ShootWeapon: int shootWeaponID = (int)temp["shootWeaponID"].n; int shootDamage = (int)temp["shootDamage"].n; int s_meleeDamage = (int)temp["meleeDamage"].n; float s_attackInterval = temp["attackInterval"].n; float lashuanTime = temp["lashuanTime"].n; float reloadTime = temp["reloadTime"].n; float damageRange = temp["damageRange"].n; ShootWeapon.ShootWeaponType swType = (ShootWeapon.ShootWeaponType)System.Enum.Parse(typeof(ShootWeapon.ShootWeaponType), temp["swType"].str); ShootWeapon.AmmoType amType = (ShootWeapon.AmmoType)System.Enum.Parse(typeof(ShootWeapon.AmmoType), temp["amType"].str); int ammoCount = (int)temp["ammoCount"].n; int accuracy = (int)temp["accuracy"].n; item = new ShootWeapon(id, name, description, type, technology, value, maxStark, sprite, shootWeaponID, shootDamage, s_meleeDamage, s_attackInterval, lashuanTime, reloadTime, damageRange, swType, amType, ammoCount, accuracy); break; #endregion #region 解析材料,蓝图,子弹 case Item.ItemType.Unuseable: item = new Unuseable(id, name, description, type, technology, value, maxStark, sprite); break; case Item.ItemType.Blueprint: int[] craftIDs = new int[temp["craftIDs"].list.Count]; for (int i = 0; i < temp["craftIDs"].list.Count; i++) { craftIDs[i] = int.Parse(temp["craftIDs"].list[i].str); } item = new Blueprint(id, name, description, type, technology, value, maxStark, sprite, craftIDs); break; case Item.ItemType.Ammo: item = new Ammo(id, name, description, type, technology, value, maxStark, sprite); break; #endregion #region 解析BUFF,技能 case Item.ItemType.Buff: int buffID = (int)temp["buffID"].n; int durationTime = (int)temp["durationTime"].n; string effectDescription = temp["effectDescription"].str; string[] effectProp = new string[temp["effectProp"].list.Count]; int[] effectValue = new int[temp["effectValue"].list.Count]; for (int i = 0; i < temp["effectProp"].list.Count; i++) { effectProp[i] = temp["effectProp"].list[i].str; } for (int i = 0; i < temp["effectValue"].list.Count; i++) { effectValue[i] = int.Parse(temp["effectValue"].list[i].str); } item = new Buff(id, name, description, type, technology, value, maxStark, sprite, buffID, durationTime, effectDescription, effectProp, effectValue); break; case Item.ItemType.Skill: int skillID = (int)temp["skillID"].n; int maxPoint = (int)temp["maxPoint"].n; string skillDescription = temp["skillDescription"].str; int[] preSkillID = new int[temp["preSkillID"].list.Count]; for (int i = 0; i < temp["preSkillID"].list.Count; i++) { preSkillID[i] = int.Parse(temp["preSkillID"].list[i].str); } int[] eachSkillNeed = new int[temp["eachSkillNeed"].list.Count]; for (int i = 0; i < temp["eachSkillNeed"].list.Count; i++) { eachSkillNeed[i] = int.Parse(temp["eachSkillNeed"].list[i].str); } item = new Skill(id, name, description, type, technology, value, maxPoint, sprite, skillID, maxPoint, skillDescription, preSkillID, eachSkillNeed); break; #endregion } itemList.Add(item); } //拳头,只用于属性调整 MeleeWeapon hand = new MeleeWeapon(999, "拳头", " ", Item.ItemType.MeleeWeapon, Item.ItemTechnology.T0, 0, 1, " ", 0, 20, 0, 2, MeleeWeapon.MeleeWeaponType.刀); itemList.Add(hand); }
/// <summary> /// 右键物品栏且物品栏有物品 /// </summary> public virtual void OnButtonRight() { ItemUI currentItem = transform.GetChild(0).GetComponent <ItemUI>(); if (currentItem.Item.Type == Item.ItemType.Equipment || currentItem.Item.Type == Item.ItemType.ShootWeapon || currentItem.Item.Type == Item.ItemType.MeleeWeapon) { currentItem.ReduceAmount(1); Item tempItem = currentItem.Item; if (currentItem.Amount <= 0) { DestroyImmediate(currentItem.gameObject); InventoryManager.Instance.HideToolTip(); } CharacterPanel.Instance.Equip(tempItem); } if (currentItem.Item.Type == Item.ItemType.Consumable) { //TODO 消耗品 //TODO 普通消耗品(无持续性) //TODO 滋补品(有持续时间) currentItem.ReduceAmount(1); Consumable tempItem = (Consumable)currentItem.Item; if (currentItem.Amount <= 0) { DestroyImmediate(currentItem.gameObject); InventoryManager.Instance.HideToolTip(); } if (tempItem.ContinuedTime != 0) { //使用了滋补品 //Debug.Log("使用了"+tempItem.Name); CharacterPanel.Instance.AddBuff(tempItem.BuffID); } else { } } if (currentItem.Item.Type == Item.ItemType.Package) { //TODO 打开包裹 currentItem.ReduceAmount(1); Package tempItem = (Package)currentItem.Item; if (currentItem.Amount <= 0) { DestroyImmediate(currentItem.gameObject); InventoryManager.Instance.HideToolTip(); } if (tempItem.ItemIDs != null) { int getItemID = 0; int getItemAmount = 1; float randomProb = Random.value; for (int i = 0; i < tempItem.ItemProbabilities.Length; i++) { float minProb = 0; float maxProb = 0; for (int j = 0; j < i; j++) { minProb += tempItem.ItemProbabilities[j]; } for (int k = -1; k < i; k++) { maxProb += tempItem.ItemProbabilities[k + 1]; } //string text= string.Format("第{0}组:最小概率:{1} 最大概率:{2} 本次概率:{3}", i, minProb, maxProb, randomProb); if (randomProb >= minProb && randomProb <= maxProb) { getItemID = tempItem.ItemIDs[i]; getItemAmount = tempItem.ItemCount[i]; } //Debug.Log(text); } for (int i = 0; i < getItemAmount; i++) { BackPack.Instance.SetItem(getItemID); } } else if (tempItem.ItemTypes != null) { if (tempItem.ItemTechnologies != null && tempItem.ItemProbabilities[0] == 1) { for (int i = 0; i < tempItem.ItemTypes.Length; i++) { List <Item> items = InventoryManager.Instance.FindItemsWithCondition(tempItem.ItemTypes[i], tempItem.ItemTechnologies[i]); int randomID = Random.Range(0, items.Count); Item getItem = items[randomID]; int itemCount = tempItem.ItemCount[i] > getItem.MaxStark ? getItem.MaxStark : tempItem.ItemCount[i]; for (int j = 0; j < itemCount; j++) { BackPack.Instance.SetItem(getItem); } } } if (tempItem.ItemTechnologies != null && tempItem.ItemProbabilities[0] != 1) { float randomProb = Random.value; Item.ItemTechnology randomTech = Item.ItemTechnology.T1; for (int i = 0; i < tempItem.ItemProbabilities.Length; i++) { float minProb = 0; float maxProb = 0; for (int j = 0; j < i; j++) { minProb += tempItem.ItemProbabilities[j]; } for (int k = -1; k < i; k++) { maxProb += tempItem.ItemProbabilities[k + 1]; } //string text = string.Format("第{0}组:最小概率:{1} 最大概率:{2} 本次概率:{3}", i, minProb, maxProb, randomProb); //Debug.Log(text); if (randomProb >= minProb && randomProb <= maxProb) { randomTech = (Item.ItemTechnology)(i + 1); } } for (int i = 0; i < tempItem.ItemTypes.Length; i++) { List <Item> items = InventoryManager.Instance.FindItemsWithCondition(tempItem.ItemTypes[i], randomTech); int randomID = Random.Range(0, items.Count); Item getItem = items[randomID]; int itemCount = tempItem.ItemCount[i] > getItem.MaxStark ? getItem.MaxStark : tempItem.ItemCount[i]; for (int j = 0; j < itemCount; j++) { BackPack.Instance.SetItem(getItem); } } } } } if (currentItem.Item.Type == Item.ItemType.Blueprint) { //TODO 学习蓝图 currentItem.ReduceAmount(1); Blueprint tempItem = (Blueprint)currentItem.Item; if (currentItem.Amount <= 0) { DestroyImmediate(currentItem.gameObject); InventoryManager.Instance.HideToolTip(); } foreach (int craftID in tempItem.CraftIDs) { InventoryManager.Instance.LearnCraft(craftID); } } }