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 override int HandlePacket(GamePlayer player, GSPacketIn packet) { int bagType = packet.ReadInt(); int place = packet.ReadInt(); int goodsID = packet.ReadInt(); int type = packet.ReadInt(); bool ignoreBagLock = packet.ReadBoolean(); int result; if (player.PlayerCharacter.HasBagPassword && player.PlayerCharacter.IsLocked && !ignoreBagLock) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked", new object[0])); result = 0; } else { ItemInfo item; string msg; if (place == -1) { int gold = 0; int money = 0; int offer = 0; int gifttoken = 0; ShopItemInfo info = ShopMgr.GetShopItemInfoById(goodsID); if (null == info) { result = 1; return(result); } List <int> payGoods = ShopMgr.GetShopItemBuyConditions(info, type, ref gold, ref money, ref offer, ref gifttoken); if (offer > 0 || payGoods.Count > 0) { result = 1; return(result); } item = ShopMgr.CreateItem(info, 102, type, "", "", true); if (item == null) { result = 1; return(result); } player.RemoveMoney(money, LogMoneyType.Shop, LogMoneyType.Shop_Card); player.RemoveGold(gold); player.RemoveOffer(offer); player.RemoveGiftToken(gifttoken); //LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Card, player.PlayerCharacter.ID, money, gold, 0, 0, "", item.TemplateID, 1, item.Count); msg = "CardUseHandler.Success"; } else { item = player.PropBag.GetItemAt(place); msg = "CardUseHandler.Success"; } if (item != null) { string msg2 = string.Empty; if (item.Template.Property1 != 21) { AbstractBuffer buffer = BufferList.CreateBuffer(item.Template, item.ValidDate); if (buffer != null) { buffer.Start(player); if (place != -1) { player.OnUsingItem(item.TemplateID); player.PropBag.RemoveItem(item, eItemRemoveType.Use); } } player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation(msg, new object[0])); } else { if (item.IsValidItem()) { player.AddGpDirect(item.Template.Property2); player.OnUsingItem(item.TemplateID); player.RemoveItem(item, eItemRemoveType.Use); msg2 = "GPDanUser.Success"; } player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation(msg2, new object[] { item.Template.Property2 })); } } result = 0; } return(result); }
public override int HandlePacket(GamePlayer player, GSPacketIn packet) { int totalMoney = 0; eMessageType eMsg = eMessageType.Normal; string msg = "GoodsPresentHandler.Success"; GSPacketIn pkg = new GSPacketIn(57); string content = packet.ReadString(); string nickName = packet.ReadString(); List <ItemInfo> buyItems = new List <ItemInfo>(); List <ItemInfo> canNotBuyItems = new List <ItemInfo>(); Dictionary <int, int> changeLimitShopsID = new Dictionary <int, int>(); StringBuilder allItemsStr = new StringBuilder(); StringBuilder allTypesStr = new StringBuilder(); bool buyResult = false; int result; if (player.PlayerCharacter.HasBagPassword && player.PlayerCharacter.IsLocked) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked", new object[0])); result = 0; } else { using (PlayerBussiness db = new PlayerBussiness()) { PlayerInfo receiver = db.GetUserSingleByNickName(nickName); if (receiver != null) { int count = packet.ReadInt(); for (int i = 0; i < count; i++) { int goodsId = packet.ReadInt(); int type = packet.ReadInt(); string color = packet.ReadString(); string skin = packet.ReadString(); 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) { List <int> tempInfo = ShopMgr.GetShopItemBuyConditions(shopItem, type, ref gold, ref money, ref offer, ref gifttoken); if (gold <= 0 && offer <= 0 && gifttoken <= 0 && tempInfo.Count <= 0) { ItemInfo item = ShopMgr.CreateItem(shopItem, 102, type, color, skin, false); int limitCount = ShopMgr.GetLimitCountByID(goodsId); if (limitCount == -1 || limitCount > 0) { if (player.PlayerCharacter.Money >= money + totalMoney) { totalMoney += money; allTypesStr.Append(type).Append(","); allItemsStr.Append(item.TemplateID).Append(","); buyItems.Add(item); 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); } } //LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Present, player.PlayerCharacter.ID, money, gold, gifttoken, offer, "", item.TemplateID, 2, item.Count); } else { canNotBuyItems.Add(item); } } } } } if (buyItems.Count == 0) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserBuyItemHandler.Failed", new object[0])); result = 1; return(result); } player.RemoveMoney(totalMoney, LogMoneyType.Shop, LogMoneyType.Shop_Present); int annexIndex = 0; MailInfo message = new MailInfo(); StringBuilder annexRemark = new StringBuilder(); annexRemark.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark", new object[0])); player.StackItem(ref buyItems); player.OnPlayerGoodsPresent(buyItems.Count); foreach (ItemInfo item in buyItems) { // ItemInfo item; db.AddGoods(item); annexIndex++; annexRemark.Append(annexIndex); annexRemark.Append("、"); annexRemark.Append(item.Template.Name); annexRemark.Append("x"); annexRemark.Append(item.Count); annexRemark.Append(";"); switch (annexIndex) { case 1: message.Annex1 = item.ItemID.ToString(); message.Annex1Name = item.Template.Name; break; case 2: message.Annex2 = item.ItemID.ToString(); message.Annex2Name = item.Template.Name; break; case 3: message.Annex3 = item.ItemID.ToString(); message.Annex3Name = item.Template.Name; break; case 4: message.Annex4 = item.ItemID.ToString(); message.Annex4Name = item.Template.Name; break; case 5: message.Annex5 = item.ItemID.ToString(); message.Annex5Name = item.Template.Name; break; } if (annexIndex == 5) { annexIndex = 0; message.AnnexRemark = annexRemark.ToString(); annexRemark.Remove(0, annexRemark.Length); annexRemark.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark", new object[0])); message.Content = content; message.Gold = 0; message.Money = 0; message.GiftToken = 0; message.Receiver = receiver.NickName; message.ReceiverID = receiver.ID; message.Sender = player.PlayerCharacter.NickName; message.SenderID = player.PlayerCharacter.ID; message.Title = message.Sender + LanguageMgr.GetTranslation("GoodsPresentHandler.Content", new object[0]) + message.Annex1Name + "]"; message.Type = 10; db.SendMail(message); message.Revert(); } } if (annexIndex > 0) { message.AnnexRemark = annexRemark.ToString(); message.Content = content; message.Gold = 0; message.Money = 0; message.GiftToken = 0; message.Receiver = receiver.NickName; message.ReceiverID = receiver.ID; message.Sender = player.PlayerCharacter.NickName; message.SenderID = player.PlayerCharacter.ID; message.Title = message.Sender + LanguageMgr.GetTranslation("GoodsPresentHandler.Content", new object[0]) + message.Annex1Name + "]"; message.Type = 10; db.SendMail(message); message.Revert(); } 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)); } } if (player.SendMail(Content.ToString(), title, null, eMailType.BuyItem)) { player.Out.SendMailResponse(player.PlayerCharacter.ID, eMailRespose.Receiver); } } player.OnPaid(totalMoney, 0, 0, 0, ""); player.Out.SendMailResponse(receiver.ID, eMailRespose.Receiver); player.Out.SendMailResponse(player.PlayerCharacter.ID, eMailRespose.Send); buyResult = (buyItems.Count == count); } else { buyResult = false; eMsg = eMessageType.ERROR; msg = "GoodsPresentHandler.NoUser"; } } this.UpdateLimitShopCount(player, changeLimitShopsID); pkg.WriteBoolean(buyResult); player.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg, new object[0])); player.Out.SendTCP(pkg); result = 0; } return(result); }
public override int HandlePacket(GamePlayer player, GSPacketIn packet) { int gold = 0; int money = 0; int offer = 0; int gifttoken = 0; StringBuilder payGoods = new StringBuilder(); int GoodsID = packet.ReadInt(); int type = 1; ShopItemInfo shopItem = ShopMgr.GetShopItemInfoById(GoodsID); int result2; if (shopItem == null) { result2 = 1; } else { List <int> needitemsinfo = ShopMgr.GetShopItemBuyConditions(shopItem, type, ref gold, ref money, ref offer, ref gifttoken); ItemInfo prop = ShopMgr.CreateItem(shopItem, 102, 1, "", "", false); if (prop == null) { result2 = 1; } else { if (prop.Template.CategoryID == 10) { PlayerInfo pi = player.PlayerCharacter; if (player.PlayerCharacter.HasBagPassword && player.PlayerCharacter.IsLocked && (money > 0 || offer > 0 || gifttoken > 0 || GoodsID == 11408)) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked", new object[0])); result2 = 1; return(result2); } int icount = player.MainBag.GetItems().Count; bool result = true; for (int i = 0; i < needitemsinfo.Count; i += 2) { if (player.GetItemCount(needitemsinfo[i]) < needitemsinfo[i + 1]) { result = false; } } if (!result) { eMessageType eMsg = eMessageType.ERROR; string msg = "UserBuyItemHandler.NoBuyItem"; player.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg, new object[0])); result2 = 1; return(result2); } if (gold <= pi.Gold && money <= ((pi.Money < 0) ? 0 : pi.Money) && offer <= pi.Offer && gifttoken <= pi.GiftToken) { if (player.FightBag.AddItem(prop, 0)) { player.RemoveGold(gold); player.RemoveMoney(money, LogMoneyType.Shop, LogMoneyType.Shop_Buy); player.RemoveOffer(offer); player.RemoveGiftToken(gifttoken); for (int i = 0; i < needitemsinfo.Count; i += 2) { player.RemoveTemplate(needitemsinfo[i], needitemsinfo[i + 1], eItemRemoveType.Shopping); payGoods.Append(needitemsinfo[i].ToString() + ":"); } //LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Buy, player.PlayerCharacter.ID, money, gold, gifttoken, offer, "", prop.TemplateID, 3, prop.Count); } } else { player.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("PropBuyHandler.NoMoney", new object[0])); } } result2 = 0; } } return(result2); }
public override int HandlePacket(GamePlayer player, GSPacketIn packet) { int gold = 0; int money = 0; int offer = 0; int gifttoken = 0; int totalGold = 0; int totalMoney = 0; int totalOffer = 0; int totalGifttoken = 0; List <ItemJoinShopInfo> itemPrice = new List <ItemJoinShopInfo>(); int GroupID = packet.ReadInt(); eMessageType eMsg = eMessageType.Normal; string msg = "UserBuyItemHandler.Success"; List <ItemInfo> buyItems = new List <ItemInfo>(); int result; if (player.PlayerCharacter.HasBagPassword && player.PlayerCharacter.IsLocked) { player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked", new object[0])); result = 1; } else { List <ShopItemInfo> infos = ShopMgr.FindShopByGroupID(GroupID); foreach (ShopItemInfo info in infos) { ItemInfo item = ShopMgr.CreateItem(info, 102, 1, "", "", true); buyItems.Add(item); ShopMgr.GetShopItemBuyConditions(info, 1, ref gold, ref money, ref offer, ref gifttoken); itemPrice.Add(new ItemJoinShopInfo(info.TemplateID, item.Count, money, gold, gifttoken, offer, "")); totalGold += gold; totalMoney += money; totalOffer += offer; totalGifttoken += gifttoken; } if (buyItems.Count == 0) { result = 1; } else { if (totalGold <= player.PlayerCharacter.Gold && totalMoney <= player.PlayerCharacter.Money && totalOffer <= player.PlayerCharacter.Offer && totalGifttoken <= player.PlayerCharacter.GiftToken) { player.RemoveGold(totalGold); player.RemoveMoney(totalMoney, LogMoneyType.Shop, LogMoneyType.Shop_BuySale); player.RemoveOffer(totalOffer); player.RemoveGiftToken(totalGifttoken); foreach (ItemJoinShopInfo log in itemPrice) { //LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_BuySale, player.PlayerCharacter.ID, log.Moneys, log.Gold, log.GiftToken, log.Offer, log.OtherPay, log.TemplateID, 5, log.Data); } List <ItemInfo> remainitems = new List <ItemInfo>(); List <ItemInfo> sendMailItem = new List <ItemInfo>(); for (int i = 0; i < buyItems.Count; i++) { if (!player.HideBag.AddItemTo(buyItems[i], buyItems.Count - (i + 1))) { remainitems.Add(buyItems[i]); } } player.StackItem(ref remainitems); foreach (ItemInfo info2 in remainitems) { if (!player.AddItem(info2)) { sendMailItem.Add(info2); } } if (sendMailItem.Count > 0) { using (new PlayerBussiness()) { string title = ""; if (player.SendItemsToMail(sendMailItem, "", title, eMailType.BuyItem)) { player.Out.SendMailResponse(player.PlayerCharacter.ID, eMailRespose.Receiver); } eMsg = eMessageType.ERROR; msg = "UserBuyItemHandler.Mail"; } } player.OnPaid(totalMoney, totalGold, totalOffer, totalGifttoken, ""); player.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg, new object[0])); player.SaveIntoDatabase(); result = 0; } else { if (money > player.PlayerCharacter.Money) { player.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserBuyItemHandler.Money", new object[0])); } result = 1; } } } return(result); }