• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Core.ActionInput类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中WheelMUD.Core.ActionInput的典型用法代码示例。如果您正苦于以下问题:C# ActionInput类的具体用法?C# ActionInput怎么用?C# ActionInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ActionInput类属于WheelMUD.Core命名空间,在下文中一共展示了ActionInput类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Guards

        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            // Rule: Do we have an item matching in our inventory?
            // @@@ TODO: Support drinking from, for instance, a fountain sitting in the room.
            string itemIdentifier = actionInput.Tail.Trim();
            this.thingToDrink = sender.Thing.FindChild(itemIdentifier.ToLower());
            if (this.thingToDrink == null)
            {
                return "You do not hold " + actionInput.Tail.Trim() + ".";
            }

            // Rule: Is the item drinkable?
            this.drinkableBehavior = this.thingToDrink.Behaviors.FindFirst<DrinkableBehavior>();
            if (this.drinkableBehavior == null)
            {
                return itemIdentifier + " is not drinkable";
            }

            return null;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:30,代码来源:Drink.cs


示例2: Execute

        /// <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 contextMessage = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = "You cast ThunderClap at $ActiveThing.Name!",
                ToReceiver = "$Aggressor.Name casts ThunderClap at you, you only hear a ringing in your ears now.",
                ToOthers = "You hear $Aggressor.Name cast ThunderClap at $ActiveThing.Name!  It was very loud.",
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            var attackEvent = new AttackEvent(this.target, sm, sender.Thing);
            sender.Thing.Eventing.OnCombatRequest(attackEvent, EventScope.ParentsDown);
            if (!attackEvent.IsCancelled)
            {
                var deafenEffect = new AlterSenseEffect()
                {
                    SensoryType = SensoryType.Hearing,
                    AlterAmount = -1000,
                    Duration = new TimeSpan(0, 0, 45),
                };

                this.target.Behaviors.Add(deafenEffect);
                sender.Thing.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:28,代码来源:ThunderClap.cs


示例3: Execute

        /// <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;

            this.itemToWieldBehavior.Wielder = sender.Thing;

            // Create an event handler that intercepts the ChangeOwnerEvent and
            // prevents dropping/trading the item around while it is wielded.
            // A reference is stored in the WieldableBehavior instance so it
            // can be easily removed by the unwield command.
            var interceptor = new CancellableGameEventHandler(this.Eventing_MovementRequest);
            this.itemToWieldBehavior.MovementInterceptor = interceptor;
            this.itemToWield.Eventing.MovementRequest += interceptor;

            var contextMessage = new ContextualString(sender.Thing, this.itemToWield.Parent)
            {
                ToOriginator = "You wield the $WieldedItem.Name.",
                ToOthers = "$ActiveThing.Name wields a $WieldedItem.Name.",
            };

            var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var wieldEvent = new WieldUnwieldEvent(this.itemToWield, true, sender.Thing, sensoryMessage);

            sender.Thing.Eventing.OnCombatRequest(wieldEvent, EventScope.ParentsDown);

            if (!wieldEvent.IsCancelled)
            {
                sender.Thing.Eventing.OnCombatEvent(wieldEvent, EventScope.ParentsDown);
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:33,代码来源:Wield.cs


示例4: Execute

        /// <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;

            // Remove "weapon" from input tail and use the rest as the name.
            string weaponName = actionInput.Tail.Substring(6).Trim().ToLower();

            Thing weaponItem = new Thing(new WieldableBehavior(), new MovableBehavior());
            weaponItem.Name = weaponName;
            weaponItem.SingularPrefix = "a";
            //weaponItem.ID = Guid.NewGuid().ToString();
            weaponItem.ID = "0";

            var wasAdded = sender.Thing.Parent.Add(weaponItem);

            var userControlledBehavior = sender.Thing.Behaviors.FindFirst<UserControlledBehavior>();
            if (wasAdded)
            {
                userControlledBehavior.Controller.Write(string.Format("You create a weapon called {0}.", weaponItem.Name));
            }
            else
            {
                userControlledBehavior.Controller.Write(string.Format("Could not add {0} to the room!", weaponItem.Name));
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:27,代码来源:CreateWeapon.cs


示例5: Execute

        /// <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 parameters = actionInput.Params;

            // Ensure two 'credits' commands at the same time do not race for shared cache, etc.
            lock (cacheLockObject)
            {
                if (cachedContents == null || (parameters.Length > 0 && parameters[0].ToLower() == "reload"))
                {
                    StreamReader reader = new StreamReader("Files\\Credits.txt");
                    StringBuilder stringBuilder = new StringBuilder();
                    string s;
                    while ((s = reader.ReadLine()) != null)
                    {
                        if (!s.StartsWith(";"))
                        {
                            stringBuilder.AppendLine(s);
                        }
                    }

                    cachedContents = stringBuilder.ToString();
                }

                sender.Write(cachedContents);
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:29,代码来源:Credits.cs


示例6: Guards

        /// <summary>Prepare for, and determine if the command's prerequisites have been met.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            // Rule: We should have at least 1 item in our words array.
            int numberWords = actionInput.Params.Length;
            if (numberWords < 2)
            {
                return "You must specify a room to create a portal to.";
            }

            // Check to see if the first word is a number.
            string roomToGet = actionInput.Params[1];
            if (string.IsNullOrEmpty(roomToGet))
            {
                // Its not a number so it could be an entity... try it.
                this.targetPlace = GameAction.GetPlayerOrMobile(actionInput.Params[0]);
                if (this.targetPlace == null)
                {
                    return "Could not convert " + actionInput.Params[0] + " to a room number.";
                }
            }

            //            this.targetRoom = bridge.World.FindRoom(roomToGet);
            if (this.targetPlace == null)
            {
                return string.Format("Could not find the room {0}.", roomToGet);
            }

            return null;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:38,代码来源:CreatePortal.cs


示例7: TestParseText

        public void TestParseText()
        {
            // Test empty string
            var actionInput = new ActionInput(string.Empty, null);
            Verify.IsNull(actionInput.Noun);
            Verify.IsNull(actionInput.Tail);
            Verify.IsNull(actionInput.Params);

            // Test simple 1-word command
            var oneWordInput = new ActionInput("look", null);
            Verify.AreEqual(oneWordInput.Noun, "look");
            Verify.IsNull(actionInput.Tail);
            Verify.IsNull(actionInput.Params);

            // Test 2-word command
            var twoWordInput = new ActionInput("look foo", null);
            Verify.AreEqual(twoWordInput.Noun, "look");
            Verify.AreEqual(twoWordInput.Tail, "foo");
            Verify.IsNotNull(twoWordInput.Params);
            Verify.AreEqual(twoWordInput.Params.Length, 1);

            // Test 2-word command
            var threeWordInput = new ActionInput("create consumable metal", null);
            Verify.AreEqual(threeWordInput.Noun, "create");
            Verify.AreEqual(threeWordInput.Tail, "consumable metal");
            Verify.IsNotNull(threeWordInput.Params);
            Verify.AreEqual(threeWordInput.Params.Length, 2);

            // Test input with leading/trailing spaces
            var spacedWordInput = new ActionInput(" look  foo ", null);
            Verify.AreEqual(spacedWordInput.Noun, "look");
            Verify.AreEqual(spacedWordInput.Tail, "foo");
            Verify.IsNotNull(spacedWordInput.Params);
            Verify.AreEqual(spacedWordInput.Params.Length, 1);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:35,代码来源:TestActionInput.cs


示例8: Execute

        /// <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;
            if (sender != null && sender.Thing != null)
            {
                Thing entity = sender.Thing;

                if (entity != null)
                {
                    if (!string.IsNullOrEmpty(this.NewDescription))
                    {
                        entity.Description = this.NewDescription;
                        entity.Save();
                        sender.Write("Description successfully changed.");
                    }
                    else
                    {
                        sender.Write(string.Format("Your current description is \"{0}\".", entity.Description));
                    }
                }
                else
                {
                    sender.Write("Unexpected error occurred changing description, please contact admin.");
                }
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:28,代码来源:Description.cs


示例9: Guards

        /// <summary>Prepare for, and determine if the command's prerequisites have been met.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            // Rule: Did they specify a tree to chop?
            // @@@ TODO: Better thing finders...
            Thing parent = actionInput.Controller.Thing.Parent;
            Thing thing = parent.Children.Find(t => t.Name.Equals(actionInput.Params[0], StringComparison.CurrentCultureIgnoreCase));
            if (thing == null)
            {
                return string.Format("{0} is not here.", actionInput.Params[0]);
            }

            // @@@ TODO: Detect ConsumableProviderBehavior on the item, and detect if it is choppable.
            //if (!(item is Item))
            //{
            //    return string.Format("{0} is not a tree.", actionInput.Params[0]);
            //}

            //this.tree = (Item) item;

            //if (this.tree.NumberOfResources <= 0)
            //{
            //    return string.Format("The tree doesn't contain any suitable wood.");
            //}

            return null;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:35,代码来源:Chop.cs


示例10: Execute

        /// <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;

            this.itemToUnwieldBehavior.Wielder = null;

            // Remove the event handler that prevents dropping the item while wielded.
            var interceptor = this.itemToUnwieldBehavior.MovementInterceptor;
            this.itemToUnwield.Eventing.MovementRequest -= interceptor;

            var contextMessage = new ContextualString(sender.Thing, this.itemToUnwield.Parent)
            {
                ToOriginator = "You unwield the $WieldedItem.Name.",
                ToOthers = "$ActiveThing.Name unwields a $WieldedItem.Name.",
            };

            var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var unwieldEvent = new WieldUnwieldEvent(this.itemToUnwield, true, sender.Thing, sensoryMessage);

            sender.Thing.Eventing.OnCombatRequest(unwieldEvent, EventScope.ParentsDown);

            if (!unwieldEvent.IsCancelled)
            {
                sender.Thing.Eventing.OnCombatEvent(unwieldEvent, EventScope.ParentsDown);
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:29,代码来源:Unwield.cs


示例11: Guards

        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;
            Thing wielder = sender.Thing;
            Thing room = wielder.Parent;

            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            string itemName = actionInput.Tail.Trim().ToLower();

            // First look for a matching item in inventory and make sure it can
            // be wielded. If nothing was found in inventory, look for a matching
            // wieldable item in the surrounding environment.
            this.itemToUnwield = wielder.FindChild(item => item.Name.ToLower() == itemName && item.HasBehavior<WieldableBehavior>() && item.Behaviors.FindFirst<WieldableBehavior>().Wielder == sender.Thing);

            if (this.itemToUnwield == null)
            {
                this.itemToUnwield = wielder.Parent.FindChild(item => item.Name.ToLower() == itemName && item.HasBehavior<WieldableBehavior>() && item.Behaviors.FindFirst<WieldableBehavior>().Wielder == sender.Thing);
            }

            if (this.itemToUnwield == null)
            {
                return "You are not wielding the " + itemName + ".";
            }

            this.itemToUnwieldBehavior = this.itemToUnwield.Behaviors.FindFirst<WieldableBehavior>();

            return null;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:36,代码来源:Unwield.cs


示例12: Execute

        /// <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;
            string[] normalizedParams = this.NormalizeParameters(sender);
            string role = normalizedParams[0];
            string playerName = normalizedParams[1];

            Thing player = GameAction.GetPlayerOrMobile(playerName);
            if (player == null)
            {
                // If the player is not online, then load the player from the database
                //player = PlayerBehavior.Load(playerName);
            }

            var userControlledBehavior = player.Behaviors.FindFirst<UserControlledBehavior>();
            var existingRole = (from r in userControlledBehavior.Roles where r.Name == role select r).FirstOrDefault();
            if (existingRole == null)
            {
                var roleRepository = new RoleRepository();

                // @@@ TODO: The role.ToUpper is a hack. Need to create a case insensitive method for the RoleRepository.NoGen.cs class.
                RoleRecord record = roleRepository.GetByName(role.ToUpper());
                //userControlledBehavior.RoleRecords.Add(record);
                //userControlledBehavior.UpdateRoles();
                player.Save();

                sender.Write(player.Name + " has been granted the " + role + " role.", true);
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:31,代码来源:RoleGrant.cs


示例13: Guards

        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            string[] normalizedParams = this.NormalizeParameters(actionInput.Controller);
            string role = normalizedParams[0];
            string playerName = normalizedParams[1];

            Thing player = GameAction.GetPlayerOrMobile(playerName);
            if (player == null)
            {
                // If the player is not online, then load the player from the database
                //player = PlayerBehavior.Load(playerName);
            }

            // Rule: Does the player exist in our Universe?
            // @@@ TODO: Add code to make sure the player exists.

            // Rule: Does player already have role?
            /* @@@ FIX
            if (Contains(player.Roles, role))
            {
                return player.Name + " already has the " + role + " role.";
            }*/

            return null;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:34,代码来源:RoleGrant.cs


示例14: Execute

        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Not sure what would call this other than a player, but exit early just in case.
            // Implicitly also verifies that this.sender exists.
            if (this.userControlledBehavior == null)
            {
                return;
            }

            // No arguments were provided. Just show the current buffer setting and exit.
            if (string.IsNullOrEmpty(actionInput.Tail))
            {
                this.ShowCurrentBuffer();
                return;
            }

            // Set the value for the current session
            if (this.session.Connection != null)
            {
                this.session.Connection.PagingRowLimit = (this.parsedBufferLength == -1) ? this.session.Terminal.Height : this.parsedBufferLength;
            }

            this.userControlledBehavior.PagingRowLimit = this.parsedBufferLength;

            this.userControlledBehavior.Save();

            this.ShowCurrentBuffer();
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:30,代码来源:Buffer.cs


示例15: Execute

        /// <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;
            Thing parent = sender.Thing.Parent;
            string searchString = actionInput.Tail.Trim().ToLower();

            if (string.IsNullOrEmpty(searchString))
            {
                sender.Write("You must specify something to search for.");
                return;
            }

            // Unique case. Use 'here' to list the contents of the room.
            if (searchString == "here")
            {
                sender.Write(this.ListRoomItems(parent));
                return;
            }

            // First check the place where the sender is located (like a room) for the target,
            // and if not found, search the sender's children (like inventory) for the target.
            Thing thing = parent.FindChild(searchString) ?? sender.Thing.FindChild(searchString);
            if (thing != null)
            {
                // @@@ TODO: Send a SensoryEvent?
                sender.Write(thing.Description);
            }
            else
            {
                sender.Write("You cannot find " + searchString + ".");
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:34,代码来源:Examine.cs


示例16: Guards

        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            // The comon guards already guarantees the sender is a player, hence no null checks here.
            this.player = sender.Thing;
            this.playerBehavior = sender.Thing.Behaviors.FindFirst<PlayerBehavior>();

            // Rule: The new pretitle must be empty or meet the length requirements.
            this.oldPretitle = this.player.SingularPrefix;

            if (!string.IsNullOrEmpty(actionInput.Tail)) {
                this.newPretitle = actionInput.Tail;

                if (this.newPretitle.Length < 2 || this.newPretitle.Length > 15)
                {
                    return "The pretitle may not be less than 2 nor more than 15 characters long.";
                }
            }

            //// One could implement 'no color' or 'no swearing' or 'no non-alpha character' rules here, etc.

            return null;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:32,代码来源:Pretitle.cs


示例17: Execute

        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Generate an item changed owner event.
            IController sender = actionInput.Controller;
            ContextualStringBuilder csb = new ContextualStringBuilder(sender.Thing, this.parent);
            csb.Append(@"$ActiveThing.Name drops $Thing.Name.", ContextualStringUsage.WhenNotBeingPassedToOriginator);
            csb.Append(@"You drop $Thing.Name.", ContextualStringUsage.OnlyWhenBeingPassedToOriginator);
            SensoryMessage message = new SensoryMessage(SensoryType.Sight, 100, csb);
            var changeOwnerEvent = new ChangeOwnerEvent(sender.Thing, message, sender.Thing, this.parent, this.thing);

            // Broadcast as a request and see if anything wants to prevent the event.
            this.parent.Eventing.OnMovementRequest(changeOwnerEvent, EventScope.ParentsDown);
            if (!changeOwnerEvent.IsCancelled)
            {
                // Always have to remove an item before adding it because of the event observer system.
                // @@@ TODO: Test, this may be broken now...
                this.thing.Parent.Remove(this.thing);
                this.parent.Add(this.thing);

                //// @@@ BUG: Saving currently throws a NotImplementedException. Disabled for now...
                this.thing.Save();
                this.parent.Save();

                // Broadcast the event.
                this.parent.Eventing.OnMovementEvent(changeOwnerEvent, EventScope.ParentsDown);
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:29,代码来源:Drop.cs


示例18: Guards

        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            // Rule: A thing must be singly targeted.
            // @@@ TODO: Try to find a single target according to the specified identifiers.  If more than one thing
            //           meets the identifiers then use a disambiguation targeting system to try to narrow to one thing.
            // @@@ TODO: This sort of find pattern may become common; maybe we need to simplify
            //           to having a Thing method which does this?  IE "List<Thing> FindChildren<T>(string id)"?
            Predicate<Thing> findPredicate = (Thing t) => t.Behaviors.FindFirst<EnterableExitableBehavior>() != null;
            List<Thing> enterableThings = sender.Thing.Parent.FindAllChildren(findPredicate);

            if (enterableThings.Count > 1)
            {
                return "There is more than one thing by that identity.";
            }
            else if (enterableThings.Count == 1)
            {
                Thing thing = enterableThings.First();
                this.enterableBehavior = thing.Behaviors.FindFirst<EnterableExitableBehavior>();
                if (this.enterableBehavior == null)
                {
                    return "You can not enter " + thing.Name + ".";
                }
            }

            // If we got this far, we couldn't find an appropriate enterable thing in the room.
            return "You can't see anything like that to enter.";
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:37,代码来源:Enter.cs


示例19: Execute

        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Send just one message to the command sender since they know what's going on.
            IController sender = actionInput.Controller;

            // Attempt exact ID match
            var targetPlace = ThingManager.Instance.FindThing(actionInput.Tail);

            // If input is a simple number, assume we mean a room
            int roomNum;
            targetPlace = int.TryParse(actionInput.Tail, out roomNum) ? ThingManager.Instance.FindThing("room/" + roomNum) : ThingManager.Instance.FindThingByName(actionInput.Tail, false, true);

            if (targetPlace == null)
            {
                sender.Write("Room or Entity not found.\n");
                return;
            }

            if (targetPlace.FindBehavior<RoomBehavior>() == null)
            {
                // If the target's parent is a room, go there instead
                if (targetPlace.Parent != null && targetPlace.Parent.FindBehavior<RoomBehavior>() != null)
                {
                    targetPlace = targetPlace.Parent;
                }
                else
                {
                    sender.Write("Target is not a room and is not in a room!\n");
                    return;
                }
            }

            var leaveContextMessage = new ContextualString(sender.Thing, sender.Thing.Parent)
            {
                ToOriginator = null,
                ToReceiver = @"$ActiveThing.Name disappears into nothingness.",
                ToOthers = @"$ActiveThing.Name disappears into nothingness.",
            };
            var arriveContextMessage = new ContextualString(sender.Thing, targetPlace)
            {
                ToOriginator = "You teleport to " + targetPlace.Name + ".",
                ToReceiver = @"$ActiveThing.Name appears from nothingness.",
                ToOthers = @"$ActiveThing.Name appears from nothingness.",
            };
            var leaveMessage = new SensoryMessage(SensoryType.Sight, 100, leaveContextMessage);
            var arriveMessage = new SensoryMessage(SensoryType.Sight, 100, arriveContextMessage);

            // If we successfully move (IE the move may get cancelled if the user doesn't have permission
            // to enter a particular location, some other behavior cancels it, etc), then perform a 'look'
            // command to get immediate feedback about the new location.
            // @@@ TODO: This should not 'enqueue' a command since, should the player have a bunch of
            //     other commands entered, the 'look' feedback will not immediately accompany the 'goto'
            //     command results like it should.
            var movableBehavior = sender.Thing.FindBehavior<MovableBehavior>();

            if (movableBehavior != null && movableBehavior.Move(targetPlace, sender.Thing, leaveMessage, arriveMessage))
            {
                CommandManager.Instance.EnqueueAction(new ActionInput("look", sender));
            }
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:62,代码来源:GoTo.cs


示例20: Execute

        /// <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;

            // Strings to be displayed when the effect is applied/removed.
            var muteString = new ContextualString(sender.Thing, this.playerToMute)
            {
                ToOriginator = "You mute $Target.",
                ToReceiver = "You are muted by $ActiveThing.",
                ToOthers = "$ActiveThing mutes $Target."
            };
            var unmuteString = new ContextualString(sender.Thing, this.playerToMute)
            {
                ToOriginator = "$Target is no longer mute.",
                ToReceiver = "You are no longer mute."
            };

            // Turn the above sets of strings into sensory messages.
            var muteMessage = new SensoryMessage(SensoryType.Sight, 100, muteString);
            var unmuteMessage = new SensoryMessage(SensoryType.Sight, 100, unmuteString);

            // Create the effect.
            var muteEffect = new MutedEffect(sender.Thing, this.muteDuration, muteMessage, unmuteMessage);

            // Apply the effect.
            this.playerToMute.Behaviors.Add(muteEffect);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:29,代码来源:Mute.cs



注:本文中的WheelMUD.Core.ActionInput类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Factory.InitializeOption类代码示例发布时间:2022-05-26
下一篇:
C# Parser.FMessage类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap