예제 #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);
         }
     }
 }
예제 #2
0
    /// <summary>
    /// 卸下装备更新数据
    /// </summary>
    /// <param name="_item"></param>
    public static void UnloadEquip(Item _item)
    {
        EquipModel gm = EquipList.Find(x => x.Id == _item.item_ID);

        EquipList.Remove(gm);
        Item item = DataMgr.GetInstance().GetItemByID(gm.Id);

        BuyItem(item);
        UpdateUser();
        SaveEquip();
    }
예제 #3
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);
 }
예제 #4
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);
 }
예제 #5
0
    public BattlePlayerData(MapPlayerData mapPlayerData, BattlePlayer owner) : base(null, null)
    {
        Name           = mapPlayerData.Name;
        Level          = mapPlayerData.Level;
        HP             = mapPlayerData.HP;
        MaxHP          = mapPlayerData.MaxHP;
        MP             = mapPlayerData.MP;
        MaxMP          = mapPlayerData.MaxMP;
        HeadIcon       = mapPlayerData.HeadIcon;
        MapSkillID     = mapPlayerData.MapSkillID;
        BattleSkillID  = mapPlayerData.BattleSkillID;
        UsingCharacter = mapPlayerData.UsingCharacter;
        Food           = mapPlayerData.Food;
        MaxFood        = mapPlayerData.MaxFood;
        Gold           = mapPlayerData.Gold;
        SkillId        = mapPlayerData.BattleSkillID;
        ClassData      = mapPlayerData.ClassData;
        //玩家的行动值初始
        AP = MaxAP = 0;

        CardList.Clear();

        EquipList.Capacity = (mapPlayerData.EquipList.Count);
        for (int i = 0; i < mapPlayerData.EquipList.Count; i++)
        {
            List <int> actions = mapPlayerData.EquipList[i].Data.ActionTypes;
            for (int j = 0; j < actions.Count; j++)
            {
                if (actions[i] == (int)BattleActionType.AddEquipment)
                {
                    EquipList.Add(new BattleEquipData(mapPlayerData.EquipList[j].Data.ActionParams[0], owner));
                    break;
                }
            }
        }
        CardList.Capacity = mapPlayerData.CardList.Count;
        for (int i = 0; i < mapPlayerData.CardList.Count; i++)
        {
            CardList.Add(new BattleCardData(mapPlayerData.CardList[i].CardId, owner));
        }
        BuffList.Capacity = mapPlayerData.BuffList.Count;
        for (int i = 0; i < mapPlayerData.BuffList.Count; i++)
        {
            BuffList.Add(new BattleBuffData(mapPlayerData.BuffList[i].Data.ActionParams[0], -1, 0, new BattleCardData(mapPlayerData.BuffList[i].CardId, owner), owner, owner));
        }

        CurrentCardList.Capacity = CardList.Count;
        for (int i = 0; i < CardList.Count; i++)
        {
            CurrentCardList.Add(new BattleCardData(CardList[i].CardId, owner));
        }
    }
예제 #6
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);
        }
예제 #7
0
        private void InitBagInfo()
        {
            BagList.Items.Clear();
            EquipList.Items.Clear();
            this.BagList.BeginUpdate();
            this.EquipList.BeginUpdate();

            RepeatedField <BagItem> bags = player.Bags.Bag;

            for (int i = 0; i < bags.Count; i++)
            {
                ListViewItem item = new ListViewItem();
                //imgList.Images.Add(Image.FromFile(dicId2File[bags[i].ItemID]));
                if (!dicId2File.ContainsKey(bags[i].ItemID))
                {
                    continue;
                }
                item.Text       = Path.GetFileNameWithoutExtension(dicId2File[bags[i].ItemID]) + ":" + bags[i].Count;
                item.ImageIndex = bags[i].ItemID;
                BagList.Items.Add(item);
            }
            BagList.LargeImageList = imgList;
            BagList.Show();


            RepeatedField <EquipItem> equips = player.Bags.Equipment;

            for (int i = 0; i < equips.Count; i++)
            {
                ListViewItem item = new ListViewItem();
                //imgList.Images.Add(Image.FromFile(dicId2File[bags[i].ItemID]));
                if (!dicId2File.ContainsKey(equips[i].ItemID))
                {
                    continue;
                }
                item.Text       = Path.GetFileNameWithoutExtension(dicId2File[equips[i].ItemID]) + ":" + equips[i].Count;
                item.ImageIndex = equips[i].ItemID;
                EquipList.Items.Add(item);
            }
            EquipList.LargeImageList = imgList;
            EquipList.Show();


            this.BagList.EndUpdate();
            this.EquipList.EndUpdate();
        }
예제 #8
0
    /// <summary>
    /// 使用物品时装备栏更新和人物属性更新
    /// </summary>
    /// <param name="_item">要使用的物品</param>
    public static void UseItem(Item _item)
    {
        if (equipList == null)
        {
            equipList = new List <EquipModel>();
        }

        GoodsModel gm = GoodsList.Find(x => x.Id == _item.item_ID); //在背包找到这个物品

        if (gm.Num <= 1)                                            //使用了这个物品,背包要移除这个物品
        {
            GoodsList.Remove(gm);                                   //如果背包栏这个物品数据为1则移除这个物品
        }
        else
        {
            gm.Num -= 1;                                 //如果这个物品数据大于1则数量减一
        }
        if (_item.equipment_Type != Equipment_Type.Null) //判断这个物品是不是装备
        {
            //判断背包栏是不是有这个类型的武器,类型是穿戴在武器穿戴的位置
            EquipModel em = EquipList.Find(x => x.Equipment_Type == _item.equipment_Type);
            if (em != null)                                               //如果这个位置已经有物体就要替换
            {
                em.Value += 1;                                            //如果这个位置有物体了,让这个物体的数量加1
                if (em.Value > 1)                                         //看这个位置的物体数量是不是1,如果大于一则移除这个物体
                {
                    EquipList.Remove(em);                                 //在武器数据中移除这个数据
                    Item item = DataMgr.GetInstance().GetItemByID(em.Id); //在数据库中找到移除的这个物体
                    BuyItem(item);                                        //将他保存回背包数据中
                }
            }
            //给背包数据添加这个新的要使用的物品,达到替换的效果
            equipList.Add(new EquipModel()
            {
                Id = _item.item_ID, Equipment_Type = _item.equipment_Type, Value = 1
            });
        }
        else
        {
            if (saveUser[0].Hp < saveUser[0].MaxHp)
            {
                saveUser[0].Hp += _item.hp;
            }
        }
        SaveEquip();
    }
예제 #9
0
        private void ShowEquipName(int itemCount)
        {
            canUseEquipNameList = ItemListTool.GetCanUseItemList(EquipList.gameObject, "Equip");
            for (int i = 0; i < itemCount; i++)
            {
                GameObject go = ItemListTool.GetNewItemObj(canUseEquipNameList, EquipList.gameObject, Equip0.gameObject);
                go.transform.name = "Equip" + i.ToString();
                go.GetComponent <UILabel>().text = levelNameList[i];
            }
            EquipList.Reposition();
            ItemListTool.ActiveUnuseItem(canUseEquipNameList);
            float   addPosition;
            Vector3 listPos = AttributeList.transform.position;

            addPosition = EquipList.cellHeight * EquipList.gameObject.transform.childCount;
            listPos.y   = AttributeList.transform.position.y - addPosition;
            AttributeList.transform.localPosition = listPos;
        }
예제 #10
0
        public void Deserialize(BinaryReader binaryReader)
        {
            Clear();

            int size = binaryReader.ReadInt32();

            for (int i = 0; i < size; i++)
            {
                BaseGoods equipment = Context.LibData.GetGoods(binaryReader.ReadInt32(), binaryReader.ReadInt32());
                equipment.GoodsNum = binaryReader.ReadInt32();
                EquipList.Add(equipment);
            }

            size = binaryReader.ReadInt32();
            for (int i = 0; i < size; i++)
            {
                BaseGoods goods = Context.LibData.GetGoods(binaryReader.ReadInt32(), binaryReader.ReadInt32());
                goods.GoodsNum = binaryReader.ReadInt32();
                GoodsList.Add(goods);
            }
        }
예제 #11
0
 /// <summary>
 /// 清空物品列表
 /// </summary>
 public void Clear()
 {
     EquipList.Clear();
     GoodsList.Clear();
 }
예제 #12
0
    void Awake()
    {
        //init characters
        characters.init ();

        //init enemys
        enemys.init ();

        //init skills
        skills.init ();

        //init materials
        materials.init ();

        //init buffs
        buffs.init();

        //init makePlans;
        makePlans.init();

        //init equip_data
        foreach(EquipGroup data in equipGroupObj){
            data.init();
            equip.Add(data.equipType, data );
        }

        //init equipList
        for(ItemType i = ItemType.WEAPON; i < ItemType.EQUIP_NUM ; i++ ){
            List<EquipList> list = new List<EquipList>();
            equipList.Add(i, list);
        }

        //gameObject.transform.FindChild("Character")
        EquipList sword = new EquipList(0, 5);
        sword.set_equiper (0);
        equipList [ItemType.WEAPON].Add (sword);

        EquipList sword2 = new EquipList(0, 1);
        //		sword2.set_equiper (1);
        equipList [ItemType.WEAPON].Add (sword2);

        EquipList sword3 = new EquipList(0, 4);
        sword2.set_equiper (1);
        equipList [ItemType.WEAPON].Add (sword3);

        EquipList sword4 = new EquipList(0, 10);
        //		sword2.set_equiper (1);
        equipList [ItemType.WEAPON].Add (sword4);

        EquipList sword5 = new EquipList(0, 8);
        //		sword2.set_equiper (1);
        equipList [ItemType.WEAPON].Add (sword5);

        EquipList sword6 = new EquipList(0, 6);
        //		sword2.set_equiper (1);
        equipList [ItemType.WEAPON].Add (sword6);

        EquipList sword7 = new EquipList(0, 3);
        //		sword2.set_equiper (1);
        equipList [ItemType.WEAPON].Add (sword7);

        EquipList armor = new EquipList(0, 2);
        armor.set_equiper (0);
        equipList [ItemType.ARMOR].Add (armor);

        EquipList armor2 = new EquipList(0, 1);
        armor2.set_equiper (1);
        equipList [ItemType.ARMOR].Add (armor2);

        patch_item(ItemType.MATERIAL, 0, 1, 20);
        patch_item(ItemType.MATERIAL, 3, 1, 10);
    }
예제 #13
0
    public PatchRes patch_item(ItemType item_type, int item_id, int item_lv, int num)
    {
        if (item_type >= ItemType.WEAPON && item_type <= ItemType.EQUIP_NUM) {
            if( num > 0){
                if (equipList [item_type].Count >= ITEM_LIMIT)
                return PatchRes.ITEM_FULL;

                EquipList equip_data = new EquipList (item_id, item_lv);
                equipList [item_type].Add (equip_data);
                return PatchRes.SUCCESS;
            } else {
                return PatchRes.COST_EQUIP_NEED_SEQ;
            }
        } else if (item_type == ItemType.MATERIAL) {
            if( materialList.ContainsKey( item_id ) ){
                Item material = materialList[item_id] as Item;
                if( material.item_num + num < 0 ){
                    return PatchRes.ITEM_NOT_ENOUGH;
                } else if( material.item_num + num == 0 ){
                    materialList.Remove(item_id);
                } else {
                    material.item_num += num;
                }
            } else {
                if( num <= 0 )
                    return PatchRes.ITEM_NOT_ENOUGH;
                Item item = new Item(item_type, item_id, num, item_lv);
                materialList.Add( item_id, item );
            }

            return PatchRes.SUCCESS;
        }

        return PatchRes.WRONG_TYPE;
    }