Пример #1
0
        public override Task ExecuteAsync(ExcListPacket packet, ClientSession clientSession)
        {
            if ((packet.Gold > clientSession.Character.Gold) || (packet.BankGold > clientSession.Account.BankMoney))
            {
                _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.NOT_ENOUGH_GOLD));
                return(Task.CompletedTask);
            }

            var subPacketList = new List <ServerExcListSubPacket?>();

            var target = Broadcaster.Instance.GetCharacter(s =>
                                                           (s.VisualId == _exchangeProvider.GetTargetId(clientSession.Character.VisualId)) &&
                                                           (s.MapInstanceId == clientSession.Character.MapInstanceId)) as Character;

            if ((packet.SubPackets !.Count > 0) && (target != null))
            {
                byte i = 0;
                foreach (var value in packet.SubPackets)
                {
                    var item = clientSession.Character.InventoryService.LoadBySlotAndType(value !.Slot,
                                                                                          (NoscorePocketType)value.PocketType);

                    if ((item == null) || (item.ItemInstance !.Amount < value.Amount))
                    {
                        var closeExchange =
                            _exchangeProvider.CloseExchange(clientSession.Character.VisualId,
                                                            ExchangeResultType.Failure);
                        clientSession.SendPacketAsync(closeExchange);
                        target.SendPacketAsync(closeExchange);
                        _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVALID_EXCHANGE_LIST));
                        return(Task.CompletedTask);
                    }

                    if (!item.ItemInstance.Item !.IsTradable)
                    {
                        clientSession.SendPacketAsync(_exchangeProvider.CloseExchange(clientSession.Character.CharacterId,
                                                                                      ExchangeResultType.Failure));
                        target.SendPacketAsync(_exchangeProvider.CloseExchange(target.VisualId, ExchangeResultType.Failure));
                        _logger.Error(
                            LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.CANNOT_TRADE_NOT_TRADABLE_ITEM));
                        return(Task.CompletedTask);
                    }

                    _exchangeProvider.AddItems(clientSession.Character.CharacterId, item, value.Amount);

                    var subPacket = new ServerExcListSubPacket
                    {
                        ExchangeSlot = i,
                        PocketType   = value.PocketType,
                        ItemVnum     = item.ItemInstance.ItemVNum,
                        Upgrade      = item.ItemInstance.Upgrade,
                        AmountOrRare = value.PocketType == PocketType.Equipment ? item.ItemInstance.Rare : value.Amount
                    };


                    subPacketList.Add(subPacket);
                    i++;
                }
            }
Пример #2
0
        public void ExchangeList(ExcListPacket packet)
        {
            if (packet.Gold > Session.Character.Gold || packet.BankGold > Session.Account.BankMoney)
            {
                _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.NOT_ENOUGH_GOLD));
                return;
            }

            var subPacketList = new List <ServerExcListSubPacket>();

            var target = Broadcaster.Instance.GetCharacter(s =>
                                                           s.VisualId == _exchangeProvider.GetTargetId(Session.Character.VisualId) &&
                                                           s.MapInstanceId == Session.Character.MapInstanceId) as Character;

            if (packet.SubPackets.Count > 0 && target != null)
            {
                byte i = 0;
                foreach (var value in packet.SubPackets)
                {
                    var item = Session.Character.Inventory.LoadBySlotAndType <IItemInstance>(value.Slot,
                                                                                             value.PocketType);

                    if (item == null || item.Amount < value.Amount)
                    {
                        var closeExchange =
                            _exchangeProvider.CloseExchange(Session.Character.VisualId, ExchangeResultType.Failure);
                        Session.SendPacket(closeExchange);
                        target.SendPacket(closeExchange);
                        _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVALID_EXCHANGE_LIST));
                        return;
                    }

                    if (!item.Item.IsTradable)
                    {
                        Session.SendPacket(_exchangeProvider.CloseExchange(Session.Character.CharacterId,
                                                                           ExchangeResultType.Failure));
                        target.SendPacket(_exchangeProvider.CloseExchange(target.VisualId, ExchangeResultType.Failure));
                        _logger.Error(
                            LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.CANNOT_TRADE_NOT_TRADABLE_ITEM));
                        return;
                    }

                    _exchangeProvider.AddItems(Session.Character.CharacterId, item, value.Amount);

                    var subPacket = new ServerExcListSubPacket
                    {
                        ExchangeSlot = i,
                        PocketType   = value.PocketType,
                        ItemVnum     = item.ItemVNum,
                        Upgrade      = item.Upgrade,
                        AmountOrRare = value.PocketType == PocketType.Equipment ? item.Rare : value.Amount
                    };


                    subPacketList.Add(subPacket);
                    i++;
                }
            }
            else
            {
                subPacketList.Add(new ServerExcListSubPacket {
                    ExchangeSlot = null
                });
            }

            _exchangeProvider.SetGold(Session.Character.CharacterId, packet.Gold, packet.BankGold);
            target?.SendPacket(
                Session.Character.GenerateServerExcListPacket(packet.Gold, packet.BankGold, subPacketList));
        }