Пример #1
0
        public void StartPatrolling()
        {
            Waypoint next = this.FindNextWaypoint();

            // If a suitable waypoint is found
            if (next != null)
            {
                if (next.Running)
                {
                    this.Run();
                }
                else
                {
                    this.Walk();
                }
                this.followCoordinates = next.Position;
                Vector3 temp = this.Character.Coordinates().coordinate - next.Position;
                temp.y = 0;
                this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(temp).Normalize();
                LogUtil.Debug(DebugInfoDetail.Movement, "Direction: " + this.Character.Heading.ToString());
                FollowTargetMessageHandler.Default.Send(
                    this.Character,
                    this.Character.Coordinates().coordinate,
                    next.Position);
                this.StartMovement();
                LogUtil.Debug(DebugInfoDetail.Movement, "Walking to: " + this.followCoordinates);
            }
        }
Пример #2
0
        public void MoveTo(SmokeLounge.AOtomation.Messaging.GameData.Vector3 destination)
        {
            FollowTargetMessageHandler.Default.Send(this.Character, this.Character.RawCoordinates, destination);
            Vector3 dest  = destination;
            Vector3 start = this.Character.RawCoordinates;

            dest = start - dest;
            dest = dest.Normalize();
            this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(dest);
            this.Run();

            Coordinate c = new Coordinate(destination);

            this.followCoordinates = c.coordinate;

            /*bool arrived = false;
             * double lastDistance = double.MaxValue;
             * while (!arrived)
             * {
             *  Coordinate temp = this.Character.Coordinates;
             *  double distance = this.Character.Coordinates.Distance2D(c);
             *  arrived = (distance < 0.2f) || (lastDistance < distance);
             *  lastDistance = distance;
             *  // LogUtil.Debug(DebugInfoDetail.Movement,"Moving...");
             *  Thread.Sleep(100);
             * }
             * LogUtil.Debug(DebugInfoDetail.Movement, "Arrived at "+this.Character.Coordinates.ToString());
             * this.StopMovement();*/
        }
Пример #3
0
 public void AddWaypoint(Vector3 v, bool running)
 {
     this.Waypoints.Add(new Waypoint(new Vector3(v.x, v.y, v.z), running));
     if (this.Waypoints.Count > 1)
     {
         this.Controller.State = CharacterState.Patrolling;
     }
 }
Пример #4
0
 public void StopFollow()
 {
     this.followIdentity = Identity.None;
     lock (this.followCoordinates)
     {
         this.followCoordinates = new Vector3();
     }
 }
Пример #5
0
        public void DoFollow()
        {
            Coordinate sourceCoord    = this.Character.Coordinates();
            Vector3    targetPosition = this.followCoordinates;

            if (!this.followIdentity.Equals(Identity.None))
            {
                ICharacter targetChar = Pool.Instance.GetObject <ICharacter>(
                    this.Character.Playfield.Identity,
                    this.followIdentity);
                if (targetChar == null)
                {
                    // If target does not longer exist (death or zone or logoff) then stop following
                    this.followIdentity    = Identity.None;
                    this.followCoordinates = new Vector3();
                    return;
                }

                targetPosition = targetChar.Coordinates().coordinate;
            }

            // Do we have coordinates to follow?
            if (targetPosition.Distance2D(new Vector3()) < 0.01f)
            {
                return;
            }

            // /!\ If target flies away, there has to be some kind of adjustment
            Vector3 start = sourceCoord.coordinate;
            Vector3 dest  = targetPosition;

            // Check if we have arrived
            if (start.Distance2D(dest) < 0.3f)
            {
                this.StopMovement();
                this.Character.RawCoordinates = dest;
                FollowTargetMessageHandler.Default.Send(this.Character, dest);
                this.followCoordinates = new Vector3();
                return;
            }

            LogUtil.Debug(DebugInfoDetail.Movement, "Distance to target: " + start.Distance2D(dest).ToString());

            // If target moved or first call, then issue a new follow
            if (targetPosition.Distance2D(this.followCoordinates) > 2.0f)
            {
                this.StopMovement();
                this.Character.Coordinates(start);
                FollowTargetMessageHandler.Default.Send(this.Character, start);
                Vector3 temp = start - dest;
                temp.y = 0;
                this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(temp);
                this.followCoordinates = dest;
                FollowTargetMessageHandler.Default.Send(this.Character, start, dest);
                this.StartMovement();
            }
        }
Пример #6
0
        public override bool Execute(
            INamedEntity self,
            IEntity caller,
            IInstancedEntity target,
            MessagePackObject[] arguments)
        {
            ICharacter character = (ICharacter)self;

            int statelId = (int)((uint)0xC0000000 | arguments[1].AsInt32() | (arguments[2].AsInt32() << 16));

            character.Stats[StatIds.externaldoorinstance].BaseValue      = 0;
            character.Stats[StatIds.externalplayfieldinstance].BaseValue = 0;

            if (arguments[1].AsInt32() > 0)
            {
                StatelData sd = PlayfieldLoader.PFData[arguments[1].AsInt32()].GetDoor(statelId);
                if (sd == null)
                {
                    throw new Exception(
                              "Statel " + arguments[3].AsInt32().ToString("X") + " not found? Check the rdb dammit");
                }

                Vector3 v = new Vector3(sd.X, sd.Y, sd.Z);

                Quaternion q = new Quaternion(sd.HeadingX, sd.HeadingY, sd.HeadingZ, sd.HeadingW);

                Quaternion.Normalize(q);
                Vector3 n = (Vector3)q.RotateVector3(Vector3.AxisZ);

                v.x += n.x * 2.5;
                v.z += n.z * 2.5;
                character.Playfield.Teleport(
                    (Dynel)character,
                    new Coordinate(v),
                    q,
                    new Identity()
                {
                    Type = (IdentityType)arguments[0].AsInt32(), Instance = arguments[1].AsInt32()
                });
            }

            return(true);

            self.Stats[StatIds.externalplayfieldinstance].Value = 0;
            self.Stats[StatIds.externaldoorinstance].Value      = 0;
            self.Playfield.Teleport(
                (Dynel)self,
                new Coordinate(100, 10, 100),
                ((ICharacter)self).Heading,
                new Identity()
            {
                Type = (IdentityType)arguments[0].AsInt32(), Instance = arguments[1].AsInt32()
            });
            return(true);
        }
Пример #7
0
        public bool Follow(Identity target)
        {
            this.followIdentity = target;
            ICharacter npc = Pool.Instance.GetObject <ICharacter>(this.Character.Playfield.Identity, target);

            if (npc != null)
            {
                Vector3 temp = npc.Coordinates().coordinate - this.Character.Coordinates().coordinate;
                temp.y = 0;
                this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(temp).Normalize();
                FollowTargetMessageHandler.Default.Send(
                    this.Character,
                    this.Character.Coordinates().coordinate,
                    npc.Coordinates().coordinate);
                this.Run();
                this.StartMovement();
            }
            return(true);
        }
Пример #8
0
        public void SpawnRandomMob(ICharacter character)
        {
            Coordinate coord = character.Coordinates();

            DBMobTemplate[] templates = MobTemplateDao.Instance.GetAll().ToArray();
            Random          rnd       = new Random(Environment.TickCount);

            int mobNumber = rnd.Next(templates.Length);

            DBMobTemplate template      = templates[mobNumber];
            NPCController npcController = new NPCController();
            Character     mobCharacter  = NonPlayerCharacterHandler.SpawnMobFromTemplate(
                template.Hash,
                character.Playfield.Identity,
                character.Coordinates(),
                character.RawHeading,
                npcController);

            mobCharacter.Playfield = character.Playfield;
            SimpleCharFullUpdateMessage mess = SimpleCharFullUpdate.ConstructMessage(mobCharacter);

            character.Playfield.Announce(mess);
            AppearanceUpdateMessageHandler.Default.Send(mobCharacter);

            Vector3 v = new Vector3(coord.x, coord.y, coord.z + 5);

            mobCharacter.AddWaypoint(v, false);
            v.x += 10 - rnd.Next(20);
            v.z -= 10 - rnd.Next(20);

            mobCharacter.AddWaypoint(v, false);
            v.x += 10 - rnd.Next(20);
            v.z -= 10 - rnd.Next(20);
            mobCharacter.AddWaypoint(v, false);
            v.x += 10 - rnd.Next(20);
            v.z -= 10 - rnd.Next(20);
            mobCharacter.AddWaypoint(v, false);
            mobCharacter.Stats[StatIds.health].Value = 10000;
            mobCharacter.DoNotDoTimers = false;
        }
        public override bool Execute(
            INamedEntity self,
            IEntity caller,
            IInstancedEntity target,
            MessagePackObject[] arguments)
        {
            uint externalDoorInstance = self.Stats[StatIds.externaldoorinstance].BaseValue;
            int  externalPlayfieldId  = self.Stats[StatIds.externalplayfieldinstance].Value;

            StatelData door =
                PlayfieldLoader.PFData[externalPlayfieldId].Statels.FirstOrDefault(
                    x =>
                    (uint)x.Identity.Instance == externalDoorInstance &&
                    (x.Identity.Type == IdentityType.Door /*|| x.Identity.Type==IdentityType.MissionEntrance*/));

            if (door != null)
            {
                Vector3 v = new Vector3(door.X, door.Y, door.Z);

                Quaternion q = new Quaternion(door.HeadingX, door.HeadingY, door.HeadingZ, door.HeadingW);

                Quaternion.Normalize(q);
                Vector3 n = (Vector3)q.RotateVector3(Vector3.AxisZ);

                v.x += n.x * 2.5;
                v.z += n.z * 2.5;
                self.Playfield.Teleport(
                    (Dynel)self,
                    new Coordinate(v),
                    q,
                    new Identity()
                {
                    Type = IdentityType.Playfield, Instance = externalPlayfieldId
                });
            }
            return(door != null);
        }
Пример #10
0
        public void StartPatrolling()
        {
            Waypoint next = this.FindNextWaypoint();

            // If a suitable waypoint is found
            if (next != null)
            {
                if (next.Running)
                {
                    this.Run();
                }
                else
                {
                    this.Walk();
                }
                this.followCoordinates = next.Position;
                Vector3 temp = this.Character.Coordinates().coordinate - next.Position;
                temp.y = 0;
                this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(temp).Normalize();
                LogUtil.Debug(DebugInfoDetail.Movement, "Direction: " + this.Character.Heading.ToString());
                FollowTargetMessageHandler.Default.Send(
                    this.Character,
                    this.Character.Coordinates().coordinate,
                    next.Position);
                this.StartMovement();
                LogUtil.Debug(DebugInfoDetail.Movement, "Walking to: " + this.followCoordinates);
            }
        }
Пример #11
0
        public void MoveTo(SmokeLounge.AOtomation.Messaging.GameData.Vector3 destination)
        {
            FollowTargetMessageHandler.Default.Send(this.Character, this.Character.RawCoordinates, destination);
            Vector3 dest = destination;
            Vector3 start = this.Character.RawCoordinates;
            dest = start - dest;
            dest = dest.Normalize();
            this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(dest);
            this.Run();

            Coordinate c = new Coordinate(destination);
            this.followCoordinates = c.coordinate;
            /*bool arrived = false;
            double lastDistance = double.MaxValue;
            while (!arrived)
            {
                Coordinate temp = this.Character.Coordinates;
                double distance = this.Character.Coordinates.Distance2D(c);
                arrived = (distance < 0.2f) || (lastDistance < distance);
                lastDistance = distance;
                // LogUtil.Debug(DebugInfoDetail.Movement,"Moving...");
                Thread.Sleep(100);
            }
            LogUtil.Debug(DebugInfoDetail.Movement, "Arrived at "+this.Character.Coordinates.ToString());
            this.StopMovement();*/
        }
Пример #12
0
        public void DoFollow()
        {
            Coordinate sourceCoord = this.Character.Coordinates();
            Vector3 targetPosition = this.followCoordinates;
            if (!this.followIdentity.Equals(Identity.None))
            {
                ICharacter targetChar = Pool.Instance.GetObject<ICharacter>(
                    this.Character.Playfield.Identity,
                    this.followIdentity);
                if (targetChar == null)
                {
                    // If target does not longer exist (death or zone or logoff) then stop following
                    this.followIdentity = Identity.None;
                    this.followCoordinates = new Vector3();
                    return;
                }

                targetPosition = targetChar.Coordinates().coordinate;
            }

            // Do we have coordinates to follow?
            if (targetPosition.Distance2D(new Vector3()) < 0.01f)
            {
                return;
            }

            // /!\ If target flies away, there has to be some kind of adjustment
            Vector3 start = sourceCoord.coordinate;
            Vector3 dest = targetPosition;

            // Check if we have arrived
            if (start.Distance2D(dest) < 0.3f)
            {
                this.StopMovement();
                this.Character.RawCoordinates = dest;
                FollowTargetMessageHandler.Default.Send(this.Character, dest);
                this.followCoordinates = new Vector3();
                return;
            }

            LogUtil.Debug(DebugInfoDetail.Movement, "Distance to target: " + start.Distance2D(dest).ToString());

            // If target moved or first call, then issue a new follow
            if (targetPosition.Distance2D(this.followCoordinates) > 2.0f)
            {
                this.StopMovement();
                this.Character.Coordinates(start);
                FollowTargetMessageHandler.Default.Send(this.Character, start);
                Vector3 temp = start - dest;
                temp.y = 0;
                this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(temp);
                this.followCoordinates = dest;
                FollowTargetMessageHandler.Default.Send(this.Character, start, dest);
                this.StartMovement();
            }
        }
Пример #13
0
        public void SpawnRandomMob(ICharacter character)
        {
            Coordinate coord = character.Coordinates();

            DBMobTemplate[] templates = MobTemplateDao.Instance.GetAll().ToArray();
            Random rnd = new Random(Environment.TickCount);

            int mobNumber = rnd.Next(templates.Length);

            DBMobTemplate template = templates[mobNumber];
            NPCController npcController = new NPCController();
            Character mobCharacter = NonPlayerCharacterHandler.SpawnMobFromTemplate(
                template.Hash,
                character.Playfield.Identity,
                character.Coordinates(),
                character.RawHeading,
                npcController);
            mobCharacter.Playfield = character.Playfield;
            SimpleCharFullUpdateMessage mess = SimpleCharFullUpdate.ConstructMessage(mobCharacter);
            character.Playfield.Announce(mess);
            AppearanceUpdateMessageHandler.Default.Send(mobCharacter);

            Vector3 v = new Vector3(coord.x, coord.y, coord.z + 5);
            mobCharacter.AddWaypoint(v, false);
            v.x += 10 - rnd.Next(20);
            v.z -= 10 - rnd.Next(20);

            mobCharacter.AddWaypoint(v, false);
            v.x += 10 - rnd.Next(20);
            v.z -= 10 - rnd.Next(20);
            mobCharacter.AddWaypoint(v, false);
            v.x += 10 - rnd.Next(20);
            v.z -= 10 - rnd.Next(20);
            mobCharacter.AddWaypoint(v, false);
            mobCharacter.Stats[StatIds.health].Value = 10000;
            mobCharacter.DoNotDoTimers = false;
        }
Пример #14
0
        internal Coordinate CalculatePredictedPosition()
        {
            if ((this.moveDirection == MoveDirections.None) && (this.strafeDirection == SpinOrStrafeDirections.None))
            {
                return(new Coordinate(this.RawCoordinates));
            }
            else if (this.spinDirection == SpinOrStrafeDirections.None)
            {
                Vector3 moveVector = this.CalculateMoveVector();

                moveVector = moveVector * this.PredictionDuration.TotalSeconds;

                /*this.RawCoordinates = new Vector3()
                 *                    {
                 *                        x = this.RawCoordinates.X + moveVector.x,
                 *                        y = this.RawCoordinates.Y + moveVector.y,
                 *                        z = this.RawCoordinates.Z + moveVector.z
                 *                    };
                 *
                 * this.PredictionTime = DateTime.UtcNow;*/
                Coordinate result =
                    new Coordinate(
                        new Vector3(
                            this.RawCoordinates.X + moveVector.x,
                            this.RawCoordinates.Y + moveVector.y,
                            this.RawCoordinates.Z + moveVector.z));
                LogUtil.Debug(
                    DebugInfoDetail.Movement,
                    moveVector.ToString().PadRight(40) + "/" + result.ToString() + "/");
                return(result);
            }
            else
            {
                Vector3 moveVector;
                Vector3 positionFromCentreOfTurningCircle;
                double  turnArcAngle;
                double  y;
                double  duration;

                duration = this.PredictionDuration.TotalSeconds;

                moveVector   = this.CalculateMoveVector();
                turnArcAngle = this.calculateTurnArcAngle();

                // This is calculated seperately as height is unaffected by turning
                y = this.RawCoordinates.Y + (moveVector.y * duration);

                if (this.spinDirection == SpinOrStrafeDirections.Left)
                {
                    positionFromCentreOfTurningCircle = new Vector3(moveVector.z, y, -moveVector.x);
                }
                else
                {
                    positionFromCentreOfTurningCircle = new Vector3(-moveVector.z, y, moveVector.x);
                }

                return
                    (new Coordinate(
                         new Vector3(this.RawCoordinates.X, this.RawCoordinates.Y, this.RawCoordinates.Z)
                         + (Vector3)
                         Quaternion.RotateVector3(
                             new Quaternion(Vector3.AxisY, turnArcAngle),
                             positionFromCentreOfTurningCircle) - positionFromCentreOfTurningCircle));
            }
        }
Пример #15
0
 public void AddWaypoint(Vector3 v, bool running)
 {
     this.Waypoints.Add(new Waypoint(new Vector3(v.x, v.y, v.z), running));
     if (this.Waypoints.Count > 1)
     {
         this.Controller.State = CharacterState.Patrolling;
     }
 }
Пример #16
0
 public void StopFollow()
 {
     this.followIdentity = Identity.None;
     lock (this.followCoordinates)
     {
         this.followCoordinates = new Vector3();
     }
 }
Пример #17
0
 public Waypoint(Vector3 position, bool running)
 {
     this.Running = running;
     this.Position = position;
 }
Пример #18
0
        internal Coordinate CalculatePredictedPosition()
        {
            if ((this.moveDirection == MoveDirections.None) && (this.strafeDirection == SpinOrStrafeDirections.None))
            {
                return new Coordinate(this.RawCoordinates);
            }
            else if (this.spinDirection == SpinOrStrafeDirections.None)
            {
                Vector3 moveVector = this.CalculateMoveVector();

                moveVector = moveVector * this.PredictionDuration.TotalSeconds;

                /*this.RawCoordinates = new Vector3()
                                      {
                                          x = this.RawCoordinates.X + moveVector.x,
                                          y = this.RawCoordinates.Y + moveVector.y,
                                          z = this.RawCoordinates.Z + moveVector.z
                                      };

                this.PredictionTime = DateTime.UtcNow;*/
                Coordinate result =
                    new Coordinate(
                        new Vector3(
                            this.RawCoordinates.X + moveVector.x,
                            this.RawCoordinates.Y + moveVector.y,
                            this.RawCoordinates.Z + moveVector.z));
                LogUtil.Debug(
                    DebugInfoDetail.Movement,
                    moveVector.ToString().PadRight(40) + "/" + result.ToString() + "/");
                return result;
            }
            else
            {
                Vector3 moveVector;
                Vector3 positionFromCentreOfTurningCircle;
                double turnArcAngle;
                double y;
                double duration;

                duration = this.PredictionDuration.TotalSeconds;

                moveVector = this.CalculateMoveVector();
                turnArcAngle = this.calculateTurnArcAngle();

                // This is calculated seperately as height is unaffected by turning
                y = this.RawCoordinates.Y + (moveVector.y * duration);

                if (this.spinDirection == SpinOrStrafeDirections.Left)
                {
                    positionFromCentreOfTurningCircle = new Vector3(moveVector.z, y, -moveVector.x);
                }
                else
                {
                    positionFromCentreOfTurningCircle = new Vector3(-moveVector.z, y, moveVector.x);
                }

                return
                    new Coordinate(
                        new Vector3(this.RawCoordinates.X, this.RawCoordinates.Y, this.RawCoordinates.Z)
                        + (Vector3)
                            Quaternion.RotateVector3(
                                new Quaternion(Vector3.AxisY, turnArcAngle),
                                positionFromCentreOfTurningCircle) - positionFromCentreOfTurningCircle);
            }
        }
Пример #19
0
 public override void Coordinates(Vector3 position)
 {
     this.RawCoordinates = position;
     LogUtil.Debug(DebugInfoDetail.Movement, "Coord Set at: " + position.ToString());
     this.PredictionTime = DateTime.UtcNow;
 }
        public override bool Execute(
            INamedEntity self,
            IEntity caller,
            IInstancedEntity target,
            MessagePackObject[] arguments)
        {
            ICharacter character = (ICharacter)self;

            int statelId = (int)((uint)0xC0000000 | arguments[1].AsInt32() | (arguments[2].AsInt32() << 16));
            character.Stats[StatIds.externaldoorinstance].BaseValue = 0;
            character.Stats[StatIds.externalplayfieldinstance].BaseValue = 0;

            if (arguments[1].AsInt32() > 0)
            {
                StatelData sd = PlayfieldLoader.PFData[arguments[1].AsInt32()].GetDoor(statelId);
                if (sd == null)
                {
                    throw new Exception(
                        "Statel " + arguments[3].AsInt32().ToString("X") + " not found? Check the rdb dammit");
                }

                Vector3 v = new Vector3(sd.X, sd.Y, sd.Z);

                Quaternion q = new Quaternion(sd.HeadingX, sd.HeadingY, sd.HeadingZ, sd.HeadingW);

                Quaternion.Normalize(q);
                Vector3 n = (Vector3)q.RotateVector3(Vector3.AxisZ);

                v.x += n.x * 2.5;
                v.z += n.z * 2.5;
                character.Playfield.Teleport(
                    (Dynel)character,
                    new Coordinate(v),
                    q,
                    new Identity() { Type = (IdentityType)arguments[0].AsInt32(), Instance = arguments[1].AsInt32() });
            }

            return true;

            self.Stats[StatIds.externalplayfieldinstance].Value = 0;
            self.Stats[StatIds.externaldoorinstance].Value = 0;
            self.Playfield.Teleport(
                (Dynel)self,
                new Coordinate(100, 10, 100),
                ((ICharacter)self).Heading,
                new Identity() { Type = (IdentityType)arguments[0].AsInt32(), Instance = arguments[1].AsInt32() });
            return true;
        }
Пример #21
0
 public override void Coordinates(Vector3 position)
 {
     this.RawCoordinates = position;
     LogUtil.Debug(DebugInfoDetail.Movement, "Coord Set at: " + position.ToString());
     this.PredictionTime = DateTime.UtcNow;
 }
        public override bool Execute(
            INamedEntity self,
            IEntity caller,
            IInstancedEntity target,
            MessagePackObject[] arguments)
        {
            uint externalDoorInstance = self.Stats[StatIds.externaldoorinstance].BaseValue;
            int externalPlayfieldId = self.Stats[StatIds.externalplayfieldinstance].Value;

            StatelData door =
                PlayfieldLoader.PFData[externalPlayfieldId].Statels.FirstOrDefault(
                    x =>
                        (uint)x.Identity.Instance == externalDoorInstance
                        && (x.Identity.Type == IdentityType.Door /*|| x.Identity.Type==IdentityType.MissionEntrance*/));
            if (door != null)
            {
                Vector3 v = new Vector3(door.X, door.Y, door.Z);

                Quaternion q = new Quaternion(door.HeadingX, door.HeadingY, door.HeadingZ, door.HeadingW);

                Quaternion.Normalize(q);
                Vector3 n = (Vector3)q.RotateVector3(Vector3.AxisZ);

                v.x += n.x * 2.5;
                v.z += n.z * 2.5;
                self.Playfield.Teleport(
                    (Dynel)self,
                    new Coordinate(v),
                    q,
                    new Identity() { Type = IdentityType.Playfield, Instance = externalPlayfieldId });
            }
            return door != null;
        }