Esempio n. 1
0
        /// <summary>
        /// Removes an Item from the Inventory, unstacking it if necessary.
        /// </summary>
        /// <param name="item">The Item to remove from the Inventory</param>
        public bool RemoveItem(ItemBase item)
        {
            if (item != null && BagItems.Contains(item))
            {
                if (item is ConsumableBase)
                {
                    var stackable = item as ConsumableBase;

                    if (!stackable.Unstack())
                    {
                        BagItems.Remove(stackable);
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    BagItems.Remove(item);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
    /// <summary>
    /// 获胜后的奖励
    /// </summary>
    private void WinResoult()
    {
        var    bagitems        = ResourceController.Instance.UseBagUItemDict.Keys;
        var    trainer         = context.playerData.scriptableObject;
        var    trainerBagItems = trainer.bagItems;
        int    randomIndex     = RandomService.game.Int(0, bagitems.Count);
        int    i        = 0;
        string itemName = "";

        foreach (var item in bagitems)
        {
            if (i++ == randomIndex)
            {
                itemName = item;
                break;
            }
        }
        if (bagitems.Contains(itemName))
        {
            int itemCount = RandomService.game.Int(1, 5);
            DebugHelper.LogFormat("玩家获得 {0} {1}个", itemName, itemCount);
            trainerBagItems.Add(BagItems.Build(itemName, itemCount));
            context.ReplacePlayerData(trainer);
        }
    }
Esempio n. 3
0
    public static BagItems Build(string ItemName, int count)
    {
        BagItems items = ScriptableObject.CreateInstance <BagItems>();

        items.count    = count;
        items.ItemName = ItemName;
        return(items);
    }
    private void StoreItem(Notification <BagItems> notific)
    {
        BagItems param = notific.param;

        if (null == param || "" == param.ItemName || 0 == param.count)
        {
            if (ItemUI != null)
            {
                ItemUI.Hide();
            }
            return;
        }
        StoreItem(param);
    }
    private static void UseBagItem(ItemUI itemUI)
    {
        BagItems bagItems = itemUI.Items;

        if (0 >= bagItems.count)
        {
            Debug.LogError("数量为0的道具不该存在");
        }
        bagItems.count -= 1;
        ShowBagItem();
        if (context.isBattleFlag)
        {
            NotificationCenter <string> .Get().DispatchEvent("UseBagItem", bagItems.ItemName);
        }
    }
    public void Initialize()
    {
        string json = null;

        if (File.Exists(ResourceController.Instance.TrainerDataPath.ToString()))
        {
            json = File.ReadAllText(ResourceController.Instance.TrainerDataPath.ToString());
        }

        Trainer trainer = ScriptableObject.CreateInstance <Trainer>();

        if (json != null)
        {
            trainer = JsonConvert.DeserializeObject <Trainer>(json);
        }
        if (null == trainer || null == trainer.pokemons || 0 == trainer.pokemons.Count)
        {
            //如果没有精灵,就给一只皮卡丘和小火龙
            Pokemon Pikaqiu = PokemonFactory.BuildPokemon(25);

            Pokemon Charmander = PokemonFactory.BuildPokemon(4);
            trainer.pokemons = new List <Pokemon>(6)
            {
                Pikaqiu, Charmander
            };
        }
        else
        {
            foreach (Pokemon pokemon in trainer.pokemons)
            {
                new BattlePokemonData(pokemon);
            }
        }
        if (null == trainer || null == trainer.bagItems || 0 == trainer.bagItems.Count)
        {
            //如果道具背包没有物品,给5个精灵球
            trainer.bagItems = new List <BagItems>(24)
            {
                BagItems.Build("精灵球", 5)
            };
        }
        context.ReplacePlayerData(trainer);
    }
Esempio n. 7
0
    /// <summary>
    /// 获胜后的奖励
    /// </summary>
    private void WinResoult()
    {
        if (null == bagitems)
        {
            bagitems = ResourceController.Instance.UseBagUItemDict.Keys;
        }
        var    trainerBagItems = trainer.bagItems;
        int    randomIndex     = RandomService.game.Int(0, bagitems.Count);
        int    i        = 0;
        string itemName = "";

        foreach (var item in bagitems)
        {
            if (i++ == randomIndex)
            {
                itemName = item;
                break;
            }
        }
        if (ResourceController.Instance.UseBagUItemDict.ContainsKey(itemName))
        {
            int itemCount = RandomService.game.Int(1, 6);
            DebugHelper.Log(
                new StringBuilder(30)
                .AppendFormat("玩家获得 {0}", itemName)
                .Append(itemCount)
                .Append("个")
                .ToString());

            var item = trainerBagItems.Find(x => x.ItemName == itemName);
            if (null == item)
            {
                trainerBagItems.Add(BagItems.Build(itemName, itemCount));
            }
            else
            {
                item.count += itemCount;
            }
            context.ReplacePlayerData(trainer);
        }
    }
 /// <summary>
 ///更新item的UI显示,默认数量为1个
 /// </summary>
 /// <param name="item"></param>
 public void SetItem(BagItems items)
 {
     rectTransform.anchoredPosition = new Vector2(30, -30);;
     this.transform.localScale      = this.animationScale;//物品更新时放大UI,用于动画
     this.Items = items;
     this.Item  = ResourceController.Instance.ItemDic[items.ItemName];
     if (null != Item && null != Item.sprite)
     {
         this.itemImage.sprite = Item.sprite;        //更新UI
     }
     else
     {
         this.itemImage.sprite = defaultSprite;
     }
     if (Items.count > 1)
     {
         this.amountText.text = Items.count.ToString();
     }
     else
     {
         this.amountText.text = "";
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Adds an Item to the Inventory, stacking it if necessary.
        /// </summary>
        /// <param name="item">The Item to add to the Inventory</param>
        /// <returns>True if the Item was successfully added to the Inventory, false if not</returns>
        public bool AddItem(ItemBase item)
        {
            if (item != null && ItemCount < MaxItemCount)
            {
                if (item is ConsumableBase)
                {
                    var stackable = item as ConsumableBase;

                    if (!stackable.Stack())
                    {
                        BagItems.Add(stackable);
                    }

                    return(true);
                }
                else
                {
                    BagItems.Add(item);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 10
0
 public void Empty()
 {
     BagItems.Clear();
 }
Esempio n. 11
0
 private void StoreItem(BagItems bagItems)
 {
     ItemUI.SetItem(bagItems);//更新ItemUI
 }
Esempio n. 12
0
 public int ItemCount(int itemId) => BagItems.Where(bi => bi.ItemId == itemId).Sum(bi => bi.Count);