private static void MakeSpawner(string[] types, int x, int y, Map map) { if (types.Length == 0) { return; } int z = GetSpawnerZ(x, y, map); ClearSpawners(x, y, z, map); Spawner sp = new Spawner { MinDelay = MinTime, MaxDelay = MaxTime, Team = Team, HomeRange = HomeRange }; int count = 0; for (int i = 0; i < types.Length; ++i) { bool isGuildMaster = types[i].EndsWith("Guildmaster"); count += isGuildMaster ? 1 : NPCCount; if (isGuildMaster) { count++; } sp.AddEntry(types[i], 100, isGuildMaster ? 1 : NPCCount); } sp.Count = count; sp.MoveToWorld(new Point3D(x, y, z), map); if (TotalRespawn) { sp.Respawn(); sp.BringToHome(); } m_Count += types.Length; }
private static void GenenerateSpawners_OnCommand(CommandEventArgs e) { if (e.Arguments.Length == 0) { e.Mobile.SendMessage("Usage: GenerateSpawners filename"); return; } string fullPath = "Spawns/" + e.Arguments[0].ToLower() + ".json"; if (!File.Exists(fullPath)) { e.Mobile.SendMessage($"Cannot find file {fullPath}..."); return; } e.Mobile.SendMessage($"Generating spawners for {e.Arguments[0].ToLower()}"); using JsonTextReader jtr = new JsonTextReader(new StreamReader(fullPath)); JsonSerializer serializer = JsonSerializer.Create(); SpawnDefinition[] data = serializer.Deserialize <SpawnDefinition[]>(jtr); int spawnersCreated = 0; Stopwatch sw = new Stopwatch(); sw.Start(); int stepSize = data.Length / 10; foreach (SpawnDefinition definition in data) { Map map = definition.Map switch { SpawnDefinition.MapId.Felucca => Map.Felucca, SpawnDefinition.MapId.Trammel => Map.Trammel, SpawnDefinition.MapId.Ilshenar => Map.Ilshenar, SpawnDefinition.MapId.Malas => Map.Malas, SpawnDefinition.MapId.Tokuno => Map.Tokuno, SpawnDefinition.MapId.TerMur => Map.TerMur, _ => throw new IndexOutOfRangeException() }; Point3D location = new Point3D(definition.X, definition.Y, definition.Z); CheckLocation(ref location, map); Spawner spawner = new Spawner { HomeRange = definition.HomeRange, WalkingRange = definition.WalkingRange, MinDelay = definition.MinDelay, MaxDelay = definition.MaxDelay, Running = false }; foreach (SpawnEntry entry in definition.Entries) { spawner.AddEntry(entry.Name, entry.Probability, entry.MaxCount); } spawner.MoveToWorld(location, map); spawner.Count = definition.Count; spawner.Running = true; spawner.Respawn(); spawnersCreated++; if ((spawnersCreated % stepSize) == 0) { e.Mobile.SendMessage($"generation is {(int)Math.Ceiling((spawnersCreated / (float)data.Length) * 100f)}% complete"); } } sw.Stop(); e.Mobile.SendMessage($"{spawnersCreated} spawners generated in {sw.Elapsed}."); }