Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LFGMgr::TeleportPlayer(Player* plr, bool out, bool fromOpcode /*= false*/)
- {
- sLog.outDebug("LFGMgr::TeleportPlayer: [" UI64FMTD "] is being teleported %s", plr->GetGUID(), out ? "out" : "in");
- if (out)
- {
- plr->RemoveAurasDueToSpell(LFG_SPELL_LUCK_OF_THE_DRAW);
- plr->TeleportToBGEntryPoint();
- return;
- }
- // TODO Add support for LFG_TELEPORTERROR_FATIGUE
- LfgTeleportError error = LFG_TELEPORTERROR_OK;
- Group* grp = plr->GetGroup();
- if (!grp || !grp->isLFGGroup()) // should never happen, but just in case...
- error = LFG_TELEPORTERROR_INVALID_LOCATION;
- else if (!plr->isAlive())
- error = LFG_TELEPORTERROR_PLAYER_DEAD;
- else if (plr->IsFalling() || plr->hasUnitState(UNIT_STAT_JUMPING))
- error = LFG_TELEPORTERROR_FALLING;
- else
- {
- LFGDungeonEntry const* dungeon = sLFGDungeonStore.LookupEntry(grp->GetLfgDungeonEntry());
- if (!dungeon)
- error = LFG_TELEPORTERROR_INVALID_LOCATION;
- else if (plr->GetMapId() != uint32(dungeon->map)) // Do not teleport players in dungeon to the entrance
- {
- uint32 mapid = 0;
- float x = 0;
- float y = 0;
- float z = 0;
- float orientation = 0;
- if (!fromOpcode)
- {
- Player *plrg;
- // Select a player inside to be teleported to
- for (GroupReference* itr = grp->GetFirstMember(); itr != NULL && !mapid; itr = itr->next())
- {
- plrg = itr->getSource();
- if (plrg && plrg != plr && plrg->GetMapId() == uint32(dungeon->map))
- {
- mapid = plrg->GetMapId();
- x = plrg->GetPositionX();
- y = plrg->GetPositionY();
- z = plrg->GetPositionZ();
- orientation = plrg->GetOrientation();
- }
- }
- }
- if (!mapid)
- {
- AreaTrigger const* at = sObjectMgr.GetMapEntranceTrigger(dungeon->map);
- if (!at)
- {
- sLog.outError("LfgMgr::TeleportPlayer: Failed to teleport [" UI64FMTD "]: No areatrigger found for map: %u difficulty: %u", plr->GetGUID(), dungeon->map, dungeon->difficulty);
- error = LFG_TELEPORTERROR_INVALID_LOCATION;
- }
- else
- {
- mapid = at->target_mapId;
- x = at->target_X;
- y = at->target_Y;
- z = at->target_Z;
- orientation = at->target_Orientation;
- }
- }
- if (error == LFG_TELEPORTERROR_OK)
- {
- if (!plr->GetMap()->IsDungeon() && !plr->GetMap()->IsRaid())
- plr->SetBattlegroundEntryPoint();
- if (plr->isInFlight())
- {
- plr->GetMotionMaster()->MovementExpired();
- plr->CleanupAfterTaxiFlight();
- }
- if (plr->TeleportTo(mapid, x, y, z, orientation))
- plr->RemoveAurasByType(SPELL_AURA_MOUNTED);
- else
- {
- error = LFG_TELEPORTERROR_INVALID_LOCATION;
- sLog.outError("LfgMgr::TeleportPlayer: Failed to teleport [" UI64FMTD "] to map %u: ", plr->GetGUID(), mapid);
- }
- }
- }
- }
- if (error != LFG_TELEPORTERROR_OK)
- plr->GetSession()->SendLfgTeleportError(error);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement