Exemple #1
0
        /// <summary>
        /// Get the point at the given heading and distance
        /// </summary>
        /// <param name="gameHeading">DOL Heading</param>
        /// <param name="distance">Distance to point</param>
        /// <returns>Point at the given heading and distance</returns>
        public Point2D GetPointFromHeading(ushort heading, int distance)
        {
            distance = (int)((float)distance*13.2f);
            double angle = heading*HEADING_TO_RADIAN;
            double targetX = X - (Math.Sin(angle)*distance);
            double targetY = Y + (Math.Cos(angle)*distance);

            var point = new Point2D();

            if (targetX > 0)
                point.X = (int) targetX;
            else
                point.X = 0;

            if (targetY > 0)
                point.Y = (int) targetY;
            else
                point.Y = 0;

            return point;
        }
Exemple #2
0
        public static void CreateNew(Player plr, int entry)
        {
            Point3D destPos;
            ushort  destHeading;

            RvRStructure curStruct = plr.CbtInterface.GetCurrentTarget() as RvRStructure;

            RvRObjectInfo info = BattlefrontService.GetRvRObjectInfo(entry);

            _logger.Debug($"RVRStructure BattlefrontService.GetRvRObjectInfo Entry={entry} info={info.Name} {info.ModelId} {info.ObjectId}");

            if (curStruct != null)
            {
                ushort shiftHeading = (ushort)((curStruct.Heading + 1024) & 0xFFF);
                destPos     = new Point3D(curStruct.WorldPosition);
                destHeading = curStruct.Heading;

                Point2D offsetPoint = GetOffsetFromHeading(shiftHeading, (ushort)(info.ExclusionRadius + curStruct._info.ExclusionRadius + 1));

                Vector2 offsetVector = new Vector2(offsetPoint.X, offsetPoint.Y);
                offsetVector.Normalize();

                Vector2 toPlayer = new Vector2(plr.WorldPosition.X - curStruct.WorldPosition.X, plr.WorldPosition.Y - curStruct.WorldPosition.Y);
                toPlayer.Normalize();

                float dotP = Vector2.DotProduct2D(offsetVector, toPlayer);

                if (dotP >= 0)
                {
                    destPos.X += offsetPoint.X;
                    destPos.Y += offsetPoint.Y;
                }

                else
                {
                    destPos.X -= offsetPoint.X;
                    destPos.Y -= offsetPoint.Y;
                }
            }

            else
            {
                Point2D offset = GetOffsetFromHeading(plr.Heading, 10);
                destHeading = plr.Heading;
                destPos     = new Point3D(plr.WorldPosition.X + offset.X, plr.WorldPosition.Y + offset.Y, plr.WorldPosition.Z);
            }

            foreach (Object obj in plr.ObjectsInRange)
            {
                RvRStructure structure = obj as RvRStructure;

                if (structure == null)
                {
                    continue;
                }

                if (structure.WorldPosition.GetDistanceTo(destPos) < info.ExclusionRadius + structure._info.ExclusionRadius)
                {
                    plr.SendClientMessage("Too close to existing structure", ChatLogFilters.CHATLOGFILTERS_C_ABILITY_ERROR);
                    plr.SendClientMessage("Too close to an existing structure (one exists within " + structure.WorldPosition.GetDistanceTo(destPos) + "ft and " + (info.ExclusionRadius + structure._info.ExclusionRadius) + "ft clearance is required)", ChatLogFilters.CHATLOGFILTERS_USER_ERROR);
                    return;
                }
            }

            RvRStructure newStruct = new RvRStructure(info, destPos, destHeading, plr);

            plr.Region.AddObject(newStruct, plr.Zone.ZoneId, true);

            _logger.Debug($"RVRStructure CreateNew Entry={entry} {curStruct.Name} {curStruct.Oid} Zone={plr.Zone.ZoneId}");
        }