public void Parse(string arguments) { string token = MyStrings.GetQuotedToken(ref arguments).ToLower(); this.What = BuildingType.GetByAnyName(token); if (this.What == null) { throw new Exception("Bad object " + token); } // TODO: missing check if item is buildable }
private static BuildOrder ReadBuildOrder(string s) { string t1 = MyStrings.GetQuotedToken(ref s).ToLower(); BuildOrder ord = new BuildOrder(); ord.What = BuildingType.GetByAnyName(t1); if (ord.What == null) { throw new Exception("Bad object"); } return(ord); }
public void Parse(string arguments) { string targetToken = MyStrings.GetToken(ref arguments).ToLower(); #region target token switch switch (targetToken) { case "faction": string factionToken = MyStrings.GetToken(ref arguments); if (!MyStrings.IsNumber(factionToken)) { throw new Exception("Bad faction " + factionToken); } this.FactionNum = Convert.ToInt32(factionToken); break; case "item": string itemToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); ItemType itemType = ItemType.GetByAnyName(itemToken); if (itemType == null) { throw new Exception("Bad item " + itemToken); } this.ItemType = itemType; break; case "skill": string skillToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); SkillType skillType = SkillType.GetByAnyName(skillToken); if (skillType == null) { throw new Exception("Bad skill " + skillToken); } this.SkillType = skillType; break; case "object": string objectToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); BuildingType buildingType = BuildingType.GetByAnyName(objectToken); if (buildingType == null) { throw new Exception("Bad object"); } this.BuildingType = buildingType; break; default: throw new Exception("Bad parameter " + targetToken); } #endregion }
private static ShowOrder ReadShowOrder(string s) { ShowOrder ord = new ShowOrder(); string t1 = MyStrings.GetToken(ref s).ToLower(); if (t1 == "faction") { string t2 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad faction"); } ord.FactionNum = Convert.ToInt32(t2); } else if (t1 == "item") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ord.ItemType = ItemType.GetByAnyName(t2); if (ord.ItemType == null) { throw new Exception("Bad item"); } } else if (t1 == "skill") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ord.SkillType = SkillType.GetByAnyName(t2); if (ord.SkillType == null) { throw new Exception("Bad skill"); } } else if (t1 == "object") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ord.BuildingType = BuildingType.GetByAnyName(t2); if (ord.BuildingType == null) { throw new Exception("Bad object"); } } else { throw new Exception("Bad parameter"); } return(ord); }