public EquipableItem(string name, Sprite icon, Dictionary <Attribute.AttributeType, AttributeBuff> buffTable, Equipment.EquipmentType equipmentType, float curDurability, float maxDurability) : base(name, icon, buffTable) { _equipmentType = equipmentType; _curDurability = curDurability; _maxDurability = maxDurability; }
/// <summary> /// 解析物品信息 /// </summary> void ParseItemJson() { itemList = new List <Item>(); //文本为在Unity里面是 TextAsset类型 TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemsJson = itemText.text;//物品信息的Json格式 JSONObject j = new JSONObject(itemsJson); foreach (JSONObject temp in j.list) { string typeStr = temp["type"].str; Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); //下面的事解析这个对象里面的公有属性 int id = (int)(temp["id"].n); string name = temp["name"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; Item item = null; switch (type) { case Item.ItemType.Consumable: //int hp = (int)(temp["hp"].n); //int mp = (int)(temp["mp"].n); int exp = (int)(temp["exp"].n); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, exp); break; case Item.ItemType.Equipment: // //int strength = (int)temp["strength"].n; //int intellect = (int)temp["intellect"].n; //int agility = (int)temp["agility"].n; //int stamina = (int)temp["stamina"].n; int hp = (int)temp["hp"].n; Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, equipType); break; case Item.ItemType.Weapon: // int damage = (int)temp["damage"].n; //Weapon.WeaponType wpType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].str); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage); break; case Item.ItemType.Material: // item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); //Debug.Log(item); } }
private void RegistItem() { //将信息读取成string类型 string tmpPath = Application.dataPath + "/Resources" + "/Data" + "/ItemData.json"; StreamReader sr = new StreamReader(tmpPath); string tmpItem = sr.ReadToEnd(); sr.Close(); //将string类型信息转成jsondata JsonData itemJson = JsonMapper.ToObject(tmpItem); //将JsonData变成一个个的ItemData类型的格式 foreach (JsonData item in itemJson) { int id = (int)item["id"]; string name = (string)item["name"]; string tmpType = (string)item["type"]; string tmpQuality = (string)item["quality"]; string describe = (string)item["describe"]; int capacity = (int)item["capacity"]; int buyPrice = (int)item["buyPrice"]; int sellPrice = (int)item["sellPrice"]; string path = (string)item["path"]; //将string强转成枚举类型 ItemData.ItemType type = (ItemData.ItemType)System.Enum.Parse(typeof(ItemData.ItemType), tmpType); ItemData.ItemQuality quality = (ItemData.ItemQuality)System.Enum.Parse(typeof(ItemData.ItemQuality), tmpQuality); ItemData newItem = null; //根据不同的类型提供不同的构造方法 switch (type) { case ItemData.ItemType.Consumable: int hp = (int)item["hp"]; int mp = (int)item["mp"]; newItem = new Consumable(id, name, type, quality, describe, capacity, buyPrice, sellPrice, path, hp, mp); items.Add(newItem); break; case ItemData.ItemType.Equipment: int defensive = (int)item["defensive"]; int maxHP = (int)item["maxHP"]; string tmpEquipType = (string)item["equipType"]; Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), tmpEquipType); newItem = new Equipment(id, name, type, quality, describe, capacity, buyPrice, sellPrice, path, defensive, maxHP, equipType); items.Add(newItem); break; case ItemData.ItemType.Weapon: int hurt = (int)item["hurt"]; newItem = new Weapon(id, name, type, quality, describe, capacity, buyPrice, sellPrice, path, hurt); items.Add(newItem); break; case ItemData.ItemType.Material: newItem = new Material(id, name, type, quality, describe, capacity, buyPrice, sellPrice, path); items.Add(newItem); break; } } }
public static bool IsOverOrEqualBagMaxSlotCount(this User user, Equipment.EquipmentType equipmentType) { var usedCountString = GetUsedCountString(equipmentType); var totalCountString = GetTotalCountString(equipmentType); var userBagCapacity = user.userBagCapacity; return(userBagCapacity[usedCountString].AsInt32 >= userBagCapacity[totalCountString].AsInt32); }
public Equipment(Equipment equipment) { this._itemSlots = new EquipmentElement[12]; for (int index = 0; index < 12; ++index) { this._itemSlots[index] = new EquipmentElement(equipment[index]); } this._equipmentType = equipment._equipmentType; }
/// <summary> /// 解析物品信息 /// </summary> private void ParseItemJson() { itemList = new List <Item>(); //文本为在Unity里面是TextAsset类型 TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemJson = itemText.text; //物品信息的Json格式 JSONObject j = new JSONObject(itemJson); foreach (JSONObject temp in j.list) { string typeStr = temp["type"].str; Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); int id = (int)temp["id"].n; string name = temp["name"].str; Item.QualityType qualitype = (Item.QualityType)System.Enum.Parse(typeof(Item.QualityType), temp["qualityType"].str); string description = temp["description"].str; int capacity = (int)temp["capacity"].n; int buyPrice = (int)temp["buyPrice"].n; int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = int.Parse(temp["hp"].ToString()); int mp = int.Parse(temp["mp"].ToString()); item = new Consumable(id, name, type, qualitype, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: //TODO int strength = (int)temp["strength"].n; int intelligent = (int)temp["intelligent"].n; int agility = (int)temp["agility"].n; int stamina = (int)temp["stamina"].n; Equipment.EquipmentType equipType = (Equipment.EquipmentType) System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, qualitype, description, capacity, buyPrice, sellPrice, sprite, strength, intelligent, agility, stamina, equipType); break; case Item.ItemType.Weapon: //TODO break; case Item.ItemType.Material: break; } itemList.Add(item); } }
void ParseItemJson() { itemList = new List <Item>(); TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemsJson = itemText.text; JSONObject j = new JSONObject(itemsJson); Debug.Log(string.Format("{0} {1} {2} {3}", j.IsArray, j.isContainer, j.Count, j.list.Count)); foreach (JSONObject temp in j.list) { string typeStr = temp["type"].str; Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); int id = (int)(temp["id"].n); string name = temp["name"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = (int)(temp["hp"].n); int mp = (int)(temp["mp"].n); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = (int)(temp["strength"].n); int intellect = (int)(temp["intellect"].n); int agility = (int)(temp["agility"].n); int stamina = (int)(temp["stamina"].n); Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType); break; case Item.ItemType.Weapon: int damage = (int)(temp["damage"].n); Weapon.WeaponType wpType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].str); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, wpType); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); //Debug.Log(item); } }
void ParseItemJson() { itemList = new List <Item>(); TextAsset itemText = Resources.Load <TextAsset>("Items"); JsonData itemsData = JsonMapper.ToObject(itemText.text); Item item = null; foreach (JsonData itemData in itemsData) { int id = (int)itemData["id"]; string itemName = itemData["name"].ToString(); Item.ItemQuality quality = (Item.ItemQuality)Enum.Parse(typeof(Item.ItemQuality), itemData["quality"].ToString()); string des = itemData["description"].ToString(); int capacity = (int)itemData["capacity"]; int buyPrice = (int)itemData["buyPrice"]; int sellPrice = (int)itemData["sellPrice"]; string sprite = itemData["sprite"].ToString(); switch (itemData["type"].ToString()) { case "Consumable": int hp = (int)itemData["hp"]; int mp = (int)itemData["mp"]; item = new Consumable(id, itemName, Item.ItemType.Consumable, quality, des, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case "Equipment": int strength = (int)itemData["strength"]; int intellect = (int)itemData["intellect"]; int agility = (int)itemData["agility"]; int stamina = (int)itemData["stamina"]; Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)Enum.Parse(typeof(Equipment.EquipmentType), itemData["equipmentType"].ToString()); item = new Equipment(id, itemName, Item.ItemType.Consumable, quality, des, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipmentType); break; case "Weapon": int damage = (int)itemData["damage"]; Weapon.WeaponType weaponType = (Weapon.WeaponType)Enum.Parse(typeof(Weapon.WeaponType), itemData["weaponType"].ToString()); item = new Weapon(id, itemName, Item.ItemType.Consumable, quality, des, capacity, buyPrice, sellPrice, sprite, damage, weaponType); break; case "Material": item = new Material(id, itemName, Item.ItemType.Consumable, quality, des, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); //Debug.Log(item); } }
public void RemoveItem(Equipment.EquipmentType type) { Debug.Assert(_equipmentTable[type].IsEmpty == false); _equipmentTable[type].RemoveItem(); EventManager.TriggerEvent(EventName.UPDATE_EQUIPMENT); Debug.Log(this.ToString()); }
public void Hide(Equipment.EquipmentType type) { foreach (var eq in Equipments.Where(e => e.Type == type)) { foreach (var eqItem in eq.Items) { eqItem.gameObject.SetActive(false); } } }
/// <summary> /// 解析JSON /// </summary> private void ParseItemsJSON() { itemList = new List <Item>(); TextAsset ta = Resources.Load <TextAsset>("items"); JSONObject j = new JSONObject(ta.text); foreach (JSONObject temp in j.list) { string itemType = temp["type"].str; Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), itemType); int id = (int)temp["id"].n; //公用物品解析 string name = temp["name"].str; //string Quality = temp["quality"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = (int)temp["hp"].n; int mp = (int)temp["mp"].n; item = new Consumable (id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = (int)temp["strength"].n; int intellect = (int)temp["intellect"].n; int agility = (int)temp["agility"].n; int stamina = (int)temp["stamina"].n; Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment (id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType); break; case Item.ItemType.Weapon: int damage = (int)temp["damage"].n; Weapon.WeaponType weaponType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].str); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, weaponType); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); //Debug.Log(item); } }
/// <summary> /// 解析Json文件 /// </summary> public void ParseItemJson() { itemList = new List <Item>(); //文本在unity里面是TextAsset类型 TextAsset itemText = Resources.Load <TextAsset>("Item"); //加载json文本 string itemJson = itemText.text; //得到json文本里面的内容 //bug.Log(itemJson); JSONObject j = new JSONObject(itemJson); foreach (var temp in j.list) { //物品类型字符串转化为枚举类型 Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), temp["type"].str); //print(type); //下面解析的是物品的共有属性:id,name,quality。。。注:temp["id"].n 的 .n,.str等是json插件的写法,用于解析 int id = (int)(temp["id"].n); string name = temp["name"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = (int)(temp["hp"].n); int mp = (int)(temp["mp"].n); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = (int)(temp["strength"].n); int intellect = (int)(temp["intellect"].n); int agility = (int)(temp["agility"].n); int stamina = (int)(temp["stamina"].n); Equipment.EquipmentType equiType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equiType); break; case Item.ItemType.Weapon: int damage = (int)(temp["damage"].n); Weapon.WeaponType weaponType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].str); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, weaponType); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item);//把解析到的物品信息加入物品列表里面 Debug.Log(item); } }
/// <summary> /// 解析物品Json /// </summary> public void ParseItemJson() { TextAsset textAsset = Resources.Load <TextAsset>("Items"); string itemsJson = textAsset.text; //List<Item> itemList = JsonConvert.DeserializeObject<List<Item>>(itemsJson); JSONObject j = new JSONObject(itemsJson); foreach (JSONObject temp in j.list) { int id = (int)temp["id"].n; string name = temp["name"].str; string description = temp["description"].str; int capacity = (int)temp["capacity"].n; int buyPrice = (int)temp["buyPrice"].n; int sellPrice = (int)temp["sellPrice"].n; string sprite = temp["sprite"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), temp["type"].str); Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = (int)temp["hp"].n; int mp = (int)temp["mp"].n; item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = (int)temp["strength"].n; int intelligence = (int)temp["intelligence"].n; int agility = (int)temp["agility"].n; int stamina = (int)temp["stamina"].n; Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, strength, intelligence, agility, stamina, equipType, sprite); break; case Item.ItemType.Weapon: int damage = (int)temp["damage"].n; Weapon.WeaponType weaponType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].str); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, weaponType); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; default: break; } itemList.Add(item); } }
public void AddItem(Item item) { Debug.Assert(item is IEquipable); Equipment.EquipmentType type = ((IEquipable)item).EquipmentType; _equipmentTable[type].AddItem(item); EventManager.TriggerEvent(EventName.UPDATE_EQUIPMENT); Debug.Log(this.ToString()); }
/// <summary> /// 解析物品信息 /// </summary> private void ParseItemJson() { //文本在Unity里是TextAsset类型 itemText = Resources.Load <TextAsset>("ItemJson"); //string itemContent = itemText.ToString(); string itemContent = itemText.text; JsonData json = JsonMapper.ToObject(itemContent); //下面的是解析这个对象里面的共有属性 for (int i = 0; i < json.Count; i++) { int id = int.Parse(json[i]["id"].ToString()); string name = json[i]["name"].ToString(); Item.ItemType type = (Item.ItemType)Enum.Parse(typeof(Item.ItemType), json[i]["type"].ToString()); Item.ItemQuality quality = (Item.ItemQuality)Enum.Parse(typeof(Item.ItemQuality), json[i]["quality"].ToString()); string description = json[i]["description"].ToString(); int capacity = int.Parse(json[i]["capacity"].ToString()); int buyPrice = int.Parse(json[i]["buyPrice"].ToString()); int sellPrice = int.Parse(json[i]["sellPrice"].ToString()); string sprite = json[i]["sprite"].ToString(); Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = int.Parse(json[i]["hp"].ToString()); int mp = int.Parse(json[i]["mp"].ToString()); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = int.Parse(json[i]["strength"].ToString()); int intellect = int.Parse(json[i]["intellect"].ToString()); int agility = int.Parse(json[i]["agility"].ToString()); int stamina = int.Parse(json[i]["stamina"].ToString()); Equipment.EquipmentType equipType = (Equipment.EquipmentType)Enum.Parse(typeof(Equipment.EquipmentType), json[i]["equipType"].ToString()); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType); break; case Item.ItemType.Weapon: int damage = int.Parse(json[i]["damage"].ToString()); Weapon.WeaponType wpType = (Weapon.WeaponType)Enum.Parse(typeof(Weapon.WeaponType), json[i]["weaponType"].ToString()); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, wpType); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); } }
public void ParseItemJson() { Items = new Dictionary <int, Item>(); //文本为在Unity里面是 TextAsset类型 TextAsset itemText = Resources.Load <TextAsset>("Item"); string itemsJson = itemText.text;//物品信息的Json格式 JSONObject j = new JSONObject(itemsJson); foreach (JSONObject temp in j.list) { string typeStr = temp["type"].str; Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); //下面的事解析这个对象里面的公有属性 int id = (int)(temp["id"].n); string name = temp["name"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; Item item = null; switch (type) { case Item.ItemType.Consumable: int function = (int)(temp["function"].n); int value = (int)(temp["value"].n); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, function, value); break; case Item.ItemType.Equipment: Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); JSONObject equipProperty = temp["equipProperty"]; int[] property = new int[21]; int i = 0; foreach (JSONObject temp2 in equipProperty.list) { property[i] = (int)temp2.n; i++; } item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, property, equipType); break; case Item.ItemType.Material: // item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } Items.Add(id, item); } }
/// <summary> /// 解析物品信息 - Json,添加到 list 里 /// </summary> private void ParseItemJson() { itemList = new List <Item>(); // 加载 Resources 下的 json 文件,文本为在 Unity 里面是 TextAsset 类型 TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemsJson = itemText.text; // 物品信息的 Json 格式文本 JSONObject jo = new JSONObject(itemsJson); foreach (JSONObject temp in jo.list) { // 解析 Items 里面的公有属性 int id = (int)(temp["id"].n); string name = temp["name"].str; Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; string typeStr = temp["type"].str; // 解析 type,不同类型的物体拥有各自不同的属性 Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); // 将 string 转 枚举 Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = (int)(temp["hp"].n); int mp = (int)(temp["mp"].n); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = (int)temp["strength"].n; int intellect = (int)temp["intellect"].n; int agility = (int)temp["agility"].n; int stamina = (int)temp["stamina"].n; Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType); break; case Item.ItemType.Weapon: int damage = (int)temp["damage"].n; Weapon.WeaponType wpType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].str); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, wpType); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); } }
/// <summary> /// 解析物品信息 /// </summary> void ParseItemJson() { itemList = new List <Item>(); //文本为在Unity里面是 TextAsset类型 TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemsJson = itemText.text;//物品信息的Json格式 JsonData data = JsonMapper.ToObject(itemsJson); for (int i = 0; i < data.Count; i++) { string typeStr = data[i]["type"].ToString(); Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); //下面的事解析这个对象里面的公有属性 int id = int.Parse((data[i]["id"]).ToString()); string name = data[i]["name"].ToString(); Item.ItemQuality quality = (Item.ItemQuality)System.Enum.Parse(typeof(Item.ItemQuality), data[i]["quality"].ToString()); string description = data[i]["description"].ToString(); int capacity = int.Parse((data[i]["capacity"]).ToString()); int buyPrice = int.Parse((data[i]["buyPrice"]).ToString()); int sellPrice = int.Parse((data[i]["sellPrice"]).ToString()); string sprite = data[i]["sprite"].ToString(); Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = int.Parse(data[i]["hp"].ToString()); int mp = int.Parse(data[i]["mp"].ToString()); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case Item.ItemType.Equipment: int strength = int.Parse(data[i]["strength"].ToString()); int intellect = int.Parse(data[i]["intellect"].ToString()); int agility = int.Parse(data[i]["agility"].ToString()); int stamina = int.Parse(data[i]["stamina"].ToString()); Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), data[i]["equipType"].ToString()); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType); break; case Item.ItemType.Weapon: int damage = int.Parse(data[i]["damage"].ToString()); Weapon.WeaponType wpType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), data[i]["weaponType"].ToString()); item = new Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, wpType); break; } itemList.Add(item); //Debug.Log(item); } }
protected override async ETTask <bool> _IsValid() { var command = new BsonDocument { { "find", "User" } }; BsonDocument results = await db.database.RunCommandAsync <BsonDocument>(command); List <BsonDocument> users = BsonSerializer.Deserialize <List <BsonDocument> >(results["cursor"]["firstBatch"].ToJson()); if (users.Count == 0) { return(true); } var configComponent = Game.Scene.GetComponent <ConfigComponent>(); var bagLimitSettings = configComponent.GetAll(typeof(BagLimitSetting)).OfType <BagLimitSetting>().ToList(); bool valid = users.All(e => { if (e.TryGetValue("userBagCapacity", out BsonValue val)) { var doc = val.ToBsonDocument(); if (doc == null) { return(false); } for (int i = 0; i < bagLimitSettings.Count; i++) { var bagLimitSetting = bagLimitSettings[i]; Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)bagLimitSetting.Id; var usedCountString = EquipmentDataHelper.GetUsedCountString(equipmentType); var totalCountString = EquipmentDataHelper.GetTotalCountString(equipmentType); if (doc[usedCountString].AsInt32 <0 || doc[usedCountString].AsInt32> doc[totalCountString].AsInt32) { return(false); } if (doc[totalCountString].AsInt32 > bagLimitSetting.MaxSlotCount) { return(false); } } return(true); } return(false); }); if (!valid) { failedReason = $"DBSchema.User.userBagCapacity with invalid slot count or no the element on document!"; } return(valid); }
private List <string> GetEquipmentPropertyNames(Equipment.EquipmentType type, Equipment equipment) { var prop = new List <string>(); prop.Add("LastEdited"); prop.Add("Model"); prop.Add("Serial"); prop.Add("Owner"); prop.Add("Location"); switch (type) { case Equipment.EquipmentType.Laptop: case Equipment.EquipmentType.Chromebook: case Equipment.EquipmentType.Mac: case Equipment.EquipmentType.Desktop: case Equipment.EquipmentType.Tablet: break; case Equipment.EquipmentType.Projector: prop.Add("Resolution"); break; case Equipment.EquipmentType.Mobile: prop.Add("Mobile Number"); break; case Equipment.EquipmentType.Printer: prop.Add("IP"); break; case Equipment.EquipmentType.Router: case Equipment.EquipmentType.Switch: prop.Add("IP"); prop.Add("Ports"); break; case Equipment.EquipmentType.Misc: break; default: break; } prop.Add("Notes"); return(prop); }
private Equipment generateEquipment() { int id = this.getNextEquipmentId(); Equipment.EquipmentType[] types = Enum.GetValues(typeof(Equipment.EquipmentType)).Cast <Equipment.EquipmentType>().ToArray(); Equipment.EquipmentType type = Utils.uniformFromArray(types); Equipment equipment = new Equipment(id, type); this.generateAttributes(equipment); this.nameEquipment(equipment); this.setPrice(equipment); return(equipment); }
public static BsonDocument GetDefaultUserBag() { var configComponent = Game.Scene.GetComponent <ConfigComponent>(); var bagLimitSettings = configComponent.GetAll(typeof(BagLimitSetting)).OfType <BagLimitSetting>().ToList(); var userBagCapacity = new BsonDocument(); for (int i = 0; i < bagLimitSettings.Count; i++) { var bagLimitSetting = bagLimitSettings[i]; Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)bagLimitSetting.Id; var usedCountString = GetUsedCountString(equipmentType); var totalCountString = GetTotalCountString(equipmentType); userBagCapacity[usedCountString] = 0; userBagCapacity[totalCountString] = bagLimitSetting.MaxSlotCount; } return(userBagCapacity); }
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); }
/** * 解析Json文件 * */ public void ParseItemJson() { itemList = new List <ItemDetail>(); TextAsset itemText = Resources.Load <TextAsset>("ItemDetail"); string itemJson = itemText.text; JSONObject j = new JSONObject(itemJson); foreach (var temp in j.list) { int id = (int)(temp["id"].n); string name = temp["name"].str; ItemDetail.ItemType type = (ItemDetail.ItemType)System.Enum.Parse(typeof(ItemDetail.ItemType), temp["type"].str); ItemDetail.ItemQuality quality = (ItemDetail.ItemQuality)System.Enum.Parse(typeof(ItemDetail.ItemQuality), temp["quality"].str); string description = temp["description"].str; int capacity = (int)(temp["capacity"].n); int buyPrice = (int)(temp["buyPrice"].n); int sellPrice = (int)(temp["sellPrice"].n); string sprite = temp["sprite"].str; ItemDetail item = null; switch (type) { case ItemDetail.ItemType.Consumable: int hp = (int)(temp["hp"].n); int mp = (int)(temp["mp"].n); item = new Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case ItemDetail.ItemType.Equipment: int M_MaxHp = (int)(temp["M_MaxHp"].n); int M_MaxMp = (int)(temp["M_MaxMp"].n); int M_Atk = (int)(temp["M_Atk"].n); int M_Def = (int)(temp["M_Def"].n); int M_Mgk = (int)(temp["M_Mgk"].n); int M_Rgs = (int)(temp["M_Rgs"].n); int M_Spd = (int)(temp["M_Spd"].n); Equipment.EquipmentType equiType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipType"].str); item = new Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, M_MaxHp, M_MaxMp, M_Atk, M_Def, M_Mgk, M_Rgs, M_Spd, equiType); break; case ItemDetail.ItemType.QuestRelated: item = new QuestRelated(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); } }
private void ReturnAirItem(object[] eventParams) { if (_airItem.IsEmpty) { return; } SlotPosition originalPosition = _airItem.OriginalPosition; Item itemAir = _airItem.Item; IPickupable pickupableAir = itemAir as IPickupable; IEquipable equipableAir = itemAir as IEquipable; IStackable stackableAir = itemAir as IStackable; pickupableAir.OnRemoveFromAir(_airItem); if (originalPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX) { Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)originalPosition.SlotIndex; if (_equipment.EquipmentTable[equipmentType].IsEmpty) { equipableAir.OnEquip(_equipment, _stats); } else { pickupableAir.OnPutInInventory(_inventory); } } else { if (stackableAir != null) { stackableAir.OnStack(_inventory, originalPosition); } else if (_inventory.IsItemEmpty(originalPosition)) { pickupableAir.OnPutInInventory(_inventory, originalPosition); } else { pickupableAir.OnPutInInventory(_inventory); } } }
private List <string> GetEquipmentPropertyNames(Equipment.EquipmentType type, Equipment equipment) { var prop = new List <string> { "LastEdited", "Model", "Serial", "OwnerName", "Location" }; switch (type) { case Equipment.EquipmentType.Projector: prop.Add("Resolution"); break; case Equipment.EquipmentType.Mobile: prop.Add("Mobile Number"); break; case Equipment.EquipmentType.Printer: prop.Add("IP"); break; case Equipment.EquipmentType.Router: case Equipment.EquipmentType.Switch: prop.Add("IP"); prop.Add("Ports"); break; default: break; } prop.Add("Notes"); return(prop); }
// Dew it ! public void Deal(Action p_CallBack, Equipment.EquipmentType p_EquipmentType) { if (Requisite != Equipment.EquipmentType.Nill) { if (p_EquipmentType != Requisite) { Debug.Log("F****d : " + p_EquipmentType); return; } } Progress += Time.deltaTime / Level * 10; if (Progress >= 10) { if (FinishEvent != null) { p_CallBack.Invoke(); FinishEvent.Invoke(); } } }
/// <summary> /// 解析物品的信息 /// </summary> void ParseItemJson() { itemList = new List <Item>(); //Resource加载text资源 TextAsset itemText = Resources.Load <TextAsset>("Items"); //将text转为json支持的jsonReader的类型 string itemJson = itemText.text; JsonReader itemReader = new JsonReader(itemJson); //获取json的对象 JsonData jsonData = JsonMapper.ToObject(itemReader); //遍历json对象 foreach (JsonData temp in jsonData) { string typeStr = temp["type"].ToString(); //将string 类转为object类,再转为type类型 Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), typeStr); int id = int.Parse(temp["id"].ToString()); string name = temp["name"].ToString(); Item.Quality quality = (Item.Quality)System.Enum.Parse(typeof(Item.Quality), temp["quality"].ToString()); string description = temp["description"].ToString(); int capacity = int.Parse(temp["capacity"].ToString()); int price = int.Parse(temp["price"].ToString()); int sellPrice = int.Parse(temp["sellPrice"].ToString()); string sprite = temp["sprite"].ToString(); Item item = null; switch (type) { case Item.ItemType.Consumable: int hp = int.Parse(temp["hp"].ToString()); int mp = int.Parse(temp["mp"].ToString()); item = new Consumable(id, name, type, quality, description, capacity, price, sellPrice, hp, mp, sprite); break; case Item.ItemType.Equipment: int strength = int.Parse(temp["strength"].ToString()); int intelligence = int.Parse(temp["intelligence"].ToString()); int agility = int.Parse(temp["agility"].ToString()); int stamina = int.Parse(temp["stamina"].ToString()); Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), temp["equipmentType"].ToString()); item = new Equipment(id, name, type, quality, description, capacity, price, sellPrice, strength, intelligence, agility, stamina, equipType, sprite); break; case Item.ItemType.Weapon: int damage = int.Parse(temp["damage"].ToString()); Weapon.WeaponType weaponType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), temp["weaponType"].ToString()); item = new Weapon(id, name, type, quality, description, capacity, price, sellPrice, damage, weaponType, sprite); break; case Item.ItemType.Material: item = new Material(id, name, type, quality, description, capacity, price, sellPrice, sprite); break; default: break; } itemList.Add(item); } }
public EquipmentSlot(Character character, Equipment.EquipmentType type) { this.character = character; this.type = type; }
//public bool IsPickItem //{ // get { return isPickItem; } // set { IsPickItem = value; } //} #endregion #region 使用json解析物品信息,读取json中的物品信息 void ParseItemJson()//从json文件中取出所有物品信息 { itemList = new List <Item>(); TextAsset itemText = Resources.Load <TextAsset>("Items"); string itemJson = itemText.text;//物品信息的json格式 JsonData jd = JsonMapper.ToObject(itemJson); foreach (JsonData i in jd) { // print(i["type"]); //提取出类型,判断当前物品的类型 Item.ItemType it = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), i["type"].ToString()); //获取type属性字符串并将其转为枚举 //共有属性先提取出来 int id = int.Parse(i["id"].ToString()); // print(id); string name = i["name"].ToString(); // print(name); Item.Quality quality = (Item.Quality)System.Enum.Parse(typeof(Item.Quality), i["quality"].ToString()); // print(quality); string description = i["Description"].ToString(); //print(description); int capacity = int.Parse(i["Capacity"].ToString()); //print(capacity); int buyprice = int.Parse(i["BuyPrice"].ToString()); //print(buyprice); int sellprice = int.Parse(i["SellPrice"].ToString()); //print(sellprice); string sprite = i["sprite"].ToString(); //print(sprite); Item item = null;//创建item接收物体 switch (it) { case Item.ItemType.Consumable: int hp = int.Parse(i["hp"].ToString()); int mp = int.Parse(i["mp"].ToString()); item = new Consumable(hp, mp, id, name, it, quality, description, capacity, buyprice, sellprice, sprite); break; case Item.ItemType.Equipment: int stength = int.Parse(i["stength"].ToString()); int intellect = int.Parse(i["intellect"].ToString()); int agility = int.Parse(i["agility"].ToString()); int stamina = int.Parse(i["stamina"].ToString()); Equipment.EquipmentType equipType = (Equipment.EquipmentType)System.Enum.Parse(typeof(Equipment.EquipmentType), i["equipType"].ToString()); item = new Equipment(stength, intellect, agility, stamina, equipType, id, name, it, quality, description, capacity, buyprice, sellprice, sprite); break; case Item.ItemType.Weapon: int Damage = int.Parse(i["damage"].ToString());; Weapon.WeaponType wpType = (Weapon.WeaponType)System.Enum.Parse(typeof(Weapon.WeaponType), i["wpType"].ToString()); item = new Weapon(Damage, wpType, id, name, it, quality, description, capacity, buyprice, sellprice, sprite); break; case Item.ItemType.Material: //材料类 item = new Material(id, name, it, quality, description, capacity, buyprice, sellprice, sprite); break; default: break; } itemList.Add(item);//将物品保存在链表中 } }