Пример #1
0
        static SpawnGroup()
        {
            string path = Path.Combine(Core.BaseDirectory, "Data/SpawnDefinitions.xml");

            if (!File.Exists(path))
            {
                return;
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);

                XmlElement root = doc["spawnDefinitions"];
                if (root == null)
                {
                    return;
                }

                foreach (XmlElement xmlDef in root.SelectNodes("spawnGroup"))
                {
                    string name = null;
                    if (!Region.ReadString(xmlDef, "name", ref name))
                    {
                        continue;
                    }

                    List <SpawnGroupElement> list = new List <SpawnGroupElement>();
                    foreach (XmlNode node in xmlDef.ChildNodes)
                    {
                        XmlElement el = node as XmlElement;

                        if (el != null)
                        {
                            SpawnDefinition def = GetSpawnDefinition(el);
                            if (def == null)
                            {
                                continue;
                            }

                            int weight = 1;
                            Region.ReadInt32(el, "weight", ref weight, false);

                            SpawnGroupElement groupElement = new SpawnGroupElement(def, weight);
                            list.Add(groupElement);
                        }
                    }

                    SpawnGroupElement[] elements = list.ToArray();
                    SpawnGroup          group    = new SpawnGroup(name, elements);
                    Register(group);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not load SpawnDefinitions.xml: ");
                Diagnostics.ExceptionLogging.LogException(ex);
            }
        }
		public override object Spawn( SpawnEntry entry )
		{
			int index = Utility.Random( m_TotalWeight );

			for ( int i = 0; i < m_Elements.Length; i++ )
			{
				SpawnGroupElement element = m_Elements[i];

				if ( index < element.Weight )
					return element.SpawnDefinition.Spawn( entry );

				index -= element.Weight;
			}

			return null;
		}
Пример #3
0
        public override ISpawnable Spawn(SpawnEntry entry)
        {
            int index = Utility.Random(m_TotalWeight);

            for (int i = 0; i < m_Elements.Length; i++)
            {
                SpawnGroupElement element = m_Elements[i];

                if (index < element.Weight)
                {
                    return(element.SpawnDefinition.Spawn(entry));
                }

                index -= element.Weight;
            }

            return(null);
        }
Пример #4
0
		public SpawnGroup( string name, SpawnGroupElement[] elements )
		{
			m_Name = name;
			m_Elements = elements;

			m_TotalWeight = 0;
			for ( int i = 0; i < elements.Length; i++ )
				m_TotalWeight += elements[i].Weight;
		}
Пример #5
0
		static SpawnGroup()
		{
			string path = Path.Combine( Core.BaseDirectory, "Data/SpawnDefinitions.xml" );
			if ( !File.Exists( path ) )
				return;

			try
			{
				XmlDocument doc = new XmlDocument();
				doc.Load( path );

				XmlElement root = doc["spawnDefinitions"];
				if ( root == null )
					return;

				foreach ( XmlElement xmlDef in root.SelectNodes( "spawnGroup" ) )
				{
					string name = null;
					if ( !Region.ReadString( xmlDef, "name", ref name ) )
						continue;

					List<SpawnGroupElement> list = new List<SpawnGroupElement>();
					foreach ( XmlNode node in xmlDef.ChildNodes )
					{
						XmlElement el = node as XmlElement;

						if ( el != null )
						{
							SpawnDefinition def = GetSpawnDefinition( el );
							if ( def == null )
								continue;

							int weight = 1;
							Region.ReadInt32( el, "weight", ref weight, false );

							SpawnGroupElement groupElement = new SpawnGroupElement( def, weight );
							list.Add( groupElement );
						}
					}

					SpawnGroupElement[] elements = list.ToArray();
					SpawnGroup group = new SpawnGroup( name, elements );
					Register( group );
				}
			}
			catch ( Exception ex )
			{
				Console.WriteLine( "Could not load SpawnDefinitions.xml: " + ex.Message );
			}
		}