コード例 #1
0
        bool CreateServer(Map map, AreaTriggerTemplate areaTriggerTemplate, AreaTriggerSpawn position)
        {
            SetMap(map);
            Relocate(position.Location);
            if (!IsPositionValid())
            {
                Log.outError(LogFilter.AreaTrigger, $"AreaTriggerServer (id {areaTriggerTemplate.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})");
                return(false);
            }

            _areaTriggerTemplate = areaTriggerTemplate;

            _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), areaTriggerTemplate.Id.Id, GetMap().GenerateLowGuid(HighGuid.AreaTrigger)));

            SetEntry(areaTriggerTemplate.Id.Id);

            SetObjectScale(1.0f);

            if (position.PhaseUseFlags != 0 || position.PhaseId != 0 || position.PhaseGroup != 0)
            {
                PhasingHandler.InitDbPhaseShift(GetPhaseShift(), (PhaseUseFlagsValues)position.PhaseUseFlags, position.PhaseId, position.PhaseGroup);
            }

            UpdateShape();

            AI_Initialize();

            _ai.OnCreate();

            return(true);
        }
コード例 #2
0
ファイル: Transport.cs プロジェクト: Tithand/CypherCore
        public Creature CreateNPCPassenger(ulong guid, CreatureData data)
        {
            Map map = GetMap();

            if (map.GetCreatureRespawnTime(guid) != 0)
            {
                return(null);
            }

            Creature creature = Creature.CreateCreatureFromDB(guid, map, false, true);

            if (!creature)
            {
                return(null);
            }

            float x, y, z, o;

            data.spawnPoint.GetPosition(out x, out y, out z, out o);

            creature.SetTransport(this);
            creature.m_movementInfo.transport.guid = GetGUID();
            creature.m_movementInfo.transport.pos.Relocate(x, y, z, o);
            creature.m_movementInfo.transport.seat = -1;
            CalculatePassengerPosition(ref x, ref y, ref z, ref o);
            creature.Relocate(x, y, z, o);
            creature.SetHomePosition(creature.GetPositionX(), creature.GetPositionY(), creature.GetPositionZ(), creature.GetOrientation());
            creature.SetTransportHomePosition(creature.m_movementInfo.transport.pos);

            // @HACK - transport models are not added to map's dynamic LoS calculations
            //         because the current GameObjectModel cannot be moved without recreating
            creature.AddUnitState(UnitState.IgnorePathfinding);

            if (!creature.IsPositionValid())
            {
                Log.outError(LogFilter.Transport, "Creature (guidlow {0}, entry {1}) not created. Suggested coordinates aren't valid (X: {2} Y: {3})", creature.GetGUID().ToString(), creature.GetEntry(), creature.GetPositionX(), creature.GetPositionY());
                return(null);
            }

            PhasingHandler.InitDbPhaseShift(creature.GetPhaseShift(), data.phaseUseFlags, data.phaseId, data.phaseGroup);
            PhasingHandler.InitDbVisibleMapId(creature.GetPhaseShift(), data.terrainSwapMap);

            if (!map.AddToMap(creature))
            {
                return(null);
            }

            _staticPassengers.Add(creature);
            Global.ScriptMgr.OnAddCreaturePassenger(this, creature);
            return(creature);
        }
コード例 #3
0
ファイル: Transport.cs プロジェクト: Tithand/CypherCore
        GameObject CreateGOPassenger(ulong guid, GameObjectData data)
        {
            Map map = GetMap();

            if (map.GetGORespawnTime(guid) != 0)
            {
                return(null);
            }

            GameObject go = CreateGameObjectFromDB(guid, map, false);

            if (!go)
            {
                return(null);
            }

            float x, y, z, o;

            data.spawnPoint.GetPosition(out x, out y, out z, out o);

            go.SetTransport(this);
            go.m_movementInfo.transport.guid = GetGUID();
            go.m_movementInfo.transport.pos.Relocate(x, y, z, o);
            go.m_movementInfo.transport.seat = -1;
            CalculatePassengerPosition(ref x, ref y, ref z, ref o);
            go.Relocate(x, y, z, o);
            go.RelocateStationaryPosition(x, y, z, o);

            if (!go.IsPositionValid())
            {
                Log.outError(LogFilter.Transport, "GameObject (guidlow {0}, entry {1}) not created. Suggested coordinates aren't valid (X: {2} Y: {3})", go.GetGUID().ToString(), go.GetEntry(), go.GetPositionX(), go.GetPositionY());
                return(null);
            }

            PhasingHandler.InitDbPhaseShift(go.GetPhaseShift(), data.phaseUseFlags, data.phaseId, data.phaseGroup);
            PhasingHandler.InitDbVisibleMapId(go.GetPhaseShift(), data.terrainSwapMap);

            if (!map.AddToMap(go))
            {
                return(null);
            }

            _staticPassengers.Add(go);
            return(go);
        }
コード例 #4
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);
        }