Пример #1
0
        public void Init()
        {
            var testBehavior     = new TalentsBehavior(null);
            var warriorAttribute = new WarriorAttribute();
            var rogueAttribute   = new RogueAttribute();
            var mageAttribute    = new MageAttribute();
            var damageStat       = new DamageStat();

            playerThing = new Thing()
            {
                Name = "PlayerThing", Id = TestThingID.Generate("testthing")
            };

            playerThing.Behaviors.Add(testBehavior);

            warriorAttribute.Parent = playerThing;
            playerThing.AddAttribute(warriorAttribute);

            mageAttribute.Parent = playerThing;
            playerThing.AddAttribute(rogueAttribute);

            rogueAttribute.Parent = playerThing;
            playerThing.AddAttribute(mageAttribute);

            warriorAttribute.SetValue(10, playerThing);
            rogueAttribute.SetValue(10, playerThing);
            mageAttribute.SetValue(10, playerThing);

            playerThing.Stats.Add(damageStat.Name, damageStat);
        }
Пример #2
0
 public void Init()
 {
     this.playerThing = new Thing()
     {
         Name = "PlayerThing", ID = TestThingID.Generate("testthing")
     };
 }
Пример #3
0
        public void Init()
        {
            // Create the basic actor instances and behavior for test.
            witnessThing = new Thing()
            {
                Name = "WitnessThing", Id = TestThingID.Generate("testthing")
            };
            actingThing = new Thing()
            {
                Name = "ActingThing", Id = TestThingID.Generate("testthing")
            };
            openableThing = new Thing()
            {
                Name = "OpenableThing", Id = TestThingID.Generate("testthing")
            };
            opensClosesBehavior = new OpensClosesBehavior();

            // Set up the actors inside another (which we'll call a "room" although it needn't actually be a room).
            room = new Thing()
            {
                Name = "Room", Id = TestThingID.Generate("room")
            };
            room.Add(witnessThing);
            room.Add(actingThing);
            room.Add(openableThing);

            // Prepare to verify correct eventing occurs.
            witnessThing.Eventing.MiscellaneousRequest += (root, e) => { lastWitnessRequest = e; };
            witnessThing.Eventing.MiscellaneousEvent   += (root, e) => { lastWitnessEvent = e; };
            actingThing.Eventing.MiscellaneousRequest  += (root, e) => { lastActorRequest = e; };
            actingThing.Eventing.MiscellaneousEvent    += (root, e) => { lastActorEvent = e; };
        }
Пример #4
0
        public void Init()
        {
            this.playerThing = new Thing()
            {
                Name = "PlayerThing", Id = TestThingID.Generate("testthing")
            };

            var testBehavior     = new TalentsBehavior(null);
            var warriorAttribute = new WarriorAttribute();
            var rogueAttribute   = new RogueAttribute();
            var mageAttribute    = new MageAttribute();
            var damageStat       = new DamageStat();
            var attackStat       = new AttackStat();
            var initiativeStat   = new InitiativeStat();
            var awarenessSkill   = new SkillAwareness();

            warriorAttribute.Parent = this.playerThing;
            this.playerThing.AddAttribute(warriorAttribute);

            mageAttribute.Parent = this.playerThing;
            this.playerThing.AddAttribute(rogueAttribute);

            rogueAttribute.Parent = this.playerThing;
            this.playerThing.AddAttribute(mageAttribute);

            warriorAttribute.SetValue(10, this.playerThing);
            rogueAttribute.SetValue(10, this.playerThing);
            mageAttribute.SetValue(10, this.playerThing);

            this.playerThing.Stats.Add(damageStat.Name, damageStat);
            this.playerThing.Stats.Add(attackStat.Name, attackStat);
            this.playerThing.Stats.Add(initiativeStat.Name, initiativeStat);
            this.playerThing.Skills.Add(awarenessSkill.Name, awarenessSkill);
            this.playerThing.Behaviors.Add(testBehavior);
        }
Пример #5
0
        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(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.
            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(actingThing);
            exitBehaviorA.MoveThrough(actingThing);
            Assert.AreSame(roomA, actingThing.Parent);

            roomB.Add(actingThing);
            exitBehaviorB.MoveThrough(actingThing);
            Assert.AreSame(roomB, actingThing.Parent);

            // Ensure that the actingThing can open and move through each openable exit to get between rooms.
            opensClosesBehaviorB.Open(actingThing);
            exitBehaviorB.MoveThrough(actingThing);
            Assert.AreSame(roomA, actingThing.Parent);

            opensClosesBehavior.Open(actingThing);
            exitBehaviorA.MoveThrough(actingThing);
            Assert.AreSame(roomB, actingThing.Parent);
        }
Пример #6
0
 public void Init()
 {
     // Create 2 rooms and a basic ExitBehavior in prep for testing.
     this.roomA = new Thing(new RoomBehavior())
     {
         Name = "Room A", ID = TestThingID.Generate("testroom")
     };
     this.roomB = new Thing(new RoomBehavior())
     {
         Name = "Room B", ID = TestThingID.Generate("testroom")
     };
     this.exitBehavior = new ExitBehavior();
     this.exit         = new Thing(this.exitBehavior)
     {
         Name = "Exit", ID = TestThingID.Generate("testexit")
     };
 }
Пример #7
0
 public void Init()
 {
     // Create 2 things and a basic MultipleParentsBehavior for testing.
     parent1 = new Thing()
     {
         Name = "Thing1", Id = TestThingID.Generate("testthing")
     };
     parent2 = new Thing()
     {
         Name = "Thing2", Id = TestThingID.Generate("testthing")
     };
     child = new Thing()
     {
         Name = "Child1", Id = TestThingID.Generate("testthing")
     };
     multipleParentsBehavior = new MultipleParentsBehavior();
 }
Пример #8
0
        public void TestMultipleParentingBehavior()
        {
            // Verify we can add and retrieve the MultipleParentsBehavior of a Thing.
            child.Behaviors.Add(multipleParentsBehavior);
            Assert.IsTrue(child.Behaviors.FindFirst <MultipleParentsBehavior>() == multipleParentsBehavior);

            // Verify it can now be a child of multiple parents, and one of those can be found as the primary Parent.
            parent1.Add(child);
            parent2.Add(child);
            Assert.IsTrue(parent1.Children.Contains(child));
            Assert.IsTrue(parent2.Children.Contains(child));
            Assert.IsTrue(child.Parent == parent1 || child.Parent == parent2);

            // Verify we can remove the item from a secondary parent, and still be attached well to the primary.
            parent2.Remove(child);
            Assert.IsTrue(parent1.Children.Contains(child));
            Assert.IsTrue(!parent2.Children.Contains(child));
            Assert.IsTrue(child.Parent == parent1);
            parent2.Add(child);

            // Verify we can remove the item from a primary parent, and a secondary parent becomes the primary.
            parent1.Remove(child);
            Assert.IsTrue(!parent1.Children.Contains(child));
            Assert.IsTrue(parent2.Children.Contains(child));
            Assert.IsTrue(child.Parent == parent2);
            parent1.Add(child);

            // Verify we can be attached to more than 2 parents.
            Thing parent3 = new Thing()
            {
                Name = "Thing3", Id = TestThingID.Generate("testthing")
            };

            parent3.Add(child);
            Assert.IsTrue(parent1.Children.Contains(child));
            Assert.IsTrue(parent2.Children.Contains(child));
            Assert.IsTrue(parent3.Children.Contains(child));
            Assert.IsTrue(child.Parent != null);
        }
Пример #9
0
        public void TestTwoWayExitBehavior()
        {
            // Allow the exit to reside in two places, and place it in both room A and room B.
            exit.Behaviors.Add(new MultipleParentsBehavior());
            roomA.Add(exit);
            roomB.Add(exit);

            // Ensure there are no destinations before rigging them up.
            Assert.AreSame(exitBehavior.GetDestination(roomA), null);
            Assert.AreSame(exitBehavior.GetDestination(roomB), null);

            // Rig the exits and ensure both got rigged up to the correct destinations.
            exitBehavior.AddDestination("north", roomB.Id);
            exitBehavior.AddDestination("south", roomA.Id);
            Assert.AreSame(exitBehavior.GetDestination(roomA), roomB);
            Assert.AreSame(exitBehavior.GetDestination(roomB), roomA);

            // Create an unmovable actor, and ensure that said actor cannot move through.
            actor = new Thing()
            {
                Name = "Actor", Id = TestThingID.Generate("testactor")
            };
            roomA.Add(actor);
            exitBehavior.MoveThrough(actor);
            Assert.AreSame(actor.Parent, roomA);

            // Make the actoc movable, and ensure they end up in the next room when moving through.
            actor.Behaviors.Add(new MovableBehavior());
            exitBehavior.MoveThrough(actor);
            Assert.AreSame(actor.Parent, roomB);

            // Move the actor back through the exit again, and ensure they end up in the starting room.
            exitBehavior.MoveThrough(actor);
            Assert.AreSame(actor.Parent, roomA);

            // TODO: Ensure the actor does not move through when using the wrong context command?
            // TODO: Ensure the actor moves through both ways when using correct context commands?
        }
Пример #10
0
        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; };
        }