public void TestUnattachedFollowingBehaviorCanNotTrackTargets() { var followingBehavior = new FollowingBehavior(); followingBehavior.Target = this.victim1; Assert.AreEqual(null, followingBehavior.Target); }
public void TestFollowingMessages() { this.ClearTrackedEvents(); var followingBehavior = new FollowingBehavior(); this.stalker1.Behaviors.Add(followingBehavior); followingBehavior.Target = this.victim1; string witnessMessage = this.lastWitnessEvent.SensoryMessage.Message.Parse(this.witness); Verify.IsTrue(string.IsNullOrEmpty(witnessMessage)); string stalkerMessage = this.lastStalkerEvent.SensoryMessage.Message.Parse(this.stalker1); Verify.IsTrue(stalkerMessage.Contains("You start following ")); string victimMessage = this.lastVictimEvent.SensoryMessage.Message.Parse(this.victim1); Verify.IsTrue(victimMessage.Contains(" starts following you.")); followingBehavior.Target = null; witnessMessage = this.lastWitnessEvent.SensoryMessage.Message.Parse(this.witness); Verify.IsTrue(string.IsNullOrEmpty(witnessMessage)); stalkerMessage = this.lastStalkerEvent.SensoryMessage.Message.Parse(this.stalker1); Verify.IsTrue(stalkerMessage.Contains("You stop following ")); victimMessage = this.lastVictimEvent.SensoryMessage.Message.Parse(this.victim1); Verify.IsTrue(victimMessage.Contains(" stops following you.")); }
public void TestFollowingMessages() { this.ClearTrackedEvents(); var followingBehavior = new FollowingBehavior(); this.stalker1.Behaviors.Add(followingBehavior); Assert.AreEqual(this.lastWitnessEvent, null); Assert.AreEqual(this.lastStalkerEvent, null); Assert.AreEqual(this.lastVictimEvent, null); followingBehavior.Target = this.victim1; var witnessMessage = this.lastWitnessEvent.SensoryMessage.Message.Parse(this.witness); var stalkerMessage = this.lastStalkerEvent.SensoryMessage.Message.Parse(this.stalker1); var victimMessage = this.lastVictimEvent.SensoryMessage.Message.Parse(this.victim1); Assert.AreEqual(witnessMessage, "Stalker1 starts following Victim1."); Assert.AreEqual(stalkerMessage, "You start following Victim1."); Assert.AreEqual(victimMessage, "Stalker1 starts following you."); followingBehavior.Target = null; witnessMessage = this.lastWitnessEvent.SensoryMessage.Message.Parse(this.witness); stalkerMessage = this.lastStalkerEvent.SensoryMessage.Message.Parse(this.stalker1); victimMessage = this.lastVictimEvent.SensoryMessage.Message.Parse(this.victim1); Assert.IsTrue(string.IsNullOrEmpty(witnessMessage)); Assert.AreEqual(stalkerMessage, "You stop following Victim1."); Assert.AreEqual(victimMessage, "Stalker1 stops following you."); }
public void TestFollowingBehaviorStartsOutNull() { this.ClearTrackedEvents(); var followingBehavior = new FollowingBehavior(); this.stalker1.Behaviors.Add(followingBehavior); Verify.IsNull(followingBehavior.Target); }
public void TestFollowingBehaviorStartsOutNull() { ClearTrackedEvents(); var followingBehavior = new FollowingBehavior(); stalker1.Behaviors.Add(followingBehavior); Assert.IsNull(followingBehavior.Target); }
public void TestSettingTarget() { this.ClearTrackedEvents(); var followingBehavior = new FollowingBehavior(); this.stalker1.Behaviors.Add(followingBehavior); followingBehavior.Target = this.victim1; Verify.IsNotNull(followingBehavior.Target); Verify.AreEqual(followingBehavior.Target, this.victim1); }
public void TestSettingTarget() { ClearTrackedEvents(); var followingBehavior = new FollowingBehavior(); stalker1.Behaviors.Add(followingBehavior); followingBehavior.Target = victim1; Assert.IsNotNull(followingBehavior.Target); Assert.AreEqual(followingBehavior.Target, victim1); }
public void TestUnattachedFollowingBehavior() { var followingBehavior = new FollowingBehavior(); var initialState = followingBehavior.Target; followingBehavior.Target = this.victim1; Verify.Equals(this.victim1, followingBehavior.Target); followingBehavior.Target = null; Verify.Equals(initialState, followingBehavior.Target); }
public override void Initialize() { base.Initialize(); Body.Mass = 65f; followingBehaviour = GetComponent <FollowingBehavior <BoarState> >(); fleeingBehaviour = GetComponentByName <FleeingBehavior <BoarState> >("fleeing"); hitBehaviour = GetComponentByName <HitBehavior <BoarState> >("beinghit"); aiComponent.WithTrigger(FleeingTrigger).WithTrigger(FollowingTrigger); }
/// <summary>Executes the command.</summary> /// <param name="actionInput">The full input specified for executing the command.</param> public override void Execute(ActionInput actionInput) { IController sender = actionInput.Controller; var self = sender.Thing; if (actionInput.Params.Length == 0) { this.ShowStatus(actionInput); return; } // Check for existing FollowedBehavior on the target and create one if necessary. // Then add the sender to the list of followers. var targetBehaviors = this.target.Behaviors; var followedBehavior = targetBehaviors.FindFirst <FollowedBehavior>(); if (followedBehavior == null) { followedBehavior = new FollowedBehavior(); targetBehaviors.Add(followedBehavior); } followedBehavior.Followers.Add(self); // Check for existing FollowingBehavior on the sender and create one if necessary. // Then mark the target as the Thing being followed. var senderBehaviors = self.Behaviors; var followingBehavior = senderBehaviors.FindFirst <FollowingBehavior>(); if (followingBehavior == null) { followingBehavior = new FollowingBehavior(); senderBehaviors.Add(followingBehavior); } else if (followingBehavior.Target != null) { var oldTarget = followingBehavior.Target; var oldTargetFollowedBehavior = oldTarget.Behaviors.FindFirst <FollowedBehavior>(); if (oldTargetFollowedBehavior != null) { oldTargetFollowedBehavior.Followers.Remove(self); if (oldTargetFollowedBehavior.Followers.Count == 0) { oldTarget.Behaviors.Remove(oldTargetFollowedBehavior); } } } followingBehavior.Target = this.target; }
public override void Initialize() { base.Initialize(); Body.Mass = 3f; cohesionBehaviour = GetComponent <CohesionBehavior <ChickenState> >(); separationBehaviour = GetComponent <SeparationBehavior <ChickenState> >(); velocityBehaviour = GetComponent <VelocityMatchBehavior <ChickenState> >(); followingBehaviour = GetComponent <FollowingBehavior <ChickenState> >(); fleeingBehaviour = GetComponent <FleeingBehavior <ChickenState> >(); playerFleeingBehavior = GetComponent <PlayerFleeingBehavior <ChickenState> >(); aiComponent.WithTrigger(FleeingTrigger).WithTrigger(FollowingTrigger).WithTrigger(PlayerFleeingTrigger); cohesionBehaviour.TargetPositions = proximitySensor.SensedEntities.Select((e) => e.Body.Position); separationBehaviour.TargetPositions = proximitySensor.SensedEntities.Select((e) => e.Body.Position); velocityBehaviour.TargetVelocities = proximitySensor.SensedEntities.Select((e) => e.Body.LinearVelocity); }
public void TestRemovingTarget() { this.ClearTrackedEvents(); Verify.IsNull(this.lastStalkerRequest); Verify.IsNull(this.lastStalkerEvent); Verify.IsNull(this.lastVictimRequest); Verify.IsNull(this.lastVictimEvent); var followingBehavior = new FollowingBehavior(); this.stalker1.Behaviors.Add(followingBehavior); followingBehavior.Target = this.victim1; followingBehavior.Target = null; Verify.IsNull(followingBehavior.Target); Verify.IsNotNull(this.lastStalkerRequest); Verify.IsNotNull(this.lastStalkerEvent); Verify.IsNotNull(this.lastVictimRequest); Verify.IsNotNull(this.lastVictimEvent); }
public void TestRemovingTarget() { ClearTrackedEvents(); Assert.IsNull(lastStalkerRequest); Assert.IsNull(lastStalkerEvent); Assert.IsNull(lastVictimRequest); Assert.IsNull(lastVictimEvent); var followingBehavior = new FollowingBehavior(); stalker1.Behaviors.Add(followingBehavior); followingBehavior.Target = victim1; followingBehavior.Target = null; Assert.IsNull(followingBehavior.Target); Assert.IsNotNull(lastStalkerRequest); Assert.IsNotNull(lastStalkerEvent); Assert.IsNotNull(lastVictimRequest); Assert.IsNotNull(lastVictimEvent); }