Beispiel #1
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);
        }
Beispiel #2
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);
        }