Exemplo n.º 1
0
        public static bool InDbPhaseShift(WorldObject obj, PhaseUseFlagsValues phaseUseFlags, ushort phaseId, uint phaseGroupId)
        {
            PhaseShift phaseShift = new PhaseShift();

            InitDbPhaseShift(phaseShift, phaseUseFlags, phaseId, phaseGroupId);
            return(obj.GetPhaseShift().CanSee(phaseShift));
        }
Exemplo n.º 2
0
        public static void InitDbPhaseShift(PhaseShift phaseShift, PhaseUseFlagsValues phaseUseFlags, uint phaseId, uint phaseGroupId)
        {
            phaseShift.ClearPhases();
            phaseShift.IsDbPhaseShift = true;

            PhaseShiftFlags flags = PhaseShiftFlags.None;

            if (phaseUseFlags.HasAnyFlag(PhaseUseFlagsValues.AlwaysVisible))
            {
                flags = flags | PhaseShiftFlags.AlwaysVisible | PhaseShiftFlags.Unphased;
            }
            if (phaseUseFlags.HasAnyFlag(PhaseUseFlagsValues.Inverse))
            {
                flags |= PhaseShiftFlags.Inverse;
            }

            if (phaseId != 0)
            {
                phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null);
            }
            else
            {
                var phasesInGroup = Global.DB2Mgr.GetPhasesForGroup(phaseGroupId);
                foreach (uint phaseInGroup in phasesInGroup)
                {
                    phaseShift.AddPhase(phaseInGroup, GetPhaseFlags(phaseInGroup), null);
                }
            }

            if (phaseShift.Phases.Empty() || phaseShift.HasPhase(169))
            {
                if (flags.HasFlag(PhaseShiftFlags.Inverse))
                {
                    flags |= PhaseShiftFlags.InverseUnphased;
                }
                else
                {
                    flags |= PhaseShiftFlags.Unphased;
                }
            }

            phaseShift.Flags = flags;
        }
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);
        }
Exemplo n.º 4
0
        public void SpawnContinentTransports()
        {
            if (_transportTemplates.Empty())
            {
                return;
            }

            uint oldMSTime = Time.GetMSTime();

            SQLResult result = DB.World.Query("SELECT guid, entry, phaseUseFlags, phaseid, phasegroup FROM transports");

            uint count = 0;

            if (!result.IsEmpty())
            {
                do
                {
                    ulong guid  = result.Read <ulong>(0);
                    uint  entry = result.Read <uint>(1);
                    PhaseUseFlagsValues phaseUseFlags = (PhaseUseFlagsValues)result.Read <byte>(2);
                    uint phaseId      = result.Read <uint>(3);
                    uint phaseGroupId = result.Read <uint>(4);

                    if (Convert.ToBoolean(phaseUseFlags & ~PhaseUseFlagsValues.All))
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with unknown `phaseUseFlags` set, removed unknown value.");
                        phaseUseFlags &= PhaseUseFlagsValues.All;
                    }

                    if (phaseUseFlags.HasAnyFlag(PhaseUseFlagsValues.AlwaysVisible) && phaseUseFlags.HasAnyFlag(PhaseUseFlagsValues.Inverse))
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) has both `phaseUseFlags` PHASE_USE_FLAGS_ALWAYS_VISIBLE and PHASE_USE_FLAGS_INVERSE," +
                                     " removing PHASE_USE_FLAGS_INVERSE.");
                        phaseUseFlags &= ~PhaseUseFlagsValues.Inverse;
                    }

                    if (phaseGroupId != 0 && phaseId != 0)
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with both `phaseid` and `phasegroup` set, `phasegroup` set to 0");
                        phaseGroupId = 0;
                    }

                    if (phaseId != 0)
                    {
                        if (!CliDB.PhaseStorage.ContainsKey(phaseId))
                        {
                            Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with `phaseid` {phaseId} does not exist, set to 0");
                            phaseId = 0;
                        }
                    }

                    if (phaseGroupId != 0)
                    {
                        if (Global.DB2Mgr.GetPhasesForGroup(phaseGroupId).Empty())
                        {
                            Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with `phaseGroup` {phaseGroupId} does not exist, set to 0");
                            phaseGroupId = 0;
                        }
                    }

                    TransportTemplate tInfo = GetTransportTemplate(entry);
                    if (tInfo != null)
                    {
                        if (!tInfo.inInstance)
                        {
                            if (CreateTransport(entry, guid, null, phaseUseFlags, phaseId, phaseGroupId))
                            {
                                ++count;
                            }
                        }
                    }
                } while (result.NextRow());
            }

            Log.outInfo(LogFilter.ServerLoading, "Spawned {0} continent transports in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
        }
Exemplo n.º 5
0
        public void LoadTransportSpawns()
        {
            if (_transportTemplates.Empty())
            {
                return;
            }

            uint oldMSTime = Time.GetMSTime();

            SQLResult result = DB.World.Query("SELECT guid, entry, phaseUseFlags, phaseid, phasegroup FROM transports");

            uint count = 0;

            if (!result.IsEmpty())
            {
                do
                {
                    ulong guid  = result.Read <ulong>(0);
                    uint  entry = result.Read <uint>(1);
                    PhaseUseFlagsValues phaseUseFlags = (PhaseUseFlagsValues)result.Read <byte>(2);
                    uint phaseId      = result.Read <uint>(3);
                    uint phaseGroupId = result.Read <uint>(4);

                    if (GetTransportTemplate(entry) == null)
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with unknown gameobject `entry` set, skipped.");
                        continue;
                    }

                    if ((phaseUseFlags & ~PhaseUseFlagsValues.All) != 0)
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with unknown `phaseUseFlags` set, removed unknown value.");
                        phaseUseFlags &= PhaseUseFlagsValues.All;
                    }

                    if (phaseUseFlags.HasFlag(PhaseUseFlagsValues.AlwaysVisible) && phaseUseFlags.HasFlag(PhaseUseFlagsValues.Inverse))
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) has both `phaseUseFlags` PHASE_USE_FLAGS_ALWAYS_VISIBLE and PHASE_USE_FLAGS_INVERSE, removing PHASE_USE_FLAGS_INVERSE.");
                        phaseUseFlags &= ~PhaseUseFlagsValues.Inverse;
                    }

                    if (phaseGroupId != 0 && phaseId != 0)
                    {
                        Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with both `phaseid` and `phasegroup` set, `phasegroup` set to 0");
                        phaseGroupId = 0;
                    }

                    if (phaseId != 0)
                    {
                        if (!CliDB.PhaseStorage.ContainsKey(phaseId))
                        {
                            Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with `phaseid` {phaseId} does not exist, set to 0");
                            phaseId = 0;
                        }
                    }

                    if (phaseGroupId != 0)
                    {
                        if (Global.DB2Mgr.GetPhasesForGroup(phaseGroupId) == null)
                        {
                            Log.outError(LogFilter.Sql, $"Table `transports` have transport (GUID: {guid} Entry: {entry}) with `phaseGroup` {phaseGroupId} does not exist, set to 0");
                            phaseGroupId = 0;
                        }
                    }

                    TransportSpawn spawn = new();
                    spawn.SpawnId = guid;
                    spawn.TransportGameObjectId = entry;
                    spawn.PhaseUseFlags         = phaseUseFlags;
                    spawn.PhaseId    = phaseId;
                    spawn.PhaseGroup = phaseGroupId;

                    _transportSpawns[guid] = spawn;
                } while (result.NextRow());
            }

            Log.outInfo(LogFilter.ServerLoading, $"Spawned {count} continent transports in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
        }