public Asda2PushItemToTradeStatus PushItemToTrade(Character activeCharacter, short cellNum, int quantity, byte invNum, ref Asda2ItemTradeRef item) { if (cellNum < 0 || cellNum >= activeCharacter.Asda2Inventory.ShopItems.Length || quantity < 0 || (activeCharacter == FisrtChar && FirstCharShowItems) || (activeCharacter == SecondChar && SecondCharShowItems)) { activeCharacter.YouAreFuckingCheater("Trying to cheat while pushing item to trade.", 50); CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } if (invNum == 2 && cellNum == 0) { //gold item return(SetCharacterItemRefs(activeCharacter, item = new Asda2ItemTradeRef() { Amount = quantity, Item = activeCharacter.Asda2Inventory.RegularItems[cellNum] })); } if (TradeType == Asda2TradeType.RedularTrade) { return(SetCharacterItemRefs(activeCharacter, item = new Asda2ItemTradeRef() { Amount = quantity, Item = activeCharacter.Asda2Inventory.RegularItems[cellNum] })); } else { return(SetCharacterItemRefs(activeCharacter, item = new Asda2ItemTradeRef() { Amount = quantity, Item = activeCharacter.Asda2Inventory.ShopItems[cellNum] })); } }
public static void SendItemToTradePushedResponse(IRealmClient client, Asda2PushItemToTradeStatus status, Asda2ItemTradeRef item = null) { using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.ItemToTradePushed)) { packet.WriteByte((byte)status); packet.WriteByte(item == null || item.Item == null ? (byte)0 : (byte)item.Item.InventoryType); packet.WriteInt16(item == null || item.Item == null ? 0 : item.Item.Slot); packet.WriteInt32(item == null || item.Item == null ? 0 : item.Amount); client.Send(packet, false); } }
public static void SendConfimTradeFromOponentResponse(IRealmClient client, Asda2ItemTradeRef[] items) { using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.ConfimTradeFromOponent)) { packet.WriteInt32(1); packet.WriteByte(1); packet.WriteByte(1); for (int index = 0; index < 5; ++index) { Asda2ItemTradeRef asda2ItemTradeRef = items[index]; packet.WriteInt32(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.ItemId); packet.WriteByte(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Durability); packet.WriteInt16(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Weight); packet.WriteInt32(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Amount); packet.WriteByte(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Enchant); packet.WriteInt64(0L); packet.WriteInt16(0); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : (short)asda2ItemTradeRef.Item.Parametr1Type); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : asda2ItemTradeRef.Item.Parametr1Value); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : (short)asda2ItemTradeRef.Item.Parametr2Type); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : asda2ItemTradeRef.Item.Parametr2Value); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : (short)asda2ItemTradeRef.Item.Parametr3Type); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : asda2ItemTradeRef.Item.Parametr3Value); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : (short)asda2ItemTradeRef.Item.Parametr4Type); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : asda2ItemTradeRef.Item.Parametr4Value); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : (short)asda2ItemTradeRef.Item.Parametr5Type); packet.WriteInt16(asda2ItemTradeRef == null ? -1 : asda2ItemTradeRef.Item.Parametr5Value); packet.WriteByte(0); packet.WriteInt16(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Soul1Id); packet.WriteInt16(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Soul2Id); packet.WriteInt16(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Soul3Id); packet.WriteInt16(asda2ItemTradeRef == null ? 0 : asda2ItemTradeRef.Item.Soul4Id); } client.Send(packet, false); } }
[PacketHandler(RealmServerOpCode.PushItemToTrade)] //5288 public static void PushItemToTradeRequest(IRealmClient client, RealmPacketIn packet) { packet.Position += 5; //nk4 default : 1Len : 4 var invNum = packet.ReadByte(); //default : 2Len : 1 var cellNum = packet.ReadInt16(); //default : 5Len : 2 var quantity = packet.ReadInt32(); //default : 500Len : 4 if (client.ActiveCharacter.Asda2TradeWindow == null) { client.ActiveCharacter.YouAreFuckingCheater("Trying to push items to trade while not trading", 0); return; } Asda2ItemTradeRef item = null; var r = client.ActiveCharacter.Asda2TradeWindow.PushItemToTrade(client.ActiveCharacter, cellNum, quantity, invNum, ref item); SendItemToTradePushedResponse(client, r, item); }
public static void PushItemToTradeRequest(IRealmClient client, RealmPacketIn packet) { packet.Position += 5; byte invNum = packet.ReadByte(); short cellNum = packet.ReadInt16(); int quantity = packet.ReadInt32(); if (client.ActiveCharacter.Asda2TradeWindow == null) { client.ActiveCharacter.YouAreFuckingCheater("Trying to push items to trade while not trading", 0); } else { Asda2ItemTradeRef asda2ItemTradeRef = null; Asda2PushItemToTradeStatus trade = client.ActiveCharacter.Asda2TradeWindow.PushItemToTrade(client.ActiveCharacter, cellNum, quantity, invNum, ref asda2ItemTradeRef); SendItemToTradePushedResponse(client, trade, asda2ItemTradeRef); } }
public static void SendPrivateShopChatNotificationAboutBuyResponse(Asda2PrivateShop shop, List <Asda2ItemTradeRef> itemsBuyed, Character buyer) { Asda2ItemTradeRef[] asda2ItemTradeRefArray = new Asda2ItemTradeRef[6]; for (int index = 0; index < itemsBuyed.Count; ++index) { asda2ItemTradeRefArray[index] = itemsBuyed[index]; } using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.PrivateShopChatNotificationAboutBuy)) { packet.WriteInt32(shop.Owner.AccId); packet.WriteInt16(shop.Owner.SessionId); packet.WriteByte( ((IEnumerable <Asda2ItemTradeRef>)asda2ItemTradeRefArray).Count <Asda2ItemTradeRef>( (Func <Asda2ItemTradeRef, bool>)(i => i != null))); packet.WriteInt32(buyer.AccId); for (int index = 0; index < 6; ++index) { Asda2Item asda2Item = asda2ItemTradeRefArray[index] == null || asda2ItemTradeRefArray[index].Item == null ? (Asda2Item)null : asda2ItemTradeRefArray[index].Item; packet.WriteInt32(asda2Item == null ? 0 : asda2Item.ItemId); packet.WriteByte(0); packet.WriteInt16(-1); packet.WriteInt32(asda2ItemTradeRefArray[index] == null ? -1 : asda2ItemTradeRefArray[index].Amount); packet.WriteInt32(asda2ItemTradeRefArray[index] == null ? -1 : (int)asda2ItemTradeRefArray[index].TradeSlot); packet.WriteInt16(0); packet.WriteSkip(Asda2PrivateShopHandler.stub18); } shop.Send(packet); } }
public static void SendItemBuyedFromPrivateShopToOwnerNotifyResponse(Asda2PrivateShop shop, List <Asda2ItemTradeRef> itemsBuyed, Character buyer) { Asda2ItemTradeRef[] asda2ItemTradeRefArray = new Asda2ItemTradeRef[6]; for (int index = 0; index < itemsBuyed.Count; ++index) { asda2ItemTradeRefArray[index] = itemsBuyed[index]; } using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.ItemBuyedFromPrivateShopToOwnerNotify)) { packet.WriteInt16(shop.Owner.Asda2Inventory.Weight); packet.WriteInt32(shop.Owner.Money); packet.WriteByte( ((IEnumerable <Asda2ItemTradeRef>)asda2ItemTradeRefArray).Count <Asda2ItemTradeRef>( (Func <Asda2ItemTradeRef, bool>)(i => i != null))); packet.WriteInt32(buyer.AccId); for (int index = 0; index < 6; ++index) { Asda2Item asda2Item = asda2ItemTradeRefArray[index] == null || asda2ItemTradeRefArray[index].Item == null ? (Asda2Item)null : asda2ItemTradeRefArray[index].Item; packet.WriteInt32(asda2Item == null ? 0 : asda2Item.ItemId); packet.WriteByte(asda2Item == null ? (byte)0 : (byte)asda2Item.InventoryType); packet.WriteInt16(asda2Item == null ? 0 : (int)asda2Item.Slot); packet.WriteInt32(asda2ItemTradeRefArray[index] == null ? -1 : asda2ItemTradeRefArray[index].Amount); packet.WriteInt32(asda2ItemTradeRefArray[index] == null ? -1 : (int)asda2ItemTradeRefArray[index].TradeSlot); packet.WriteInt16(0); packet.WriteSkip(Asda2PrivateShopHandler.stub17); } shop.Owner.Send(packet, false); } }
Asda2PushItemToTradeStatus SetCharacterItemRefs(Character character, Asda2ItemTradeRef itemRef) { if (itemRef.Item.IsDeleted) { character.YouAreFuckingCheater("Trying to add to trade deleted item."); CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } if (itemRef.Item.Record == null) { character.YouAreFuckingCheater("Trying to add to trade item record null."); CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } Asda2ItemTradeRef[] chrItemsRefs; if (FisrtChar == character) { chrItemsRefs = FirstCharacterItems; } else { chrItemsRefs = SecondChar == character ? SecondCharacterItems : null; } if (chrItemsRefs == null || itemRef.Item == null || (itemRef.Item.Amount < itemRef.Amount && itemRef.Item.ItemId != 20551) || (itemRef.Item.ItemId == 20551 && itemRef.Amount >= character.Money)) { character.YouAreFuckingCheater("Trying to cheat while trading (1).", 50); CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } var itemExist = chrItemsRefs.FirstOrDefault(i => i != null && i.Item == itemRef.Item); if (itemExist != null) { if ((itemExist.Amount + itemRef.Amount > itemRef.Item.Amount && itemRef.Item.ItemId != 20551) || (itemExist.Amount + itemRef.Amount >= character.Money && itemRef.Item.ItemId == 20551)) { character.YouAreFuckingCheater("Trying to cheat while trading (2).", 50); CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } itemExist.Amount += itemRef.Amount; return(Asda2PushItemToTradeStatus.Ok); } //item not exist var freeSlot = -1; for (int i = 0; i < 5; i++) { if (chrItemsRefs[i] == null) { freeSlot = i; break; } } if (freeSlot == -1) { character.YouAreFuckingCheater("Trying to cheat while trading (3).", 50); CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } if (itemRef.Item.IsSoulbound) { return(Asda2PushItemToTradeStatus.ItemCantBeTraded); } chrItemsRefs[freeSlot] = itemRef; return(Asda2PushItemToTradeStatus.Ok); }
private Asda2PushItemToTradeStatus SetCharacterItemRefs(Character character, Asda2ItemTradeRef itemRef) { if (itemRef.Item.IsDeleted) { character.YouAreFuckingCheater("Trying to add to trade deleted item.", 1); this.CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } if (itemRef.Item.Record == null) { character.YouAreFuckingCheater("Trying to add to trade item record null.", 1); this.CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } Asda2ItemTradeRef[] asda2ItemTradeRefArray = this.FisrtChar != character ? (this.SecondChar == character ? this.SecondCharacterItems : (Asda2ItemTradeRef[])null) : this.FirstCharacterItems; if (asda2ItemTradeRefArray == null || itemRef.Item == null || itemRef.Item.Amount < itemRef.Amount && itemRef.Item.ItemId != 20551 || itemRef.Item.ItemId == 20551 && (long)itemRef.Amount >= (long)character.Money) { character.YouAreFuckingCheater("Trying to cheat while trading (1).", 50); this.CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } Asda2ItemTradeRef asda2ItemTradeRef = ((IEnumerable <Asda2ItemTradeRef>)asda2ItemTradeRefArray).FirstOrDefault <Asda2ItemTradeRef>( (Func <Asda2ItemTradeRef, bool>)(i => { if (i != null) { return(i.Item == itemRef.Item); } return(false); })); if (asda2ItemTradeRef != null) { if (asda2ItemTradeRef.Amount + itemRef.Amount > itemRef.Item.Amount && itemRef.Item.ItemId != 20551 || (long)(asda2ItemTradeRef.Amount + itemRef.Amount) >= (long)character.Money && itemRef.Item.ItemId == 20551) { character.YouAreFuckingCheater("Trying to cheat while trading (2).", 50); this.CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } asda2ItemTradeRef.Amount += itemRef.Amount; return(Asda2PushItemToTradeStatus.Ok); } int index1 = -1; for (int index2 = 0; index2 < 5; ++index2) { if (asda2ItemTradeRefArray[index2] == null) { index1 = index2; break; } } if (index1 == -1) { character.YouAreFuckingCheater("Trying to cheat while trading (3).", 50); this.CancelTrade(); return(Asda2PushItemToTradeStatus.AnErrorWasFoundWithTransferedItem); } if (itemRef.Item.IsSoulbound) { return(Asda2PushItemToTradeStatus.ItemCantBeTraded); } asda2ItemTradeRefArray[index1] = itemRef; return(Asda2PushItemToTradeStatus.Ok); }
public void BuyItems(Character activeCharacter, List <Asda2ItemTradeRef> itemsToBuyRefs) { Owner.Map.AddMessage(() => { List <Asda2ItemTradeRef> source = new List <Asda2ItemTradeRef>(); foreach (Asda2ItemTradeRef itemsToBuyRef in itemsToBuyRefs) { Asda2ItemTradeRef asda2ItemTradeRef = ItemsOnTrade[itemsToBuyRef.TradeSlot]; if (asda2ItemTradeRef == null || asda2ItemTradeRef.Amount == -1 || asda2ItemTradeRef.Amount != 0 && asda2ItemTradeRef.Amount < itemsToBuyRef.Amount) { Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter, PrivateShopBuyResult.RequestedNumberOfItemsIsNoLongerAvaliable, null); return; } source.Add(new Asda2ItemTradeRef { Amount = itemsToBuyRef.Amount, Item = asda2ItemTradeRef.Item, Price = asda2ItemTradeRef.Price, TradeSlot = asda2ItemTradeRef.TradeSlot }); } ulong num1 = source.Aggregate(0UL, (current, asda2ItemTradeRef) => current + (ulong)(asda2ItemTradeRef.Price * asda2ItemTradeRef.Amount)); if (num1 > int.MaxValue) { activeCharacter.YouAreFuckingCheater("Trying to buy items with wrong money amount.", 50); Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter, PrivateShopBuyResult.NotEnoghtGold, null); } else if (activeCharacter.Money < num1) { Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter, PrivateShopBuyResult.NotEnoghtGold, null); } else if (Owner.Money + num1 > int.MaxValue) { Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter, PrivateShopBuyResult.Error, null); SendMessage(Owner.Name + " has to much gold.", Owner, Locale.Start); } else if (source.Any(asda2ItemTradeRef => { if (asda2ItemTradeRef.Item == null || asda2ItemTradeRef.Item.IsDeleted) { return(true); } if (asda2ItemTradeRef.Item.Amount != 0) { return(asda2ItemTradeRef.Item.Amount < asda2ItemTradeRef.Amount); } return(false); })) { Owner.YouAreFuckingCheater("Trying to cheat while trading items from private shop", 10); Exit(Owner); } else if (activeCharacter.Asda2Inventory.FreeRegularSlotsCount < source.Count(i => i.Item.InventoryType == Asda2InventoryType.Regular) || activeCharacter.Asda2Inventory.FreeShopSlotsCount < source.Count( i => i.Item.InventoryType == Asda2InventoryType.Shop)) { Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter, PrivateShopBuyResult.NoSlotAreAvailable, null); } else { activeCharacter.SubtractMoney((uint)num1); Owner.AddMoney((uint)num1); List <Asda2Item> buyedItems = new List <Asda2Item>(); List <Asda2ItemTradeRef> itemsBuyed = new List <Asda2ItemTradeRef>(); foreach (Asda2ItemTradeRef asda2ItemTradeRef1 in source) { if (asda2ItemTradeRef1.Amount == 0) { asda2ItemTradeRef1.Amount = 1; } if (asda2ItemTradeRef1.Amount >= asda2ItemTradeRef1.Item.Amount) { LogHelperEntry lgDelete = Log .Create(Log.Types.ItemOperations, LogSourceType.Character, Owner.EntryId) .AddAttribute("source", 0.0, "selled_from_private_shop") .AddItemAttributes(asda2ItemTradeRef1.Item, "") .AddAttribute("buyer_id", activeCharacter.EntryId, "") .AddAttribute("amount", asda2ItemTradeRef1.Amount, "").Write(); Asda2Item itemToCopyStats = asda2ItemTradeRef1.Item; Asda2Item asda2Item = null; int num2 = (int)activeCharacter.Asda2Inventory.TryAdd(itemToCopyStats.ItemId, itemToCopyStats.Amount, true, ref asda2Item, new Asda2InventoryType?(), itemToCopyStats); Log.Create(Log.Types.ItemOperations, LogSourceType.Character, activeCharacter.EntryId) .AddAttribute("source", 0.0, "buyed_from_private_shop").AddItemAttributes(asda2Item, "") .AddAttribute("seller_id", Owner.EntryId, "").AddReference(lgDelete) .AddAttribute("amount", asda2ItemTradeRef1.Amount, "").Write(); buyedItems.Add(asda2Item); itemToCopyStats.Destroy(); ItemsOnTrade[asda2ItemTradeRef1.TradeSlot].Amount = -1; ItemsOnTrade[asda2ItemTradeRef1.TradeSlot].Price = 0; } else { LogHelperEntry lgDelete = Log .Create(Log.Types.ItemOperations, LogSourceType.Character, Owner.EntryId) .AddAttribute("source", 0.0, "selled_from_private_shop_split") .AddItemAttributes(asda2ItemTradeRef1.Item, "") .AddAttribute("buyer_id", activeCharacter.EntryId, "") .AddAttribute("amount", asda2ItemTradeRef1.Amount, "").Write(); asda2ItemTradeRef1.Item.Amount -= asda2ItemTradeRef1.Amount; Asda2Item asda2Item = null; int num2 = (int)activeCharacter.Asda2Inventory.TryAdd( (int)asda2ItemTradeRef1.Item.Template.ItemId, asda2ItemTradeRef1.Amount, true, ref asda2Item, new Asda2InventoryType?(), asda2ItemTradeRef1.Item); Log.Create(Log.Types.ItemOperations, LogSourceType.Character, activeCharacter.EntryId) .AddAttribute("source", 0.0, "buyed_from_private_shop_split") .AddItemAttributes(asda2Item, "new_item") .AddItemAttributes(asda2ItemTradeRef1.Item, "old_item") .AddAttribute("amount", asda2ItemTradeRef1.Amount, "") .AddAttribute("seller_id", Owner.EntryId, "").AddReference(lgDelete) .Write(); asda2ItemTradeRef1.Item.Save(); buyedItems.Add(asda2Item); } Asda2ItemTradeRef asda2ItemTradeRef2 = ItemsOnTrade[asda2ItemTradeRef1.TradeSlot]; itemsBuyed.Add(asda2ItemTradeRef2); if (asda2ItemTradeRef2 != null && asda2ItemTradeRef2.Amount > 0) { asda2ItemTradeRef2.Amount -= asda2ItemTradeRef1.Amount; if (asda2ItemTradeRef2.Amount <= 0) { asda2ItemTradeRef2.Amount = -1; } } } Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter, PrivateShopBuyResult.Ok, buyedItems); Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopToOwnerNotifyResponse(this, itemsBuyed, activeCharacter); Asda2PrivateShopHandler.SendPrivateShopChatNotificationAboutBuyResponse(this, itemsBuyed, activeCharacter); Owner.SendMoneyUpdate(); activeCharacter.SendMoneyUpdate(); } }); }
public static void SendItemToTradePushedResponse(IRealmClient client, Asda2PushItemToTradeStatus status, Asda2ItemTradeRef item = null) { using (var packet = new RealmPacketOut(RealmServerOpCode.ItemToTradePushed)) //5289 { packet.WriteByte((byte)status); //{status}default value : 1 Len : 1 packet.WriteByte((byte)(item == null || item.Item == null ? 0 : item.Item.InventoryType)); //{inv}default value : 2 Len : 1 packet.WriteInt16(item == null || item.Item == null ? 0 : item.Item.Slot); //{cell}default value : 2 Len : 2 packet.WriteInt32(item == null || item.Item == null ? 0 : item.Amount); //{quanity}default value : 5 Len : 4 client.Send(packet, addEnd: false); } }