示例#1
0
void Transport::UpdateForMap(Map const* targetMap)
{
    Map::PlayerList const& pl = targetMap->GetPlayers();
    if (pl.isEmpty())
        return;

    if (GetMapId() == targetMap->GetId())
    {
        for (Map::PlayerList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr)
        {
            if (this != itr->getSource()->GetTransport())
            {
                UpdateData transData(itr->getSource()->GetMapId());
                BuildCreateUpdateBlockForPlayer(&transData, itr->getSource());
                WorldPacket packet;
                transData.BuildPacket(&packet);

                // Prevent sending transport maps in player update object
                if (packet.ReadUInt16() != itr->getSource()->GetMapId())
                    return;

                itr->getSource()->SendDirectMessage(&packet);
            }
        }
    }
    else
    {
        UpdateData transData(GetMapId());
        BuildOutOfRangeUpdateBlock(&transData);
        WorldPacket out_packet;
        transData.BuildPacket(&out_packet);

        for (Map::PlayerList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr)
        {
            if (this != itr->getSource()->GetTransport())
            {
                // Prevent sending transport maps in player update object
                if (out_packet.ReadUInt16() != itr->getSource()->GetMapId())
                    return;

                itr->getSource()->SendDirectMessage(&out_packet);
            }
        }
    }
}