예제 #1
0
파일: Mail.cs 프로젝트: eiyaya/mmorpgserver
        //领取邮件
        public ErrorCodes ReceiveMail(MailManager _this, ulong uId)
        {
            var mail = GetMail(_this, uId);

            if (mail == null)
            {
                return(ErrorCodes.Error_MailNotFind);
            }
            if (mail.State == (int)MailStateType.Receive)
            {
                return(ErrorCodes.Error_MailReceiveOver);
            }
            if (mail.Reward.Count > 0)
            {
                //有物品需要奖励
                ErrorCodes result;
                if (mail.Reward.Count == 1)
                {
                    //result = mCharacter.mBag.AddItem(mail.Reward[0].ItemId, mail.Reward[0].Count, eCreateItemType.Mail);
                    result = _this.mCharacter.mBag.AddItem(mail.Reward[0], eCreateItemType.Mail);
                    if (result == ErrorCodes.OK)
                    {
                        mail.State = (int)MailStateType.Receive;
                    }
                    return(result);
                }
                //多个物品需要奖励时
                var items = new Dictionary <int, int>();
                foreach (var i in mail.Reward)
                {
                    if (i.Count > 0)
                    {
                        items.modifyValue(i.ItemId, i.Count);
                    }
                }
                result = BagManager.CheckAddItemList(_this.mCharacter.mBag, items);
                if (result == ErrorCodes.OK)
                {
                    foreach (var i in mail.Reward)
                    {
                        if (i.Count > 0)
                        {
                            _this.mCharacter.mBag.AddItem(i, eCreateItemType.Mail);
                        }
                    }
                    mail.State = (int)MailStateType.Receive;
                }
                else
                {
                    return(result);
                }
            }
            else
            {
                mail.State = (int)MailStateType.OldMail;
            }
            return(ErrorCodes.OK);
        }
예제 #2
0
        public ErrorCodes ReplaceElfSkill(CharacterController character,
                                          int elfBagIndex,
                                          int exBuffIdx,
                                          int itemBagId,
                                          int itemBagindex,
                                          ref int nextBuffId)
        {
            var item = character.GetItemByBagByIndex((int)eBagType.Elf, elfBagIndex) as ElfItem;

            if (item == null)
            {
                return(ErrorCodes.Error_ItemNotFind);
            }
            var tbElf = Table.GetElf(item.GetId());

            if (tbElf == null)
            {
                return(ErrorCodes.Error_ElfNotFind);
            }

            // 检查物品
            var costItem = character.GetItemByBagByIndex(itemBagId, itemBagindex);

            if (costItem == null)
            {
                return(ErrorCodes.Error_ItemNoInBag);
            }

            var tbItem = Table.GetItemBase(costItem.GetId());

            if (tbItem == null)
            {
                return(ErrorCodes.Error_ItemID);
            }

            if (tbItem.Type != 26900)
            {
                return(ErrorCodes.Error_ELfItemType);
            }

            // 物品类型
            var buffType = tbItem.Exdata[1];

            if (buffType != exBuffIdx)
            {
                return(ErrorCodes.Error_ELfItemType);
            }

            var oldBuff      = item.GetBuffId(exBuffIdx);
            var oldBuffLevel = item.GetBuffLevel(exBuffIdx);

            // 返还升级所需要的物品
            var recycleDict = new Dictionary <int, int>();
            var tbOldBuff   = Table.GetBuff(oldBuff);

            if (tbOldBuff != null)
            {
                // 返还升级到oldBuffLevel等级所需要的物品
                for (var i = 0; i < oldBuffLevel; ++i)
                {
                    var index = Math.Max(0, i - 1);  // 因为ElfSkillUp[0]是1升2级的,所以都是i-1,当i == 0时,设置为1级的消耗

                    if (index >= tbOldBuff.ElfSkillUp.Count)
                    {
                        continue;
                    }

                    var tbConsume = Table.GetConsumArray(tbOldBuff.ElfSkillUp[index]);
                    if (tbConsume == null)
                    {
                        continue;
                    }

                    for (var j = 0; j < tbConsume.ItemId.Length; ++j)
                    {
                        var itemId = tbConsume.ItemId[j];
                        if (itemId < 0)
                        {
                            continue;
                        }
                        if (itemId == (int)eResourcesType.ElfPiece)     // 不返还精魄
                        {
                            continue;
                        }
                        var itemCount = tbConsume.ItemCount[j];
                        recycleDict.modifyValue(itemId, itemCount);
                    }
                }
                var result = BagManager.CheckAddItemList(character.mBag, recycleDict);
                if (result != ErrorCodes.OK)
                { // 不能增加返还物品
                    return(result);
                }
            }

            // 换技能
            var buffId = item.ReplaceBuff(tbItem.Exdata[0], exBuffIdx);

            if (buffId < 0)
            {
                return(ErrorCodes.Error_ELfItemType);
            }
            int buffLevel = 1;

            item.SetBuffLevel(exBuffIdx, buffLevel);

            // 删除物品
            character.mBag.GetBag(itemBagId).ReduceCountByIndex(itemBagindex, 1, eDeleteItemType.ELfSkillReplace);
            // 增加返还物品
            if (recycleDict.Count > 0)
            {
                character.mBag.AddItems(recycleDict, eCreateItemType.ElfReplaceBuff);
            }

            if (elfBagIndex < 3)
            {
                if (elfBagIndex == 0)
                {
                    character.SetRankFlag(RankType.PetFight);
                }

                var allBuff = new Dictionary <int, int>();
                for (var i = 0; i < 3; ++i)
                {
                    var tempItem = character.GetItemByBagByIndex((int)eBagType.Elf, i) as ElfItem;
                    if (tempItem == null)
                    {
                        continue;
                    }
                    tempItem.FillAllBuff(allBuff);
                }

                var removeBuff = new List <int>();
                var addBuff    = new Dictionary <int, int>();
                int tempBuffLevel;
                if (oldBuff != -1)
                {
                    if (allBuff.TryGetValue(oldBuff, out tempBuffLevel))
                    {
                        if (tempBuffLevel != oldBuffLevel)
                        {
                            removeBuff.Add(oldBuff);
                            addBuff[oldBuff] = tempBuffLevel;
                        }
                    }
                    else
                    {
                        removeBuff.Add(oldBuff);
                    }
                }

                if (allBuff.TryGetValue(buffId, out tempBuffLevel))
                {
                    addBuff[buffId] = tempBuffLevel;
                }

                character.ElfChange(removeBuff, addBuff);
            }

            nextBuffId = buffId;

            try
            {
                var klog = string.Format("jinglingjinengtihuan#{0}|{1}|{2}|{3}|{4}|{5}|{6}",
                                         character.mGuid,
                                         character.GetLevel(),
                                         character.serverId,
                                         item.GetId(),
                                         oldBuff,
                                         nextBuffId, // 替换为的技能id
                                         DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                PlayerLog.Kafka(klog, 2);
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
            }

            return(ErrorCodes.OK);
        }
예제 #3
0
        //检查奖励
        public ErrorCodes CheckGift(CharacterController character, eActivationRewardType type, int giftId)
        {
            switch (type)
            {
            case eActivationRewardType.TableGift:
            {
                var tbGift = Table.GetGift(giftId);
                if (tbGift == null)
                {
                    return(ErrorCodes.Error_GiftID);
                }
                if (character.GetFlag(tbGift.Flag))
                {
                    return(ErrorCodes.Error_GiftAlreadyReceive);
                }

                switch ((eRewardType)tbGift.Type)
                {
                //固定礼包
                case eRewardType.GiftBag:
                {
                    var items = new Dictionary <int, int>();
                    for (var i = 0; i != 4; ++i)
                    {
                        if (tbGift.Param[i * 2] != -1)
                        {
                            items.modifyValue(tbGift.Param[i * 2], tbGift.Param[i * 2 + 1]);
                        }
                    }
                    return(BagManager.CheckAddItemList(character.mBag, items));
                }

                //在线时长
                case eRewardType.OnlineReward:
                {
                    var times = character.TodayTimes + DateTime.Now.GetDiffSeconds(character.OnlineTime);
                    if (times >= tbGift.Param[0])
                    {
                        return(character.mBag.CheckAddItem(tbGift.Param[1], tbGift.Param[2]));
                    }
                    return(ErrorCodes.Error_GiftTimeNotEnough);
                }

                //等级奖励
                case eRewardType.LevelReward:
                {
                    if (character.GetLevel() >= tbGift.Param[0])
                    {
                        var items = new Dictionary <int, int>();
                        for (var i = 1; i <= 5; ++i)
                        {
                            var count = tbGift.Param[i + 5];
                            if (tbGift.Param[i] != -1)
                            {
                                items.modifyValue(tbGift.Param[i], count);
                            }
                        }
                        return(BagManager.CheckAddItemList(character.mBag, items));
                    }
                    return(ErrorCodes.Error_LevelNoEnough);
                }

                //连续登陆
                case eRewardType.ContinuesLoginReward:
                {
                    var days = character.GetExData(17);
                    if (days < 1)
                    {
                        return(ErrorCodes.Error_GiftTimeNotEnough);
                    }
                    if (days > 5)
                    {
                        days = 5;
                    }
                    var items = new Dictionary <int, int>();
                    for (var i = 0; i < days; ++i)
                    {
                        var tbGift2 = Table.GetGift(13 + i);
                        if (character.GetFlag(tbGift.Flag))
                        {
                            continue;
                        }
                        items.modifyValue(tbGift2.Param[1], tbGift2.Param[2]);
                    }
                    return(BagManager.CheckAddItemList(character.mBag, items));
                }

                //累计登陆
                case eRewardType.MonthCheckinReward:
                {
                    var months = DateTime.Now.Month;
                    if (tbGift.Param[0] != 999 && months != tbGift.Param[0])
                    {
                        return(ErrorCodes.Error_GiftTimeNotEnough);
                    }
                    var days        = DateTime.Now.Day;
                    var exdataValue = character.GetExData(tbGift.Exdata);
                    if (exdataValue + 1 != tbGift.Param[1])
                    {
                        return(ErrorCodes.Unknow);
                    }
                    if (days >= tbGift.Param[1])
                    {
                        if (character.GetFlag(466))
                        {
//补签
                            var SupplementCount = character.GetExData(18);
                            var needGold        =
                                (int)
                                (tbGift.Param[4] *
                                 SkillExtension.Pow(tbGift.Param[5] / 10000.0f, SupplementCount));
                            needGold = needGold - needGold % 5;
                            if (character.mBag.GetRes(eResourcesType.DiamondRes) < needGold)
                            {
                                return(ErrorCodes.MoneyNotEnough);
                            }
                            return(character.mBag.CheckAddItem(tbGift.Param[2], tbGift.Param[3]));
                        }
                        //签到
                        return(character.mBag.CheckAddItem(tbGift.Param[2], tbGift.Param[3]));
                    }
                    return(ErrorCodes.Error_GiftTimeNotEnough);
                }

                //每日活跃度
                case eRewardType.DailyActivity:
                {
                    if (character.GetExData(tbGift.Exdata) >= 0)
                    {
                        if (character.GetExData(tbGift.Exdata) < tbGift.Param[1])
                        {
                            return(ErrorCodes.Error_GiftCountNotEnough);
                        }
                    }
                }
                break;

                //每日活跃奖励
                case eRewardType.DailyActivityReward:
                {
                    if (character.GetExData(15) >= tbGift.Param[2])
                    {
                        return(character.mBag.CheckAddItem(tbGift.Param[0], tbGift.Param[1]));
                    }
                    return(ErrorCodes.Error_ActivityPointNotEnough);
                }

                //七天登录奖励
                case eRewardType.SevenDayReward:
                {
                    if (character.GetExData((int)eExdataDefine.e94) < tbGift.Param[0])
                    {
                        return(ErrorCodes.Error_GiftTimeNotEnough);
                    }
                    if (character.GetFlag(tbGift.Flag))
                    {
                        return(ErrorCodes.Error_GiftAlreadyReceive);
                    }
                    var items = new Dictionary <int, int>();
                    for (var i = 0; i != 3; i++)
                    {
                        items.modifyValue(tbGift.Param[i * 2 + 1], tbGift.Param[i * 2 + 2]);
                    }
                    items.modifyValue(tbGift.Param[7], tbGift.Param[8]);

                    return(BagManager.CheckAddItemList(character.mBag, items));
                }

                default:
                    Logger.Warn("Gift[{0}] type is overflow", giftId);
                    break;
                }
            }
            break;

            case eActivationRewardType.DailyVipGift:
            {
                var vipLevel = character.mBag.GetRes(eResourcesType.VipLevel);
                var tbVip    = Table.GetVIP(vipLevel);

                if (tbVip == null)
                {
                    return(ErrorCodes.Error_NoVipGift);
                }
                Dictionary <int, int> dic = new Dictionary <int, int>();
                Utils.GetVipReward(vipLevel, ref dic);
                if (dic.Count == 0)
                {
                    return(ErrorCodes.Error_NoVipGift);
                }
                var tbDA = Table.GetDailyActivity(giftId);
                if (character.GetFlag(tbDA.CommonParam[0]))
                {
                    return(ErrorCodes.Error_VipGiftGained);
                }
                return(BagManager.CheckAddItemList(character.mBag, dic));
            }

            case eActivationRewardType.MonthCard:
            {
                var now  = DateTime.Now;
                var date = character.lExdata64.GetTime(Exdata64TimeType.MonthCardExpirationDate);
                if (date < now)
                {
                    return(ErrorCodes.Error_NoMonthCard);
                }
                var tbDA = Table.GetDailyActivity(giftId);
                var flag = tbDA.CommonParam[0];
                if (character.GetFlag(flag))
                {
                    return(ErrorCodes.Error_MonthCardGained);
                }
            }
            break;

            case eActivationRewardType.LifeCard:
            {
                if (!character.GetFlag(2682))    //终生卡标记
                {
                    return(ErrorCodes.Error_NoLifeCard);
                }
                var tbRecharge = Table.GetRecharge(giftId);
                if (null == tbRecharge)
                {
                    return(ErrorCodes.Error_GiftID);
                }
                var flagId = tbRecharge.Param[2];
                if (character.GetFlag(flagId))
                {
                    return(ErrorCodes.Error_LifeCardGained);
                }
            }
            break;

            case eActivationRewardType.WeekCard:
            {
                var now  = DateTime.Now;
                var date = character.lExdata64.GetTime(Exdata64TimeType.WeekCardExpirationDate);
                if (date < now)
                {
                    return(ErrorCodes.Error_NoWeekCard);
                }
                var tbDA = Table.GetDailyActivity(giftId);
                var flag = tbDA.CommonParam[0];
                if (character.GetFlag(flag))
                {
                    return(ErrorCodes.Error_WeekCardGained);
                }
            }
            break;
            }
            return(ErrorCodes.OK);
        }
예제 #4
0
        //给予奖励
        public ErrorCodes GiveGift(CharacterController character, eActivationRewardType type, int giftId)
        {
            var result = ErrorCodes.OK;

            switch (type)
            {
            case eActivationRewardType.TableGift:
            {
                var tbGift = Table.GetGift(giftId);
                if (tbGift == null)
                {
                    return(ErrorCodes.Error_GiftID);
                }
                if (character.GetFlag(tbGift.Flag))
                {
                    return(ErrorCodes.Error_GiftAlreadyReceive);
                }

                //执行领取
                switch ((eRewardType)tbGift.Type)
                {
                //固定礼包
                case eRewardType.GiftBag:
                {
                    //Dictionary<int, int> items = new Dictionary<int, int>();
                    for (var i = 0; i != 4; ++i)
                    {
                        if (tbGift.Param[i * 2] != -1)
                        {
                            character.mBag.AddItem(tbGift.Param[i * 2], tbGift.Param[i * 2 + 1],
                                                   eCreateItemType.Gift);
                        }
                    }
                }
                break;

                //在线时长
                case eRewardType.OnlineReward:
                {
                    result = character.mBag.AddItem(tbGift.Param[1], tbGift.Param[2], eCreateItemType.Online);
                }
                break;

                //等级奖励
                case eRewardType.LevelReward:
                {
                    for (var i = 1; i <= 5; ++i)
                    {
                        var count = tbGift.Param[i + 5];
                        if (tbGift.Param[i] != -1)
                        {
                            character.mBag.AddItem(tbGift.Param[i], count, eCreateItemType.LevelUp);
                        }
                    }
                }
                break;

                //连续登陆
                case eRewardType.ContinuesLoginReward:
                {
                    //result = character.mBag.AddItem(tbGift.Param[1], tbGift.Param[2]);

                    var days = character.GetExData(17);
                    if (days > 5)
                    {
                        days = 5;
                    }
                    for (var i = 0; i < days; ++i)
                    {
                        var tbGift2 = Table.GetGift(13 + i);
                        if (character.GetFlag(tbGift2.Flag))
                        {
                            continue;
                        }
                        character.mBag.AddItem(tbGift2.Param[1], tbGift2.Param[2], eCreateItemType.ContinueDay);
                        character.SetFlag(tbGift2.Flag);
                    }
                    return(ErrorCodes.OK);
                }

                //签到
                case eRewardType.MonthCheckinReward:
                {
                    if (character.GetFlag(466))
                    {
//补签
                        var SupplementCount = character.GetExData(18);
                        var needGold        =
                            (int)
                            (tbGift.Param[4] * SkillExtension.Pow(tbGift.Param[5] / 10000.0f, SupplementCount));
                        needGold = needGold - needGold % 5;
                        character.mBag.DeleteItem((int)eResourcesType.DiamondRes, needGold,
                                                  eDeleteItemType.ReSign);
                        character.SetExData(18, SupplementCount + 1);
                        character.AddExData(tbGift.Exdata, 1);
                        result = character.mBag.AddItem(tbGift.Param[2], tbGift.Param[3], eCreateItemType.ReSign);
                    }
                    else
                    {
//签到
                        character.SetFlag(466);
                        character.AddExData(tbGift.Exdata, 1);
                        result = character.mBag.AddItem(tbGift.Param[2], tbGift.Param[3], eCreateItemType.Sign);
                    }
                }
                break;

                ////每日活跃度
                //case eRewardType.DailyActivity:
                //    {
                //        character.AddExData(tbGift.Param[3], tbGift.Param[0]);
                //    }
                //    break;
                //每日活跃奖励
                case eRewardType.DailyActivityReward:
                {
                    result = character.mBag.AddItem(tbGift.Param[0], tbGift.Param[1], eCreateItemType.Activity);
                }
                break;

                //七天登录奖励
                case eRewardType.SevenDayReward:
                {
                    for (var i = 0; i != 3; i++)
                    {
                        character.mBag.AddItem(tbGift.Param[i * 2 + 1], tbGift.Param[i * 2 + 2],
                                               eCreateItemType.SevenDayReward);
                    }
                    character.mBag.AddItem(tbGift.Param[7], tbGift.Param[8], eCreateItemType.SevenDayReward);
                    character.SetFlag(tbGift.Flag);
                }
                break;

                default:
                    Logger.Warn("Gift[{0}] type is overflow", giftId);
                    break;
                }
                if (result == ErrorCodes.OK)
                {
                    character.SetFlag(tbGift.Flag);
                }
            }
            break;

            case eActivationRewardType.DailyVipGift:
            {
                var vipLevel = character.mBag.GetRes(eResourcesType.VipLevel);
                var tbVip    = Table.GetVIP(vipLevel);
                Dictionary <int, int> dic = new Dictionary <int, int>();
                Utils.GetVipReward(vipLevel, ref dic);



                if (dic.Count == 0)
                {
                    return(ErrorCodes.Error_NoVipGift);
                }
                var tbDA = Table.GetDailyActivity(giftId);
                var flag = tbDA.CommonParam[0];
                if (character.GetFlag(flag))
                {
                    return(ErrorCodes.Error_VipGiftGained);
                }
                result = BagManager.CheckAddItemList(character.mBag, dic);
                if (result != ErrorCodes.OK)
                {
                    return(result);
                }
                character.SetFlag(flag);

                result = character.mBag.AddItems(dic, eCreateItemType.DailyVipGift);
            }
            break;

            case eActivationRewardType.MonthCard:
            {
                var diaCount = Table.GetServerConfig(419).ToInt();
                result = character.mBag.AddRes(eResourcesType.DiamondRes, diaCount, eCreateItemType.MonthCard);
                var tbDA = Table.GetDailyActivity(giftId);
                var flag = tbDA.CommonParam[0];
                if (character.GetFlag(flag))
                {
                    return(ErrorCodes.Error_MonthCardGained);
                }
                character.SetFlag(flag);
                character.SetFlag(tbDA.CommonParam[0]);
                character.AddExData((int)eExdataDefine.e778, 1);
            }
            break;

            case eActivationRewardType.WeekCard:
            {
                var tbRecharge = Table.GetRecharge(43);
                var diaCount   = tbRecharge.Param[0];      //策划配置到此列
                result = character.mBag.AddRes(eResourcesType.DiamondRes, diaCount, eCreateItemType.WeekCard);
                var tbDA = Table.GetDailyActivity(giftId);
                var flag = tbDA.CommonParam[0];
                if (character.GetFlag(flag))
                {
                    return(ErrorCodes.Error_WeekCardGained);
                }
                character.SetFlag(flag);
                character.AddExData((int)eExdataDefine.e779, 1);
            }
            break;

            case eActivationRewardType.LifeCard:
            {
                var tbRecharge = Table.GetRecharge(giftId);
                if (null == tbRecharge)
                {
                    return(ErrorCodes.Error_GiftID);
                }
                var flagId = tbRecharge.Param[2];
                if (character.GetFlag(flagId))
                {
                    return(ErrorCodes.Error_LifeCardGained);
                }
                var diaCount = tbRecharge.Param[0];
                result = character.mBag.AddRes(eResourcesType.DiamondRes, diaCount, eCreateItemType.LifeCard);
                if (result == ErrorCodes.OK)
                {
                    character.SetFlag(flagId);
                }
                else
                {
                    return(result);
                }
            }
            break;
            }
            return(result);
        }