コード例 #1
0
 protected virtual void OnCommand(DungeonCommandState state)
 {
 }
コード例 #2
0
        public bool HandleSubCommand(DungeonZone zone, PlayerMobile pm, string speech)
        {
            if (pm == null || pm.Deleted || String.IsNullOrWhiteSpace(speech))
            {
                return(false);
            }

            speech = speech.Trim();

            if (!speech.StartsWith(SubCommandPrefix.ToString(CultureInfo.InvariantCulture)))
            {
                return(false);
            }

            var command = String.Empty;
            var args    = new string[0];

            speech = speech.TrimStart(SubCommandPrefix);

            var split = speech.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (split.Length > 0)
            {
                command = split[0];
                args    = new string[split.Length - 1];

                for (var i = 0; i < args.Length; i++)
                {
                    args[i] = split[i + 1];
                }
            }

            if (!IsCommand(command))
            {
                pm.SendMessage("Command not found.");
                return(true);
            }

            var info = SubCommands[command];

            if (pm.AccessLevel < info.Access)
            {
                pm.SendMessage("You do not have access to that command.");
                return(true);
            }

            if (args.Length > 0 && (args[0] == "?" || Insensitive.Equals(args[0], "help")))
            {
                pm.SendMessage("Usage: {0}{1} {2}", SubCommandPrefix, info.Command, info.Usage);
                pm.SendMessage(info.Description);
                return(true);
            }

            var state = new DungeonCommandState(this, pm, command, args);

            if (info.Handler.Invoke(state))
            {
                OnCommand(state);
                return(true);
            }

            pm.SendMessage("Usage: {0}{1} {2}", SubCommandPrefix, info.Command, info.Usage);
            pm.SendMessage(info.Description);
            return(true);
        }