public int HandlePacket(GameClient client, GSPacketIn packet) { if (client.Player.PlayerCharacter.ConsortiaID == 0) return 0; int money = packet.ReadInt(); if (client.Player.PlayerCharacter.HasBagPassword && client.Player.PlayerCharacter.IsLocked) { client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked")); return 1; } if (money < 1 || client.Player.PlayerCharacter.Money < money) { client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ConsortiaRichesOfferHandler.NoMoney")); return 1; } bool result = false; string msg = "ConsortiaRichesOfferHandler.Failed"; using (ConsortiaBussiness db = new ConsortiaBussiness()) { int riches = money / 2; if (db.ConsortiaRichAdd(client.Player.PlayerCharacter.ConsortiaID, ref riches, 5, client.Player.PlayerCharacter.NickName)) { result = true; client.Player.PlayerCharacter.RichesOffer += riches; //client.Player.SetMoney(-money); client.Player.RemoveMoney(money); LogMgr.LogMoneyAdd(LogMoneyType.Consortia, LogMoneyType.Consortia_Rich, client.Player.PlayerCharacter.ID, money, client.Player.PlayerCharacter.Money, 0, 0, (int)eSubConsumerType.Consortia_Riches_Offer,0, "", "", ""); msg = "ConsortiaRichesOfferHandler.Successed"; GameServer.Instance.LoginServer.SendConsortiaRichesOffer(client.Player.PlayerCharacter.ConsortiaID, client.Player.PlayerCharacter.ID, client.Player.PlayerCharacter.NickName, riches); } } packet.WriteBoolean(result); packet.WriteString(LanguageMgr.GetTranslation(msg)); client.Out.SendTCP(packet); return 0; }
/// <summary> /// 用户领奖 /// </summary> /// <param name="quest"></param> /// <param name="rewardItemID"></param> /// <returns></returns> public bool Finish(BaseQuest baseQuest, int selectedItem) { //if (baseQuest.CanCompleted(m_player) == false) // return false; #region 定义变量 //提示用户 string msg = ""; //奖励Buff string RewardBuffName = string.Empty; int RewardBuffTime = 0; QuestInfo qinfo = baseQuest.Info; QuestDataInfo qdata = baseQuest.Data; #endregion #region 从游戏中领取奖品 m_player.BeginAllChanges(); try { if (baseQuest.Finish(m_player)) { RemoveQuest(baseQuest); //固定奖励&选择奖励 List<QuestAwardInfo> awards = QuestMgr.GetQuestGoods(qinfo); List<ItemInfo> mainBg = new List<ItemInfo>(); List<ItemInfo> propBg = new List<ItemInfo>(); foreach (QuestAwardInfo award in awards) { //获取固定奖励 或者 已经选取的可选奖励 if (award.IsSelect == false || award.RewardItemID == selectedItem) { ItemTemplateInfo temp = Bussiness.Managers.ItemMgr.FindItemTemplate(award.RewardItemID); if (temp != null) { msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardProp", temp.Name, award.RewardItemCount1) + " "; Int32 tempCount = award.RewardItemCount1; if (award.IsCount == true) { tempCount = tempCount * qdata.RandDobule; } for (int len = 0; len < tempCount; len += temp.MaxCount) { int count = len + temp.MaxCount > award.RewardItemCount1 ? award.RewardItemCount1 - len : temp.MaxCount; ItemInfo item = ItemInfo.CreateFromTemplate(temp, count, (int)ItemAddType.Quest); if (item == null) continue; item.ValidDate = award.RewardItemValid; item.IsBinds = true; item.StrengthenLevel = award.StrengthenLevel;//等级 item.AttackCompose = award.AttackCompose; //攻击加成 item.DefendCompose = award.DefendCompose; //防御加成 item.AgilityCompose = award.AgilityCompose; //敏捷加成 item.LuckCompose = award.LuckCompose; //幸运加成 if (temp.BagType == eBageType.PropBag) { propBg.Add(item); } else { mainBg.Add(item); } } } } } //判断背包的空位是否足够 if (mainBg.Count > 0 && m_player.MainBag.GetEmptyCount() < mainBg.Count) { baseQuest.CancelFinish(m_player); m_player.Out.SendMessage(eMessageType.ERROR, m_player.GetInventoryName(eBageType.MainBag) + LanguageMgr.GetTranslation("Game.Server.Quests.BagFull") + " "); return false; } if (propBg.Count > 0 && m_player.PropBag.GetEmptyCount() < propBg.Count) { baseQuest.CancelFinish(m_player); m_player.Out.SendMessage(eMessageType.ERROR, m_player.GetInventoryName(eBageType.PropBag) + LanguageMgr.GetTranslation("Game.Server.Quests.BagFull") + " "); return false; } //把物品放入背包 foreach (ItemInfo item in mainBg) { m_player.AddTemplate(item,eBageType.MainBag,1); } foreach (ItemInfo item in propBg) { if (item.TemplateID == 11408)//trminhpc { int rewardMedal = item.Count; m_player.AddMedal(rewardMedal); //msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.Medal", rewardMedal + " "); } else { m_player.AddTemplate(item, eBageType.PropBag, 1); } } msg = LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.Reward") + msg; //发放Buff if ((qinfo.RewardBuffID > 0) && (qinfo.RewardBuffDate > 0)) { ItemTemplateInfo temp = Bussiness.Managers.ItemMgr.FindItemTemplate(qinfo.RewardBuffID); if (temp != null) { RewardBuffTime = qinfo.RewardBuffDate * qdata.RandDobule; AbstractBuffer buffer = BufferList.CreateBufferHour(temp, RewardBuffTime); buffer.Start(m_player); msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardBuff", temp.Name, RewardBuffTime) + " "; } } //奖励金币 if (qinfo.RewardGold != 0) { int rewardGold = qinfo.RewardGold * qdata.RandDobule; m_player.AddGold(rewardGold); msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardGold", rewardGold) + " "; } //奖励点卷 if (qinfo.RewardMoney != 0) { int rewardMoney = qinfo.RewardMoney * qdata.RandDobule; m_player.AddMoney(qinfo.RewardMoney * qdata.RandDobule); LogMgr.LogMoneyAdd(LogMoneyType.Award, LogMoneyType.Award_Quest, m_player.PlayerCharacter.ID, rewardMoney, m_player.PlayerCharacter.Money, 0, 0, 0,0, "", "", "");//添加日志 msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardMoney", rewardMoney) + " "; } //奖励GP if (qinfo.RewardGP != 0) { int rewardGp = qinfo.RewardGP * qdata.RandDobule; m_player.AddGP(rewardGp); msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardGB1", rewardGp) + " "; } //有公会则奖励财富 if ((qinfo.RewardRiches != 0) && (m_player.PlayerCharacter.ConsortiaID != 0)) { int riches = qinfo.RewardRiches * qdata.RandDobule; m_player.AddRichesOffer(riches); using (ConsortiaBussiness db = new ConsortiaBussiness()) { db.ConsortiaRichAdd(m_player.PlayerCharacter.ConsortiaID, ref riches); } msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardRiches", riches) + " "; } //奖励功勋 if (qinfo.RewardOffer != 0) { int rewardOffer = qinfo.RewardOffer * qdata.RandDobule; m_player.AddOffer(rewardOffer,false); msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardOffer", rewardOffer) + " "; } //奖励礼劵 if (qinfo.RewardBindMoney != 0) { int rewardGiftToken = qinfo.RewardBindMoney * qdata.RandDobule; m_player.AddGiftToken(rewardGiftToken); msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.RewardGiftToken", rewardGiftToken + " "); } //if (qinfo.RewardMedal != 0)//trminhpc //{ // int rewardMedal = qinfo.RewardMedal * qdata.RandDobule; // m_player.AddMedal(rewardMedal); // msg = msg + LanguageMgr.GetTranslation("Game.Server.Quests.FinishQuest.Medal", rewardMedal + " "); // } m_player.Out.SendMessage(eMessageType.Normal, msg); SetQuestFinish(baseQuest.Info.ID); m_player.PlayerCharacter.QuestSite =m_states; } OnQuestsChanged(baseQuest); } catch (Exception ex) { if (log.IsErrorEnabled) log.Error("Quest Finish:" + ex); return false; } finally { m_player.CommitAllChanges(); } #endregion return true; }