Ejemplo n.º 1
0
        public void SaveToDB()
        {
            // save instance data too
            string data = "";
            uint   completedEncounters = 0;

            Map map = Global.MapMgr.FindMap(GetMapId(), m_instanceid);

            if (map != null)
            {
                Cypher.Assert(map.IsDungeon());
                InstanceScript instanceScript = ((InstanceMap)map).GetInstanceScript();
                if (instanceScript != null)
                {
                    data = instanceScript.GetSaveData();
                    completedEncounters = instanceScript.GetCompletedEncounterMask();
                    m_entranceId        = instanceScript.GetEntranceLocation();
                }

                InstanceScenario scenario = map.ToInstanceMap().GetInstanceScenario();
                if (scenario != null)
                {
                    scenario.SaveToDB();
                }
            }

            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_INSTANCE_SAVE);

            stmt.AddValue(0, m_instanceid);
            stmt.AddValue(1, GetMapId());
            stmt.AddValue(2, GetResetTimeForDB());
            stmt.AddValue(3, (uint)GetDifficultyID());
            stmt.AddValue(4, completedEncounters);
            stmt.AddValue(5, data);
            stmt.AddValue(6, m_entranceId);
            DB.Characters.Execute(stmt);
        }
Ejemplo n.º 2
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);
        }