public static void Load(string filePath, DropMacroCollection <Item> dropMacros, Content content) { foreach (PropertyBag raceProp in PropertyBag.FromFile(filePath)) { int depth; int rarity; Race race = LoadRace(raceProp, dropMacros, content, out depth, out rarity); content.Races.Add(race, depth, rarity); } Console.WriteLine("Loaded " + content.Races.Count + " races"); }
public static void Load(string filePath, DropMacroCollection <Item> dropMacros, Content content) { var parser = new ItemDropParser(content); foreach (PropertyBag storeProperty in PropertyBag.FromFile(filePath)) { int depth = storeProperty.GetOrDefault("depth", 0); // parse the drops PropertyBag dropProp = storeProperty["drops"]; IDrop <Item> drop = parser.ParseMacro(dropProp, dropMacros); content.Stores.Add(new StoreType(content, storeProperty.Name, depth, drop)); } Console.WriteLine("Loaded " + content.Stores.Count + " stores"); }
/// <summary> /// Loads the collection of <see cref="IDrop"/> macros from the /// given file. /// </summary> /// <param name="dirPath">Path to a directory with <see cref="PropertyFile"> /// PropertyFiles</see> containing IDrop macros.</param> /// <returns>The collection of macros.</returns> public static DropMacroCollection <T> LoadDrops <T>(string dirPath, DropParser <T> parser) { DropMacroCollection <T> collection = new DropMacroCollection <T>(); // load them foreach (string filePath in Directory.GetFiles(dirPath, "*.txt")) { foreach (PropertyBag macroProp in PropertyBag.FromFile(filePath)) { IDrop <T> drop = parser.ParseMacro(macroProp, collection); collection.Add(macroProp.Name, drop); } } Console.WriteLine("Loaded " + collection.Count + " drop macros"); return(collection); }
public static Content Load() { // only load once if (sContent == null) { sContent = new Content(); // load items and powers first so that monsters can drop them Items.Load(@"Data\Items.txt", sContent); Powers.Load(@"Data\Prefix Powers.txt", sContent, true); Powers.Load(@"Data\Suffix Powers.txt", sContent, false); DropMacroCollection <Item> dropMacros = Macros.LoadItemDrops(@"Data\Drops", sContent); Races.Load(@"Data\Monsters.txt", dropMacros, sContent); Stores.Load(@"Data\Town\Stores.txt", dropMacros, sContent); HeroRaces.Load(@"Data\Hero\Races.txt", sContent); Features.Load(@"Data\Dungeon\Rooms.txt", sContent); } return(sContent); }
private static Race LoadRace(PropertyBag raceProp, DropMacroCollection <Item> dropMacros, Content content, out int depth, out int rarity) { Character character = new Character('*', TermColor.Purple); PropertyBag art; if (raceProp.TryGetValue("art", out art)) { //### bob: old style color and glyph combined character = Character.Parse(art.Value); } else { // separate glyph and color character = new Character( Character.ParseGlyph(raceProp["glyph"].Value), TermColors.FromName(raceProp["color"].Value)); } // depth depth = raceProp["depth"].ToInt32(); // speed int speed = raceProp.GetOrDefault("speed", 0) + Energy.NormalSpeed; // health Roller health = Roller.Parse(raceProp["health"].Value); // rarity rarity = raceProp.GetOrDefault("rarity", 1); // create the race Race race = new Race(content, raceProp.Name, depth, character, speed, health); // attacks PropertyBag attacks; if (raceProp.TryGetValue("attacks", out attacks)) { foreach (PropertyBag attackProp in attacks) { string[] attackParts = attackProp.Value.Split(' '); // create the attack Roller damage = Roller.Parse(attackParts[0]); FlagCollection flags = new FlagCollection(); Element element = Element.Anima; // add the flags or element for (int i = 1; i < attackParts.Length; i++) { try { // see if the part is an element element = (Element)Enum.Parse(typeof(Element), attackParts[i], true); } catch (ArgumentException) { // must be a flag flags.Add(attackParts[i]); } } //### bob: need to support different effect types Attack attack = new Attack(damage, 0, 1.0f, element, attackProp.Name, EffectType.Hit, flags); race.Attacks.Add(attack); } } // moves PropertyBag moves; if (raceProp.TryGetValue("moves", out moves)) { foreach (PropertyBag moveProp in moves) { string moveName = moveProp.Name; // if an explicit move field is provided, then the prop name is not the name of the move itself PropertyBag explicitMove; if (moveProp.TryGetValue("move", out explicitMove)) { moveName = explicitMove.Value; } // parse the specific move info MoveInfo info = ParseMove(moveProp); Move move; // construct the move switch (moveName) { case "haste self": move = new HasteSelfMove(); break; case "ball self": move = new BallSelfMove(); break; case "cone": move = new ElementConeMove(); break; case "breathe": move = new BreatheMove(); break; case "bolt": move = new BoltMove(); break; case "message": move = new MessageMove(); break; case "breed": move = new BreedMove(); break; default: throw new Exception("Unknown move \"" + moveName + "\"."); } move.BindInfo(info); race.Moves.Add(move); } } // flags foreach (PropertyBag childProp in raceProp) { if (childProp.Name.StartsWith("+ ")) { string flag = childProp.Name.Substring(2).Trim(); // handle the flags switch (flag) { case "groups": race.SetGroupSize(GroupSize.Group); break; case "packs": race.SetGroupSize(GroupSize.Pack); break; case "swarms": race.SetGroupSize(GroupSize.Swarm); break; case "hordes": race.SetGroupSize(GroupSize.Horde); break; case "very-bright": race.SetLightRadius(2); break; case "bright": race.SetLightRadius(1); break; case "glows": race.SetLightRadius(0); break; case "unmoving": race.SetPursue(Pursue.Unmoving); break; case "slightly-erratic": race.SetPursue(Pursue.SlightlyErratically); break; case "erratic": race.SetPursue(Pursue.Erratically); break; case "very-erratic": race.SetPursue(Pursue.VeryErratically); break; case "unique": race.SetFlag(RaceFlags.Unique); break; case "boss": race.SetFlag(RaceFlags.Boss); break; case "opens-doors": race.SetFlag(RaceFlags.OpensDoors); break; default: Console.WriteLine("Unknown flag \"{0}\"", flag); break; } } } // resists PropertyBag resists; if (raceProp.TryGetValue("resists", out resists)) { ParseResists(resists.Value, race); } // drops PropertyBag drops; if (raceProp.TryGetValue("drops", out drops)) { var parser = new ItemDropParser(content); IDrop <Item> drop = parser.ParseDefinition(drops, dropMacros); race.SetDrop(drop); } // description PropertyBag description; if (raceProp.TryGetValue("description", out description)) { race.SetDescription(description.Value); } // groups PropertyBag groups; if (raceProp.TryGetValue("groups", out groups)) { race.SetGroups(groups.Value.Split(' ')); } return(race); }
private IDrop <T> Parse(PropertyBag property, DropMacroCollection <T> macros, bool defining, out float odds) { // default odds = 0; // check for a repeat string[] parts = property.Name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Roller repeat = null; bool hasOdds = false; if (parts.Length > 1) { // repeat (may return null) repeat = Roller.Parse(parts[0]); // odds, formatted like (12%) string oddsString = parts[parts.Length - 1]; if ((oddsString.Length > 3) && (oddsString[0] == '(') && (oddsString[oddsString.Length - 2] == '%') && (oddsString[oddsString.Length - 1] == ')')) { hasOdds = Single.TryParse(oddsString.Substring(1, oddsString.Length - 3), out odds); } // bob: hack. also allow no percent sign for "choose by level" odds, formatted like (12) if (!hasOdds && (oddsString.Length > 2) && (oddsString[0] == '(') && (oddsString[oddsString.Length - 1] == ')')) { hasOdds = Single.TryParse(oddsString.Substring(1, oddsString.Length - 2), out odds); } } int start = (repeat != null) ? 1 : 0; int count = parts.Length - start - (hasOdds ? 1 : 0); // put the remaining item type back together string text = String.Join(" ", parts, start, count); // see what the underlying type is IDrop <T> drop = null; if (defining || (text == "any of") || (text == "drops")) { var allDrop = new AllDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); allDrop.Add(childDrop, childOdds); } drop = allDrop; } else if ((text == "one of") || (text == "drops one")) { var chooseDrop = new ChooseDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } chooseDrop.FixOdds(); drop = chooseDrop; } else if (text == "one from level") { var chooseDrop = new ChooseByLevelDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } drop = chooseDrop; } else if (text == "one up to level") { var chooseDrop = new ChooseUpToLevelDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } drop = chooseDrop; } else if (text == "one near level") { var chooseDrop = new ChooseNearLevelDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } drop = chooseDrop; } else if ((macros != null) && (macros.ContainsKey(text))) { // use the macro's drop (note: not cloned because drops are immutable) drop = macros[text]; } else { drop = ParseDrop(text); if (drop == null) { Console.WriteLine("Could not parse drop \"" + text + "\"."); } } // wrap it in a repeater if (repeat != null) { drop = new RepeatDrop <T>(repeat, drop); } return(drop); }
private IDrop <T> Parse(PropertyBag property, DropMacroCollection <T> macros, out float odds) { return(Parse(property, macros, false, out odds)); }
private IDrop <T> Parse(PropertyBag property, DropMacroCollection <T> macros) { float dummy; return(Parse(property, macros, false, out dummy)); }
public IDrop <T> ParseDefinition(PropertyBag property, DropMacroCollection <T> macros) { float dummy; return(Parse(property, macros, false, out dummy)); }
public IDrop <T> ParseMacro(PropertyBag property, DropMacroCollection <T> macros) { float dummy; return(Parse(property, macros, true, out dummy)); }