public InstanceBossSpawn RezInstanceSpawn()
        {
            InstanceBossSpawn newCreature = new InstanceBossSpawn(Spawn, InstanceGroupSpawnID, BossID, InstanceID, Instance);

            Region.AddObject(newCreature, Spawn.ZoneId);
            Destroy();
            return(newCreature);
        }
        public void OnBossDeath(uint GroupID)
        {
            List <InstanceBossSpawn> spawns;

            Boolean allbossesdead = true;

            InstanceBossSpawn boss = null;

            _BossSpawns.TryGetValue(GroupID, out spawns);
            for (int i = 0; i < spawns.Count; i++)
            {
                boss = spawns[i].GetInstanceBossSpawn();
                if (!spawns[i].IsDead)
                {
                    allbossesdead = false;
                }
            }
            if (allbossesdead)
            {
                if (Lockout == null)
                {
                    Lockout              = new Instance_Lockouts();
                    Lockout.InstanceID   = boss.InstanceID + ":" + (TCPManager.GetTimeStamp() + Info.LockoutTimer * 60);
                    Lockout.Bosseskilled = boss.ZoneId + ":" + boss.BossID;
                    InstanceService._InstanceLockouts.Add(Lockout.InstanceID, Lockout);
                    Lockout.Dirty = true;
                    WorldMgr.Database.AddObject(Lockout);
                }
                else
                {
                    Lockout.Bosseskilled += ";" + boss.ZoneId + ":" + boss.BossID;
                    //InstanceService._InstanceLockouts.Add(Lockout.InstanceID,Lockout);
                    Lockout.Dirty = true;
                    WorldMgr.Database.SaveObject(Lockout);
                }

                foreach (Player pl in Region.Players)
                {
                    pl._Value.AddLogout(Lockout.InstanceID);
                    pl.SendLockouts();
                }
                Encounterinprogress = false;
            }
        }
        public void BossRespawnInstanceGroup(uint GroupID, bool rezall = false)
        {
            lock (GroupsinCombat)
            {
                if (!GroupsinCombat.Contains(GroupID) || rezall)
                {
                    return;
                }
                GroupsinCombat.Remove(GroupID);

                List <InstanceBossSpawn> spawns;
                _BossSpawns.TryGetValue(GroupID, out spawns);
                for (int i = 0; i < spawns.Count; i++)
                {
                    if (spawns[i].IsDead)
                    {
                        InstanceBossSpawn IS = spawns[i].RezInstanceSpawn();
                        spawns[i] = (IS);
                    }
                }
                _BossSpawns[GroupID] = spawns;
            }
            Encounterinprogress = false;
        }
        private void LoadBossSpawns()
        {
            List <Instance_Boss_Spawn> Obj;

            List <uint> deadbossids = new List <uint>();

            if (Lockout != null)
            {
                for (int i = 0; i < Lockout.Bosseskilled.Split(';').Count(); i++)
                {
                    deadbossids.Add(UInt16.Parse(Lockout.Bosseskilled.Split(';')[i].Split(':')[1]));
                }
            }


            InstanceService._InstanceBossSpawns.TryGetValue(Info.Entry, out Obj);


            if (Obj == null)
            {
                return;
            }

            foreach (var obj in Obj)
            {
                if (obj.Realm == 0 || obj.Realm == this.Realm)
                {
                    if (deadbossids.Contains(obj.BossID))
                    {
                        continue;
                    }

                    if (obj.ZoneID != ZoneID)
                    {
                        continue;
                    }


                    Creature_spawn spawn = new Creature_spawn();
                    spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
                    spawn.BuildFromProto(CreatureService.GetCreatureProto((uint)obj.Entry));
                    spawn.WorldO  = (int)obj.WorldO;
                    spawn.WorldY  = obj.WorldY;
                    spawn.WorldZ  = obj.WorldZ;
                    spawn.WorldX  = obj.WorldX;
                    spawn.ZoneId  = obj.ZoneID;
                    spawn.Enabled = 1;


                    InstanceBossSpawn IS = new InstanceBossSpawn(spawn, obj.SpawnGroupID, obj.BossID, obj.InstanceID, this);

                    if (obj.SpawnGroupID > 0)
                    {
                        List <InstanceBossSpawn> spawns;
                        _BossSpawns.TryGetValue(obj.SpawnGroupID, out spawns);
                        if (spawns == null)
                        {
                            spawns = new List <InstanceBossSpawn>();
                        }
                        spawns.Add(IS);
                        _BossSpawns[obj.SpawnGroupID] = spawns;
                    }
                    Region.AddObject(IS, obj.ZoneID);
                }
            }
        }