public void Init() { // Create the basic actor instances and behavior for test. this.witness = new Thing() { Name = "Witness", ID = TestThingID.Generate("testthing") }; this.stalker1 = new Thing() { Name = "Stalker1", ID = TestThingID.Generate("testthing") }; this.stalker2 = new Thing() { Name = "Stalker2", ID = TestThingID.Generate("testthing") }; this.victim1 = new Thing() { Name = "Victim1", ID = TestThingID.Generate("testthing") }; this.victim2 = new Thing() { Name = "Victim2", ID = TestThingID.Generate("testthing") }; // Set up the rooms. this.room1 = new Thing() { Name = "Room", ID = TestThingID.Generate("room") }; this.room2 = new Thing() { Name = "Room 2", ID = TestThingID.Generate("room") }; // Set up an exit connecting the two rooms. this.exit = new Thing() { Name = "East Exit", ID = TestThingID.Generate("exit") }; var exitBehavior = new ExitBehavior(); ////exitBehavior.AddDestination("west", room1.ID); ////exitBehavior.AddDestination("east", room1.ID); ////this.exit.BehaviorManager.Add(exitBehavior); this.room1.Add(this.exit); this.room2.Add(this.exit); // Populate the first room. this.room1.Add(this.witness); this.room1.Add(this.stalker1); this.room1.Add(this.stalker2); this.room1.Add(this.victim1); this.room1.Add(this.victim2); // Prepare to verify correct eventing occurs. this.witness.Eventing.MovementRequest += (root, e) => { this.lastWitnessRequest = e; }; this.witness.Eventing.MovementEvent += (root, e) => { this.lastWitnessEvent = e; }; this.stalker1.Eventing.MovementRequest += (root, e) => { this.lastStalkerRequest = e; }; this.stalker1.Eventing.MovementEvent += (root, e) => { this.lastStalkerEvent = e; }; this.stalker2.Eventing.MovementRequest += (root, e) => { this.lastStalkerRequest = e; }; this.stalker2.Eventing.MovementEvent += (root, e) => { this.lastStalkerEvent = e; }; this.victim1.Eventing.MovementRequest += (root, e) => { this.lastVictimRequest = e; }; this.victim1.Eventing.MovementEvent += (root, e) => { this.lastVictimEvent = e; }; this.victim2.Eventing.MovementRequest += (root, e) => { this.lastVictimRequest = e; }; this.victim2.Eventing.MovementEvent += (root, e) => { this.lastVictimEvent = e; }; }
/// <summary>Initializes a new instance of the ExitBehaviorCommands class.</summary> /// <param name="exitBehavior">The ExitBehavior this class belongs to.</param> public ExitBehaviorCommands(ExitBehavior exitBehavior) : base() { this.exitBehavior = exitBehavior; }
/// <summary>Loads the exits for this room behavior.</summary> public void Load() { var roomRepository = new RelationalRepository <RoomRecord>(); // Standard exits are simple DB records, so we need to load them specifically for this room; // non-standard exits should be loaded just like any other generic Thing. // TODO: These should come as part of the world areas with the document repository, so that // exit Things could get customized with brand new Behaviors without difficulty, etc. string roomNumber = this.Parent.Id.Replace("room/", string.Empty); long persistedRoomID = long.Parse(roomNumber); ICollection <ExitRecord> exits = roomRepository.LoadExitsForRoom(persistedRoomID); foreach (var exitRecord in exits) { // Create a Thing to represent this exit, which can live in multiple places (IE rooms) // as a child of each parent - thus sharing substate (like for doors) will be automatic. var exitBehavior = new ExitBehavior() { ID = exitRecord.ID, }; var exit = new Thing(exitBehavior, new MultipleParentsBehavior()) { Name = "[StandardExit]", Id = "exit/" + exitRecord.ID, }; // Add the exit destinations. string exitRoomA = "room/" + exitRecord.ExitRoomAID.ToString(CultureInfo.InvariantCulture); string exitRoomB = "room/" + exitRecord.ExitRoomBID.ToString(CultureInfo.InvariantCulture); exitBehavior.AddDestination(exitRecord.DirectionA, exitRoomB); exitBehavior.AddDestination(exitRecord.DirectionB, exitRoomA); // Add this Exit Thing as a child of the Room Thing. this.Parent.Add(exit); // Look for the other room; if it exists, add this exit to that room too, else // set up an event reaction to add the exit to the room when it gets loaded. var otherRoom = ThingManager.Instance.FindThing(exitRoomB); if (otherRoom != null) { otherRoom.Add(exit); } else { lock (pendingExitRiggings) { pendingExitRiggings.Add(new PendingExitRigging() { RoomID = exitRoomB, ExitThing = exit, }); } } } // If this room is the secondary parent for a pending exit rigging, rig it up. lock (pendingExitRiggings) { var matchedExitRiggings = this.FindMatchedPendingExitRiggings(this.Parent.Id); foreach (var matchedExitRigging in matchedExitRiggings) { this.Parent.Add(matchedExitRigging.ExitThing); pendingExitRiggings.Remove(matchedExitRigging); } } }
public void TestOpeningClosingAndMovementForExits() { // Create two one-way exits and two rooms to attach them to. var openableExitA = new Thing() { Name = "OpenableExitA", ID = TestThingID.Generate("testthing") }; var openableExitB = new Thing() { Name = "OpenableExitB", ID = TestThingID.Generate("testthing") }; var roomA = new Thing(new RoomBehavior()) { Name = "Room A", ID = TestThingID.Generate("testroom") }; var roomB = new Thing(new RoomBehavior()) { Name = "Room B", ID = TestThingID.Generate("testroom") }; roomA.Add(openableExitA); roomB.Add(openableExitB); // Attach ExitBehavior and OpensClosesBehaviors in different orders though, to verify in test that // eventing and such work correctly regardless of attachment order. var exitBehaviorA = new ExitBehavior(); var exitBehaviorB = new ExitBehavior(); var opensClosesBehaviorB = new OpensClosesBehavior(); openableExitA.Behaviors.Add(exitBehaviorA); openableExitA.Behaviors.Add(this.opensClosesBehavior); openableExitB.Behaviors.Add(opensClosesBehaviorB); openableExitB.Behaviors.Add(exitBehaviorB); // Rig up behaviors so the actor can move, and move from one A to B, and from B to A. this.actingThing.Behaviors.Add(new MovableBehavior()); exitBehaviorA.AddDestination("toB", roomB.ID); exitBehaviorB.AddDestination("toA", roomA.ID); // Ensure that the actingThing cannot move through either exit while it is in default (closed) state. roomA.Add(this.actingThing); exitBehaviorA.MoveThrough(this.actingThing); Verify.AreSame(roomA, this.actingThing.Parent); roomB.Add(this.actingThing); exitBehaviorB.MoveThrough(this.actingThing); Verify.AreSame(roomB, this.actingThing.Parent); // Ensure that the actingThing can open and move through each openable exit to get between rooms. opensClosesBehaviorB.Open(this.actingThing); exitBehaviorB.MoveThrough(this.actingThing); Verify.AreSame(roomA, this.actingThing.Parent); this.opensClosesBehavior.Open(this.actingThing); exitBehaviorA.MoveThrough(this.actingThing); Verify.AreSame(roomB, this.actingThing.Parent); }
/// <summary> /// Initializes a new instance of the ExitBehaviorCommands class. /// </summary> /// <param name="exitBehavior">The ExitBehavior this class belongs to.</param> public ExitBehaviorCommands(ExitBehavior exitBehavior) : base() { this.exitBehavior = exitBehavior; }