public static LosTreeType InitializeForTestOnly(string filename) { var reg = WorldMgr.GetAllRegions().FirstOrDefault(); var zone = new Zone(reg, 0, "Test zone", 8, 8, 8, 8, 0, false, 0, false, 0, 0, 0, 0, 0); return(_LoadZone(reg, zone, filename)); }
public static void Initialize() { LosTreeType.MaxObjectsPerNode = MAX_TRIANGLE_PER_TREE_NODE; Parallel.ForEach(WorldMgr.GetAllRegions(), region => { var tick = GameServer.Instance.TickCount; log.Debug($"loading region {region.Description} (id:{region.ID})..."); var zoneTriangles = new LosTreeType[region.Zones.Count]; lock (_regionTriangles) _regionTriangles.Add(region.ID, zoneTriangles); int i = 0; foreach (var zone in region.Zones) { zoneTriangles[i++] = _LoadZone(region, zone, Path.Combine("obj", $"zone{zone.ZoneSkinID:D3}.obj")); } if (log.IsDebugEnabled) { log.Debug($"[LosMgr] region {region.Description} (id:{region.ID}): {GameServer.Instance.TickCount - tick}ms"); } }); // just useful to do some tests, I keep it in case I want to implement a BVH version //StressTests(); }
private static IEnumerable <Zone2> GetZonesToBuild() { // Zones foreach (var zone in Arguments.RecastBuildZoneID.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { yield return(WorldMgr.GetZone(int.Parse(zone))); } // Regions foreach (var region in Arguments.RecastBuildRegionID.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(r => WorldMgr.GetRegion(int.Parse(r))).Where(r => r != null)) { foreach (var zone in region.Values) { yield return(zone); } } // All? if (Arguments.RecastBuildAll) { foreach (var zone in WorldMgr.GetAllRegions().SelectMany(r => r.Values)) { yield return(zone); } } }
/// <summary> /// Decides whether player can jump to the target point. /// All messages with reasons must be sent here. /// Can change destination too. /// </summary> /// <param name="targetPoint">The jump destination</param> /// <param name="player">The jumping player</param> /// <returns>True if allowed</returns> public bool IsAllowedToJump(ZonePoint targetPoint, GamePlayer player) { //Handles zoning INTO an instance. GameLocation loc = null; AdventureWingInstance previousInstance = null; // Do we have a group ? if (player.Group != null) { //Check if there is an instance dedicated to this group foreach (Region region in WorldMgr.GetAllRegions()) { if (region is AdventureWingInstance && ((AdventureWingInstance)region).Group != null && ((AdventureWingInstance)region).Group == player.Group) { // Our group has an instance ! previousInstance = (AdventureWingInstance)region; break; } else if (region is AdventureWingInstance && ((AdventureWingInstance)region).Player != null && ((AdventureWingInstance)region).Player == player.Group.Leader) { // Our leader has an instance ! previousInstance = (AdventureWingInstance)region; previousInstance.Group = player.Group; break; } } } else { // I am solo ! //Check if there is an instance dedicated to me foreach (Region region in WorldMgr.GetAllRegions()) { if (region is AdventureWingInstance && ((AdventureWingInstance)region).Player != null && ((AdventureWingInstance)region).Player == player) { // I have an Instance ! previousInstance = (AdventureWingInstance)region; previousInstance.Group = player.Group; break; } } } if (previousInstance != null) { // We should check if we can go in ! if (previousInstance.Skin != targetPoint.TargetRegion) { //we're trying to enter in an other instance and we still have one ! //check if previous one is empty if (previousInstance.NumPlayers > 0) { //We can't jump ! player.Out.SendMessage("You have another instance (" + previousInstance.Description + ") running with people in it !", eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); } else { log.Warn("Player : " + player.Name + " requested new Instance, destroying instance " + previousInstance.Description + ", ID: " + previousInstance.ID + ", type=" + previousInstance.GetType().ToString() + "."); WorldMgr.RemoveInstance(previousInstance); previousInstance = null; } } } if (previousInstance == null) { // I have no instance to go to, create one ! previousInstance = (AdventureWingInstance)WorldMgr.CreateInstance(targetPoint.TargetRegion, typeof(AdventureWingInstance)); if (targetPoint.SourceRegion != 0 && targetPoint.SourceRegion == player.CurrentRegionID) { //source loc seems legit... previousInstance.SourceEntrance = new GameLocation("source", targetPoint.SourceRegion, targetPoint.SourceX, targetPoint.SourceY, targetPoint.SourceZ); } if (player.Group != null) { previousInstance.Group = player.Group; previousInstance.Player = player.Group.Leader; } else { previousInstance.Group = null; previousInstance.Player = player; } //get region data long mobs = 0; long merchants = 0; long items = 0; long bindpoints = 0; previousInstance.LoadFromDatabase(previousInstance.RegionData.Mobs, ref mobs, ref merchants, ref items, ref bindpoints); if (log.IsInfoEnabled) { log.Info("Total Mobs: " + mobs); log.Info("Total Merchants: " + merchants); log.Info("Total Items: " + items); } //Attach Loot Generator LootMgr.RegisterLootGenerator(new LootGeneratorAurulite(), null, null, null, previousInstance.ID); // Player created new instance // Destroy all other instance that should be... List <Region> to_delete = new List <Region>(); foreach (Region region in WorldMgr.GetAllRegions()) { if (region is AdventureWingInstance && (AdventureWingInstance)region != previousInstance) { AdventureWingInstance to_clean = (AdventureWingInstance)region; // Won't clean up populated Instance if (to_clean.NumPlayers == 0) { if (to_clean.Group != null && player.Group != null && to_clean.Group == player.Group) { // Got another instance for the same group... Destroy it ! to_delete.Add(to_clean); } else if (to_clean.Player != null && (to_clean.Player == player || (player.Group != null && player.Group.Leader == to_clean.Player))) { // Got another instance for the same player... Destroy it ! to_delete.Add(to_clean); } else if (to_clean.Group == null && to_clean.Player == null) { //nobody owns this instance anymore to_delete.Add(to_clean); } } } } //enumerate to_delete foreach (Region region in to_delete) { log.Warn("Player : " + player.Name + " has provoked an instance cleanup - " + region.Description + ", ID: " + region.ID + ", type=" + region.GetType().ToString() + "."); WorldMgr.RemoveInstance((BaseInstance)region); } } //get loc of instance if (previousInstance != null) { loc = new GameLocation(previousInstance.Description + " (instance)", previousInstance.ID, targetPoint.TargetX, targetPoint.TargetY, targetPoint.TargetZ, targetPoint.TargetHeading); } if (loc != null) { // Move Player, changing target destination is failing !! player.MoveTo(loc); return(false); } player.Out.SendMessage("Something went Wrong when creating Instance !", eChatType.CT_System, eChatLoc.CL_SystemWindow); return(false); }
private static void Resynch(object nullValue) { long syncTime = watch.ElapsedMilliseconds; //Check alive foreach (GameTimer.TimeManager mgr in WorldMgr.GetRegionTimeManagers()) { if (old_time.ContainsKey(mgr) && old_time[mgr] > 0 && old_time[mgr] == mgr.CurrentTime) { if (log.IsErrorEnabled) { // Tolakram: Can't do StackTrace call here. If thread is stopping will result in UAE app stop log.ErrorFormat("----- Found Frozen Region Timer -----\nName: {0} - Current Time: {1}", mgr.Name, mgr.CurrentTime); } //if(mgr.Running) try { if (!mgr.Stop()) { log.ErrorFormat("----- Failed to Stop the TimeManager: {0}", mgr.Name); } } catch (Exception mex) { log.ErrorFormat("----- Errors while trying to stop the TimeManager: {0}\n{1}", mgr.Name, mex); } foreach (GameClient clients in WorldMgr.GetAllClients()) { if (clients.Player == null || clients.ClientState == GameClient.eClientState.Linkdead) { if (log.IsErrorEnabled) { log.ErrorFormat("----- Disconnected Client: {0}", clients.Account.Name); } if (clients.Player != null) { clients.Player.SaveIntoDatabase(); clients.Player.Quit(true); } clients.Out.SendPlayerQuit(true); clients.Disconnect(); GameServer.Instance.Disconnect(clients); WorldMgr.RemoveClient(clients); } } if (!mgr.Start()) { log.ErrorFormat("----- Failed to (re)Start the TimeManager: {0}", mgr.Name); } foreach (Region reg in WorldMgr.GetAllRegions()) { if (reg.TimeManager == mgr) { foreach (GameObject obj in reg.Objects) { //Restart Player regen & remove PvP immunity if (obj is GamePlayer) { GamePlayer plr = obj as GamePlayer; if (plr.IsAlive) { plr.StopHealthRegeneration(); plr.StopPowerRegeneration(); plr.StopEnduranceRegeneration(); plr.StopCurrentSpellcast(); plr.StartHealthRegeneration(); plr.StartPowerRegeneration(); plr.StartEnduranceRegeneration(); plr.StartInvulnerabilityTimer(1000, null); try { foreach (IGameEffect effect in plr.EffectList) { var gsp = effect as GameSpellEffect; if (gsp != null) { gsp.RestartTimers(); } } } catch (Exception e) { log.Error("Can't cancel immunty effect : " + e); } } // Warn Player plr.Client.Out.SendMessage("[" + reg.Description + "] detected as frozen, restarting the zone.", eChatType.CT_Broadcast, eChatLoc.CL_ChatWindow); } //Restart Brains & Paths if (obj is GameNPC && (obj as GameNPC).Brain != null) { GameNPC npc = obj as GameNPC; if (npc.Brain is IControlledBrain) { npc.Die(null); } else if (!(npc.Brain is BlankBrain)) { npc.Brain.Stop(); DOL.AI.ABrain brain = npc.Brain; npc.RemoveBrain(npc.Brain); //npc.Brain.Stop(); if (npc.MaxSpeedBase > 0 && npc.PathID != null && npc.PathID != "" && npc.PathID != "NULL") { npc.StopMovingOnPath(); PathPoint path = MovementMgr.LoadPath(npc.PathID); if (path != null) { var p = path.GetNearestNextPoint(npc.Position); npc.CurrentWayPoint = p; npc.MoveOnPath((short)p.MaxSpeed); } } try { npc.SetOwnBrain(brain); npc.Brain.Start(); } catch (Exception e) { log.Error("Can't restart Brain in RegionTimerResynch, NPC Name = " + npc.Name + " Position=" + npc.Position.ToString("F0") + "/R=" + npc.CurrentRegion.ID + " " + e); try { npc.Die(null); } catch (Exception ee) { log.Error("Can't restart Brain and Kill NPC in RegionTimerResynch, NPC Name = " + npc.Name + " Position=" + npc.Position.ToString("F0") + "/R=" + npc.CurrentRegion.ID + " " + ee); } } } } } //Restart Respawn Timers List <GameNPC> respawnings = new List <GameNPC>(reg.MobsRespawning.Keys); foreach (GameNPC deadMob in respawnings) { GameNPC mob = deadMob; if (mob != null) { mob.StartRespawn(); } } } } //RegionTimerUnfrozen(mgr, syncTime); } if (old_time.ContainsKey(mgr)) { old_time[mgr] = mgr.CurrentTime; } else { old_time.Add(mgr, mgr.CurrentTime); } } }