public static void Load(string filePath, Content content) { foreach (PropertyBag itemProp in PropertyBag.FromFile(filePath)) { string category = itemProp["category"].Value; string subcategory = itemProp.GetOrDefault("subcategory", String.Empty); // name string name = itemProp.Name; // art Character character = new Character('*', TermColor.Purple); PropertyBag art; if (itemProp.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(itemProp["glyph"].Value), TermColors.FromName(itemProp["color"].Value)); } // amount Roller amount = itemProp.GetOrDefault("amount", value => Roller.Parse(value), Roller.Fixed(1)); // charges Roller charges = itemProp.GetOrDefault("charges", value => Roller.Parse(value), Roller.Fixed(0)); // effect type EffectType effect = itemProp.GetOrDefault("effect", value => (EffectType)Enum.Parse(typeof(EffectType), value, true), EffectType.Hit); // attack Attack attack = null; PropertyBag attackProp; if (itemProp.TryGetValue("attack", out attackProp)) { string attackText = attackProp.Value; if (attackText.Contains(" ")) { // element included string[] parts = attackText.Split(' '); Roller damage = Roller.Parse(parts[0]); Element element = (Element)Enum.Parse(typeof(Element), parts[1], true); attack = new Attack(damage, element, Verbs.Hit, effect); } else { // default element Roller damage = Roller.Parse(attackText); attack = new Attack(damage, Verbs.Hit, effect); } } // armor int armor = itemProp.GetOrDefault("armor", 0); // use ItemScript useScript = itemProp.GetOrDefault("use", value => ItemScript.Create(value), null); // usage ChargeType chargeType = ChargeType.None; // default to single use if there is a use specified if (useScript != null) { chargeType = ChargeType.Single; } chargeType = itemProp.GetOrDefault("usage", value => (ChargeType)Enum.Parse(typeof(ChargeType), value, true), chargeType); // price int price = itemProp.GetOrDefault("price", 999999); ItemType itemType = new ItemType(content, name, category, subcategory, character, amount, charges, attack, armor, chargeType, useScript, price); // flags foreach (PropertyBag childProp in itemProp) { if (childProp.Name.StartsWith("+ ")) { string flag = childProp.Name.Substring(2).Trim(); itemType.Flags.Add(flag); } } // light PropertyBag light; if (itemProp.TryGetValue("light", out light)) { itemType.SetLightRadius(light.ToInt32()); } // target PropertyBag target; if (itemProp.TryGetValue("target", out target)) { itemType.SetTarget((ItemTarget)Enum.Parse(typeof(ItemTarget), target.Value, true)); } // ammunition PropertyBag ammunition; if (itemProp.TryGetValue("ammunition", out ammunition)) { itemType.SetAmmunition(ammunition.Value); } // hit scripts foreach (Element element in Enum.GetValues(typeof(Element))) { ItemScript hitScript = itemProp.GetOrDefault("on hit by " + element.ToString().ToLower(), value => ItemScript.Create(value), null); itemType.SetHitScript(element, hitScript); } content.Items.Add(itemType); } }
public static void Load(string filePath, Content content, bool isPrefix) { foreach (PropertyBag powerProp in PropertyBag.FromFile(filePath)) { // categories string[] categories = powerProp["categories"].Value.Split('|'); // appearance object appearance = powerProp.GetOrDefault <object>("appearance", value => TermColors.FromName(value), null); // level int minLevel = 1; int maxLevel = 1; PropertyBag level; if (powerProp.TryGetValue("level", out level)) { level.ToRange(out minLevel, out maxLevel); } // rarity int rarity = powerProp.GetOrDefault("rarity", 1); PowerType power = new PowerType(content, powerProp.Name, isPrefix, categories, appearance); content.Powers.Add(power, minLevel, maxLevel, rarity); // brand power.Element = powerProp.GetOrDefault("element", value => (Element)Enum.Parse(typeof(Element), value, true), power.Element); // bonuses power.StrikeBonus = powerProp.GetOrDefault("strike", value => Roller.Parse(value), power.StrikeBonus); power.DamageBonus = powerProp.GetOrDefault("damage", value => Roller.Parse(value), power.DamageBonus); power.ArmorBonus = powerProp.GetOrDefault("armor", value => Roller.Parse(value), power.ArmorBonus); power.StatBonus = powerProp.GetOrDefault("stats", value => Roller.Parse(value), power.StatBonus); power.SpeedBonus = powerProp.GetOrDefault("speed", value => Roller.Parse(value), power.SpeedBonus); // flags foreach (PropertyBag childProp in powerProp) { if (childProp.Name.StartsWith("+ ")) { string flag = childProp.Name.Substring(2).Trim(); power.Flags.Add(flag); } } } }
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); }