示例#1
0
        public virtual ErrorCodes AquireReward(int id, out int result)
        {
            result = -1;
            if (!IsActive)
            {
                return(ErrorCodes.Error_Operation_NotInActivity);
            }


            for (int i = 0; i < Items.Count; i++)
            {
                var item = Items[i];
                if (id == item.Id)
                {
                    if (!item.IsActive)
                    {
                        return(ErrorCodes.Error_Operation_NotInActivity);
                    }
                    if (!item.CanAquire)
                    {
                        return(ErrorCodes.Error_Operation_CannotAquire);
                    }
                    if (null == Controller)
                    {
                        return(ErrorCodes.Unknow);
                    }

                    var tb = Table.GetYunYing(item.Id);
                    if (null == tb)
                    {
                        return(ErrorCodes.Error_Operation_NotInActivity);
                    }

                    if (-1 != tb.ConditionId)
                    {
                        if (-2 != Controller.CheckCondition(tb.ConditionId))
                        {
                            return(ErrorCodes.Error_Condition);
                        }
                    }

                    if (-1 != tb.NeetItem && tb.NeetItemCount > 0)
                    {
                        var nowCount = Controller.mBag.GetItemCount(tb.NeetItem);
                        if (nowCount < tb.NeetItemCount)
                        {
                            return(ErrorCodes.ItemNotEnough);
                        }
                        var ret = Controller.mBag.DeleteItem(tb.NeetItem, tb.NeetItemCount, eDeleteItemType.OperationActivity, tb.Name);
                        if (ErrorCodes.OK != ret)
                        {
                            return(ret);
                        }
                    }

                    item.Aquire();

                    if (null != item.Rewards)
                    {
                        var items = new Dictionary <int, int>();
                        for (int j = 0; j < item.Rewards.Count; j++)
                        {
                            var reward = item.Rewards[j];
                            if (-1 == reward.Id || reward.Count <= 0)
                            {
                                continue;
                            }
                            items.Add(reward.Id, reward.Count);
                            var tbItem = Table.GetItemBase(reward.Id);
                            if (null != tbItem)
                            {
                                if (10500 == tbItem.Type)//时装
                                {
                                    var tbYunYing = Table.GetYunYing(item.Id);
                                    if (null != tbYunYing)
                                    {
                                        //开服活动购买时装后,修改时装的扩展计数,刷新时装商城
                                        Controller.SetExData(tbYunYing.Param[2], 0);
                                    }
                                }
                                else
                                {
                                    Controller.BroadCastGetEquip(reward.Id, 100002166);
                                }
                            }
                        }
                        if (items.Count > 0)
                        {
                            Controller.mBag.AddItemOrMail(200, items, null, eCreateItemType.OperationActivity, tb.Name);
                        }
                    }
                    return(ErrorCodes.OK);
                }
            }
            return(ErrorCodes.Error_Operation_NotFound);
        }
示例#2
0
        public ErrorCodes ComposeItem(CharacterController character, int id, int count, ref int rewardId)
        {
            var tbCompose = Table.GetItemCompose(id);

            if (tbCompose == null)
            {
                return(ErrorCodes.Error_ItemComposeID);
            }
            //黄金检查
            if (tbCompose.NeedRes > 0 && tbCompose.NeedRes < 10)
            {
                if (character.mBag.GetRes((eResourcesType)tbCompose.NeedRes) < tbCompose.NeedValue * count)
                {
                    return(ErrorCodes.MoneyNotEnough);
                }
            }

            //物品数量检查
            for (var i = 0; i != tbCompose.NeedId.Length; ++i)
            {
                var itemId    = tbCompose.NeedId[i];
                var itemCount = tbCompose.NeedCount[i] * count;
                if (itemId == -1)
                {
                    continue;
                }
                if (character.mBag.GetItemCount(itemId) < itemCount)
                {
                    return(ErrorCodes.ItemNotEnough);
                }
            }
            //奖励物品
            var items    = new Dictionary <int, int>();
            var RewardId = -1;

            for (var i = 0; i != count; ++i)
            {
                var r  = MyRandom.Random(10000);
                var tr = 0;
                for (var j = 0; j != 8; ++j)
                {
                    tr += tbCompose.ProId[j];
                    if (r < tr)
                    {
                        RewardId = tbCompose.ComposeId[j];
                        items.Add(tbCompose.ComposeId[j], count);
                        break;
                    }
                }
            }
            //包裹空位是否足够

            //ErrorCodes result= BagManager.CheckAddItemList(character.mBag, items);
            var result = character.mBag.CheckAddItem(RewardId, count);

            if (result != ErrorCodes.OK)
            {
                return(result);
            }

            //执行
            if (tbCompose.NeedRes > 0 && tbCompose.NeedRes < 10)
            {
                character.mBag.DeleteItem(tbCompose.NeedRes, tbCompose.NeedValue * count, eDeleteItemType.Compose);
            }

            for (var i = 0; i != tbCompose.NeedId.Length; ++i)
            {
                var itemId    = tbCompose.NeedId[i];
                var itemCount = tbCompose.NeedCount[i] * count;
                if (itemId == -1)
                {
                    continue;
                }
                character.mBag.DeleteItem(itemId, itemCount, eDeleteItemType.Compose);
            }
            var isTrue = false;

            if (character.GetExData((int)eExdataDefine.e342) == 0)
            {
                isTrue = true;
            }
            else
            {
                var pro = tbCompose.Pro /*+ character.mCity.GetComposePro()*/;
                if (MyRandom.Random(10000) < pro)
                {
                    isTrue = true;
                }
            }
            if (isTrue)
            {
                character.mBag.AddItem(RewardId, count, eCreateItemType.Compose);
                rewardId = RewardId;
                var e = new ComposeItemEvent(character, id, RewardId);
                EventDispatcher.Instance.DispatchEvent(e);

                character.BroadCastGetEquip(RewardId, 100002167);

                /*
                 * var build = character.mCity.GetBuildByType((int) BuildingType.CompositeHouse);
                 * if (build != null)
                 * {
                 * build.GiveReward(407, 1, build.TbBs, 121, eCreateItemType.Compose);
                 * var addexp = build.TbBs.Param[2];
                 * var okCount = character.GetExData((int) eExdataDefine.e556);
                 * if (okCount < build.TbBs.Param[3])
                 * {
                 * character.mCity.CityAddExp(addexp);
                 * character.AddExData((int) eExdataDefine.e556, 1);
                 * }
                 * }
                 * */
            }
            //var build=character.mCity.GetBuildByType((int) BuildingType.CompositeHouse);

            character.AddExData((int)eExdataDefine.e342, 1);
            character.AddExData((int)eExdataDefine.e415, 1);
            return(ErrorCodes.OK);
        }