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"); }
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); }
public static DropMacroCollection <Item> LoadItemDrops(string dirPath, Content content) { var parser = new ItemDropParser(content); return(LoadDrops <Item>(dirPath, parser)); }