Esempio n. 1
0
        public void Handle(WorldClient client, MoveItemInInventoryPacket packet)
        {
            if (packet.CurrentBag == WarehouseManager.GUILD_WAREHOUSE_BAG && _guildManager.GuildRank > 2)
            {
                // Characters of high rank can not take items of guild warehouse.
                return;
            }

            if (packet.DestinationBag == WarehouseManager.GUILD_WAREHOUSE_BAG && _guildManager.GuildRank > 8)
            {
                // Characters with rank 8+ can not store items in guild warehouse.
                return;
            }

            if (packet.DestinationBag == WarehouseManager.GUILD_WAREHOUSE_BAG)
            {
                var level = (byte)(packet.DestinationSlot / 40);
                if (!_guildManager.HasNpcLevel(NpcType.Warehouse, level))
                {
                    // NPC level is less than tab index. Can not use guild warehouse in this case.
                    return;
                }
            }

            var items = _inventoryManager.MoveItem(packet.CurrentBag, packet.CurrentSlot, packet.DestinationBag, packet.DestinationSlot);

            if (items.sourceItem.Bag == WarehouseManager.GUILD_WAREHOUSE_BAG)
            {
                // Looks like there is some bug in client game.exe and bag 255 is not processed correctly.
                items.sourceItem.Bag--;
            }

            _packetFactory.SendMoveItem(client, items.sourceItem, items.destinationItem, _inventoryManager.Gold);
            _packetFactory.SendGoldUpdate(client, _inventoryManager.Gold);
        }
Esempio n. 2
0
        public void Handle(WorldClient client, NpcBuyItemPacket packet)
        {
            var cellId = _gameWorld.Players[_gameSession.CharId].CellId;

            var npc = _mapProvider.Map.GetNPC(cellId, packet.NpcId);

            if (npc is null || !npc.ContainsProduct(packet.ItemIndex))
            {
                _logger.LogWarning("NPC with id {npcId} doesn't contain item at index: {itemIndex}.", packet.NpcId, packet.ItemIndex);
                return;
            }

            var discount = 0f;

            if (_mapProvider.Map is GuildHouseMap)
            {
                if (!_guildManager.HasGuild)
                {
                    _packetFactory.SendGuildHouseActionError(client, GuildHouseActionError.LowRank, 30);
                    return;
                }

                var allowed = _guildManager.CanUseNpc(npc.Type, npc.TypeId, out var requiredRank);
                if (!allowed)
                {
                    _packetFactory.SendGuildHouseActionError(client, GuildHouseActionError.LowRank, requiredRank);
                    return;
                }

                allowed = _guildManager.HasNpcLevel(npc.Type, npc.TypeId);
                if (!allowed)
                {
                    _packetFactory.SendGuildHouseActionError(client, GuildHouseActionError.LowLevel, 0);
                    return;
                }

                discount = _guildManager.GetDiscount(npc.Type, npc.TypeId);
            }

            var buyItem    = npc.Products[packet.ItemIndex];
            var boughtItem = _inventoryManager.BuyItem(buyItem, packet.Count, discount, out var result);

            _packetFactory.SendBoughtItem(client, result, boughtItem, _inventoryManager.Gold);
        }
Esempio n. 3
0
        public void HandleNpcTeleport(WorldClient client, CharacterTeleportViaNpcPacket packet)
        {
            var npc = _mapProvider.Map.GetNPC(_gameWorld.Players[_gameSession.CharId].CellId, packet.NpcId);

            if (npc is null)
            {
                _logger.LogWarning("Character {Id} is trying to get non-existing npc via teleport packet.", _gameSession.CharId);
                return;
            }

            if (!npc.ContainsGate(packet.GateId))
            {
                _logger.LogWarning("NPC type {type} type id {typeId} doesn't contain teleport gate {gateId}. Check it out!", npc.Type, npc.TypeId, packet.GateId);
                return;
            }

            if (_mapProvider.Map is GuildHouseMap)
            {
                if (!_guildManager.HasGuild)
                {
                    _packetFactory.SendGuildHouseActionError(client, GuildHouseActionError.LowRank, 30);
                    return;
                }

                var allowed = _guildManager.CanUseNpc(npc.Type, npc.TypeId, out var requiredRank);
                if (!allowed)
                {
                    _packetFactory.SendGuildHouseActionError(client, GuildHouseActionError.LowRank, requiredRank);
                    return;
                }

                allowed = _guildManager.HasNpcLevel(npc.Type, npc.TypeId);
                if (!allowed)
                {
                    _packetFactory.SendGuildHouseActionError(client, GuildHouseActionError.LowLevel, 0);
                    return;
                }
            }

            var gate = npc.Gates[packet.GateId];

            if (_inventoryManager.Gold < gate.Cost)
            {
                _packetFactory.SendTeleportViaNpc(client, NpcTeleportNotAllowedReason.NotEnoughMoney, _inventoryManager.Gold);
                return;
            }

            var mapConfig = _mapLoader.LoadMapConfiguration((ushort)gate.MapId);

            if (mapConfig is null)
            {
                _packetFactory.SendTeleportViaNpc(client, NpcTeleportNotAllowedReason.MapCapacityIsFull, _inventoryManager.Gold);
                return;
            }

            // TODO: there should be somewhere player's level check. But I can not find it in gate config.

            _inventoryManager.Gold = (uint)(_inventoryManager.Gold - gate.Cost);
            _packetFactory.SendTeleportViaNpc(client, NpcTeleportNotAllowedReason.Success, _inventoryManager.Gold);
            _teleportationManager.Teleport((ushort)gate.MapId, gate.Position.X, gate.Position.Y, gate.Position.Z);
        }