Exemple #1
0
        public override void Execute(CBuyPacket packet, ClientSession clientSession)
        {
            if (clientSession.Character.InExchangeOrTrade)
            {
                return;
            }

            var bz = _bazaarHttpClient.GetBazaarLink(packet.BazaarId);

            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;
                        clientSession.SendPacket(clientSession.Character.GenerateGold());

                        var itemInstance = _itemInstanceDao.FirstOrDefault(s => s.Id == bz.ItemInstance.Id);
                        var item         = _itemProvider.Convert(itemInstance);
                        item.Id = Guid.NewGuid();
                        var newInv =
                            clientSession.Character.InventoryService.AddItemToPocket(
                                InventoryItemInstance.Create(item, clientSession.Character.CharacterId));
                        clientSession.SendPacket(newInv.GeneratePocketChange());

                        var remove = _bazaarHttpClient.Remove(packet.BazaarId, packet.Amount,
                                                              clientSession.Character.Name);
                        if (remove)
                        {
                            clientSession.HandlePackets(new[]
                                                        { new CBListPacket {
                                                              Index = 0, ItemVNumFilter = new List <short>()
                                                          } });
                            clientSession.SendPacket(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
                            });
                            clientSession.SendPacket(clientSession.Character.GenerateSay(
                                                         $"{Language.Instance.GetMessageFromKey(LanguageKey.ITEM_ACQUIRED, clientSession.Account.Language)}: {item.Item.Name[clientSession.Account.Language]} x {packet.Amount}"
                                                         , SayColorType.Yellow
                                                         ));

                            return;
                        }

                        _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.BAZAAR_BUY_ERROR));
                    }
                    else
                    {
                        clientSession.SendPacket(clientSession.Character.GenerateSay(
                                                     Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_MONEY,
                                                                                         clientSession.Account.Language), SayColorType.Yellow
                                                     ));
                        clientSession.SendPacket(new ModalPacket
                        {
                            Message = Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_MONEY,
                                                                          clientSession.Account.Language),
                            Type = 1
                        });
                        return;
                    }
                }
                else
                {
                    clientSession.SendPacket(new InfoPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_PLACE,
                                                                      clientSession.Account.Language)
                    });
                    return;
                }
            }

            clientSession.SendPacket(new ModalPacket
            {
                Message = Language.Instance.GetMessageFromKey(LanguageKey.STATE_CHANGED_BAZAAR,
                                                              clientSession.Account.Language),
                Type = 1
            });
        }
        public override void Execute(CScalcPacket packet, ClientSession clientSession)
        {
            if (clientSession.Character.InExchangeOrTrade)
            {
                return;
            }

            var bz = _bazaarHttpClient.GetBazaarLink(packet.BazaarId);

            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;
                        clientSession.SendPacket(clientSession.Character.GenerateGold());
                        clientSession.SendPacket(clientSession.Character.GenerateSay(string.Format(
                                                                                         Language.Instance.GetMessageFromKey(LanguageKey.REMOVE_FROM_BAZAAR,
                                                                                                                             clientSession.Account.Language), price), SayColorType.Yellow));
                        var itemInstance = _itemInstanceDao.FirstOrDefault(s => s.Id == bz.ItemInstance.Id);
                        var item         = _itemProvider.Convert(itemInstance);
                        item.Id = Guid.NewGuid();

                        var newInv =
                            clientSession.Character.InventoryService.AddItemToPocket(
                                InventoryItemInstance.Create(item, clientSession.Character.CharacterId));
                        clientSession.SendPacket(newInv.GeneratePocketChange());
                        var remove = _bazaarHttpClient.Remove(packet.BazaarId, bz.ItemInstance.Amount,
                                                              clientSession.Character.Name);
                        if (remove)
                        {
                            clientSession.SendPacket(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
                            });
                            clientSession.HandlePackets(new[]
                                                        { new CSListPacket {
                                                              Index = 0, Filter = BazaarStatusType.Default
                                                          } });
                            return;
                        }

                        _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.BAZAAR_DELETE_ERROR));
                    }
                    else
                    {
                        clientSession.SendPacket(new MsgPacket
                        {
                            Message = Language.Instance.GetMessageFromKey(LanguageKey.MAX_GOLD,
                                                                          clientSession.Account.Language),
                            Type = MessageType.Whisper
                        });
                    }
                }
                else
                {
                    clientSession.SendPacket(new InfoPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_PLACE,
                                                                      clientSession.Account.Language)
                    });
                }

                clientSession.SendPacket(new RCScalcPacket
                {
                    Type   = VisualType.Player, Price = bz.BazaarItem.Price, RemainingAmount = 0,
                    Amount = bz.BazaarItem.Amount, Taxes = 0, Total = 0
                });
            }
            else
            {
                clientSession.SendPacket(new RCScalcPacket
                {
                    Type = VisualType.Player, Price = 0, RemainingAmount = 0, Amount = 0, Taxes = 0, Total = 0
                });
            }
        }