public override async Task ExecuteAsync(CBuyPacket packet, ClientSession clientSession) { var bz = await _bazaarHttpClient.GetBazaarLinkAsync(packet.BazaarId).ConfigureAwait(false); if ((bz != null) && (bz.SellerName != clientSession.Character.Name) && (packet.Price == bz.BazaarItem?.Price) && (bz.ItemInstance?.Amount >= packet.Amount)) { if (bz.BazaarItem.IsPackage && (bz.BazaarItem.Amount != packet.Amount)) { return; } var price = bz.BazaarItem.Price * packet.Amount; if (clientSession.Character.InventoryService.CanAddItem(bz.ItemInstance.ItemVNum)) { if (clientSession.Character.Gold - price > 0) { clientSession.Character.Gold -= price; await clientSession.SendPacketAsync(clientSession.Character.GenerateGold()).ConfigureAwait(false); var itemInstance = await _itemInstanceDao.FirstOrDefaultAsync(s => s !.Id == bz.ItemInstance.Id).ConfigureAwait(false); var item = _itemProvider.Convert(itemInstance !); item.Id = Guid.NewGuid(); var newInv = clientSession.Character.InventoryService.AddItemToPocket( InventoryItemInstance.Create(item, clientSession.Character.CharacterId)); await clientSession.SendPacketAsync(newInv !.GeneratePocketChange()).ConfigureAwait(false); var remove = await _bazaarHttpClient.RemoveAsync(packet.BazaarId, packet.Amount, clientSession.Character.Name).ConfigureAwait(false); if (remove) { await clientSession.HandlePacketsAsync(new[] { new CBListPacket { Index = 0, ItemVNumFilter = new List <short>() } }).ConfigureAwait(false); await clientSession.SendPacketAsync(new RCBuyPacket { Type = VisualType.Player, VNum = bz.ItemInstance.ItemVNum, Owner = bz.BazaarItem.SellerId, Amount = packet.Amount, Price = packet.Price, Unknown1 = 0, Unknown2 = 0, Unknown3 = 0 }).ConfigureAwait(false); await clientSession.SendPacketAsync(clientSession.Character.GenerateSay( $"{GameLanguage.Instance.GetMessageFromKey(LanguageKey.ITEM_ACQUIRED, clientSession.Account.Language)}: {item.Item!.Name[clientSession.Account.Language]} x {packet.Amount}" , SayColorType.Yellow )).ConfigureAwait(false); return; } _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.BAZAAR_BUY_ERROR)); } else { await clientSession.SendPacketAsync(clientSession.Character.GenerateSay( GameLanguage.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_MONEY, clientSession.Account.Language), SayColorType.Yellow )).ConfigureAwait(false); await clientSession.SendPacketAsync(new ModalPacket { Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_MONEY, clientSession.Account.Language), Type = 1 }).ConfigureAwait(false); return; } } else { await clientSession.SendPacketAsync(new InfoPacket { Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_PLACE, clientSession.Account.Language) }).ConfigureAwait(false); return; } } await clientSession.SendPacketAsync(new ModalPacket { Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.STATE_CHANGED_BAZAAR, clientSession.Account.Language), Type = 1 }).ConfigureAwait(false); }
public override async Task ExecuteAsync(CScalcPacket packet, ClientSession clientSession) { var bz = await _bazaarHttpClient.GetBazaarLinkAsync(packet.BazaarId).ConfigureAwait(false); if ((bz != null) && (bz.SellerName == clientSession.Character.Name)) { var soldedamount = bz.BazaarItem !.Amount - bz.ItemInstance !.Amount; var taxes = bz.BazaarItem.MedalUsed ? (short)0 : (short)(bz.BazaarItem.Price * 0.10 * soldedamount); var price = bz.BazaarItem.Price * soldedamount - taxes; if (clientSession.Character.InventoryService.CanAddItem(bz.ItemInstance.ItemVNum)) { if (clientSession.Character.Gold + price <= _worldConfiguration.MaxGoldAmount) { clientSession.Character.Gold += price; await clientSession.SendPacketAsync(clientSession.Character.GenerateGold()).ConfigureAwait(false); await clientSession.SendPacketAsync(clientSession.Character.GenerateSay(string.Format( GameLanguage.Instance.GetMessageFromKey(LanguageKey.REMOVE_FROM_BAZAAR, clientSession.Account.Language), price), SayColorType.Yellow)).ConfigureAwait(false); var itemInstance = await _itemInstanceDao.FirstOrDefaultAsync(s => s !.Id == bz.ItemInstance.Id).ConfigureAwait(false); if (itemInstance == null) { return; } var item = _itemProvider.Convert(itemInstance); item.Id = Guid.NewGuid(); var newInv = clientSession.Character.InventoryService.AddItemToPocket( InventoryItemInstance.Create(item, clientSession.Character.CharacterId)); await clientSession.SendPacketAsync(newInv !.GeneratePocketChange()).ConfigureAwait(false); var remove = await _bazaarHttpClient.RemoveAsync(packet.BazaarId, bz.ItemInstance.Amount, clientSession.Character.Name).ConfigureAwait(false); if (remove) { await clientSession.SendPacketAsync(new RCScalcPacket { Type = VisualType.Player, Price = bz.BazaarItem.Price, RemainingAmount = (short)(bz.BazaarItem.Amount - bz.ItemInstance.Amount), Amount = bz.BazaarItem.Amount, Taxes = taxes, Total = price + taxes }).ConfigureAwait(false); await clientSession.HandlePacketsAsync(new[] { new CSListPacket { Index = 0, Filter = BazaarStatusType.Default } }).ConfigureAwait(false); return; } _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.BAZAAR_DELETE_ERROR)); } else { await clientSession.SendPacketAsync(new MsgPacket { Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.MAX_GOLD, clientSession.Account.Language), Type = MessageType.Whisper }).ConfigureAwait(false); } } else { await clientSession.SendPacketAsync(new InfoPacket { Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_PLACE, clientSession.Account.Language) }).ConfigureAwait(false); } await clientSession.SendPacketAsync(new RCScalcPacket { Type = VisualType.Player, Price = bz.BazaarItem.Price, RemainingAmount = 0, Amount = bz.BazaarItem.Amount, Taxes = 0, Total = 0 }).ConfigureAwait(false); } else { await clientSession.SendPacketAsync(new RCScalcPacket { Type = VisualType.Player, Price = 0, RemainingAmount = 0, Amount = 0, Taxes = 0, Total = 0 }).ConfigureAwait(false); } }