public override int HandlePacket(GamePlayer player, GSPacketIn packet) { int totalGold = 0; int totalMoney = 0; int totalOffer = 0; int totalGifttoken = 0; int buyItemCount = 0; eMessageType eMsg = eMessageType.Normal; string msg = "UserBuyItemHandler.Success"; GSPacketIn pkg = new GSPacketIn(44); List <ItemInfo> buyItems = new List <ItemInfo>(); List <ItemInfo> canNotBuyItems = new List <ItemInfo>(); List <int> needitemsinfo = new List <int>(); Dictionary <int, int> changeLimitShopsID = new Dictionary <int, int>(); List <bool> dresses = new List <bool>(); List <int> places = new List <int>(); List <ItemJoinShopInfo> log = new List <ItemJoinShopInfo>(); Dictionary <int, int> playerPayGoods = new Dictionary <int, int>(); int result2; if (player.PlayerCharacter.HasBagPassword && player.PlayerCharacter.IsLocked) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked", new object[0])); result2 = 1; } else { ConsortiaInfo consotia = ConsortiaMgr.FindConsortiaInfo(player.PlayerCharacter.ConsortiaID); int count = packet.ReadInt(); for (int i = 0; i < count; i++) { int goodsId = packet.ReadInt(); int type = packet.ReadInt(); string color = packet.ReadString(); bool isDress = packet.ReadBoolean(); string skin = packet.ReadString(); int place = packet.ReadInt(); bool isBind = false; int gold = 0; int money = 0; int offer = 0; int gifttoken = 0; ShopItemInfo shopItem = ShopMgr.GetShopItemInfoById(goodsId); if (shopItem != null && shopItem.ShopID != 21 && shopItem.ShopID != 22) { if (shopItem.ShopID == 2 || !ShopMgr.CanBuy(shopItem.ShopID, (consotia == null) ? 1 : consotia.ShopLevel, ref isBind, player.PlayerCharacter.ConsortiaID, player.PlayerCharacter.Riches)) { player.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserBuyItemHandler.FailbyPermission", new object[0])); result2 = 1; return(result2); } List <int> needsItems = ShopMgr.GetShopItemBuyConditions(shopItem, type, ref gold, ref money, ref offer, ref gifttoken); for (int j = 0; j < needsItems.Count; j += 2) { if (!playerPayGoods.ContainsKey(needsItems[j])) { playerPayGoods.Add(needsItems[j], player.GetItemCount(needsItems[j])); } } bool result = true; string needsItemsLog = ""; for (int j = 0; j < needsItems.Count; j += 2) { if (playerPayGoods.ContainsKey(needsItems[j]) && playerPayGoods[needsItems[j]] >= needsItems[j + 1]) { foreach (int a in needsItems) { needitemsinfo.Add(a); } string text = needsItemsLog; needsItemsLog = string.Concat(new string[] { text, needsItems[j].ToString(), ":", needsItems[j + 1].ToString(), "|" }); Dictionary <int, int> dictionary; int key; (dictionary = playerPayGoods)[key = needsItems[j]] = dictionary[key] - needsItems[j + 1]; } else { result = false; } } ItemInfo item = ShopMgr.CreateItem(shopItem, 102, type, color, skin, isBind); int limitCount = ShopMgr.GetLimitCountByID(goodsId); if (limitCount == -1 || limitCount > 0) { if (result && player.PlayerCharacter.Gold >= gold + totalGold && player.PlayerCharacter.Money >= money + totalMoney && player.PlayerCharacter.Offer >= offer + totalOffer && player.PlayerCharacter.GiftToken >= gifttoken + totalGifttoken) { totalGold += gold; totalMoney += money; totalOffer += offer; totalGifttoken += gifttoken; buyItemCount++; buyItems.Add(item); dresses.Add(isDress); places.Add(place); if (limitCount != -1) { ShopMgr.SubtractShopLimit(goodsId); this.Notice(player, goodsId, item.Template.Name); if (!changeLimitShopsID.ContainsKey(goodsId)) { changeLimitShopsID.Add(goodsId, ShopMgr.GetLimitCountByID(goodsId)); } else { changeLimitShopsID[goodsId] = ShopMgr.GetLimitCountByID(goodsId); } } log.Add(new ItemJoinShopInfo(item.TemplateID, item.Count, money, gold, gifttoken, offer, needsItemsLog)); } else { canNotBuyItems.Add(item); } } } } if (buyItems.Count == 0) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserBuyItemHandler.Failed", new object[0])); result2 = 1; } else { int buyFrom = packet.ReadInt(); player.RemoveMoney(totalMoney, LogMoneyType.Shop, LogMoneyType.Shop_Buy); player.RemoveGold(totalGold); player.RemoveOffer(totalOffer); player.RemoveGiftToken(totalGifttoken); StringBuilder allPayItemsStr = new StringBuilder(); for (int j = 0; j < needitemsinfo.Count; j += 2) { player.RemoveTemplate(needitemsinfo[j], needitemsinfo[j + 1], eItemRemoveType.Shopping); allPayItemsStr.Append(needitemsinfo[j]).Append(","); } foreach (ItemJoinShopInfo templog in log) { //LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Buy, player.PlayerCharacter.ID, templog.Moneys, templog.Gold, templog.GiftToken, templog.Offer, templog.OtherPay, templog.TemplateID, 4, templog.Data); } List <ItemInfo> lastItems = new List <ItemInfo>(); player.StackItem(ref buyItems); for (int i = 0; i < buyItems.Count; i++) { switch (buyFrom) { case 0: case 3: if (player.AddItem(buyItems[i])) { if (dresses[i]) { player.EquipItem(buyItems[i], places[i]); msg = "UserBuyItemHandler.Save"; } } else { lastItems.Add(buyItems[i]); } break; case 1: if (!UserBuyItemHandler.AddStrengthItemsToHideBag(player, buyItems[i])) { lastItems.Add(buyItems[i]); } break; case 2: if (!UserBuyItemHandler.AddComposeItemsToHideBag(player, buyItems[i])) { lastItems.Add(buyItems[i]); } break; case 4: if (!UserBuyItemHandler.AddFusionItemsToHideBag(player, buyItems[i])) { lastItems.Add(buyItems[i]); } break; } } bool sentMail = false; if (lastItems.Count > 0) { string title = ""; sentMail = player.SendItemsToMail(lastItems, "", title, eMailType.BuyItem); msg = "UserBuyItemHandler.Mail"; } if (canNotBuyItems.Count > 0) { string title = LanguageMgr.GetTranslation("UserBuyItemHandler.ListTitle", new object[0]); StringBuilder content = new StringBuilder(); if (buyItems.Count > 0) { content.Append(LanguageMgr.GetTranslation("UserBuyItemHandler.BuyList", new object[] { buyItems.Count })); for (int i = 0; i < buyItems.Count; i++) { content.Append(string.Format("{0}{1}", (i == 0) ? "" : ";", buyItems[i].Template.Name)); } } if (canNotBuyItems.Count > 0) { content.Append(LanguageMgr.GetTranslation("UserBuyItemHandler.NoBuyList", new object[] { "\n" })); for (int j = 0; j < canNotBuyItems.Count; j++) { content.Append(string.Format("{0}{1}", (j == 0) ? "" : ";", canNotBuyItems[j].Template.Name)); } } sentMail = player.SendMail(content.ToString(), title, null, eMailType.BuyItem); } if (sentMail) { player.Out.SendMailResponse(player.PlayerCharacter.ID, eMailRespose.Receiver); } player.OnPaid(totalMoney, totalGold, totalOffer, totalGifttoken, allPayItemsStr.ToString()); int buyResult = 0; if (buyItemCount == count) { buyResult = (sentMail ? 2 : 1); } pkg.WriteInt(buyResult); pkg.WriteInt(buyFrom); player.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg, new object[0])); player.Out.SendTCP(pkg); player.SaveIntoDatabase(); this.UpdateLimitShopCount(player, changeLimitShopsID); result2 = 0; } } return(result2); }
public int HandlePacket(GameClient client, GSPacketIn packet) { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; StringBuilder stringBuilder = new StringBuilder(); eMessageType eMessageType = eMessageType.Normal; string translateId = "UserBuyItemHandler.Success"; GSPacketIn gSPacketIn = new GSPacketIn(44); List <ItemInfo> list = new List <ItemInfo>(); List <bool> list2 = new List <bool>(); List <int> list3 = new List <int>(); StringBuilder stringBuilder2 = new StringBuilder(); bool flag = false; ConsortiaInfo consortiaInfo = ConsortiaMgr.FindConsortiaInfo(client.Player.PlayerCharacter.ConsortiaID); int num6 = packet.ReadInt(); for (int i = 0; i < num6; i++) { packet.ReadInt(); int iD = packet.ReadInt(); int num7 = packet.ReadInt(); string text = packet.ReadString(); bool item = packet.ReadBoolean(); string text2 = packet.ReadString(); int item2 = packet.ReadInt(); packet.ReadBoolean(); ShopItemInfo shopItemInfoById = ShopMgr.GetShopItemInfoById(iD); if (shopItemInfoById == null) { client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserBuyItemHandler.FailByPermission", new object[0])); return(1); } if (!ShopMgr.CanBuy(shopItemInfoById.ShopID, (consortiaInfo == null) ? 1 : consortiaInfo.ShopLevel, ref flag, client.Player.PlayerCharacter.ConsortiaID, client.Player.PlayerCharacter.Riches)) { client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserBuyItemHandler.FailByPermission", new object[0])); return(1); } ItemTemplateInfo goods = ItemMgr.FindItemTemplate(shopItemInfoById.TemplateID); ItemInfo itemInfo = ItemInfo.CreateFromTemplate(goods, 1, 102); if (shopItemInfoById.BuyType == 0) { if (1 == num7) { itemInfo.ValidDate = shopItemInfoById.AUnit; } if (2 == num7) { itemInfo.ValidDate = shopItemInfoById.BUnit; } if (3 == num7) { itemInfo.ValidDate = shopItemInfoById.CUnit; } } else { if (1 == num7) { itemInfo.Count = shopItemInfoById.AUnit; } if (2 == num7) { itemInfo.Count = shopItemInfoById.BUnit; } if (3 == num7) { itemInfo.Count = shopItemInfoById.CUnit; } } if (itemInfo != null || shopItemInfoById != null) { itemInfo.Color = ((text == null) ? "" : text); itemInfo.Skin = ((text2 == null) ? "" : text2); if (flag) { itemInfo.IsBinds = true; } else { itemInfo.IsBinds = Convert.ToBoolean(shopItemInfoById.IsBind); } stringBuilder2.Append(num7); stringBuilder2.Append(","); list.Add(itemInfo); list2.Add(item); list3.Add(item2); ItemInfo.SetItemType(shopItemInfoById, num7, ref num, ref num2, ref num3, ref num4, ref num5); } } int val = packet.ReadInt(); if (list.Count == 0) { return(1); } if (client.Player.PlayerCharacter.HasBagPassword && client.Player.PlayerCharacter.IsLocked) { client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked", new object[0])); return(1); } bool flag2 = false; int num8 = 0; if (num <= client.Player.PlayerCharacter.Gold && num2 <= client.Player.PlayerCharacter.Money && num3 <= client.Player.PlayerCharacter.Offer && num4 <= client.Player.PlayerCharacter.GiftToken) { num8++; client.Player.AddExpVip(num2); client.Player.RemoveMoney(num2); client.Player.RemoveGold(num); client.Player.RemoveOffer(num3); client.Player.RemoveGiftToken(num4); string text3 = ""; int num9 = 0; MailInfo mailInfo = new MailInfo(); StringBuilder stringBuilder3 = new StringBuilder(); stringBuilder3.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark", new object[0])); for (int j = 0; j < list.Count; j++) { text3 += ((text3 == "") ? list[j].TemplateID.ToString() : ("," + list[j].TemplateID.ToString())); if (!client.Player.AddTemplate(list[j], list[j].Template.BagType, list[j].Count)) { flag2 = true; using (PlayerBussiness playerBussiness = new PlayerBussiness()) { list[j].UserID = 0; playerBussiness.AddGoods(list[j]); num9++; stringBuilder3.Append(num9); stringBuilder3.Append("、"); stringBuilder3.Append(list[j].Template.Name); stringBuilder3.Append("x"); stringBuilder3.Append(list[j].Count); stringBuilder3.Append(";"); switch (num9) { case 1: mailInfo.Annex1 = list[j].ItemID.ToString(); mailInfo.Annex1Name = list[j].Template.Name; break; case 2: mailInfo.Annex2 = list[j].ItemID.ToString(); mailInfo.Annex2Name = list[j].Template.Name; break; case 3: mailInfo.Annex3 = list[j].ItemID.ToString(); mailInfo.Annex3Name = list[j].Template.Name; break; case 4: mailInfo.Annex4 = list[j].ItemID.ToString(); mailInfo.Annex4Name = list[j].Template.Name; break; case 5: mailInfo.Annex5 = list[j].ItemID.ToString(); mailInfo.Annex5Name = list[j].Template.Name; break; } if (num9 == 5) { num9 = 0; mailInfo.AnnexRemark = stringBuilder3.ToString(); stringBuilder3.Remove(0, stringBuilder3.Length); stringBuilder3.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark", new object[0])); mailInfo.Content = LanguageMgr.GetTranslation("UserBuyItemHandler.Title", new object[0]) + mailInfo.Annex1Name + "]"; mailInfo.Gold = 0; mailInfo.Money = 0; mailInfo.Receiver = client.Player.PlayerCharacter.NickName; mailInfo.ReceiverID = client.Player.PlayerCharacter.ID; mailInfo.Sender = mailInfo.Receiver; mailInfo.SenderID = mailInfo.ReceiverID; mailInfo.Title = mailInfo.Content; mailInfo.Type = 8; playerBussiness.SendMail(mailInfo); eMessageType = eMessageType.ERROR; translateId = "UserBuyItemHandler.Mail"; mailInfo.Revert(); } } } } if (num9 > 0) { using (PlayerBussiness playerBussiness2 = new PlayerBussiness()) { mailInfo.AnnexRemark = stringBuilder3.ToString(); mailInfo.Content = LanguageMgr.GetTranslation("UserBuyItemHandler.Title", new object[0]) + mailInfo.Annex1Name + "]"; mailInfo.Gold = 0; mailInfo.Money = 0; mailInfo.Receiver = client.Player.PlayerCharacter.NickName; mailInfo.ReceiverID = client.Player.PlayerCharacter.ID; mailInfo.Sender = mailInfo.Receiver; mailInfo.SenderID = mailInfo.ReceiverID; mailInfo.Title = mailInfo.Content; mailInfo.Type = 8; playerBussiness2.SendMail(mailInfo); eMessageType = eMessageType.ERROR; translateId = "UserBuyItemHandler.Mail"; } } if (eMessageType == eMessageType.ERROR) { client.Out.SendMailResponse(client.Player.PlayerCharacter.ID, eMailRespose.Receiver); } client.Player.OnPaid(num2, num, num3, num4, num5, stringBuilder.ToString()); LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Buy, client.Player.PlayerCharacter.ID, num2, client.Player.PlayerCharacter.Money, num, num4, num3, num5, "牌子编号", text3, stringBuilder2.ToString()); } else { if (num2 > client.Player.PlayerCharacter.Money) { translateId = "UserBuyItemHandler.NoMoney"; } if (num > client.Player.PlayerCharacter.Gold) { translateId = "UserBuyItemHandler.NoGold"; } if (num3 > client.Player.PlayerCharacter.Offer) { translateId = "UserBuyItemHandler.NoOffer"; } if (num4 > client.Player.PlayerCharacter.GiftToken) { translateId = "UserBuyItemHandler.GiftToken"; } if (num5 > client.Player.PlayerCharacter.medal) { translateId = "UserBuyItemHandler.Medal"; } eMessageType = eMessageType.ERROR; } int val2 = 0; if (num8 == num6) { val2 = (flag2 ? 2 : 1); } client.Player.MainBag.SaveToDatabase(); client.Player.PropBag.SaveToDatabase(); gSPacketIn.WriteInt(val2); gSPacketIn.WriteInt(val); client.Out.SendMessage(eMessageType, LanguageMgr.GetTranslation(translateId, new object[0])); client.Out.SendTCP(gSPacketIn); return(0); }