Example #1
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; };
        }
Example #2
0
 /// <summary>Clear all potentially tracked events so we can verify new ones.</summary>
 private void ClearTrackedEvents()
 {
     lastActorEvent     = null;
     lastActorRequest   = null;
     lastWitnessEvent   = null;
     lastWitnessRequest = null;
 }
 /// <summary>
 /// Clear all potentially tracked events so we can verify new ones.
 /// </summary>
 private void ClearTrackedEvents()
 {
     this.lastStalkerEvent   = null;
     this.lastStalkerRequest = null;
     this.lastVictimEvent    = null;
     this.lastVictimRequest  = null;
     this.lastWitnessEvent   = null;
     this.lastWitnessRequest = null;
 }
Example #4
0
        /// <summary>Deny communication requests by the host Thing.</summary>
        /// <param name="root">The thing making the request.</param>
        /// <param name="e">The communication request event args.</param>
        private void DenyCommunicationRequest(IThing root, CancellableGameEvent e)
        {
            var communicationRequest = e as VerbalCommunicationEvent;

            if (communicationRequest != null && communicationRequest.ActiveThing == Parent)
            {
                e.Cancel("You are currently muted.");
            }
        }
Example #5
0
 /// <summary>Intercepts and cancels a movement request for the wielded item.</summary>
 /// <remarks>This way a player will not accidentally drop a wielded weapon, etc.</remarks>
 /// <param name="root">The root.</param>
 /// <param name="e">The event.</param>
 private void Eventing_MovementRequest(Thing root, CancellableGameEvent e)
 {
     if (e is ChangeOwnerEvent changeOwnerEvent)
     {
         if (changeOwnerEvent.Thing.Id == itemToWield.Id)
         {
             changeOwnerEvent.Cancel(string.Format("The {0} is still wielded!", itemToWield.Name));
         }
     }
 }
Example #6
0
        /// <summary>
        /// Intercepts and cancels a movement request for the wielded item.
        /// This way a player will not accidentally drop a wielded weapon, etc.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="e">The event.</param>
        private void Eventing_MovementRequest(Thing root, CancellableGameEvent e)
        {
            var evt = e as ChangeOwnerEvent;

            if (evt != null)
            {
                if (evt.Thing.ID == this.itemToWield.ID)
                {
                    evt.Cancel(string.Format("The {0} is still wielded!", this.itemToWield.Name));
                }
            }
        }
 /// <summary>Handle any requests this behavior is registered to.</summary>
 /// <param name="root">The root Thing where this event broadcast started.</param>
 /// <param name="e">The cancellable event/request arguments.</param>
 private void RequestHandler(Thing root, CancellableGameEvent e)
 {
     // Only cancel requestes to open our parent if it is currently locked.
     if (IsLocked)
     {
         var parent = Parent;
         if (parent != null)
         {
             // If this is a standard open request, find out if we need to cancel it.
             var openCloseEvent = e as OpenCloseEvent;
             if (openCloseEvent != null && openCloseEvent.IsBeingOpened && openCloseEvent.Target == Parent)
             {
                 string message = string.Format("You cannot open {0} since it is locked!", Parent.Name);
                 openCloseEvent.Cancel(message);
             }
         }
     }
 }
        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; };
        }
Example #9
0
 /// <summary>Handle movement requests from the parent Thing.</summary>
 /// <param name="root">The root Thing where this event broadcast started.</param>
 /// <param name="e">The cancellable event/request arguments.</param>
 private void Parent_MovementRequest(Thing root, CancellableGameEvent e)
 {
     // TODO: When our parent Thing gets an Arrive request (such as when a thing is attempting to enter an
     // enterable portal), we want to cancel the event and replace it with our own movement request to enter the
     // portal's target location.
 }