Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | None | 0 0
  1. void LFGMgr::TeleportPlayer(Player* plr, bool out, bool fromOpcode /*= false*/)
  2. {
  3.     sLog.outDebug("LFGMgr::TeleportPlayer: [" UI64FMTD "] is being teleported %s", plr->GetGUID(), out ? "out" : "in");
  4.     if (out)
  5.     {
  6.         plr->RemoveAurasDueToSpell(LFG_SPELL_LUCK_OF_THE_DRAW);
  7.         plr->TeleportToBGEntryPoint();
  8.         return;
  9.     }
  10.  
  11.     // TODO Add support for LFG_TELEPORTERROR_FATIGUE
  12.     LfgTeleportError error = LFG_TELEPORTERROR_OK;
  13.     Group* grp = plr->GetGroup();
  14.  
  15.     if (!grp || !grp->isLFGGroup())                          // should never happen, but just in case...
  16.         error = LFG_TELEPORTERROR_INVALID_LOCATION;
  17.     else if (!plr->isAlive())
  18.         error = LFG_TELEPORTERROR_PLAYER_DEAD;
  19.     else if (plr->IsFalling() || plr->hasUnitState(UNIT_STAT_JUMPING))
  20.         error = LFG_TELEPORTERROR_FALLING;
  21.     else
  22.     {
  23.         LFGDungeonEntry const* dungeon = sLFGDungeonStore.LookupEntry(grp->GetLfgDungeonEntry());
  24.  
  25.         if (!dungeon)
  26.             error = LFG_TELEPORTERROR_INVALID_LOCATION;
  27.         else if (plr->GetMapId() != uint32(dungeon->map))    // Do not teleport players in dungeon to the entrance
  28.         {
  29.             uint32 mapid = 0;
  30.             float x = 0;
  31.             float y = 0;
  32.             float z = 0;
  33.             float orientation = 0;
  34.  
  35.             if (!fromOpcode)
  36.             {
  37.                 Player *plrg;
  38.                 // Select a player inside to be teleported to
  39.                 for (GroupReference* itr = grp->GetFirstMember(); itr != NULL && !mapid; itr = itr->next())
  40.                 {
  41.                     plrg = itr->getSource();
  42.                     if (plrg && plrg != plr && plrg->GetMapId() == uint32(dungeon->map))
  43.                     {
  44.                         mapid = plrg->GetMapId();
  45.                         x = plrg->GetPositionX();
  46.                         y = plrg->GetPositionY();
  47.                         z = plrg->GetPositionZ();
  48.                         orientation = plrg->GetOrientation();
  49.                     }
  50.                 }
  51.             }
  52.  
  53.             if (!mapid)
  54.             {
  55.                 AreaTrigger const* at = sObjectMgr.GetMapEntranceTrigger(dungeon->map);
  56.                 if (!at)
  57.                 {
  58.                     sLog.outError("LfgMgr::TeleportPlayer: Failed to teleport [" UI64FMTD "]: No areatrigger found for map: %u difficulty: %u", plr->GetGUID(), dungeon->map, dungeon->difficulty);
  59.                     error = LFG_TELEPORTERROR_INVALID_LOCATION;
  60.                 }
  61.                 else
  62.                 {
  63.                     mapid = at->target_mapId;
  64.                     x = at->target_X;
  65.                     y = at->target_Y;
  66.                     z = at->target_Z;
  67.                     orientation = at->target_Orientation;
  68.                 }
  69.             }
  70.  
  71.             if (error == LFG_TELEPORTERROR_OK)
  72.             {
  73.                 if (!plr->GetMap()->IsDungeon() && !plr->GetMap()->IsRaid())
  74.                     plr->SetBattlegroundEntryPoint();
  75.  
  76.                 if (plr->isInFlight())
  77.                 {
  78.                     plr->GetMotionMaster()->MovementExpired();
  79.                     plr->CleanupAfterTaxiFlight();
  80.                 }
  81.  
  82.                 if (plr->TeleportTo(mapid, x, y, z, orientation))
  83.                     plr->RemoveAurasByType(SPELL_AURA_MOUNTED);
  84.                 else
  85.                 {
  86.                     error = LFG_TELEPORTERROR_INVALID_LOCATION;
  87.                     sLog.outError("LfgMgr::TeleportPlayer: Failed to teleport [" UI64FMTD "] to map %u: ", plr->GetGUID(), mapid);
  88.                 }
  89.             }
  90.         }
  91.     }
  92.  
  93.     if (error != LFG_TELEPORTERROR_OK)
  94.         plr->GetSession()->SendLfgTeleportError(error);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement