Ejemplo n.º 1
0
        public ICommand GetCommand()
        {
            Type[] gameCommands = ScriptFactory.GetTypesWithInterface("ICommand");
            var    input        = currentPlayer.ReceiveInput().ToLower();

            string[] args = input.Split(' ');

            if (args.Length >= 1)
            {
                input = args[0];
            }

            if (string.IsNullOrEmpty(input))
            {
                return(new InvalidCommand());
            }

            foreach (Type command in gameCommands)
            {
                string correctedCommand = command.Name.ToLower();

                if (correctedCommand.StartsWith("command"))
                {
                    correctedCommand = correctedCommand.Substring("command".Length);
                }

                if (correctedCommand.EndsWith("command"))
                {
                    correctedCommand = correctedCommand.Substring(0, correctedCommand.Length - "command".Length);
                }

                if (correctedCommand == input)
                {
                    var commandToExecute = ScriptFactory.GetScript(command.FullName);

                    if (commandToExecute != null)
                    {
                        return((ICommand)commandToExecute);
                    }
                }
            }

            return(new InvalidCommand());
        }
Ejemplo n.º 2
0
        public ICommand GetCommand()
        {
            var input = connectedPlayer.ReceiveInput().ToLower().Trim();

            if (string.IsNullOrEmpty(input))
            {
                connectedPlayer.SendMessage("Invalid selection, you must choose either a Male or a Female");
                return(new NoOpCommand());
            }

            Type[] genders = ScriptFactory.GetTypesWithInterface("IGender");

            //Fail safe in the event gender scripts are deleted.
            if (genders.Length == 0)
            {
                connectedPlayer.SendMessage("No genders are available for you to select from. Please contact the server admin!");
                Log.Error("No genders are available for users to select from! You should not create the GenderSelect state until Gender scripts are created");
                //Logger.WriteLine("No genders are available for users to select from! You should not create the GenderSelect state until Gender scripts are created", Logger.Importance.Critical);
                connectedPlayer.SwitchState(new CreationManager(director, CreationManager.CreationState.Completed)); //Just skip to the next step;
            }

            foreach (Type type in genders)
            {
                //Our classes are called "GenderMale" etc. If user typed "Male", we need to add "Gender" to the front
                //so that we can make sure we choose the right gender
                if (type.Name.ToLower() == "gender" + input)
                {
                    connectedPlayer.Gender = (IGender)ScriptFactory.GetScript(type.FullName);

                    //We have the gender, move on to the next step in the character creation process.
                    connectedPlayer.SwitchState(new CreationManager(director, CreationManager.CreationState.Completed));
                    break;
                }
            }

            return(new NoOpCommand());
        }
Ejemplo n.º 3
0
        private void SetupComboBox(ComboBox box, Type implementInterface, string engineSetting)
        {
            //Build an array of objects that implement the specified interface.
            Type[] objects       = ScriptFactory.GetTypesWithInterface(implementInterface.Name);
            Type   defaultObject = null;

            //Collection of Types that implement the interface.
            SortedDictionary <string, string> objectCollection = new SortedDictionary <string, string>();

            if (objects.Length == 0)
            {
                MessageBox.Show("Warning! You do not have any scripts that implement " + implementInterface.FullName + "!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //Loop through the array and build our collection
            foreach (Type obj in objects)
            {
                //The object Name is placed as the Key so that the Combo Boxes
                //can use it to display. The Fullname is stored as a value so we can
                //reference the full Type later for instancing.

                if (objectCollection.ContainsKey(obj.Name))
                {
                    continue;
                }

                objectCollection.Add(obj.Name, obj.FullName);

                //If this object is the current EngineSetting, store a reference to it.
                if (obj.FullName == engineSetting)
                {
                    defaultObject = obj;
                }
            }

            if (objectCollection.Count > 0)
            {
                //Bind our combo box to the object collection
                box.DataSource = new BindingSource(objectCollection, null);;

                //Show users the keys
                box.DisplayMember = "key";

                //Tie what the user sees to the actual full Type path.
                //Example: user selects "MyRealm". They are really selecting "MudDesigner.Scripts.MyGame.MyRealm".
                box.ValueMember = "value";

                //Store this collection into the Settings Collection pool.
                //A Collection within a Collection is used, so that I don't need to have 12 different
                //Dictionary members created.
                settingCollection.Add(engineSetting, objectCollection);
            }
            //Increment the progress bar
            scriptProgressBar.Value++;

            //If the default object (current engine setting) is not null
            if (defaultObject != null && objectCollection.Count > 0)
            {
                //Select it and display it for the users so they know what
                //settings are currently being used.
                box.SelectedValue = defaultObject.FullName;
                return;
            }
            //Otherwise select the first object in the combo box.
            else if (objectCollection.Count > 0)
            {
                box.SelectedIndex = 0;
            }
        }