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); } }
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); }