Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
				}
			}
		}