private void AddSpawnTemplate(XmlNode template) { XmlNodeList spawnParamList = template.ChildNodes; Dictionary <string, string> data = new Dictionary <string, string>(); List <Dictionary <string, string> > lootItems = new List <Dictionary <string, string> >(); //int lootCount = 0; foreach (XmlNode spawnParam in spawnParamList) { if (spawnParam.Name.ToLower() == "loot") { Dictionary <string, string> loot = new Dictionary <string, string>(); foreach (XmlNode lootParam in spawnParam.ChildNodes) { loot.Add(lootParam.Name.ToLower(), lootParam.InnerText); } lootItems.Add(loot); } else { data.Add(spawnParam.Name.ToLower(), spawnParam.InnerText); } } SpawnTemplate st = new SpawnTemplate(); st.typeID = uint.Parse(data["id"]); st.name = data["name"]; st.delay = int.Parse(data["delay"]); st.AIMode = int.Parse(data["aimode"]); st.lootItems = lootItems; templates.Add(st.typeID, st); }
private int AddSpawn(XmlNode spawn) { XmlNodeList spawnParamList = spawn.ChildNodes; Dictionary <string, string> data = new Dictionary <string, string>(); List <Dictionary <string, string> > lootItems = new List <Dictionary <string, string> >(); //int lootCount = 0; int count = 0; foreach (XmlNode spawnParam in spawnParamList) { if (spawnParam.Name == "loot") { Dictionary <string, string> loot = new Dictionary <string, string>(); foreach (XmlNode lootParam in spawnParam.ChildNodes) { loot.Add(lootParam.Name, lootParam.InnerText); } lootItems.Add(loot); } else { data.Add(spawnParam.Name, spawnParam.InnerText); } } for (int j = 0; j < int.Parse(data["amount"]); j++) { try { Mob newMob; System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo("en-US"); ActorNPC newActor = new ActorNPC(uint.Parse(data["id"]), 100, 100, 100, 100); SpawnTemplate template = new SpawnTemplate(); newMob = MobFactory.GetMob(uint.Parse(data["id"]), ref newActor);//Load Mob Infos from DB if (templates.ContainsKey(newMob.Type)) { template = templates[newMob.Type]; } newMob.MapName = data["map"]; newActor.mapID = (byte)MapManager.Instance.GetMapId(newMob.MapName); if (data.ContainsKey("name")) { newMob.Name = data["name"]; } newActor.name = newMob.Name; if (data.ContainsKey("delay")) { newMob.Delay = int.Parse(data["delay"]); } else { newMob.Delay = template.delay; } newMob.AIMode = template.AIMode; Map map; MapManager.Instance.GetMap(MapManager.Instance.GetMapId(newMob.MapName), out map); float[] pos; pos = GetRandomPos(map, float.Parse(data["x"], culture), float.Parse(data["y"], culture), float.Parse(data["range"], culture)); if (!map.HasHeightMap() && data.ContainsKey("z")) { pos[2] = float.Parse(data["z"], culture); } newMob.StartX = float.Parse(data["x"], culture); newMob.StartY = float.Parse(data["y"], culture); if (data.ContainsKey("z")) { newMob.StartZ = float.Parse(data["z"], culture); } else { newMob.StartZ = map.GetHeight(newMob.StartX, newMob.StartY); } newMob.range = float.Parse(data["range"], culture); newActor.x = pos[0]; newActor.y = pos[1]; newActor.z = pos[2]; if (lootItems.Count == 0) { lootItems = template.lootItems; } foreach (Dictionary <string, string> loot in lootItems) { int amount = 1; if (loot.ContainsKey("amount")) { amount = int.Parse(loot["amount"]); } int itemid = int.Parse(loot["id"]); float perc = (float)Config.Instance.DropRate / 100; for (int i = 0; i < amount; ++i) { if (Global.Random.Next(0, 10000) <= int.Parse(loot["rate"]) * perc) { newMob.AddLoot(itemid); } } } Map newMobMap = null; if (!MapManager.Instance.GetMap(newActor.mapID, out newMobMap)) { Logger.ShowError("Could not obtain map for monster spawn ", null); return(0); } newMob.Map = newMobMap; //newMob.StartZ = newMob.Map.HeightMap.GetZ(newMob.StartX, newMob.StartY); //newActor.z = newMob.StartZ; //**********AI************* newMob.ai = new MobAI(newMob); //newMob.ai.Start(); // the ai should be switched on if there is a playere near by, for test now //newActor.sightRange = Global.MakeSightRange(1000); //it is loaded in Mobdb, no more needed if (newMobMap.RegisterActor(newActor)) { if (newMob.Delay != -1) { newMob.RespawnTask = new SpawnOnce(newMob); } scripts.Add(newMobMap.ID + "-" + newMob.Name + "-" + spawnCount++, newMob); //Logger.ShowInfo(newMob.Name.PadRight(20) + " MOB added at " + newMobMap.Name + ":" + newActor.x + "#" + newActor.y + "#" + newActor.z, null); } count++; } catch (Exception ex) { Logger.ShowError(ex, null); } } return(count); }