示例#1
0
 internal void SendPortalTeleportNotAllowed(IWorldClient client, PortalTeleportNotAllowedReason reason)
 {
     using var packet = new Packet(PacketType.CHARACTER_ENTERED_PORTAL);
     packet.Write(false); // success
     packet.Write((byte)reason);
     client.SendPacket(packet);
 }
 /// <summary>
 /// Teleports character with the help of the portal, if it's possible.
 /// </summary>
 public bool TryTeleport(byte portalIndex, out PortalTeleportNotAllowedReason reason)
 {
     if (_gameWorld.CanTeleport(this, portalIndex, out reason))
     {
         var portal = Map.Portals[portalIndex];
         Teleport(portal.MapId, portal.Destination_X, portal.Destination_Y, portal.Destination_Z);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public bool TryTeleport(byte portalIndex, out PortalTeleportNotAllowedReason reason)
        {
            reason = PortalTeleportNotAllowedReason.Unknown;
            if (_mapProvider.Map.Portals.Count <= portalIndex)
            {
                _logger.LogWarning("Unknown portal {portalIndex} for map {mapId}. Send from character {id}.", portalIndex, _mapProvider.Map.Id, _ownerId);
                return(false);
            }

            var portal = _mapProvider.Map.Portals[portalIndex];

            if (!portal.IsInPortalZone(_movementManager.PosX, _movementManager.PosY, _movementManager.PosZ))
            {
                _logger.LogWarning("Character position is not in portal, map {mapId}. Portal index {portalIndex}. Send from character {id}.", _mapProvider.Map.Id, portalIndex, _ownerId);
                return(false);
            }

            if (!portal.IsSameFaction(_countryProvider.Country))
            {
                return(false);
            }

            if (!portal.IsRightLevel(_levelProvider.Level))
            {
                return(false);
            }

            if (_gameWorld.CanTeleport(_gameWorld.Players[_ownerId], portal.MapId, out reason))
            {
                Teleport(portal.MapId, portal.Destination_X, portal.Destination_Y, portal.Destination_Z);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        /// <inheritdoc />
        public bool CanTeleport(Character player, ushort destinationMapId, out PortalTeleportNotAllowedReason reason)
        {
            reason = PortalTeleportNotAllowedReason.Unknown;

            if (Maps.ContainsKey(destinationMapId) || player.Map.Id == destinationMapId)
            {
                return(true);
            }
            else // Not "usual" map.
            {
                var destinationMapDef = _mapDefinitions.Maps.FirstOrDefault(d => d.Id == destinationMapId);

                if (destinationMapDef is null)
                {
                    _logger.LogWarning("Map {id} is not found in map definitions.", destinationMapId);
                    return(false);
                }

                if (destinationMapDef.CreateType == CreateType.Party)
                {
                    if (player.PartyManager.Party is null)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForParty;
                        return(false);
                    }

                    if (player.PartyManager.Party != null && (player.PartyManager.Party.Members.Count < destinationMapDef.MinMembersCount || (destinationMapDef.MaxMembersCount != 0 && player.PartyManager.Party.Members.Count > destinationMapDef.MaxMembersCount)))
                    {
                        reason = PortalTeleportNotAllowedReason.NotEnoughPartyMembers;
                        return(false);
                    }

                    return(true);
                }

                if (destinationMapDef.CreateType == CreateType.GuildHouse)
                {
                    if (!player.GuildManager.HasGuild)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForGuilds;
                        return(false);
                    }

                    if (!player.GuildManager.HasGuildHouse)
                    {
                        reason = PortalTeleportNotAllowedReason.NoGuildHouse;
                        return(false);
                    }

                    if (!player.GuildManager.HasTopRank)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyTop30Guilds;
                        return(false);
                    }

                    if (!player.GuildManager.HasPaidGuildHouse)
                    {
                        reason = PortalTeleportNotAllowedReason.FeeNotPaid;
                        return(false);
                    }

                    return(true);
                }

                if (destinationMapDef.CreateType == CreateType.GRB)
                {
                    if (!player.GuildManager.HasGuild)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForGuilds;
                        return(false);
                    }

                    if (!destinationMapDef.IsOpen(_timeService.UtcNow))
                    {
                        reason = PortalTeleportNotAllowedReason.NotTimeForRankingBattle;
                        return(false);
                    }

                    if (_guildRankingManager.ParticipatedPlayers.Contains(player.Id))
                    {
                        reason = PortalTeleportNotAllowedReason.AlreadyParticipatedInBattle;
                        return(false);
                    }

                    return(true);
                }

                if (!destinationMapDef.IsOpen(_timeService.UtcNow))
                {
                    reason = PortalTeleportNotAllowedReason.OnlyForPartyAndOnTime;
                    return(false);
                }

                return(true);
            }
        }
示例#5
0
        /// <inheritdoc />
        public bool CanTeleport(Character player, byte portalIndex, out PortalTeleportNotAllowedReason reason)
        {
            reason = PortalTeleportNotAllowedReason.Unknown;

            var map = player.Map;

            if (map.Portals.Count <= portalIndex)
            {
                _logger.LogWarning($"Unknown portal {portalIndex} for map {map.Id}. Send from character {player.Id}.");
                return(false);
            }

            var portal = map.Portals[portalIndex];

            if (!portal.IsInPortalZone(player.PosX, player.PosY, player.PosZ))
            {
                _logger.LogWarning($"Character position is not in portal, map {map.Id}. Portal index {portalIndex}. Send from character {player.Id}.");
                return(false);
            }

            if (!portal.IsSameFaction(player.Country))
            {
                return(false);
            }

            if (!portal.IsRightLevel(player.Level))
            {
                return(false);
            }

            if (Maps.ContainsKey(portal.MapId))
            {
                return(true);
            }
            else // Not "usual" map.
            {
                var destinationMapId  = portal.MapId;
                var destinationMapDef = _mapDefinitions.Maps.FirstOrDefault(d => d.Id == destinationMapId);

                if (destinationMapDef is null)
                {
                    _logger.LogWarning($"Map {destinationMapId} is not found in map definitions.");
                    return(false);
                }

                if (destinationMapDef.CreateType == CreateType.Party)
                {
                    if (player.Party is null)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForParty;
                        return(false);
                    }

                    if (player.Party != null && (player.Party.Members.Count < destinationMapDef.MinMembersCount || (destinationMapDef.MaxMembersCount != 0 && player.Party.Members.Count > destinationMapDef.MaxMembersCount)))
                    {
                        reason = PortalTeleportNotAllowedReason.NotEnoughPartyMembers;
                        return(false);
                    }

                    return(true);
                }

                // TODO: implement this check as soon as we have guilds.
                if (destinationMapDef.CreateType == CreateType.Guild /*&& player.Guild is null*/)
                {
                    reason = PortalTeleportNotAllowedReason.OnlyForGuilds;
                    return(false);
                }

                if (!destinationMapDef.IsOpen)
                {
                    reason = PortalTeleportNotAllowedReason.OnlyForPartyAndOnTime;
                    return(false);
                }

                return(true);
            }
        }
示例#6
0
 public void SendPortalTeleportNotAllowed(PortalTeleportNotAllowedReason reason) => _packetsHelper.SendPortalTeleportNotAllowed(Client, reason);
示例#7
0
        /// <inheritdoc />
        public bool CanTeleport(Character player, byte portalIndex, out PortalTeleportNotAllowedReason reason)
        {
            reason = PortalTeleportNotAllowedReason.Unknown;

            var map = player.Map;

            if (map.Portals.Count <= portalIndex)
            {
                _logger.LogWarning($"Unknown portal {portalIndex} for map {map.Id}. Send from character {player.Id}.");
                return(false);
            }

            var portal = map.Portals[portalIndex];

            if (!portal.IsInPortalZone(player.PosX, player.PosY, player.PosZ))
            {
                _logger.LogWarning($"Character position is not in portal, map {map.Id}. Portal index {portalIndex}. Send from character {player.Id}.");
                return(false);
            }

            if (!portal.IsSameFaction(player.Country))
            {
                return(false);
            }

            if (!portal.IsRightLevel(player.Level))
            {
                return(false);
            }

            if (Maps.ContainsKey(portal.MapId))
            {
                return(true);
            }
            else // Not "usual" map.
            {
                var destinationMapId  = portal.MapId;
                var destinationMapDef = _mapDefinitions.Maps.FirstOrDefault(d => d.Id == destinationMapId);

                if (destinationMapDef is null)
                {
                    _logger.LogWarning($"Map {destinationMapId} is not found in map definitions.");
                    return(false);
                }

                if (destinationMapDef.CreateType == CreateType.Party)
                {
                    if (player.Party is null)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForParty;
                        return(false);
                    }

                    if (player.Party != null && (player.Party.Members.Count < destinationMapDef.MinMembersCount || (destinationMapDef.MaxMembersCount != 0 && player.Party.Members.Count > destinationMapDef.MaxMembersCount)))
                    {
                        reason = PortalTeleportNotAllowedReason.NotEnoughPartyMembers;
                        return(false);
                    }

                    return(true);
                }

                if (destinationMapDef.CreateType == CreateType.GuildHouse)
                {
                    if (!player.HasGuild)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForGuilds;
                        return(false);
                    }

                    if (!player.GuildHasHouse)
                    {
                        reason = PortalTeleportNotAllowedReason.NoGuildHouse;
                        return(false);
                    }

                    if (!player.GuildHasTopRank)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyTop30Guilds;
                        return(false);
                    }

                    // TODO: check weekly payment FeeNotPaid.

                    return(true);
                }

                if (destinationMapDef.CreateType == CreateType.GRB)
                {
                    if (!player.HasGuild)
                    {
                        reason = PortalTeleportNotAllowedReason.OnlyForGuilds;
                        return(false);
                    }

                    if (!destinationMapDef.IsOpen(_timeService.UtcNow))
                    {
                        reason = PortalTeleportNotAllowedReason.NotTimeForRankingBattle;
                        return(false);
                    }

                    // TODO: check AlreadyParticipatedInBattle

                    return(true);
                }

                if (!destinationMapDef.IsOpen(_timeService.UtcNow))
                {
                    reason = PortalTeleportNotAllowedReason.OnlyForPartyAndOnTime;
                    return(false);
                }

                return(true);
            }
        }