Example #1
0
        private void Follow()
        {
            // If not a friend, ignore
            if (state == CritterState.NotFriend)
            {
                return;
            }

            // Following
            if (state != CritterState.Following)
            {
                state = CritterState.Following;
                Log.Debug("Critter is now following");
            }

            //// Stop the critter from doing whatever it's doing
            //critterPed.Task.ClearAllImmediately();

            // Run to target
            critterPed.TaskHurryToEntity(Game.Player.Character);

            // Critter fights hated targets (but for animals they really just follow(
            critterPed.Task.FightAgainstHatedTargets(50000f);

            // Critter keeps doing above
            critterPed.AlwaysKeepTask = true;
        }
Example #2
0
        private void AttackTarget()
        {
            // If not a friend, ignore
            if (state == CritterState.NotFriend)
            {
                return;
            }

            // Attacking
            if (state != CritterState.Attacking)
            {
                state = CritterState.Attacking;
                Log.Debug("Critter is now attacking");
            }

            //// Stop the critter from doing whatever it's doing
            //critterPed.Task.ClearAllImmediately();

            // Make sure we still have a target
            if (target != null)
            {
                // Run to target
                critterPed.TaskHurryToEntity(target);

                // Critter fights specific target
                critterPed.Task.FightAgainst(target);

                // Critter never stops fighting
                critterPed.AlwaysKeepTask = true;
            }
        }
Example #3
0
        /// <summary>
        /// Unfriends the critter, causing him to leave the group
        /// </summary>
        public void Unfriend()
        {
            // If not a friend, ignore
            if (state == CritterState.NotFriend)
            {
                return;
            }

            // Set as no longer friend
            state = CritterState.NotFriend;

            // Remove from group
            critterPed.RemoveFromGroup();

            // Set back to original relationship
            critterPed.RelationshipGroup = originalRGroup;

            // Remove the target
            target = null;

            // Turn off blip
            if (critterPed.CurrentBlip != null)
            {
                critterPed.CurrentBlip.Remove();
            }

            // Reset the health
            critterPed.Health    = Math.Min(critterPed.Health, originalMaxHealth);
            critterPed.MaxHealth = originalMaxHealth;

            // Mark it as no longer needed
            critterPed.MarkAsNoLongerNeeded();
        }
Example #4
0
        void InternalTest(Vector origin, Vector dest)
        {
            var critterState = new CritterState
            {
                PositionX = origin.X,
                PositionY = origin.Y,
            };

            var instr = new MoveInstruction(dest.X, dest.Y);
            var ticks = 0;

            for (; ticks < 1000; ticks++)
            {
                var finished = instr.Tick(critterState) == false;
                var pos      = new Vector(critterState.PositionX, critterState.PositionY);
                Console.WriteLine($"pos: {pos}");

                if (finished)
                {
                    Assert.IsTrue(Vector.Distance(pos, dest) < MoveInstruction.StepLength);
                    break;
                }
                else
                {
                    Assert.AreNotEqual(pos, origin);
                    Assert.IsTrue(Vector.Distance(pos, dest) < Vector.Distance(origin, dest));
                }
            }

            Console.WriteLine($"finished after {ticks + 1} ticks");
            if (ticks >= 1000)
            {
                Assert.Fail("Too many ticks");
            }
        }
Example #5
0
        public void TestLoopInstruction()
        {
            var count1 = 0;
            var count2 = 0;

            var instructions = new List <Instruction>
            {
                new CustomInstruction(_ => ++ count1 % 10 != 0),
                new CustomInstruction(_ => ++ count2 % 15 != 0),
            };

            var loop         = new LoopInstruction(instructions, 10);
            var critterState = new CritterState();

            var count = 0;

            for (; count < 1000; count++)
            {
                if (loop.Tick(critterState) == false)
                {
                    break;
                }
            }

            if (count >= 1000)
            {
                Assert.Fail("Too many ticks");
            }

            Assert.AreEqual(100, count1);
            Assert.AreEqual(150, count2);
        }
Example #6
0
        private void Follow()
        {
            // If not a friend, ignore
            if (state == CritterState.NotFriend) { return; }

            // Following
            if (state != CritterState.Following)
            {
                state = CritterState.Following;
                Log.Debug("Critter is now following");
            }

            //// Stop the critter from doing whatever it's doing
            //critterPed.Task.ClearAllImmediately();

            // Run to target
            critterPed.TaskHurryToEntity(Game.Player.Character);

            // Critter fights hated targets (but for animals they really just follow(
            critterPed.Task.FightAgainstHatedTargets(50000f);

            // Critter keeps doing above
            critterPed.AlwaysKeepTask = true;
        }
Example #7
0
        private void AttackTarget()
        {
            // If not a friend, ignore
            if (state == CritterState.NotFriend) { return; }

            // Attacking
            if (state != CritterState.Attacking)
            {
                state = CritterState.Attacking;
                Log.Debug("Critter is now attacking");
            }

            //// Stop the critter from doing whatever it's doing
            //critterPed.Task.ClearAllImmediately();

            // Make sure we still have a target
            if (target != null)
            {
                // Run to target
                critterPed.TaskHurryToEntity(target);

                // Critter fights specific target
                critterPed.Task.FightAgainst(target);

                // Critter never stops fighting
                critterPed.AlwaysKeepTask = true;
            }
        }
Example #8
0
        /// <summary>
        /// Unfriends the critter, causing him to leave the group
        /// </summary>
        public void Unfriend()
        {
            // If not a friend, ignore
            if (state == CritterState.NotFriend) { return; }

            // Set as no longer friend
            state = CritterState.NotFriend;

            // Remove from group
            critterPed.RemoveFromGroup();

            // Set back to original relationship
            critterPed.RelationshipGroup = originalRGroup;

            // Remove the target
            target = null;

            // Turn off blip
            if (critterPed.CurrentBlip != null)
            {
                critterPed.CurrentBlip.Remove();
            }

            // Reset the health
            critterPed.Health = Math.Min(critterPed.Health, originalMaxHealth);
            critterPed.MaxHealth = originalMaxHealth;

            // Mark it as no longer needed
            critterPed.MarkAsNoLongerNeeded();
        }
Example #9
0
        /// <summary>
        /// Befriend the critter.
        /// </summary>
        /// <param name="group">
        /// The group the critter should join.
        /// </param>
        /// <param name="relationshipGroup">
        /// The relationship group the critter should join.
        /// </param>
        public void Befriend(int group, int relationshipGroup)
        {
            // Only proceed if not already a friend
            if (state != CritterState.NotFriend) { return; }

            // Now it's a friend
            state = CritterState.Following;

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

            // Turn on friendly blip
            if (critterPed.CurrentBlip == null)
            {
                critterPed.AddBlip();
            }
            critterPed.CurrentBlip.IsFriendly = true;
            critterPed.CurrentBlip.Scale = 0.7f;

            // Warn for unknown animal, otherwise notify what's found
            if (animalClass != AnimalClass.Unknown)
            {
                Log.Info(string.Format("Found {0}", animalName));
            }
            #if DEBUG
            else
            {
                Log.Debug(string.Format("Unknown Animal: {0}", critterPed.Model));
                critterPed.CurrentBlip.IsFlashing = true;
            }
            #endif

            // Make the critter run (or fly) to the player
            critterPed.TaskHurryToEntity(player);

            // If the critter is not allowed in our group, we're done
            if (!IsAllowedInGroup) { return; }

            // Give the critter super health
            critterPed.MaxHealth = SUPER_HEALTH;
            critterPed.Health = SUPER_HEALTH;

            // Set the critter into the relationship group
            critterPed.RelationshipGroup = relationshipGroup;

            // Set the critter into the group?
            if (group != 0)
            {
                critterPed.SetAsGroupMember(group);
            }

            // Make sure the critter will never leave the group (unless told to do so)
            critterPed.SetNeverLeavesGroup(true);

            // Allow switch weapons (and fight?)
            critterPed.CanSwitchWeapons = true;

            // Block non-temporary events
            Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, critterPed, true);

            // Critter never flees
            Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, critterPed, 0, 0);

            // Critter fights to the death
            Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, critterPed, 46, true);

            // Start following the player
            Follow();
        }
Example #10
0
        /// <summary>
        /// Befriend the critter.
        /// </summary>
        /// <param name="group">
        /// The group the critter should join.
        /// </param>
        /// <param name="relationshipGroup">
        /// The relationship group the critter should join.
        /// </param>
        public void Befriend(int group, int relationshipGroup)
        {
            // Only proceed if not already a friend
            if (state != CritterState.NotFriend)
            {
                return;
            }

            // Now it's a friend
            state = CritterState.Following;

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

            // Turn on friendly blip
            if (critterPed.CurrentBlip == null)
            {
                critterPed.AddBlip();
            }
            critterPed.CurrentBlip.IsFriendly = true;
            critterPed.CurrentBlip.Scale      = 0.7f;

            // Warn for unknown animal, otherwise notify what's found
            if (animalClass != AnimalClass.Unknown)
            {
                Log.Info(string.Format("Found {0}", animalName));
            }
                        #if DEBUG
            else
            {
                Log.Debug(string.Format("Unknown Animal: {0}", critterPed.Model));
                critterPed.CurrentBlip.IsFlashing = true;
            }
                        #endif

            // Make the critter run (or fly) to the player
            critterPed.TaskHurryToEntity(player);

            // If the critter is not allowed in our group, we're done
            if (!IsAllowedInGroup)
            {
                return;
            }

            // Give the critter super health
            critterPed.MaxHealth = SUPER_HEALTH;
            critterPed.Health    = SUPER_HEALTH;

            // Set the critter into the relationship group
            critterPed.RelationshipGroup = relationshipGroup;

            // Set the critter into the group?
            if (group != 0)
            {
                critterPed.SetAsGroupMember(group);
            }

            // Make sure the critter will never leave the group (unless told to do so)
            critterPed.SetNeverLeavesGroup(true);

            // Allow switch weapons (and fight?)
            critterPed.CanSwitchWeapons = true;

            // Block non-temporary events
            Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, critterPed, true);

            // Critter never flees
            Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, critterPed, 0, 0);

            // Critter fights to the death
            Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, critterPed, 46, true);

            // Start following the player
            Follow();
        }