Exemplo n.º 1
0
        /// <summary>
        /// Method to Initialise the Guards
        ///
        /// Here we create the instances of the guard
        /// We add to the local array of guards
        /// We assign a Guard ID which is the Patrol ID
        /// We assign the guards component
        /// </summary>
        public void InitialiseGuards()
        {
            Component.AbstractKeep.Patrols.Add(PatrolID, this);

            //need this here becuase it's checked in add to world
            PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component);

            int guardsOnPatrol = 1;

            if (Component != null && Component.AbstractKeep != null && Component.AbstractKeep is GameKeep)
            {
                guardsOnPatrol++;

                if (Component.AbstractKeep.Level > 4)
                {
                    guardsOnPatrol++;
                }
            }

            if (PatrolGuards.Count < guardsOnPatrol)
            {
                for (int i = 0; i < guardsOnPatrol; i++)
                {
                    CreatePatrolGuard(i);
                }
            }

            // tolakram - this might be redundant
            foreach (GameKeepGuard guard in PatrolGuards)
            {
                PositionMgr.LoadGuardPosition(SpawnPosition, guard);
            }

            ChangePatrolLevel();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to start a Patrol patroling
        /// It sets a patrol leader
        /// And starts moving on Patrol
        /// </summary>
        public void StartPatrol()
        {
            if (PatrolPath == null)
            {
                PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component);
            }

            foreach (GameKeepGuard guard in PatrolGuards)
            {
                if (guard.CurrentWayPoint == null)
                {
                    guard.CurrentWayPoint = PatrolPath;
                }

                guard.MoveOnPath(PATROL_SPEED);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method to Change a Patrol's Level
        ///
        /// This method handles the add and removing of guards
        /// </summary>
        public void ChangePatrolLevel()
        {
            int guardsToPatrol = 1;

            if (Component != null && Component.AbstractKeep != null && Component.AbstractKeep is GameKeep)
            {
                guardsToPatrol++;

                if (Component.AbstractKeep.Level > 4)
                {
                    guardsToPatrol++;
                }
            }

            PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component);

            // Console.WriteLine(PatrolID + " guardstopatrol = " + guardsToPatrol + ", count = " + PatrolGuards.Count);

            while (guardsToPatrol > PatrolGuards.Count)
            {
                CreatePatrolGuard(PatrolGuards.Count);
            }

            int x = 0;
            int y = 0;

            List <GameKeepGuard> guardsToKeep = new List <GameKeepGuard>();

            for (int i = 0; i < PatrolGuards.Count; i++)
            {
                GameKeepGuard guard = PatrolGuards[i] as GameKeepGuard;

                // Console.WriteLine(PatrolID + " loading guard " + guard.Name);

                if (i < guardsToPatrol)
                {
                    // we need to reposition the patrol at their spawn point plus variation
                    if (x == 0)
                    {
                        x = guard.SpawnPoint.X;
                        y = guard.SpawnPoint.Y;
                    }
                    else
                    {
                        x += Util.Random(250, 350);
                        y += Util.Random(250, 350);
                    }

                    if (guard.IsAlive)
                    {
                        if (guard.IsMovingOnPath)
                        {
                            guard.StopMovingOnPath();
                        }

                        guard.MoveTo(guard.CurrentRegionID, x, y, guard.SpawnPoint.Z, guard.SpawnHeading);
                    }

                    guardsToKeep.Add(guard);
                }
                else
                {
                    guard.Delete();
                }
            }

            PatrolGuards = guardsToKeep;

            StartPatrol();
        }