public static Faction loadFromSave(XmlReader xmlRdr) { var _name = "UNKNOWN"; var str = ""; var flag = false; var _neededValue = 100; var num = 0; while (xmlRdr.Name != "Faction" && xmlRdr.Name != "EntropyFaction" && xmlRdr.Name != "HubFaction") { xmlRdr.Read(); } var name = xmlRdr.Name; if (xmlRdr.MoveToAttribute("name")) { _name = xmlRdr.ReadContentAsString(); } if (xmlRdr.MoveToAttribute("id")) { str = xmlRdr.ReadContentAsString(); } if (xmlRdr.MoveToAttribute("neededVal")) { _neededValue = xmlRdr.ReadContentAsInt(); } if (xmlRdr.MoveToAttribute("playerVal")) { num = xmlRdr.ReadContentAsInt(); } if (xmlRdr.MoveToAttribute("playerHasPassed")) { flag = xmlRdr.ReadContentAsString().ToLower() == "true"; } Faction faction; switch (name) { case "HubFaction": faction = new HubFaction(_name, _neededValue); break; case "EntropyFaction": faction = new EntropyFaction(_name, _neededValue); break; default: faction = new Faction(_name, _neededValue); break; } faction.playerValue = num; faction.idName = str; faction.playerHasPassedValue = flag; return(faction); }
/* Faction.loadFromSave */ private static Faction LoadFaction(ElementInfo root) { Faction result; string factionName = root.Attributes.GetValueOrDefault("name", "UNKNOWN"); int neededValue = root.Attributes.GetInt("neededVal", 100); switch (root.Name) { case "HubFaction": result = new HubFaction(factionName, neededValue); break; case "EntropyFaction": result = new EntropyFaction(factionName, neededValue); break; case "CustomFaction": CustomFaction faction; result = faction = new CustomFaction(factionName, 100); foreach (var child in root.Children.Where(e => e.Name == "Action")) { var action = new CustomFactionAction { ValueRequiredForTrigger = child.Attributes.GetInt("ValueRequired", 10), FlagsRequiredForTrigger = child.Attributes.GetValueOrDefault("Flags", null) }; foreach (var info in child.Children) { action.TriggerActions.Add(ActionsLoader.LoadAction(info)); } faction.CustomActions.Add(action); } break; default: result = new Faction(factionName, neededValue); break; } result.playerValue = root.Attributes.GetInt("playerVal", 0); result.idName = root.Attributes.GetValueOrDefault("id", ""); result.playerHasPassedValue = root.Attributes.GetBool("playerHasPassed"); return(result); }
public static Faction LoadFaction(ElementInfo info) { Faction ret; var name = info.Attributes.GetString("name", "UNKNOWN"); var needed = info.Attributes.GetInt("neededVal"); switch (info.Name) { case "HubFaction": ret = new HubFaction(name, needed); break; case "EntropyFaction": ret = new EntropyFaction(name, needed); break; case "CustomFaction": var actions = new List <CustomFactionAction>(); foreach (var actionSetInfo in info.Children) { actions.Add(new CustomFactionAction() { ValueRequiredForTrigger = actionSetInfo.Attributes.GetInt("ValueRequired"), FlagsRequiredForTrigger = actionSetInfo.Attributes.GetString("Flags", null), TriggerActions = actionSetInfo.Children.Select(ActionsLoader.ReadAction).ToList() }); } ret = new CustomFaction(name, 100) { CustomActions = actions }; break; default: ret = new Faction(name, needed); break; } ret.playerValue = info.Attributes.GetInt("playerVal"); ret.idName = info.Attributes.GetString("id"); ret.playerHasPassedValue = info.Attributes.GetBool("playerHasPassed"); return(ret); }