コード例 #1
0
    //更新角色属性的平A的伤害
    public int UpdatePlayerPropertyAtk()
    {
        int Strength  = 0;
        int Intellect = 0;
        int Agility   = 0;
        int Stamina   = 0;
        int Damage    = 0;

        foreach (EquimentSlot slot in slotlist)
        {
            if (slot.transform.childCount > 0)
            {
                Item item = slot.transform.GetChild(0).GetComponent <ItemUI>().item;
                if (item is Equipmen)
                {
                    Equipmen e = (Equipmen)item;
                    Strength  += e.Strength;
                    Intellect += e.Intellect;
                    Agility   += e.Agility;
                    Stamina   += e.Stamina;
                }
                else if (item is Weapon)
                {
                    Damage += ((Weapon)item).Damage;
                }
            }
        }
        Strength  += player.basicStrength;
        Intellect += player.basicStrength;
        Agility   += player.basicAgility;
        Stamina   += player.basicStamina;
        Damage     = (int)(player.basicDamage + Damage + Strength * 0.3f);
        return(Damage);
    }
コード例 #2
0
    //解析Json文件
    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);
                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;
                Equipmen.EquipmentType equipType = (Equipmen.EquipmentType)System.Enum.Parse(typeof(Equipmen.EquipmentType), temp["equipType"].str);
                item = new Equipmen(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 Materials(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite);
                break;
            }
            itemList.Add(item);
            Debug.Log(item);
        }
    }
コード例 #3
0
    //更新角色属性面板显示
    public void UpdatePropertyText()
    {
        int Strength    = 0;
        int Intellect   = 0;
        int Agility     = 0;
        int Stamina     = 0;
        int Damage      = 0;
        int playermaxhp = 0;


        foreach (EquimentSlot slot in slotlist)
        {
            if (slot.transform.childCount > 0)
            {
                Item item = slot.transform.GetChild(0).GetComponent <ItemUI>().item;
                if (item is Equipmen)
                {
                    Equipmen e = (Equipmen)item;
                    Strength  += e.Strength;
                    Intellect += e.Intellect;
                    Agility   += e.Agility;
                    Stamina   += e.Stamina;
                }
                else if (item is Weapon)
                {
                    Damage += ((Weapon)item).Damage;
                }
            }
        }
        Strength   += player.basicStrength;
        Intellect  += player.basicStrength;
        Agility    += player.basicAgility;
        Stamina    += player.basicStamina;
        Damage      = (int)(player.basicDamage + Damage + Strength * 0.3f);
        playermaxhp = player.PlayerMaxHp + (int)(Stamina * 0.3f);
        string text = string.Format("力量:{0}\n智力:{1}\n敏捷:{2}\n体力:{3}\n攻击力:{4}\n人物血量:{5} ", Strength, Intellect, Agility, Stamina, Damage, playermaxhp);

        PropertyText.text = text;
    }