Exemplo n.º 1
0
        Map CreateBaseMap_i(MapRecord mapEntry)
        {
            Map map;

            if (mapEntry.Instanceable())
            {
                map = new MapInstanced(mapEntry.Id, i_gridCleanUpDelay);
            }
            else
            {
                map = new Map(mapEntry.Id, i_gridCleanUpDelay, 0, Difficulty.None);
            }

            map.DiscoverGridMapFiles();

            i_maps[mapEntry.Id] = map;

            foreach (uint childMapId in _parentMapData[mapEntry.Id])
            {
                map.AddChildTerrainMap(CreateBaseMap_i(CliDB.MapStorage.LookupByKey(childMapId)));
            }

            if (!mapEntry.Instanceable())
            {
                map.LoadRespawnTimes();
                map.LoadCorpseData();
            }

            return(map);
        }
Exemplo n.º 2
0
        void _ResetOrWarnAll(uint mapid, Difficulty difficulty, bool warn, long resetTime)
        {
            // global reset for all instances of the given map
            MapRecord mapEntry = CliDB.MapStorage.LookupByKey(mapid);

            if (!mapEntry.Instanceable())
            {
                return;
            }

            Log.outDebug(LogFilter.Misc, "InstanceSaveManager.ResetOrWarnAll: Processing map {0} ({1}) on difficulty {2} (warn? {3})", mapEntry.MapName[Global.WorldMgr.GetDefaultDbcLocale()], mapid, difficulty, warn);
            long now = Time.UnixTime;

            if (!warn)
            {
                // calculate the next reset time
                long next_reset = GetSubsequentResetTime(mapid, difficulty, resetTime);
                if (next_reset == 0)
                {
                    return;
                }

                // delete them from the DB, even if not loaded
                SQLTransaction trans = new SQLTransaction();

                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_EXPIRED_CHAR_INSTANCE_BY_MAP_DIFF);
                stmt.AddValue(0, mapid);
                stmt.AddValue(1, (byte)difficulty);
                trans.Append(stmt);

                stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GROUP_INSTANCE_BY_MAP_DIFF);
                stmt.AddValue(0, mapid);
                stmt.AddValue(1, (byte)difficulty);
                trans.Append(stmt);

                stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_EXPIRED_INSTANCE_BY_MAP_DIFF);
                stmt.AddValue(0, mapid);
                stmt.AddValue(1, (byte)difficulty);
                trans.Append(stmt);

                stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_EXPIRE_CHAR_INSTANCE_BY_MAP_DIFF);
                stmt.AddValue(0, mapid);
                stmt.AddValue(1, (byte)difficulty);
                trans.Append(stmt);

                DB.Characters.CommitTransaction(trans);

                // promote loaded binds to instances of the given map
                foreach (var pair in m_instanceSaveById.ToList())
                {
                    if (pair.Value.GetMapId() == mapid && pair.Value.GetDifficultyID() == difficulty)
                    {
                        _ResetSave(pair);
                    }
                }

                SetResetTimeFor(mapid, difficulty, next_reset);
                ScheduleReset(true, next_reset - 3600, new InstResetEvent(1, mapid, difficulty, 0));

                // Update it in the DB
                stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
                stmt.AddValue(0, (uint)next_reset);
                stmt.AddValue(1, (ushort)mapid);
                stmt.AddValue(2, (byte)difficulty);

                DB.Characters.Execute(stmt);
            }

            // note: this isn't fast but it's meant to be executed very rarely
            Map  map      = Global.MapMgr.CreateBaseMap(mapid);    // _not_ include difficulty
            var  instMaps = ((MapInstanced)map).GetInstancedMaps();
            uint timeLeft;

            foreach (var pair in instMaps)
            {
                Map map2 = pair.Value;
                if (!map2.IsDungeon())
                {
                    continue;
                }

                if (warn)
                {
                    if (now >= resetTime)
                    {
                        timeLeft = 0;
                    }
                    else
                    {
                        timeLeft = (uint)(resetTime - now);
                    }

                    ((InstanceMap)map2).SendResetWarnings(timeLeft);
                }
                else
                {
                    ((InstanceMap)map2).Reset(InstanceResetMethod.Global);
                }
            }

            // @todo delete creature/gameobject respawn times even if the maps are not loaded
        }
Exemplo n.º 3
0
        public Transport CreateTransport(uint entry, ulong guid = 0, Map map = null, PhaseUseFlagsValues phaseUseFlags = 0, uint phaseId = 0, uint phaseGroupId = 0)
        {
            // instance case, execute GetGameObjectEntry hook
            if (map != null)
            {
                // SetZoneScript() is called after adding to map, so fetch the script using map
                if (map.IsDungeon())
                {
                    InstanceScript instance = ((InstanceMap)map).GetInstanceScript();
                    if (instance != null)
                    {
                        entry = instance.GetGameObjectEntry(0, entry);
                    }
                }

                if (entry == 0)
                {
                    return(null);
                }
            }

            TransportTemplate tInfo = GetTransportTemplate(entry);

            if (tInfo == null)
            {
                Log.outError(LogFilter.Sql, "Transport {0} will not be loaded, `transport_template` missing", entry);
                return(null);
            }

            // create transport...
            Transport trans = new();

            // ...at first waypoint
            TaxiPathNodeRecord startNode = tInfo.keyFrames.First().Node;
            uint  mapId = startNode.ContinentID;
            float x     = startNode.Loc.X;
            float y     = startNode.Loc.Y;
            float z     = startNode.Loc.Z;
            float o     = tInfo.keyFrames.First().InitialOrientation;

            // initialize the gameobject base
            ulong guidLow = guid != 0 ? guid : map.GenerateLowGuid(HighGuid.Transport);

            if (!trans.Create(guidLow, entry, mapId, x, y, z, o, 255))
            {
                return(null);
            }

            PhasingHandler.InitDbPhaseShift(trans.GetPhaseShift(), phaseUseFlags, phaseId, phaseGroupId);

            MapRecord mapEntry = CliDB.MapStorage.LookupByKey(mapId);

            if (mapEntry != null)
            {
                if (mapEntry.Instanceable() != tInfo.inInstance)
                {
                    Log.outError(LogFilter.Transport, "Transport {0} (name: {1}) attempted creation in instance map (id: {2}) but it is not an instanced transport!", entry, trans.GetName(), mapId);
                    //return null;
                }
            }

            // use preset map for instances (need to know which instance)
            trans.SetMap(map != null ? map : Global.MapMgr.CreateMap(mapId, null));
            if (map != null && map.IsDungeon())
            {
                trans.m_zoneScript = map.ToInstanceMap().GetInstanceScript();
            }

            // Passengers will be loaded once a player is near

            Global.ObjAccessor.AddObject(trans);
            trans.GetMap().AddToMap(trans);
            return(trans);
        }