Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.cbUltraSelection.DataSource = Enum.GetValues(typeof(ClgLevel.UltraOption));
            this.cbTargetState.DataSource    = Enum.GetValues(typeof(ClgLevel.TargetStateOption));
            this.cbCriteriaType.DataSource   = Enum.GetValues(typeof(ClgCommand.CriteriaTypeOption));
            this.cbMatrix = new[]
            {
                this.comboBox1, this.comboBox2, this.comboBox3, this.comboBox4,
                this.comboBox5, this.comboBox6, this.comboBox7, this.comboBox8
            };

            if (File.Exists("CommandIds.txt"))
            {
                CommandPart.Load(@"CommandIds.txt");
            }
            else
            {
                throw new FileNotFoundException("CommandIds.txt not found.");
            }

            Version  version     = Assembly.GetExecutingAssembly().GetName().Version;
            DateTime compileDate =
                new DateTime(Math.Max(version.Build - 1, 0) * TimeSpan.TicksPerDay + version.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999);

            this.lblAbout.Text = string.Format(
                "Last updated: {0} Author: Waterine",
                compileDate.ToShortDateString());
        }
        /// <inheritdoc />
        public override bool Parse(ref string text, out CommandPart output)
        {
            if (text.StartsWith(_value))
            {
                text   = text.Substring(_value.Length);
                output = new CommandPartLiteral(_value);
                return(true);
            }

            output = null;
            return(false);
        }
Example #3
0
            public static CommandPart ParseCmd(string cmd)
            {
                cmd = cmd.Trim();
                var         cmdarray = cmd.Split(' ');
                CommandPart part     = new CommandPart();

                if (cmdarray.Length != 0)
                {
                    part.Prefix = cmdarray[0].Trim();
                    if (cmd.Length > part.Prefix.Length + 1)
                    {
                        part.Args = cmd.Substring(part.Prefix.Length + 1).Trim();
                    }
                }
                return(part);
            }
        /// <inheritdoc />
        public override bool Parse(ref string text, out CommandPart output)
        {
            int endIndex = -1;

            if (text.StartsWith("\""))
            {
                for (int i = 1; i < text.Length; ++i)
                {
                    if (text[i] == '"' && text[i - 1] != '\\')
                    {
                        endIndex = i;
                        break;
                    }
                }

                if (endIndex == -1)
                {
                    output = null;
                    return(false);
                }

                output = new CommandPartString(text.Substring(1, endIndex - 1).Replace("\\\"", "\""));
                text   = text.Substring(endIndex + 1);
                return(true);
            }

            for (int i = 0; i < text.Length; ++i)
            {
                if (char.IsWhiteSpace(text[i]))
                {
                    endIndex = i - 1;
                }
            }

            if (endIndex == -1)
            {
                output = new CommandPartString(text);
                text   = string.Empty;
            }
            else
            {
                output = new CommandPartString(text.Substring(0, endIndex));
                text   = text.Substring(endIndex);
            }

            return(true);
        }
Example #5
0
        public static StringComparison GetStringComparison(this CaseSensitivity caseSensitivity, CommandPart part)
        {
            if (part == CommandPart.CommandName && (caseSensitivity & CaseSensitivity.Commands) == 0)
            {
                return(StringComparison.OrdinalIgnoreCase);
            }
            else if (part == CommandPart.LongOption && (caseSensitivity & CaseSensitivity.LongOptions) == 0)
            {
                return(StringComparison.OrdinalIgnoreCase);
            }

            return(StringComparison.Ordinal);
        }
Example #6
0
            public CommandPart GetCommandPart(ref int pos)
            {
                var part = new CommandPart();

                if (IsShortForm || IsLongForm)
                {
                    ++pos;
                    part.IsArgument = true;

                    if (IsLongForm)
                    {
                        ++pos;
                    }
                    else
                    {
                        part.IsShortForm = true;
                    }

                    part.Key = new StringReference
                    {
                        Start  = pos,
                        Length = Key.Length
                    };

                    pos += Key.Length;

                    if (Value != default)
                    {
                        ++pos; // Space or equals
                        pos += QuoteChar != default ? 1 : 0;

                        part.Value = new StringReference
                        {
                            Start  = pos,
                            Length = Value.Length
                        };

                        pos += Value.Length;

                        pos += QuoteChar != default ? 1 : 0;
                    }
                }
                else
                {
                    pos += QuoteChar != default ? 1 : 0;

                    part.Key = new StringReference
                    {
                        Start  = pos,
                        Length = Value.Length
                    };

                    pos += Value.Length;

                    pos += QuoteChar != default ? 1 : 0;
                }

                ++pos;

                return(part);
            }
Example #7
0
 /// <summary>
 /// Parses a string.
 /// </summary>
 /// <param name="text">The string to parse, and after this is called, the string that is left over after parsing.</param>
 /// <param name="output">The <see cref="CommandPart"/> that this text contained.</param>
 /// <returns>True if the parsing was successful, otherwise false.</returns>
 public abstract bool Parse(ref string text, out CommandPart output);
Example #8
0
 public Command(IDependency[] dependecies, CommandPart parser, Func <Kingdom, Dictionary <string, object>, ExecutionResult> func)
 {
     this.Dependencies = dependecies;
     this.Parser       = parser;
     this.ExecuteFunc  = func;
 }
Example #9
0
        public static void Init()
        {
            Commands = new List <Command>();

            List <Tuple <string, object> > jobTuples = new List <Tuple <string, object> >();

            foreach (JobDescription d in ContentManager.GetJobs())
            {
                foreach (string s in d.GetAcceptableNames())
                {
                    jobTuples.Add(new Tuple <string, object>(s, d));
                }
            }

            CommandPart jobPart = new CommandPart("job", jobTuples.ToArray());

            Commands.Add(new Command(
                             new IDependency[] { },
                             new CommandPart(Locale.GetArray("commands.hire.list"),
                                             new CommandPart[] {
                new CommandPart("count",
                                CommandsStandartFunctions.CheckInt,
                                CommandsStandartFunctions.ParseInt,
                                new CommandPart[] { jobPart }),
                jobPart,
                new CommandPart()
            }
                                             ), (k, dict) => k.Hire(dict)
                             ));

            List <Tuple <string, object> > skills = new List <Tuple <string, object> >();

            foreach (string sk in ContentManager.GetSkills())
            {
                foreach (string lsk in Locale.GetArray("skills." + sk + ".names"))
                {
                    skills.Add(new Tuple <string, object>(lsk, sk));
                }
            }
            CommandPart skillPart = new CommandPart("skill", skills.ToArray());

            Commands.Add(new Command(
                             new IDependency[] { new HumanDependency() },
                             new CommandPart(Locale.GetArray("commands.train.list"),
                                             new CommandPart[] {
                new CommandPart("count",
                                CommandsStandartFunctions.CheckInt,
                                CommandsStandartFunctions.ParseInt,
                                new CommandPart[] { skillPart }),
                skillPart,
                new CommandPart()
            }
                                             ), (k, dict) => k.Train(dict)
                             ));

            List <Tuple <string, object> > resourceTuples = new List <Tuple <string, object> >();

            foreach (ItemDescription r in ContentManager.GetResources())
            {
                foreach (string s in r.GetAcceptableNames())
                {
                    resourceTuples.Add(new Tuple <string, object>(s, r));
                }
            }
            CommandPart extractable = new CommandPart("resource", resourceTuples.FindAll(t => {
                return((t.Item2 as ItemDescription).Extractable);
            }).ToArray());

            Commands.Add(new Command(
                             new IDependency[] { new HumanDependency() },
                             new CommandPart(
                                 Locale.GetArray("commands.extract.list"),
                                 new CommandPart[] { extractable, new CommandPart() }
                                 ),
                             (k, dict) => k.Extract(dict)
                             ));
            CommandPart creatable = new CommandPart("resource", resourceTuples.FindAll(t => {
                return((t.Item2 as ItemDescription).Creatable);
            }).ToArray());

            Commands.Add(new Command(
                             new IDependency[] { new HumanDependency() },
                             new CommandPart(
                                 Locale.GetArray("commands.create.list"),
                                 new CommandPart[] { creatable, new CommandPart() }
                                 ),
                             (k, dict) => k.Create(dict)
                             ));
            CommandPart growable = new CommandPart("resource", resourceTuples.ToArray());

            Commands.Add(new Command(
                             new IDependency[] { new HumanDependency(), new BuildingDependency("field", true) },
                             new CommandPart(
                                 Locale.GetArray("commands.grow.list"),
                                 new CommandPart[] { growable, new CommandPart() }
                                 ),
                             (k, dict) => k.Grow(dict)
                             ));

            List <Tuple <string, object> > buildingsTuples = new List <Tuple <string, object> >();

            foreach (BuildingDescription b in ContentManager.GetBuildings())
            {
                foreach (string s in b.GetAcceptableNames())
                {
                    buildingsTuples.Add(new Tuple <string, object>(s, b));
                }
            }
            CommandPart buildingPart = new CommandPart("building", buildingsTuples.ToArray());

            Commands.Add(new Command(
                             new IDependency[] { },
                             new CommandPart(Locale.GetArray("commands.build.list"),
                                             new CommandPart[] { buildingPart, new CommandPart() }
                                             ), (k, dict) => k.Build(dict)
                             ));

            CommandPart kingdomPart = new CommandPart("kingdom", CommandsStandartFunctions.CheckKingdom, CommandsStandartFunctions.ParseKingomd);

            Commands.Add(new Command(
                             new IDependency[] { new HumanDependency() },
                             new CommandPart(Locale.GetArray("commands.send.list"),
                                             new CommandPart[] { kingdomPart, new CommandPart() }
                                             ), (k, dict) => SendMessage(k, dict)
                             ));

            Commands.Add(new Command(
                             new IDependency[] { new HumanDependency() },
                             new CommandPart(Locale.GetArray("commands.execute.list"),
                                             new CommandPart[] { CommandsStandartFunctions.Fill }
                                             ), (k, dict) => k.Kill(dict)
                             ));
#if DEBUG
            LoadDebugCommands();
#endif
        }