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); } } }
public override void OnEffectStart(GameSpellEffect effect) { if (effect.Owner == null) { return; } if (!effect.Owner.IsAlive || effect.Owner.ObjectState != GameLiving.eObjectState.Active) { return; } //SendEffectAnimation(effect.Owner, 0, false, 1); //send the effect if (effect.Owner is GamePlayer) { /* * Q: What does the confusion spell do against players? * A: According to the magic man, “Confusion against a player interrupts their current action, whether it's a bow shot or spellcast. */ if (Spell.Value < 0 || Util.Chance(Convert.ToInt32(Math.Abs(Spell.Value)))) { //Spell value below 0 means it's 100% chance to confuse. GamePlayer player = effect.Owner as GamePlayer; player.StartInterruptTimer(player.SpellInterruptDuration, AttackData.eAttackType.Spell, Caster); } effect.Cancel(false); } else if (effect.Owner is GameNPC) { //check if we should do anything at all. bool doConfuse = (Spell.Value < 0 || Util.Chance(Convert.ToInt32(Spell.Value))); if (!doConfuse) { return; } bool doAttackFriend = Spell.Value < 0 && Util.Chance(Convert.ToInt32(Math.Abs(Spell.Value))); GameNPC npc = effect.Owner as GameNPC; npc.IsConfused = true; if (log.IsDebugEnabled) { log.Debug("CONFUSION: " + npc.Name + " was confused(true," + doAttackFriend.ToString() + ")"); } if (npc is GamePet && npc.Brain != null && (npc.Brain as IControlledBrain) != null) { //it's a pet. GamePlayer playerowner = (npc.Brain as IControlledBrain).GetPlayerOwner(); if (playerowner != null && playerowner.CharacterClass.ID == (int)eCharacterClass.Theurgist) { //Theurgist pets die. npc.Die(Caster); effect.Cancel(false); return; } } targetList.Clear(); foreach (GamePlayer target in npc.GetPlayersInRadius(1000)) { if (doAttackFriend) { targetList.Add(target); } else { //this should prevent mobs from attacking friends. if (GameServer.ServerRules.IsAllowedToAttack(npc, target, true)) { targetList.Add(target); } } } foreach (GameNPC target in npc.GetNPCsInRadius(1000)) { //don't agro yourself. if (target == npc) { continue; } if (doAttackFriend) { targetList.Add(target); } else { //this should prevent mobs from attacking friends. if (GameServer.ServerRules.IsAllowedToAttack(npc, target, true) && !GameServer.ServerRules.IsSameRealm(npc, target, true)) { targetList.Add(target); } } } //targetlist should be full, start effect pulse. if (targetList.Count > 0) { npc.StopAttack(); npc.StopCurrentSpellcast(); GameLiving target = targetList[Util.Random(targetList.Count - 1)] as GameLiving; npc.StartAttack(target); } } }