Fix spawning in the unknown when no Resurrect 'Ems are nearby

This commit is contained in:
Gent S 2020-11-26 11:03:42 -05:00
parent faf2a0ee7d
commit 57060e9b6f
2 changed files with 17 additions and 11 deletions

View File

@ -702,7 +702,7 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
if (plr == nullptr) if (plr == nullptr)
return; return;
WarpLocation target = PlayerManager::getRespawnPoint(plr); WarpLocation* target = PlayerManager::getRespawnPoint(plr);
sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf; sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response); INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response);
@ -737,9 +737,15 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
// Response parameters // Response parameters
response.PCRegenData.iActiveNanoSlotNum = activeSlot; response.PCRegenData.iActiveNanoSlotNum = activeSlot;
response.PCRegenData.iX = move ? target.x : plr->x; if (move && target != nullptr) {
response.PCRegenData.iY = move ? target.y : plr->y; response.PCRegenData.iX = target->x;
response.PCRegenData.iZ = move ? target.z : plr->z; response.PCRegenData.iY = target->y;
response.PCRegenData.iZ = target->z;
} else {
response.PCRegenData.iX = plr->x;
response.PCRegenData.iY = plr->y;
response.PCRegenData.iZ = plr->z;
}
response.PCRegenData.iHP = plr->HP; response.PCRegenData.iHP = plr->HP;
response.iFusionMatter = plr->fusionmatter; response.iFusionMatter = plr->fusionmatter;
response.bMoveLocation = 0; response.bMoveLocation = 0;
@ -761,11 +767,11 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
sendToViewable(sock, (void*)&resp2, P_FE2CL_PC_REGEN, sizeof(sP_FE2CL_PC_REGEN)); sendToViewable(sock, (void*)&resp2, P_FE2CL_PC_REGEN, sizeof(sP_FE2CL_PC_REGEN));
if (!move) if (!move || target == nullptr)
return; return;
ChunkManager::updatePlayerChunk(sock, plr->chunkPos, std::make_tuple(0, 0, 0)); // force player to reload chunks ChunkManager::updatePlayerChunk(sock, plr->chunkPos, std::make_tuple(0, 0, 0)); // force player to reload chunks
updatePlayerPosition(sock, target.x, target.y, target.z, plr->instanceID, plr->angle); updatePlayerPosition(sock, target->x, target->y, target->z, plr->instanceID, plr->angle);
} }
void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) {
@ -875,14 +881,14 @@ std::string PlayerManager::getPlayerName(Player *plr, bool id) {
return ret; return ret;
} }
WarpLocation PlayerManager::getRespawnPoint(Player *plr) { WarpLocation* PlayerManager::getRespawnPoint(Player *plr) {
WarpLocation best; WarpLocation* best = nullptr;
uint32_t curDist, bestDist = UINT32_MAX; uint32_t curDist, bestDist = UINT32_MAX;
for (auto targ : NPCManager::RespawnPoints) { for (auto& targ : NPCManager::RespawnPoints) {
curDist = sqrt(pow(plr->x - targ.x, 2) + pow(plr->y - targ.y, 2)); curDist = sqrt(pow(plr->x - targ.x, 2) + pow(plr->y - targ.y, 2));
if (curDist < bestDist && targ.instanceID == MAPNUM(plr->instanceID)) { // only mapNum needs to match if (curDist < bestDist && targ.instanceID == MAPNUM(plr->instanceID)) { // only mapNum needs to match
best = targ; best = &targ;
bestDist = curDist; bestDist = curDist;
} }
} }

View File

@ -52,7 +52,7 @@ namespace PlayerManager {
Player *getPlayer(CNSocket* key); Player *getPlayer(CNSocket* key);
std::string getPlayerName(Player *plr, bool id=true); std::string getPlayerName(Player *plr, bool id=true);
WarpLocation getRespawnPoint(Player *plr); WarpLocation* getRespawnPoint(Player *plr);
bool isAccountInUse(int accountId); bool isAccountInUse(int accountId);
void exitDuplicate(int accountId); void exitDuplicate(int accountId);