Exemplo n.º 1
0
 /// <summary>
 /// 在物品列表中增加指定type和index的物品num个
 /// </summary>
 /// <param name="type"></param>
 /// <param name="index"></param>
 /// <param name="num"></param>
 public void AddGoods(int type, int index, int num)
 {
     if (type >= 1 && type <= 7)
     {
         // 装备
         if (EquipList.Where(m => m.Type == type && m.Index == index).FirstOrDefault() is BaseGoods equip)   //已有物品
         {
             equip.AddGoodsNum(num);
         }
         else    //增加物品
         {
             BaseGoods newGoods = Context.LibData.GetGoods(type, index);
             newGoods.GoodsNum = num;
             EquipList.Add(newGoods);
         }
     }
     else if (type >= 8 && type <= 14)
     {
         // 物品
         if (GoodsList.Where(m => m.Type == type && m.Index == index).FirstOrDefault() is BaseGoods goods)   //已有物品
         {
             goods.AddGoodsNum(num);
         }
         else    //增加物品
         {
             BaseGoods newGoods = Context.LibData.GetGoods(type, index);
             newGoods.GoodsNum = num;
             GoodsList.Add(newGoods);
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 在物品列表中减少指定type和index的物品num个
 /// </summary>
 /// <param name="type"></param>
 /// <param name="index"></param>
 /// <returns>使用成功返回true不存在该物品,或者数量不够返回false</returns>
 public bool DropGoods(int type, int index, int num)
 {
     if (type >= 1 && type <= 7)
     {
         // 装备
         if (EquipList.Where(m => m.Type == type && m.Index == index).FirstOrDefault() is BaseGoods equip)   //有物品
         {
             if (equip.GoodsNum < num)
             {
                 return(false);
             }
             else if (equip.GoodsNum == num)
             {
                 equip.GoodsNum = 0;
                 EquipList.Remove(equip);
             }
             else
             {
                 equip.AddGoodsNum(-num);
             }
             return(true);
         }
         else    //没有物品
         {
             return(false);
         }
     }
     else if (type >= 8 && type <= 14)
     {
         // 物品
         if (GoodsList.Where(m => m.Type == type && m.Index == index).FirstOrDefault() is BaseGoods goods)   //有物品
         {
             if (goods.GoodsNum < num)
             {
                 return(false);
             }
             else if (goods.GoodsNum == num)
             {
                 goods.GoodsNum = 0;
                 GoodsList.Remove(goods);
             }
             else
             {
                 goods.AddGoodsNum(-num);
             }
             return(true);
         }
         else    //没有物品
         {
             return(false);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 /// <summary>
 /// 获取链表中type index号物品
 /// 当该种物品不存在时返回null
 /// </summary>
 /// <param name="type"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 public BaseGoods GetGoods(int type, int index)
 {
     if (type >= 1 && type <= 7)
     {
         return(EquipList.Where(m => m.Type == type && m.Index == index).FirstOrDefault());
     }
     else if (type >= 8 && type <= 14)
     {
         return(GoodsList.Where(m => m.Type == type && m.Index == index).FirstOrDefault());
     }
     return(null);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 获取链表中type index号物品的数量
        /// </summary>
        /// <param name="type"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public int GetGoodsNum(int type, int index)
        {
            //TODO 此处需要确认改为LINQ后工作是否正常
            int num = 0;

            if (type >= 1 && type <= 7 && EquipList.Where(m => m.Type == type && m.Index == index).FirstOrDefault() is BaseGoods equip)
            {
                num = equip.GoodsNum;
            }
            else if (type >= 8 && type <= 14 && GoodsList.Where(m => m.Type == type && m.Index == index).FirstOrDefault() is BaseGoods goods)
            {
                num = goods.GoodsNum;
            }
            return(num);
        }