public static List <Spawner> GetSpawnersByRegion(Region region) { if (region == null) { return(null); } List <Spawner> spawners = new List <Spawner>(); //time this search, log if it takes longer than .30 seconds Utility.TimeCheck tc = new Utility.TimeCheck(); tc.Start(); foreach (Spawner s in m_Spawners) { if (Region.Find(s.Location, s.Map) == region) { spawners.Add(s); } } tc.End(); if (tc.Elapsed() > 30) { LogHelper logger = new LogHelper("SpawnerCache"); logger.Log("Warning: Spawner search by region for " + region.Name + " took " + tc.Elapsed().ToString() + "ms"); } return(spawners); }
public static Spawner GetRandomSpawner(SpawnerType type) { // if still empty, fail if (m_Spawners.Count == 0) { return(null); } Spawner spawner = null; Utility.TimeCheck tc = new Utility.TimeCheck(); tc.Start(); //try to find an appropriate spawner for (int count = 0; count < m_Spawners.Count * 2; ++count) { // pick one at random.. Spawner random = m_Spawners[Utility.Random(m_Spawners.Count)] as Spawner; Region region = Server.Region.Find(random.Location, Map.Felucca); // test if this spawner satisfies type required switch (type) { case SpawnerType.Overland: { // Must be running if (!random.Running) { continue; } if (region != null) { // No Towns if (IsTown(region.Name)) { continue; } // no green acres, inside houses, etc.. if (IsValidRegion(random.Location, region) == false) { continue; } } break; } default: { if (region != null) { // no green acres, inside houses, etc.. if (IsValidRegion(random.Location, region) == false) { continue; } } break; } } //this is a good candidate! spawner = random; break; } tc.End(); if (tc.Elapsed() > 30) { LogHelper logger = new LogHelper("SpawnerCache"); logger.Log("Warning: Spawner overland search took " + tc.Elapsed().ToString() + "ms"); } return(spawner); }
private int MobileLifespanCleanupWorker(out int mobsdeleted, double timeout) { int iChecked = 0; mobsdeleted = 0; try { ArrayList ToDelete = new ArrayList(); foreach (Mobile m in World.Mobiles.Values) { // mobiles on the internal map are handled elsewhere (includes stabled) // Note: PlayerVendors are not BaseCreature, and are handled elsewhere if (m is BaseCreature && m.Map != Map.Internal) { iChecked++; BaseCreature bc = (BaseCreature)m; // process exclusions here if (!bc.Controlled // summons, pets, IOB followers, hire fighters && !bc.SpawnerTempMob // spawner template mobs, no deleteing && !(bc is BaseVendor) // house sitters, barkeeps, auctioneers (Idea: exclude if Admin owned or InHouseRegion only. Others could be deleted.) && !bc.IOBFollower // probably handled by !bc.Controled && !bc.Blessed // Zoo animals etc. && !bc.Deleted) // duh. { // process inclusions here if (bc.IsPassedLifespan() && bc.Hits == bc.HitsMax) { bool bSkip = false; // if the creature has not thought in the last little while, then he is said to be Hibernating if (bc.Hibernating == false) bSkip = true; if (!bSkip) ToDelete.Add(bc); } } } } if (ToDelete.Count > 0) { // ToDelete.Sort(new AgeCheck()); Utility.TimeCheck tc = new Utility.TimeCheck(); tc.Start(); for (int i = 0; i < ToDelete.Count; i++) { mobsdeleted++; ((BaseCreature)ToDelete[i]).Delete(); // Adam: do not spend too much time here // this is no longer an issue as we fixed the very slow region.InternalExit and sector.OnLeave if (tc.Elapsed() > timeout) break; } tc.End(); if (ToDelete.Count - mobsdeleted > 0) System.Console.WriteLine("Ran out of time, skipping {0} mobiles", ToDelete.Count - mobsdeleted); } } catch (Exception e) { LogHelper.LogException(e); System.Console.WriteLine("Exception Caught in MOBCleanup removal code: " + e.Message); System.Console.WriteLine(e.StackTrace); } return iChecked; }