Beispiel #1
0
        /*
         *  奖励类型:
         *  1:货币 2:内币3:金币4:礼券5:经验6:道具7:装备8:功勋9:声望10:魂11:体力
         *  |为多个奖励分隔,#为不同职业分隔,
         *  职业顺序与游戏中相同资源格式:奖励类型_数量
         *  物品格式:奖励类型_id_是否绑定_数量
         *  装备固定属性值:奖励类型_id_是否绑定_数量_属性项(属性类型-属性值(多个属性用,分割)例:1-100,2-70)
         */
        /// <summary>资源字符转换资源对象</summary>
        /// <param name="res">资源字符串</param>
        public ResourcesItem SplitResources(string res)
        {
            var res_item = new ResourcesItem {
                isfixed = false
            };
            var data = res.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);

            switch (data.Length)
            {
                #region 类型_数量
            case 2:
            {
                res_item.type  = Convert.ToInt32(data[0]);
                res_item.count = Convert.ToInt32(data[1]);
                break;
            }
                #endregion

                #region 类型_id_数量
            case 3:
            {
                res_item.type  = Convert.ToInt32(data[0]);
                res_item.id    = Convert.ToInt32(data[1]);
                res_item.count = Convert.ToInt32(data[2]);
                break;
            }
                #endregion

                #region 类型_id_是否绑定_数量
            case 4:
            {
                res_item.type  = Convert.ToInt32(data[0]);
                res_item.id    = Convert.ToInt32(data[1]);
                res_item.bind  = Convert.ToInt32(data[2]);
                res_item.count = Convert.ToInt32(data[3]);
                break;
            }
                #endregion

                #region 类型_id_是否绑定_数量_属性项(属性类型-属性值(多个属性用,分割)例:1-100,2-70)
            case 5:
            {
                res_item.type    = Convert.ToInt32(data[0]);
                res_item.id      = Convert.ToInt32(data[1]);
                res_item.bind    = Convert.ToInt32(data[2]);
                res_item.count   = Convert.ToInt32(data[3]);
                res_item.isfixed = true;
                var items = data[4].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var m in items.Select(item => item.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries)).Where(m => m.Length == 2))
                {
                    res_item.items.Add(new FixedItem {
                            type = Convert.ToInt32(m[0]), value = Convert.ToDouble(m[1])
                        });
                }
                break;
            }
                #endregion
            }
            return(res_item);
        }
Beispiel #2
0
    private static ResourcesItem CreateResourcesItem(XmlNode resourcesNode)
    {
        ResourcesItem resourcesItem = new ResourcesItem();

        resourcesItem.SetBase(GetBaseItem(resourcesNode));
        resourcesItem.itemType = BaseItem.ItemType.RESOURCES;
        return(resourcesItem);
    }
Beispiel #3
0
 private tg_bag BuildBag(ResourcesItem model)
 {
     switch (model.type)
     {
         case (int)GoodsType.TYPE_EQUIP: { return (new Bag()).BuildBagByEquip(model.id); }
         case (int)GoodsType.TYPE_PROP: { return (new Bag()).BuildBag(model.id, model.count); }
         default: { return null; }
     }
 }
Beispiel #4
0
        /// <summary>构建背包数据</summary>
        /// <param name="model">资源项</param>
        public tg_bag BuildBag(ResourcesItem model)
        {
            switch (model.type)
            {
            case (int)GoodsType.TYPE_EQUIP: { return((new Bag()).BuildBagByEquip(model)); }

            case (int)GoodsType.TYPE_PROP: { return((new Bag()).BuildBag(model.id, model.userid, model.count)); }

            case (int)GoodsType.TYPE_FUSION: { return((new Bag()).BuildFusion(model.id, model.userid, model.count)); }

            default: { return(null); }
            }
        }
Beispiel #5
0
 public void AddItem(ResourcesItem item)
 {
     if (!CanAddItems(1))
     {
         throw new Exception("can't add item");
     }
     resourcesItems.Add(item);
     if (isStorage)
     {
         ResourcesManager.instance.UpdateResourcesInfo();
     }
     isFull = inventoryMaxCount <= resourcesItems.Count;
 }
Beispiel #6
0
    public static void ModifQuantity(ResourcesItem item, int amount)
    {
        int index = _instance.inventory.FindIndex(x => x.id == item.itemID);

        if (index < 0)
        {
            _instance.inventory.Add(new ResItemInven()
            {
                id       = item.itemID,
                quantity = amount
            });
        }
        else
        {
            _instance.inventory[index].quantity += amount;
        }
    }
Beispiel #7
0
        /// <summary>资源字符转换资源对象</summary>
        /// <param name="res">资源字符串</param>
        private ResourcesItem SplitResources(string res)
        {
            var res_item = new ResourcesItem();
            var data     = res.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);

            switch (data.Length)
            {
            case 2:     //类型_数量
                res_item.type  = Convert.ToInt32(data[0]);
                res_item.count = Convert.ToInt32(data[1]);
                break;

            case 4:     //类型_id_是否绑定_数量
                res_item.type  = Convert.ToInt32(data[0]);
                res_item.id    = Convert.ToInt32(data[1]);
                res_item.bind  = Convert.ToInt32(data[2]);
                res_item.count = Convert.ToInt32(data[3]);
                break;
            }
            return(res_item);
        }
Beispiel #8
0
        /// <summary> 组装装备类型物品 </summary>
        /// <param name="res">资源项</param>
        public tg_bag BuildBagByEquip(ResourcesItem res)
        {
            var baseEquip = Variable.BASE_EQUIP.FirstOrDefault(m => m.id == res.id);

            if (baseEquip == null)
            {
                return(null);
            }
            var equip = new tg_bag();

            if (!res.items.Any())
            {
                return(CommonHelper.EquipReset(res.userid, baseEquip.id));
            }
            foreach (var item in res.items)
            {
                if (equip.attribute1_type == 0)
                {
                    equip.attribute1_type  = item.type;
                    equip.attribute1_value = item.value;
                }
                else if (equip.attribute2_type == 0)
                {
                    equip.attribute2_type  = item.type;
                    equip.attribute2_value = item.value;
                }
                else if (equip.attribute3_type == 0)
                {
                    equip.attribute3_type  = item.type;
                    equip.attribute3_value = item.value;
                }
            }
            equip.base_id    = baseEquip.id;
            equip.user_id    = res.userid;
            equip.type       = (int)GoodsType.TYPE_EQUIP;
            equip.equip_type = baseEquip.typeSub;
            equip.state      = (int)LoadStateType.UNLOAD;
            equip.count      = 1;
            return(equip);
        }
Beispiel #9
0
        /// <summary>获取道具名</summary>
        /// <param name="res"></param>
        /// <returns></returns>
        public string GetString(ResourcesItem res)
        {
            string s = "道具";

            #region
            switch (res.type)
            {
            case (int)GoodsType.TYPE_PROP:
            {
                var bp = Variable.BASE_PROP.FirstOrDefault(m => m.id == res.id);
                if (bp != null)
                {
                    s = bp.name;
                }
            }
            break;

            case (int)GoodsType.TYPE_FUSION:
            {
                var bp1 = Variable.BASE_FUSION.FirstOrDefault(m => m.id == res.id);
                if (bp1 != null)
                {
                    s = bp1.name;
                }
            }
            break;

            case (int)GoodsType.TYPE_EQUIP:
            {
                var bp2 = Variable.BASE_EQUIP.FirstOrDefault(m => m.id == res.id);
                if (bp2 != null)
                {
                    s = bp2.name;
                }
            }
            break;
            }
            #endregion
            return(s);
        }