Пример #1
0
        /// <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 = NormalizeParameters(sender);
            string   roleName         = normalizedParams[0];
            string   playerName       = normalizedParams[1];

            Thing player = GameAction.GetPlayerOrMobile(playerName);

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

            var userControlledBehavior = player.Behaviors.FindFirst <UserControlledBehavior>();
            var existingRole           = userControlledBehavior.FindRole(roleName);

            if (existingRole == null)
            {
                userControlledBehavior.Roles.Add(new Role()
                {
                    Name = roleName
                });
                player.Save();
                sender.Write(player.Name + " has been granted the " + roleName + " role.", true);
            }
        }
Пример #2
0
        /// <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 targetName = actionInput.Tail.Trim().ToLower();

            // Rule: Is the target an entity?
            this.target = GameAction.GetPlayerOrMobile(targetName);
            if (this.target == null)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target in the same room?
            if (actionInput.Controller.Thing.Parent.Id != this.target.Parent.Id)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target alive?
            if (this.target.Stats["health"].Value <= 0)
            {
                return(this.target.Name + " is dead.");
            }

            return(null);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <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);
            }
        }
Пример #5
0
        /// <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 = NormalizeParameters(sender);
            string   roleName         = normalizedParams[0];
            string   playerName       = normalizedParams[1];

            Thing player = GameAction.GetPlayerOrMobile(playerName);

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

            var userControlledBehavior = player.Behaviors.FindFirst <UserControlledBehavior>();
            var existingRole           = userControlledBehavior.FindRole(roleName);

            if (existingRole != null)
            {
                userControlledBehavior.Roles.Remove(existingRole);
                player.FindBehavior <PlayerBehavior>()?.SavePlayer();
                sender.Write(string.Format("{0} had the {1} role revoked.", player.Name, existingRole.Name), true);
            }
        }
Пример #6
0
        /// <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       entity = GameAction.GetPlayerOrMobile(sender.LastActionInput.Tail);

            if (entity != null)
            {
                sender.Write(string.Format("You see {0} at {1}, id {2}", entity.Name, entity.Parent.Name, entity.Parent.ID));
            }
            else
            {
                sender.Write("You cant find " + sender.LastActionInput.Tail);
            }
        }
Пример #7
0
        /// <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)
        {
            IController sender        = actionInput.Controller;
            string      commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            // Find the most appropriate matching target.
            string targetName = actionInput.Tail.Trim().ToLower();

            this.target = GameAction.GetPlayerOrMobile(targetName);

            // Rule: Is the target an entity?
            if (this.target == null)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target the initator?
            if (sender.Thing.Name.ToLower() == this.target.Name.ToLower())
            {
                return("You can't punch yourself.");
            }

            // Rule: Is the target in the same room?
            if (sender.Thing.Parent.ID != this.target.Parent.ID)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target alive?
            if (this.target.Stats["HP"].Value <= 0)
            {
                return(this.target.Name + " is dead.");
            }

            var unbalanceEffect = sender.Thing.Behaviors.FindFirst <UnbalanceEffect>();

            if (unbalanceEffect != null)
            {
                return("You are too unbalanced to punch right now. Wait " + unbalanceEffect.RemainingDuration.Seconds + " seconds.");
            }

            return(null);
        }
Пример #8
0
        /// <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);
            }

            // Changing strings here seem to cause casting error?
            // string targetName = command.Action.Tail.Trim().ToLower();
            string targetName = actionInput.Params[0].Trim().ToLower();

            // TODO: InterMUD support? string mudName = MudEngineAttributes.Instance.MudName;

            // Rule: Target must be an entity. @@@ REMOVE CHECK?
            this.target = GameAction.GetPlayerOrMobile(targetName);
            if (this.target == null)
            {
                // Make first char Upper?  IE textInfo.ToTitleCase.
                return(targetName + " is not part of reality.");
            }

            //// TODO what if player offline ?

            // Rule: Prevent talking to yourself.
            if (actionInput.Controller.Thing.Name.ToLower() == this.target.Name.ToLower())
            {
                return("Talking to yourself is the first sign of madness!");
            }

            // Rule: Give help if too few Params, having problems with the causing casting errors ?
            if (actionInput.Params.Length <= 1)
            {
                return("Syntax:\n<tell [player] [message]>\n\nSee also say, yell, shout, emote.");
            }

            // The sentence to be relayed consists of all input beyond the first parameter,
            // which was used to identify this.entity already.
            int firstCommandLength = actionInput.Params[0].Length;

            this.sentence = actionInput.Tail.Substring(firstCommandLength).Trim();

            return(null);
        }
Пример #9
0
        /// <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);
            }

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

            /* @@@ FIX
             * if (Extensions.Contains(player.Roles, role))
             * {
             *  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());
             *  RoleRecord toDelete = null;
             *
             *  foreach (var currRole in player.RoleRecords)
             *  {
             *      if (currRole.Name == record.Name)
             *      {
             *          toDelete = currRole;
             *      }
             *  }
             *
             *  player.RoleRecords.Remove(toDelete);
             *  player.RoleRecords.TrimExcess();
             *  player.UpdateRoles();
             *  player.Save();
             *
             *  sender.Write(string.Format("{0} had the {1} role revoked.", player.Name, role), true);
             * }*/
        }
Пример #10
0
        /// <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);
            }

            CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
            TextInfo    textInfo    = cultureInfo.TextInfo;
            ////string targetName = command.Action.Tail.Trim().ToLower();
            string targetName = textInfo.ToTitleCase(actionInput.Tail.Trim().ToLower());

            // Rule: Is the target an entity?
            this.target = GameAction.GetPlayerOrMobile(targetName);
            if (this.target == null)
            {
                // Now we need to look for the user in the database.
                // @@@ What if the player is offline? Player.Load probably adds them to the world, etc...
                //     This seems quite bad.  TEST!  Ideally we should be able to get the info of an off-
                //     line player BUT if the player logs in between say, our Guards and Execute getting
                //     run, we still want nothing strange to result, we don't want this to generate any
                //     'player logged in' events (as monitored by Friends system), etc...  Probably need
                //     some sort of ghosting system for info-gathering, should be generic for all things?
                //     Maybe the players all have a 'template' that can be loaded independently and gets
                //     saved with the player instance saving.
                //this.target = PlayerBehavior.Load(targetName);
                if (this.target == null)
                {
                    return(targetName + " has never visited " + MudEngineAttributes.Instance.MudName + ".");
                }
            }

            // Rule: If there is less than 1 parameter, show help.
            if (actionInput.Params.Length != 1)
            {
                return("Syntax:\n<finger [entity]>\n\nRemarking line 31 in this file will help crash test the mud :)\n\nSee also who");
            }

            return(null);
        }
Пример #11
0
        /// <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: The targeted player must exist.
            if (player == null)
            {
                return("The player " + playerName + " does not exist.");
            }

            // Rule: The

            // Rule: Does player already have role?
            var userControlledBehavior = player.Behaviors.FindFirst <UserControlledBehavior>();
            var existingRole           = (from r in userControlledBehavior.Roles where r.Name == role select r).FirstOrDefault();

            if (existingRole == null)
            {
                return(player.Name + " does not have the " + role + " role.");
            }

            return(null);
        }
Пример #12
0
        /// <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)
        {
            IController sender        = actionInput.Controller;
            string      commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

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

            // Rule: Do we have a target?
            this.target = GameAction.GetPlayerOrMobile(targetName);
            if (this.target == null)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target the initator?
            if (sender.Thing.Name.ToLower() == this.target.Name.ToLower())
            {
                return("You can't punch yourself.");
            }

            // Rule: Is the target in the same room?
            if (sender.Thing.Parent.ID != this.target.Parent.ID)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target alive?
            if (this.target.Stats["health"].Value <= 0)
            {
                return(this.target.Name + " is dead.");
            }

            return(null);
        }
Пример #13
0
        /// <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 = NormalizeParameters(actionInput.Controller);
            string   roleName         = 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: The targeted player must exist.
            if (player == null)
            {
                return(string.Format("The player {0} does not exist.", playerName));
            }

            // Rule: The player cannot already have the role.
            var userControlledBehavior = player.Behaviors.FindFirst <UserControlledBehavior>();
            var existingRole           = userControlledBehavior.FindRole(roleName);

            if (existingRole != null)
            {
                return(string.Format("{0} already has the {1} role.", player.Name, roleName));
            }

            return(null);
        }
Пример #14
0
        /// <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);
        }
Пример #15
0
        /// <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)
        {
            IController sender        = actionInput.Controller;
            string      commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            // Check to see if the first word is a number.
            // If so, shunt up the positions of our other params.
            int itemParam   = 0;
            int numberWords = actionInput.Params.Length;

            if (int.TryParse(actionInput.Params[0], out this.numberToGive))
            {
                itemParam = 1;

                // If the user specified a number, but it is less than 1, error!
                if (this.numberToGive < 1)
                {
                    return("You can't give less than 1 of something.");
                }

                // Rule: We should now have at least 3 items in our words array.
                // (IE "give 10 coins to Karak" or "give 10 coins Karak")
                if (numberWords < 3)
                {
                    return("You must specify something to give, and a target.");
                }
            }

            // The next parameter should be the item name (possibly pluralized).
            string itemName = actionInput.Params[itemParam];

            // Do we have an item matching the name in our inventory?
            this.thing = sender.Thing.FindChild(itemName.ToLower());
            if (this.thing == null)
            {
                return("You do not hold " + itemName + ".");
            }

            // The final argument should be the target name.
            string targetName = actionInput.Params[actionInput.Params.Length - 1];

            // Rule: Do we have a target?
            if (string.IsNullOrEmpty(targetName))
            {
                return("You must specify someone to give that to.");
            }

            // @@@ Shared targeting code should be used, and this rule should be implemented like:
            //     if (this.target == sender.Thing) ...
            // Rule: The giver cannot also be the receiver.
            if (targetName == "me")
            {
                return("You can't give something to yourself.");
            }

            // Rule: Is the target an entity?
            this.target = GameAction.GetPlayerOrMobile(targetName);
            if (this.target == null)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target in the same room?
            if (sender.Thing.Parent.ID != this.target.Parent.ID)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: The thing being given must be movable.
            this.movableBehavior = this.thing.Behaviors.FindFirst <MovableBehavior>();

            return(null);
        }