예제 #1
0
 public Consumable(int id, string name, ItemType type, string description, string flavorText, int capacity,
                   int buyPrice, int sellPrice, string sprite, int hp, TemporaryBuff temporaryBuff) : base(id, name, type,
                                                                                                           description,
                                                                                                           flavorText, capacity, buyPrice, sellPrice, sprite)
 {
     Hp            = hp;
     TemporaryBuff = temporaryBuff;
 }
예제 #2
0
        // TODO: load data from boot scene
        /// <summary>
        /// Parse json file to get item list
        /// </summary>
        private void ParseItemJson()
        {
            itemList = new List <Item>();
            TextAsset itemText  = Resources.Load <TextAsset>("Items");
            string    itemsJson = itemText.text;
            JsonData  jsonData  = JsonMapper.ToObject(itemsJson);

            if (jsonData.IsArray)
            {
                foreach (JsonData data in jsonData)
                {
                    int      id          = (int)data["id"];
                    string   name        = data["name"].ToString();
                    string   typeStr     = data["type"].ToString();
                    ItemType type        = (ItemType)System.Enum.Parse(typeof(ItemType), typeStr);
                    string   description = data["description"].ToString();
                    string   flavorText  = data["flavorText"].ToString();
                    int      capacity    = (int)data["capacity"];
                    int      buyPrice    = (int)data["buyPrice"];
                    int      sellPrice   = (int)data["sellPrice"];
                    string   sprite      = data["sprite"].ToString();

                    Item item = null;
                    switch (type)
                    {
                    case ItemType.Consumable:
                        int    hp      = (int)data["hp"];
                        string buffStr = data["temporaryBuff"].ToString();

                        TemporaryBuff temporaryBuff =
                            (TemporaryBuff)System.Enum.Parse(typeof(TemporaryBuff), buffStr);
                        item = new Consumable(id, name, type, description, flavorText, capacity, buyPrice,
                                              sellPrice, sprite, hp, temporaryBuff);
                        break;

                    case ItemType.Relic:
                        // TODO
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    itemList.Add(item);
                }
            }
        }