Exemplo n.º 1
0
        private bool InnerCheckOnTarget(bool findNew, FindTargetMethod method)
        {
            // If not allowed in our group, ignore
            if (!IsAllowedInGroup) { return false; }

            // If not friend, warn and bail
            if (state == CritterState.NotFriend)
            {
                Log.Warn("Attempted to check on target with critter that is not a friend.");
                return false;
            }

            // If there is a target, check to see if it's alive and has health
            if (target != null)
            {
                // Is target still alive?
                if ((!target.IsAlive) || (target.Health <= 0))
                {
                    // Target has died and is no longer needed
                    Log.Debug("Target has died");
                    target.MarkAsNoLongerNeeded();
                    target = null;
                }
            }

            // If don't have a target now, see if we should try and find one
            if (target == null)
            {
                // Try to find a new one?
                if (findNew)
                {
                    // Yes, try to find a new one
                    FindTarget(method, true);
                }
            }

            // What time is it?
            var now = DateTime.Now;

            // If we have a target, see if we need to do a refresh attack
            if (target != null)
            {
                if ((now - lastAttackTime) > REFRESH_ATTACK)
                {
                    Log.Debug("Refresh Attack");
                    lastAttackTime = now;
                    AttackTarget();
                }
            }
            // If we don't have a target, see if we need to do a refresh follow
            else
            {
                if ((now - lastFollowTime) > REFRESH_FOLLOW)
                {
                    Log.Debug("Refresh Follow");
                    lastFollowTime = now;
                    Follow();
                }
            }

            // This method returns true if it completed with a valid target
            return (target != null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds a target
        /// </summary>
        /// <param name="method">
        /// The method for finding the target.
        /// </param>
        /// <param name="replaceExisting">
        /// <c>true</c> if any current target should be abandoned; otherwise <c>false</c>.
        /// </param>
        /// <returns>
        /// <c>true</c> if critter ends up with a valid target.
        /// </returns>
        public bool FindTarget(FindTargetMethod method, bool replaceExisting = false)
        {
            // If not replacing and already have one, ignore
            if ((!replaceExisting) && (target != null)) { return true; }

            Log.Debug(string.Format("Searching for new target using {0}", method));

            // Shortcut to player
            var player = Game.Player.Character;

            // Placeholder
            Ped[] peds = null;

            // Which method?
            switch (method)
            {
                case FindTargetMethod.CombatingPlayer:
                    // Get peds close to critter
                    peds = World.GetNearbyPeds(critterPed, SEARCH_RANGE, SEARCH_COUNT);

                    // Find first targeting player
                    Target = peds.Where(p => p.IsInCombatWith(player)).FirstOrDefault();
                    break;

                case FindTargetMethod.PlayerIsTargeting:
                    // Whatever the player is targeting
                    Target = Game.Player.GetTargetedEntity() as Ped;
                    break;

                case FindTargetMethod.HatesPlayer:
                    // Get peds close to critter
                    peds = World.GetNearbyPeds(critterPed, SEARCH_RANGE, SEARCH_COUNT);

                    // Find first that hates player
                    Target = peds.Where(p => p.GetRelationshipWithPed(player) == Relationship.Hate).FirstOrDefault();
                    break;

                case FindTargetMethod.ClosestPlayer:
                    // Get peds close to critter
                    peds = World.GetNearbyPeds(critterPed, SEARCH_RANGE, SEARCH_COUNT);

                    // Find first that doesn't respect the player (friend) and isn't a bird (since we don't let them join the group)
                    Target = peds.Where(p => (p.GetRelationshipWithPed(player) != Relationship.Respect) && (p.Model.GetAnimalClass() != Critters.AnimalClass.Flying)).FirstOrDefault();
                    break;
                default:
                    Log.Debug(string.Format("Unknown Target Method {0}", method));
                    Target = null;
                    break;
            }

            // Did we find a target?
            bool found = (target != null);
            if (found)
            {
                Log.Debug("Critter found a target");
            }
            else
            {
                Log.Debug("Critter could not find a target");
            }
            return found;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Checks to see if the critter has a live target and attempts to find a new one if not.
 /// </summary>
 /// <returns>
 /// <c>true</c> if the critter has an existing valid target or found a new one; otherwise <c>false</c>.
 /// </returns>
 public bool CheckOnTarget(FindTargetMethod findNewMethod)
 {
     return InnerCheckOnTarget(true, findNewMethod);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Finds a target
        /// </summary>
        /// <param name="method">
        /// The method for finding the target.
        /// </param>
        /// <param name="replaceExisting">
        /// <c>true</c> if any current target should be abandoned; otherwise <c>false</c>.
        /// </param>
        /// <returns>
        /// <c>true</c> if critter ends up with a valid target.
        /// </returns>
        public bool FindTarget(FindTargetMethod method, bool replaceExisting = false)
        {
            // If not replacing and already have one, ignore
            if ((!replaceExisting) && (target != null))
            {
                return(true);
            }

            Log.Debug(string.Format("Searching for new target using {0}", method));

            // Shortcut to player
            var player = Game.Player.Character;

            // Placeholder
            Ped[] peds = null;

            // Which method?
            switch (method)
            {
            case FindTargetMethod.CombatingPlayer:
                // Get peds close to critter
                peds = World.GetNearbyPeds(critterPed, SEARCH_RANGE, SEARCH_COUNT);

                // Find first targeting player
                Target = peds.Where(p => p.IsInCombatWith(player)).FirstOrDefault();
                break;

            case FindTargetMethod.PlayerIsTargeting:
                // Whatever the player is targeting
                Target = Game.Player.GetTargetedEntity() as Ped;
                break;

            case FindTargetMethod.HatesPlayer:
                // Get peds close to critter
                peds = World.GetNearbyPeds(critterPed, SEARCH_RANGE, SEARCH_COUNT);

                // Find first that hates player
                Target = peds.Where(p => p.GetRelationshipWithPed(player) == Relationship.Hate).FirstOrDefault();
                break;

            case FindTargetMethod.ClosestPlayer:
                // Get peds close to critter
                peds = World.GetNearbyPeds(critterPed, SEARCH_RANGE, SEARCH_COUNT);

                // Find first that doesn't respect the player (friend) and isn't a bird (since we don't let them join the group)
                Target = peds.Where(p => (p.GetRelationshipWithPed(player) != Relationship.Respect) && (p.Model.GetAnimalClass() != Critters.AnimalClass.Flying)).FirstOrDefault();
                break;

            default:
                Log.Debug(string.Format("Unknown Target Method {0}", method));
                Target = null;
                break;
            }

            // Did we find a target?
            bool found = (target != null);

            if (found)
            {
                Log.Debug("Critter found a target");
            }
            else
            {
                Log.Debug("Critter could not find a target");
            }
            return(found);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Checks to see if the critter has a live target and attempts to find a new one if not.
 /// </summary>
 /// <returns>
 /// <c>true</c> if the critter has an existing valid target or found a new one; otherwise <c>false</c>.
 /// </returns>
 public bool CheckOnTarget(FindTargetMethod findNewMethod)
 {
     return(InnerCheckOnTarget(true, findNewMethod));
 }
Exemplo n.º 6
0
        private bool InnerCheckOnTarget(bool findNew, FindTargetMethod method)
        {
            // If not allowed in our group, ignore
            if (!IsAllowedInGroup)
            {
                return(false);
            }

            // If not friend, warn and bail
            if (state == CritterState.NotFriend)
            {
                Log.Warn("Attempted to check on target with critter that is not a friend.");
                return(false);
            }

            // If there is a target, check to see if it's alive and has health
            if (target != null)
            {
                // Is target still alive?
                if ((!target.IsAlive) || (target.Health <= 0))
                {
                    // Target has died and is no longer needed
                    Log.Debug("Target has died");
                    target.MarkAsNoLongerNeeded();
                    target = null;
                }
            }

            // If don't have a target now, see if we should try and find one
            if (target == null)
            {
                // Try to find a new one?
                if (findNew)
                {
                    // Yes, try to find a new one
                    FindTarget(method, true);
                }
            }

            // What time is it?
            var now = DateTime.Now;

            // If we have a target, see if we need to do a refresh attack
            if (target != null)
            {
                if ((now - lastAttackTime) > REFRESH_ATTACK)
                {
                    Log.Debug("Refresh Attack");
                    lastAttackTime = now;
                    AttackTarget();
                }
            }
            // If we don't have a target, see if we need to do a refresh follow
            else
            {
                if ((now - lastFollowTime) > REFRESH_FOLLOW)
                {
                    Log.Debug("Refresh Follow");
                    lastFollowTime = now;
                    Follow();
                }
            }

            // This method returns true if it completed with a valid target
            return(target != null);
        }