Пример #1
0
        private ScriptingCommand CreateContextCommand(ActionInput actionInput, string commandAlias, Thing actionOwner)
        {
            ContextCommand contextCommand  = actionOwner.Commands[commandAlias];
            var            executeDelegate = new CommandScriptExecuteDelegate(contextCommand.CommandScript.Execute);
            var            guardsDelegate  = new CommandScriptGuardsDelegate(contextCommand.CommandScript.Guards);

            return(new ScriptingCommand(contextCommand.CommandKey, executeDelegate, guardsDelegate, SecurityRole.all, actionInput));
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the ScriptingCommand class.
 /// </summary>
 /// <param name="name">The name of the command.</param>
 /// <param name="executeDelegate">The execution delegate.</param>
 /// <param name="guardsDelegate">The guards delegate.</param>
 /// <param name="securityRole">The required security role in order to execute this command.</param>
 /// <param name="actionInput">The action input to pass through to the delegates.</param>
 public ScriptingCommand(
     string name,
     CommandScriptExecuteDelegate executeDelegate,
     CommandScriptGuardsDelegate guardsDelegate,
     SecurityRole securityRole,
     ActionInput actionInput)
 {
     this.Name = name;
     this.ExecuteDelegate = executeDelegate;
     this.GuardsDelegate = guardsDelegate;
     this.SecurityRole = securityRole;
     this.ActionInput = actionInput;
 }
Пример #3
0
 /// <summary>Initializes a new instance of the ScriptingCommand class.</summary>
 /// <param name="name">The name of the command.</param>
 /// <param name="executeDelegate">The execution delegate.</param>
 /// <param name="guardsDelegate">The guards delegate.</param>
 /// <param name="securityRole">The required security role in order to execute this command.</param>
 /// <param name="actionInput">The action input to pass through to the delegates.</param>
 public ScriptingCommand(
     string name,
     CommandScriptExecuteDelegate executeDelegate,
     CommandScriptGuardsDelegate guardsDelegate,
     SecurityRole securityRole,
     ActionInput actionInput)
 {
     Name            = name;
     ExecuteDelegate = executeDelegate;
     GuardsDelegate  = guardsDelegate;
     SecurityRole    = securityRole;
     ActionInput     = actionInput;
 }
Пример #4
0
        private ScriptingCommand TryCreateMasterCommand(ActionInput actionInput, int lastKeywordIndex)
        {
            string commandAlias = this.GetCommandAlias(actionInput, lastKeywordIndex);

            // If this isn't actually a command, bail now.
            ////if (string.IsNullOrEmpty(commandAlias) || !this.masterCommandList.ContainsKey(commandAlias))
            if (string.IsNullOrEmpty(commandAlias) || !CommandManager.Instance.MasterCommandList.ContainsKey(commandAlias))
            {
                return(null);
            }

            // Create a new instance of the specified GameAction.
            Command command       = CommandManager.Instance.MasterCommandList[commandAlias];
            var     commandScript = (GameAction)command.Constructor.Invoke(null);

            // Track the execute and guards delegates of this instance for calling soon, with the user's input.
            var executeDelegate = new CommandScriptExecuteDelegate(commandScript.Execute);
            var guardsDelegate  = new CommandScriptGuardsDelegate(commandScript.Guards);

            return(new ScriptingCommand(command.Name, executeDelegate, guardsDelegate, command.SecurityRole, actionInput));
        }
Пример #5
0
        private ScriptingCommand TryCreateContextCommand(ActionInput actionInput, int lastKeywordIndex)
        {
            string commandAlias = this.GetCommandAlias(actionInput, lastKeywordIndex);

            if (string.IsNullOrEmpty(commandAlias))
            {
                return(null);
            }

            // Find the first valid command of this name and of applicable context, if any.
            Thing sender         = actionInput.Controller.Thing;
            var   contextCommand = CommandManager.Instance.GetContextCommands(sender, commandAlias).FirstOrDefault();

            if (contextCommand == null)
            {
                return(null);
            }

            var executeDelegate = new CommandScriptExecuteDelegate(contextCommand.CommandScript.Execute);
            var guardsDelegate  = new CommandScriptGuardsDelegate(contextCommand.CommandScript.Guards);

            return(new ScriptingCommand(contextCommand.CommandKey, executeDelegate, guardsDelegate, SecurityRole.all, actionInput));
        }
Пример #6
0
 private ScriptingCommand CreateContextCommand(ActionInput actionInput, string commandAlias, Thing actionOwner)
 {
     ContextCommand contextCommand = actionOwner.Commands[commandAlias];
     var executeDelegate = new CommandScriptExecuteDelegate(contextCommand.CommandScript.Execute);
     var guardsDelegate = new CommandScriptGuardsDelegate(contextCommand.CommandScript.Guards);
     return new ScriptingCommand(contextCommand.CommandKey, executeDelegate, guardsDelegate, SecurityRole.all, actionInput);
 }
Пример #7
0
        private ScriptingCommand TryCreateMasterCommand(ActionInput actionInput, int lastKeywordIndex)
        {
            string commandAlias = this.GetCommandAlias(actionInput, lastKeywordIndex);

            // If this isn't actually a command, bail now.
            ////if (string.IsNullOrEmpty(commandAlias) || !this.masterCommandList.ContainsKey(commandAlias))
            if (string.IsNullOrEmpty(commandAlias) || !CommandManager.Instance.MasterCommandList.ContainsKey(commandAlias))
            {
                return null;
            }

            // Create a new instance of the specified GameAction.
            Command command = CommandManager.Instance.MasterCommandList[commandAlias];
            var commandScript = (GameAction)command.Constructor.Invoke(null);

            // Track the execute and guards delegates of this instance for calling soon, with the user's input.
            var executeDelegate = new CommandScriptExecuteDelegate(commandScript.Execute);
            var guardsDelegate = new CommandScriptGuardsDelegate(commandScript.Guards);
            object[] args = new object[] { actionInput.Controller, actionInput };

            return new ScriptingCommand(command.Name, executeDelegate, guardsDelegate, command.SecurityRole, actionInput);
        }