Пример #1
0
        public ZonePoint[] GetCircle(ZonePoint center, double radius, int points)
        {
            // Sanity check.
            if (points < 3)
            {
                throw new ArgumentOutOfRangeException("points", "Cannot compute a circle with fewer than 3 points.");
            }

            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint    = new Point(center);
            c.TargetVector = new Vector(radius, null);

            // For each needed point, translate the center "radius meters"
            // towards "i * 360/points".
            ZonePoint[] pts  = new ZonePoint[points];
            double      step = 360d / points;

            for (int i = 0; i < points; i++)
            {
                c.TargetVector.Bearing = step * i;
                pts[i] = TranslatePointCore(c).ToZonePoint(_dataFactory);
            }

            return(pts);
        }
Пример #2
0
        public LuaVararg VectorToSegmentLua(LuaTable zonePoint, LuaTable firstLineZonePoint, LuaTable secondLineZonePoint)
        {
            List <LuaValue> ret = new List <LuaValue>(2);

            if (zonePoint == null || firstLineZonePoint == null || secondLineZonePoint == null)
            {
                ret.Add(LuaNil.Instance);
                ret.Add(LuaNil.Instance);

                return(new LuaVararg(ret, true));
            }

            // Gets the data model entities.
            ZonePoint zonePointEntity           = _dataFactory.GetWherigoObject <ZonePoint>(zonePoint);
            ZonePoint firstLinezonePointEntity  = _dataFactory.GetWherigoObject <ZonePoint>(firstLineZonePoint);
            ZonePoint secondLinezonePointEntity = _dataFactory.GetWherigoObject <ZonePoint>(secondLineZonePoint);

            // Performs the computation.
            LocationVector lv = _mathHelper.VectorToSegment(
                _dataFactory.GetWherigoObject <ZonePoint>(zonePoint),
                _dataFactory.GetWherigoObject <ZonePoint>(firstLineZonePoint),
                _dataFactory.GetWherigoObject <ZonePoint>(secondLineZonePoint)
                );

            // Prepares the lua return.
            ret.Add(_dataFactory.GetNativeContainer(lv.Distance));
            ret.Add(lv.Bearing.GetValueOrDefault());
            return(new LuaVararg(ret, true));
        }
Пример #3
0
        override public List <ZonePoint> GetZonePointList()
        {
            List <ZonePoint> ZonePointList = new List <ZonePoint>();

            List <byte[]> ZonePointPackets = GetPacketsOfType("OP_SendZonepoints", PacketDirection.ServerToClient);

            if (ZonePointPackets.Count < 1)
            {
                return(ZonePointList);
            }

            // Assume there is only 1 packet and process the first one.

            ByteStream Buffer = new ByteStream(ZonePointPackets[0]);

            UInt32 Entries = Buffer.ReadUInt32();

            if (Entries == 0)
            {
                return(ZonePointList);
            }

            float x, y, z, Heading;

            UInt32 Number;

            UInt16 ZoneID, Instance;

            ZonePointList = new List <ZonePoint>();

            for (int i = 0; i < Entries; ++i)
            {
                Number = Buffer.ReadUInt32();

                y = Buffer.ReadSingle();

                x = Buffer.ReadSingle();

                z = Buffer.ReadSingle();

                Heading = Buffer.ReadSingle();

                if (Heading != 999)
                {
                    Heading = Heading / 2;
                }

                ZoneID = Buffer.ReadUInt16();

                Instance = Buffer.ReadUInt16();

                Buffer.SkipBytes(8);    // Skip the last UInt32

                ZonePoint NewZonePoint = new ZonePoint(Number, ZoneID, Instance, x, y, z, x, y, z, Heading, ZoneID);

                ZonePointList.Add(NewZonePoint);
            }

            return(ZonePointList);
        }
Пример #4
0
        /// <summary>
        /// Decides whether player can jump to the target point.
        /// All messages with reasons must be sent here.
        /// Can change destination too.
        /// </summary>
        /// <param name="targetPoint">The jump destination</param>
        /// <param name="player">The jumping player</param>
        /// <returns>True if allowed</returns>
        public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
        {
            // Handles zoning INTO an instance.
            GameLocation loc = null;

            // First, we try the groups mission.
            if (player.Group != null)
            {
                Group grp = player.Group;
                if (grp.Mission is TaskDungeonMission task)
                {
                    // Attempt to get the instance entrance location...
                    loc = task.TaskRegion.InstanceEntranceLocation;
                }
            }
            else if (player.Mission is TaskDungeonMission)
            {
                // Then, try personal missions...
                TaskDungeonMission task = (TaskDungeonMission)player.Mission;
                loc = task.TaskRegion.InstanceEntranceLocation;
            }

            if (loc != null)
            {
                targetPoint.TargetX       = loc.X;
                targetPoint.TargetY       = loc.Y;
                targetPoint.TargetZ       = loc.Z;
                targetPoint.TargetRegion  = loc.RegionID;
                targetPoint.TargetHeading = loc.Heading;
                return(true);
            }

            player.Out.SendMessage("You need to have a proper mission before entering this area!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            return(false);
        }
    private void GenerateCoin(ZonePoint zonePoint)
    {
        // Get coin from pull
        var coinObject = PoolManager.Instance.CoinPool.GetObject(zonePoint.GetPointPosition());

        coinObject.SetActive(true);
        coinObject.transform.parent = _coinsContainer.transform;
        zonePoint.AddElement(coinObject);
    }
Пример #6
0
            public void Remove(int x, int y)
            {
                ZonePoint zp = Points.Find(p => p.X == x && p.Y == y);

                if (zp != null)
                {
                    Points.Remove(zp);
                }
            }
Пример #7
0
        public bool ConsumeZonePointWith <T>(ZonePoint point)
            where T : IAreaConsumption
        {
            var result = Area
                         .ConsumeZoneAt(point.GetZoneInfoOn(Area).MatchingObject,
                                        _factories[typeof(T)]());

            return(result.Success);
        }
Пример #8
0
 public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
 {
     if (player.Level < 10 && player.Level > 4)
     {
         return(true);
     }
     player.Client.Out.SendMessage("You do not meet the requirements to enter this region!", eChatType.CT_System, eChatLoc.CL_ChatWindow);
     return(false);
 }
Пример #9
0
        public bool IsPointInZone(ZonePoint point, Zone target)
        {
            // Computes the calculation input.
            CalcInput c = new CalcInput();

            c.MainPoint = new Point(point);
            c.SetTargetZone(target);

            return(IsPointInZoneCore(c));
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ZonePoint zp = value as ZonePoint;

            if (zp == null)
            {
                return(null);
            }

            return(zp.ToString(GeoCoordinateUnit.DegreesMinutes));
        }
Пример #11
0
            /// <summary>
            /// Constructs a new RegionChangeRequestHandler
            /// </summary>
            /// <param name="actionSource">The action source</param>
            /// <param name="zonePoint">The target zone point</param>
            /// <param name="checker">The jump point checker instance</param>
            public RegionChangeRequestHandler(GamePlayer actionSource, ZonePoint zonePoint, IJumpPointHandler checkHandler)
                : base(actionSource)
            {
                if (zonePoint == null)
                {
                    throw new ArgumentNullException("zonePoint");
                }

                m_zonePoint    = zonePoint;
                m_checkHandler = checkHandler;
            }
Пример #12
0
 /// <summary>
 /// Decides whether player can jump to the target point.
 /// All messages with reasons must be sent here.
 /// Can change destination too.
 /// </summary>
 /// <param name="targetPoint">The jump destination</param>
 /// <param name="player">The jumping player</param>
 /// <returns>True if allowed</returns>
 public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
 {
     if (GameServer.Instance.Configuration.ServerType != eGameServerType.GST_Normal)
     {
         return(true);
     }
     if (ServerProperties.Properties.ALLOW_ALL_REALMS_DF)
     {
         return(true);
     }
     return(player.Realm == DarknessFallOwner);
 }
Пример #13
0
        public bool ConsumeZonePointWithNetwork <T>(ZonePoint point)
            where T : BaseInfrastructureNetworkZoneConsumption
        {
            var zoneInfo = point.GetZoneInfoOn(Area).MatchingObject;

            if (zoneInfo.ConsumptionState.GetIsNetworkMember <T>())
            {
                return(true);
            }

            return(ConsumeZonePointWith <T>(point));
        }
 public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
 {
     if (player.Client.Account.PrivLevel > 1)
     {
         return(true);
     }
     if (player.Level < 10 && player.Level > 4)
     {
         return(true);
     }
     player.Client.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "DemonsBreachJumpPoint.Requirements"), eChatType.CT_System, eChatLoc.CL_ChatWindow);
     return(false);
 }
        /// <summary>
        /// Decides whether player can jump to the target point.
        /// All messages with reasons must be sent here.
        /// Can change destination too.
        /// </summary>
        /// <param name="targetPoint">The jump destination</param>
        /// <param name="player">The jumping player</param>
        /// <returns>True if allowed</returns>
        public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
        {
            if (player.CurrentRegion is BaseInstance == false)
            {
                return(true);
            }

            if (((BaseInstance)player.CurrentRegion).OnInstanceDoor(player, targetPoint))
            {
                return(true);
            }

            return(false); // Let instance handle zoning by itself in this case...
        }
Пример #16
0
        public ZonePoint TranslatePoint(ZonePoint point, LocationVector vector)
        {
            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint    = new Point(point);
            c.TargetVector = new Vector(vector);

            // Performs the computation.
            Point newPoint = TranslatePointCore(c);

            // Returns the right object.
            return(newPoint.ToZonePoint(_dataFactory));
        }
Пример #17
0
        public LocationVector VectorToPoint(ZonePoint point, ZonePoint target)
        {
            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint   = new Point(point);
            c.TargetPoint = new Point(target);

            // Performs the computation.
            Vector vector = VectorToPointCore(c);

            // Returns the right object.
            return(vector.ToLocationVector(_dataFactory));
        }
Пример #18
0
        public bool IsPointInZoneLua(LuaTable zonePoint, LuaTable zone)
        {
            if (zonePoint == null || zone == null)
            {
                throw new ArgumentNullException();
            }

            // Gets the data model entities.
            ZonePoint zonePointEntity = _dataFactory.GetWherigoObject <ZonePoint>(zonePoint);
            Zone      zoneEntity      = _dataFactory.GetWherigoObject <Zone>(zone);

            // Computes and returns.
            return(_mathHelper.IsPointInZone(zonePointEntity, zoneEntity));
        }
Пример #19
0
        /// <summary>
        /// Decides whether player can jump to the target point.
        /// All messages with reasons must be sent here.
        /// Can change destination too.
        /// </summary>
        /// <param name="targetPoint">The jump destination</param>
        /// <param name="player">The jumping player</param>
        /// <returns>True if allowed</returns>
        public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
        {
            StartupLocations.StartLocation loc = StartupLocations.MainTownStartingLocations[player.CharacterClass.ID] as StartupLocations.StartLocation;

            if (loc != null)
            {
                targetPoint.TargetX       = loc.X;
                targetPoint.TargetY       = loc.Y;
                targetPoint.TargetZ       = loc.Z;
                targetPoint.TargetHeading = (ushort)loc.Heading;
                return(true);
            }

            return(false);
        }
Пример #20
0
        public LocationVector VectorToSegment(ZonePoint point, ZonePoint segmentStartPoint, ZonePoint segmentEndPoint)
        {
            // Computes the input.
            CalcInput c = new CalcInput();

            c.MainPoint     = new Point(point);
            c.SegmentPoint1 = new Point(segmentStartPoint);
            c.SegmentPoint2 = new Point(segmentEndPoint);

            // Performs the computation.
            Vector vector = VectorToSegmentCore(c);

            // Returns the right object.
            return(vector.ToLocationVector(_dataFactory));
        }
Пример #21
0
        /// <summary>
        /// Decides whether player can jump to the target point.
        /// All messages with reasons must be sent here.
        /// Can change destination too.
        /// </summary>
        /// <param name="targetPoint">The jump destination</param>
        /// <param name="player">The jumping player</param>
        /// <returns>True if allowed</returns>
        public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player)
        {
            StartupLocation loc = StartupLocations.GetNonTutorialLocation(player);

            if (loc != null)
            {
                targetPoint.TargetX       = loc.XPos;
                targetPoint.TargetY       = loc.YPos;
                targetPoint.TargetZ       = loc.ZPos;
                targetPoint.TargetHeading = (ushort)loc.Heading;
                targetPoint.TargetRegion  = (ushort)loc.Region;
                return(true);
            }

            return(false);
        }
Пример #22
0
        public LuaTable TranslatePointLua(LuaTable zonePoint, LuaTable distance, double bearing)
        {
            // Gets the data model entities.
            ZonePoint zonePointEntity = _dataFactory.GetWherigoObject <ZonePoint>(zonePoint);
            Distance  distanceEntity  = _dataFactory.GetWherigoObject <Distance>(distance);

            // Performs the computation.
            ZonePoint ret = _mathHelper.TranslatePoint(
                _dataFactory.GetWherigoObject <ZonePoint>(zonePoint),
                new LocationVector(
                    _dataFactory.GetWherigoObject <Distance>(distance),
                    bearing
                    )
                );

            return(_dataFactory.GetNativeContainer(ret));
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ZonePoint zp = value as ZonePoint;

            if (zp == null)
            {
                if (!(parameter is string) || (string)parameter != "NoNull")
                {
                    return(null);
                }
                else
                {
                    zp = new ZonePoint(0, 0, 0);
                }
            }

            return(zp.ToGeoCoordinate());
        }
Пример #24
0
        public LuaVararg VectorToPointLua(LuaTable zonePoint1, LuaTable zonePoint2)
        {
            List <LuaValue> ret = new List <LuaValue>(2);

            // Gets the data model entities.
            ZonePoint zonePoint1Entity = _dataFactory.GetWherigoObject <ZonePoint>(zonePoint1);
            ZonePoint zonePoint2Entity = _dataFactory.GetWherigoObject <ZonePoint>(zonePoint2);

            // Performs the computation.
            LocationVector lv = _mathHelper.VectorToPoint(
                _dataFactory.GetWherigoObject <ZonePoint>(zonePoint1),
                _dataFactory.GetWherigoObject <ZonePoint>(zonePoint2)
                );

            // Prepares the lua return.
            ret.Add(_dataFactory.GetNativeContainer(lv.Distance));
            ret.Add(lv.Bearing.GetValueOrDefault());
            return(new LuaVararg(ret, true));
        }
Пример #25
0
        internal GWS(
            Cartridge cart,
            Character player,
            IPlatformHelper platformHelper,
            LuaDataFactory dataFactory)
        {
            this._dataFactory = dataFactory;

            this._cartridgeEntity = cart;
            this._cartridge       = (LuaDataContainer)cart.DataContainer;
            this._player          = (LuaDataContainer)player.DataContainer;

            this._platformHelper = platformHelper;

            ZonePoint pos = player.ObjectLocation;

            this._latitude  = pos.Latitude;
            this._longitude = pos.Longitude;
            this._altitude  = pos.Latitude;
        }
Пример #26
0
        public LuaVararg VectorToZoneLua(LuaTable zonePoint, LuaTable zone)
        {
            List <LuaValue> ret = new List <LuaValue>(2);

            if (zonePoint == null || zone == null)
            {
                throw new ArgumentNullException();
            }

            // Gets the data model entities.
            ZonePoint zonePointEntity = _dataFactory.GetWherigoObject <ZonePoint>(zonePoint);
            Zone      zoneEntity      = _dataFactory.GetWherigoObject <Zone>(zone);

            // Performs the computation.
            LocationVector vector = _mathHelper.VectorToZone(zonePointEntity, zoneEntity);

            // Prepares the lua return.
            ret.Add(vector.Distance != null ? (LuaValue)_dataFactory.GetNativeContainer(vector.Distance) : LuaNil.Instance);
            ret.Add(vector.Bearing);

            return(new LuaVararg(ret, true));
        }
Пример #27
0
 public static ClientZonePoint Create(ZonePoint zonePoint) =>
 new ClientZonePoint
 {
     x = zonePoint.X,
     y = zonePoint.Y
 };
Пример #28
0
        private WherigoObject GetWherigoObjectCore(
            LuaTable obj,
            bool dontFailIfNotWigEntity = false,
            bool forceProtectFromGC     = false,
            bool allowsNullTable        = false,
            Type typeToCompare          = null)
        {
            // Sanity check.
            if (obj == null)
            {
                if (!allowsNullTable)
                {
                    throw new ArgumentNullException("Null table argument is not allowed.");
                }

                return(null);
            }

            // Gets the class of the entity.
            string cn = _luaState.SafeGetField <string>(obj, "ClassName");

            if (cn == null)
            {
                if (dontFailIfNotWigEntity)
                {
                    return(null);
                }

                throw new InvalidOperationException("obj has no ClassName string property.");
            }

            // Does the entity have an ObjIndex?
            // YES -> it should be in the AllZObjects table, so retrieve or make it.
            // NO -> make it anyway.
            WherigoObject ret   = null;
            double?       oiRaw = _luaState.SafeGetField <double?>(obj, "ObjIndex");

            if (oiRaw == null)
            {
                // Creates a container for the table.
                // It is not protected from GC by default.
                LuaDataContainer ldc = CreateContainerCore(obj, forceProtectFromGC);

                // Immediately wraps the table into its corresponding class.
                if ("ZonePoint" == cn)
                {
                    ret = new ZonePoint(ldc);
                }

                else if ("ZCommand" == cn || "ZReciprocalCommand" == cn)
                {
                    ret = new Command(
                        ldc,
                        MakeCommandCalcTargetObjectsInstance(ldc),
                        MakeCommandExecuteCommandInstance(ldc)
                        );
                }

                else if ("Distance" == cn)
                {
                    ret = new Distance(ldc);
                }
            }
            else
            {
                // Tries to get the object from the cache if it is not
                // the player or cartridge object.
                int  oi          = (int)oiRaw.Value;
                bool isPlayer    = oi < 0;
                bool isCartridge = oi == 0;
                Node node;
                if (!isPlayer && !isCartridge)
                {
                    bool hasValue;
                    lock (_syncRoot)
                    {
                        hasValue = _wEntities.TryGetValue(oi, out node);
                    }
                    // The object is known, returns it.
                    if (hasValue)
                    {
                        ret = node.Object;

                        // Double check the classname.
                        string cachedCn = ret.DataContainer.GetString("ClassName");
                        if (cn != cachedCn)
                        {
                            throw new InvalidOperationException(String.Format("The object with id {0} is known to have class {1}, but class {2} was requested.", oi, cachedCn ?? "<null>", cn ?? "<null>"));
                        }
                    }
                }

                // The object is not known, make it and create a node for it.
                if (ret == null)
                {
                    // Creates a GC-protected container for the table.
                    FriendLuaDataContainer ldc = CreateContainerCore(obj, true);

                    // Creates the object.
                    if ("ZInput" == cn)
                    {
                        ret = new Input(
                            ldc,
                            MakeInputRunOnGetInputInstance(ldc)
                            );
                    }

                    else if ("ZTimer" == cn)
                    {
                        ret = new Timer(ldc);
                    }

                    else if ("ZCharacter" == cn)
                    {
                        if (isPlayer && _helper.Player != null)
                        {
                            ret = _helper.Player;
                        }
                        else
                        {
                            ret = new Character(
                                ldc,
                                MakeUIObjectRunOnClickInstance(ldc)
                                );
                        }
                    }
                    else if ("ZItem" == cn)
                    {
                        ret = new Item(
                            ldc,
                            MakeUIObjectRunOnClickInstance(ldc)
                            );
                    }

                    else if ("ZTask" == cn)
                    {
                        ret = new Task(
                            ldc,
                            MakeUIObjectRunOnClickInstance(ldc)
                            );
                    }

                    else if ("Zone" == cn)
                    {
                        ret = new Zone(
                            ldc,
                            MakeUIObjectRunOnClickInstance(ldc)
                            );
                    }
                    else if ("ZMedia" == cn)
                    {
                        // Gets the ZMedia from the Cartridge which has the same Id.
                        Media media = _helper.Cartridge.Resources.Single(m => m.MediaId == oi);

                        // Injects the data container with metadata about the media.
                        media.DataContainer = ldc;

                        // The returned object is the media.
                        ret = media;
                    }
                    else if ("ZCartridge" == cn)
                    {
                        // Sanity checks if the Cartridge GUIDs match.
                        string baseId = _helper.Cartridge.Guid;
                        string reqId  = ldc.GetString("Id");
                        if (baseId != reqId)
                        {
                            //throw new InvalidOperationException(String.Format("Requested Cartridge with id {0}, but only knows Cartridge with id {1}.", reqId, baseId));
                            System.Diagnostics.Debug.WriteLine("LuaDataFactory: WARNING: " + String.Format("Requested Cartridge with id {0}, but only knows Cartridge with id {1}.", reqId, baseId));
                        }

                        // Returns the cartridge object.
                        ret = _helper.Cartridge;

                        // Binds the cartridge container if the cartridge is unbound.
                        if (ret.DataContainer == null)
                        {
                            ret.DataContainer = ldc;
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("obj has an unknown classname: " + cn);
                    }

                    // Creates a node and registers it. Cartridge and player are not registered.
                    if (!isPlayer && !isCartridge)
                    {
                        node = new Node()
                        {
                            Container = ldc,
                            Object    = ret
                        };
                        lock (_syncRoot)
                        {
                            _wEntities.Add(oi, node);
                        }
                    }
                }
            }

            // Final sanity checks.
            if (ret == null)
            {
                throw new InvalidOperationException("Returned value was not computed.");
            }
            if (typeToCompare != null && !typeToCompare.IsAssignableFrom(ret.GetType()))
            {
                throw new InvalidOperationException(String.Format("The wherigo object is known to have type {0}, not {1} as requested.", ret.GetType().FullName, typeToCompare.FullName));
            }

            return(ret);
        }
Пример #29
0
			public Point(ZonePoint point)
			{
				Lat = point == null ? ZonePoint.Invalid.Latitude : point.Latitude;
				Lon = point == null ? ZonePoint.Invalid.Longitude : point.Longitude;
			}
Пример #30
0
		public ZonePoint[] GetCircle(ZonePoint center, double radius, int points)
		{
			// Sanity check.
			if (points < 3)
			{
				throw new ArgumentOutOfRangeException("points", "Cannot compute a circle with fewer than 3 points.");
			}
			
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(center);
			c.TargetVector = new Vector(radius, null);
			
			// For each needed point, translate the center "radius meters"
			// towards "i * 360/points".
			ZonePoint[] pts = new ZonePoint[points];
			double step = 360d / points;
			for (int i = 0; i < points; i++)
			{
				c.TargetVector.Bearing = step * i;
				pts[i] = TranslatePointCore(c).ToZonePoint(_dataFactory);
			}

			return pts;
		}
Пример #31
0
		public ZonePoint TranslatePoint(ZonePoint point, LocationVector vector)
		{
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.TargetVector = new Vector(vector);

			// Performs the computation.
			Point newPoint = TranslatePointCore(c);

			// Returns the right object.
			return newPoint.ToZonePoint(_dataFactory);
		}
Пример #32
0
		public LocationVector VectorToPoint(ZonePoint point, ZonePoint target)
		{
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.TargetPoint = new Point(target);

			// Performs the computation.
			Vector vector = VectorToPointCore(c);

			// Returns the right object.
			return vector.ToLocationVector(_dataFactory);
		}
Пример #33
0
            private static double CalculateDistance(ZonePoint x, ZonePoint y)
            {
                int x1 = x.X, x2 = y.X, y1 = x.Y, y2 = y.Y;

                return((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
            }
Пример #34
0
		public bool IsPointInZone(ZonePoint point, Zone target)
		{
			// Computes the calculation input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.SetTargetZone(target);

			return IsPointInZoneCore(c);
		}
Пример #35
0
        public void HandlePacket(GameClient client, GSPacketIn packet)
        {
            ushort jumpSpotID = packet.ReadShort();

            eRealm targetRealm = client.Player.Realm;

            if (client.Player.CurrentRegion.Expansion == (int)eClientExpansion.TrialsOfAtlantis && client.Player.CurrentZone.Realm != eRealm.None)
            {
                // if we are in TrialsOfAtlantis then base the target jump on the current region realm instead of the players realm
                // this is only used if zone table has the proper realms defined, otherwise it reverts to old behavior - Tolakram
                targetRealm = client.Player.CurrentZone.Realm;
            }

            var zonePoint = GameServer.Database.SelectObjects <ZonePoint>("`Id` = @Id AND (`Realm` = @Realm OR `Realm` = @DefaultRealm OR `Realm` IS NULL)",
                                                                          new [] { new QueryParameter("@Id", jumpSpotID), new QueryParameter("@Realm", (byte)targetRealm), new QueryParameter("@DefaultRealm", 0) }).FirstOrDefault();

            if (zonePoint == null || zonePoint.TargetRegion == 0)
            {
                ChatUtil.SendDebugMessage(client, "Invalid Jump (ZonePoint table): [" + jumpSpotID + "]" + ((zonePoint == null) ? ". Entry missing!" : ". TargetRegion is 0!"));
                zonePoint    = new ZonePoint();
                zonePoint.Id = jumpSpotID;
            }

            if (client.Account.PrivLevel > 1)
            {
                client.Out.SendMessage("JumpSpotID = " + jumpSpotID, eChatType.CT_System, eChatLoc.CL_SystemWindow);
                client.Out.SendMessage("ZonePoint Target: Region = " + zonePoint.TargetRegion + ", ClassType = '" + zonePoint.ClassType + "'", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }

            //Dinberg: Fix - some jump points are handled code side, such as instances.
            //As such, region MAY be zero in the database, so this causes an issue.

            if (zonePoint.TargetRegion != 0)
            {
                Region reg = WorldMgr.GetRegion(zonePoint.TargetRegion);
                if (reg != null)
                {
                    // check for target region disabled if player is in a standard region
                    // otherwise the custom region should handle OnZonePoint for this check
                    if (client.Player.CurrentRegion.IsCustom == false && reg.IsDisabled)
                    {
                        if ((client.Player.Mission is TaskDungeonMission &&
                             (client.Player.Mission as TaskDungeonMission).TaskRegion.Skin == reg.Skin) == false)
                        {
                            client.Out.SendMessage("This region has been disabled!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                            if (client.Account.PrivLevel == 1)
                            {
                                return;
                            }
                        }
                    }
                }
            }

            // Allow the region to either deny exit or handle the zonepoint in a custom way
            if (client.Player.CurrentRegion.OnZonePoint(client.Player, zonePoint) == false)
            {
                return;
            }

            //check caps for battleground
            Battleground bg = GameServer.KeepManager.GetBattleground(zonePoint.TargetRegion);

            if (bg != null)
            {
                if (client.Player.Level < bg.MinLevel && client.Player.Level > bg.MaxLevel &&
                    client.Player.RealmLevel >= bg.MaxRealmLevel)
                {
                    return;
                }
            }

            IJumpPointHandler customHandler = null;

            if (string.IsNullOrEmpty(zonePoint.ClassType) == false)
            {
                customHandler = (IJumpPointHandler)m_customJumpPointHandlers[zonePoint.ClassType];

                // check for db change to update cached handler
                if (customHandler != null && customHandler.GetType().FullName != zonePoint.ClassType)
                {
                    customHandler = null;
                }

                if (customHandler == null)
                {
                    //Dinberg - Instances need to use a special handler. This is because some instances will result
                    //in duplicated zonepoints, such as if Tir Na Nog were to be instanced for a quest.
                    string type = (client.Player.CurrentRegion.IsInstance)
                                                ? "DOL.GS.ServerRules.InstanceDoorJumpPoint"
                                                : zonePoint.ClassType;
                    Type t = ScriptMgr.GetType(type);

                    if (t == null)
                    {
                        Log.ErrorFormat("jump point {0}: class {1} not found!", zonePoint.Id, zonePoint.ClassType);
                    }
                    else if (!typeof(IJumpPointHandler).IsAssignableFrom(t))
                    {
                        Log.ErrorFormat("jump point {0}: class {1} must implement IJumpPointHandler interface!", zonePoint.Id,
                                        zonePoint.ClassType);
                    }
                    else
                    {
                        try
                        {
                            customHandler = (IJumpPointHandler)Activator.CreateInstance(t);
                        }
                        catch (Exception e)
                        {
                            customHandler = null;
                            Log.Error(
                                string.Format("jump point {0}: error creating a new instance of jump point handler {1}", zonePoint.Id,
                                              zonePoint.ClassType), e);
                        }
                    }
                }

                if (customHandler != null)
                {
                    m_customJumpPointHandlers[zonePoint.ClassType] = customHandler;
                }
            }

            new RegionChangeRequestHandler(client.Player, zonePoint, customHandler).Start(1);
        }
Пример #36
0
		public LocationVector VectorToSegment(ZonePoint point, ZonePoint segmentStartPoint, ZonePoint segmentEndPoint)
		{
			// Computes the input.
			CalcInput c = new CalcInput();
			c.MainPoint = new Point(point);
			c.SegmentPoint1 = new Point(segmentStartPoint);
			c.SegmentPoint2 = new Point(segmentEndPoint);

			// Performs the computation.
			Vector vector = VectorToSegmentCore(c);

			// Returns the right object.
			return vector.ToLocationVector(_dataFactory);
		}