// Loader routine to handle XML public void RulesetLoader() { Ruleset = new ArrayList(); XmlDocument xdoc = new XmlDocument(); string filePath = Path.Combine("Data", "TourneyStone.xml"); if (!File.Exists(filePath)) throw (new FileNotFoundException()); xdoc.Load(filePath); XmlElement root = xdoc["Ruleset"]; RulesetVersion = Convert.ToDouble(Accounts.GetAttribute(root, "version", "0")); // Rules foreach (XmlElement node in root.GetElementsByTagName("Rule")) { try { Rule ReadRule = new Rule(); ReadRule.Desc = Accounts.GetText(node["Desc"], ""); ReadRule.FailText = Accounts.GetText(node["FailText"], ""); // Conditions ReadRule.Conditions = new ArrayList(); foreach (XmlElement ConNode in node.GetElementsByTagName("Condition")) { string rDef = Accounts.GetText(ConNode["Typ"], ""); RuleCondition RuleCon; if (rDef == "Property") { RuleCon = new PropertyCondition(); } else if (rDef == "ItemProperty") { RuleCon = new ItemPropertyCondition(); } else if (rDef == "Item") { RuleCon = new ItemCondition(); } else continue; RuleCon.Quantity = Accounts.GetInt32(Accounts.GetText(ConNode["Quantity"], ""), 0); RuleCon.Property = Accounts.GetText(ConNode["Property"], ""); RuleCon.PropertyVal = Accounts.GetText(ConNode["PropertyVal"], ""); RuleCon.Limit = Accounts.GetInt32(Accounts.GetText(ConNode["Limit"], ""), 0); string sItemType = Accounts.GetText(ConNode["ItemType"], ""); string Configurable = Accounts.GetText(ConNode["Configurable"], ""); if (Configurable.ToUpper() == "TRUE") RuleCon.Configurable = true; else RuleCon.Configurable = false; // Divine the type from the string if there is one if (sItemType != "") { Type tItemType = ScriptCompiler.FindTypeByName(sItemType); if (tItemType != null) RuleCon.ItemType = tItemType; } RuleCon.Rule = ReadRule; ReadRule.Conditions.Add(RuleCon); } // Default activation to false (set through gump + // deserialization process) ReadRule.Active = false; // Add to the stone's RuleSet Ruleset.Add(ReadRule); } catch (Exception e) { Console.WriteLine("TourneyStoneaddon : Exception reading XML - {0}", e); } } }
// Validate the mobile passed and add into arraylist // passed by reference public void Validate(PlayerMobile pm, ref ArrayList fp) { // Make sure we have a ruleset if (TourneyStone.Ruleset.Count == 0) return; Player = pm; ArrayList failures = new ArrayList(); ArrayList Rules = new ArrayList(); ArrayList Fallthroughs = new ArrayList(); // Grab the ruleset Rules = TourneyStone.Ruleset; int RulesetCount = Rules.Count; // Create a HeldStuff instance to figure out // what they have HeldStuff CurrentHeld = new HeldStuff(pm); // Loop through each rule & condition... deal for (int rpos = 0; rpos < RulesetCount; rpos++) { Rule RuleChecking = (Rule)Rules[rpos]; if (RuleChecking.Conditions.Count == 0 || RuleChecking.Active == false) continue; foreach (RuleCondition rc in RuleChecking.Conditions) { // What kind of condition are we dealing with here? if (rc is ItemCondition) { // ITEM CONDITION // (validate entire held item list against rule) string FailText = RuleChecking.FailText; string sDynFails = ""; bool bFails = false; // wea: 25/Feb/2007 Modified call to pass CurrentHeld rather // than one item at a time if (!rc.Guage(CurrentHeld.Contents, ref Fallthroughs)) { sDynFails += string.Format("{0}{1}", (sDynFails == "" ? "" : ", "), RuleChecking.FailTextDyn); bFails = true; } if (bFails) { if (sDynFails != "") FailText += " You have : " + sDynFails; FailText = RuleChecking.DynFill(FailText); failures.Add(FailText); } } else if (rc is ItemPropertyCondition) // wea: 28/Feb/2007 Incorrect rule handling fix { // ITEM PROPERTY CONDITION string FailText = RuleChecking.FailText; string sDynFails = ""; bool bFails = false; foreach (HeldItem hi in CurrentHeld.Contents) { if (!rc.Guage(hi, ref Fallthroughs)) { sDynFails += string.Format("{0}{1}", (sDynFails == "" ? "" : ", "), RuleChecking.FailTextDyn); bFails = true; } } if (bFails) { if (sDynFails != "") FailText += " You have : " + sDynFails; FailText = RuleChecking.DynFill(FailText); failures.Add(FailText); } } else if (rc is PropertyCondition) { // MOBILE PROPERTY CONDITION // (validate using the mobile) if (!rc.Guage(Player)) { string FailText = RuleChecking.FailText + " " + RuleChecking.FailTextDyn; FailText = RuleChecking.DynFill(FailText); failures.Add(FailText); } } } } fp = failures; }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); // Ruleset version of this saved stone double SavedVersion = reader.ReadDouble(); // Load XML ruleset base RulesetLoader(); int RuleCount = reader.ReadInt(); // Version 0 - pre RuleCondition class, load differently // to future versions // -- if (version == 0) { // Ignore for (int rpos = 0; rpos < RuleCount; rpos++) { reader.ReadBool(); bool configurable = reader.ReadBool(); if (configurable) { reader.ReadInt(); reader.ReadString(); } } } // -- else { // Compare versions.. ignore any out of date saved data if (RulesetVersion == SavedVersion && RuleCount == Ruleset.Count) { // Same XML ruleset, so load custom data // for (int rpos = 0; rpos < RuleCount; rpos++) { Rule TestRule = (Rule)Ruleset[rpos]; TestRule.Active = reader.ReadBool(); // How many conditions are we dealing with? int ConCount = reader.ReadInt(); for (int cpos = 0; cpos < ConCount; cpos++) { // Match up each condition - they should all exist RuleCondition TestCon = (RuleCondition)TestRule.Conditions[cpos]; TestCon.Configurable = reader.ReadBool(); if (TestCon.Configurable == true) { TestCon.Quantity = reader.ReadInt(); TestCon.PropertyVal = reader.ReadString(); } } } } else { // New XML ruleset, serialized data is out of date, so just deserialize // and leave the default activisation + customization data. // for (int rpos = 0; rpos < RuleCount; rpos++) { reader.ReadBool(); int ConCount = reader.ReadInt(); for (int cpos = 0; cpos < ConCount; cpos++) { bool configurable = reader.ReadBool(); if (configurable) { reader.ReadInt(); reader.ReadString(); } } } } } switch (version) { case 2: // deserialize the properties added with version change goto case 1; case 1: break; } // Add the components //AddComponent( new TourneyStoneBase(),0,0,0); //AddComponent( new TourneyStoneRune(),0,0,0); }
// Loader routine to handle XML public void RulesetLoader () { Ruleset = new ArrayList(); XmlDocument xdoc = new XmlDocument(); string filePath = Path.Combine( "Data", "TourneyStone.xml" ); if ( !File.Exists( filePath ) ) throw( new FileNotFoundException() ); xdoc.Load( filePath ); XmlElement root = xdoc["Ruleset"]; RulesetVersion = Convert.ToDouble( Accounts.GetAttribute( root, "version", "0" ) ); // Rules foreach ( XmlElement node in root.GetElementsByTagName( "Rule" ) ) { try { Rule ReadRule = new Rule(); ReadRule.Desc = Accounts.GetText( node["Desc"], "" ); ReadRule.FailText = Accounts.GetText( node["FailText"], "" ); // Conditions ReadRule.Conditions = new ArrayList(); foreach ( XmlElement ConNode in node.GetElementsByTagName( "Condition" ) ) { string rDef = Accounts.GetText( ConNode["Typ"], "" ); RuleCondition RuleCon; if( rDef == "Property" ) { RuleCon = new PropertyCondition(); } else if(rDef == "ItemProperty") { RuleCon = new ItemPropertyCondition(); } else if(rDef == "Item") { RuleCon = new ItemCondition(); } else continue; RuleCon.Quantity = Accounts.GetInt32( Accounts.GetText( ConNode["Quantity"], "" ), 0 ); RuleCon.Property = Accounts.GetText( ConNode["Property"], "" ); RuleCon.PropertyVal = Accounts.GetText( ConNode["PropertyVal"], "" ); RuleCon.Limit = Accounts.GetInt32( Accounts.GetText( ConNode["Limit"], "" ), 0 ); string sItemType = Accounts.GetText( ConNode["ItemType"], "" ); string Configurable = Accounts.GetText( ConNode["Configurable"], "" ); if( Configurable.ToUpper() == "TRUE" ) RuleCon.Configurable = true; else RuleCon.Configurable = false; // Divine the type from the string if there is one if( sItemType != "" ) { Type tItemType = ScriptCompiler.FindTypeByName( sItemType ); if ( tItemType != null ) RuleCon.ItemType = tItemType; } RuleCon.Rule = ReadRule; ReadRule.Conditions.Add( RuleCon ); } // Default activation to false (set through gump + // deserialization process) ReadRule.Active = false; // Add to the stone's RuleSet Ruleset.Add( ReadRule ); } catch (Exception e) { Console.WriteLine("TourneyStoneaddon : Exception reading XML - {0}", e); } } }