mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-24 22:11:04 +00:00
Fix #205 - if a player times out a race, warp them back to the start
This commit is contained in:
parent
f0e21b5051
commit
aa028392f0
@ -371,21 +371,6 @@ static void exitGame(CNSocket* sock, CNPacketData* data) {
|
||||
sock->sendPacket(response, P_FE2CL_REP_PC_EXIT_SUCC);
|
||||
}
|
||||
|
||||
static WarpLocation* getRespawnPoint(Player *plr) {
|
||||
WarpLocation* best = nullptr;
|
||||
uint32_t curDist, bestDist = UINT32_MAX;
|
||||
|
||||
for (auto& targ : NPCManager::RespawnPoints) {
|
||||
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
|
||||
best = &targ;
|
||||
bestDist = curDist;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
static void revivePlayer(CNSocket* sock, CNPacketData* data) {
|
||||
Player *plr = getPlayer(sock);
|
||||
WarpLocation* target = getRespawnPoint(plr);
|
||||
@ -673,6 +658,21 @@ CNSocket *PlayerManager::getSockFromAny(int by, int id, int uid, std::string fir
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WarpLocation *PlayerManager::getRespawnPoint(Player *plr) {
|
||||
WarpLocation* best = nullptr;
|
||||
uint32_t curDist, bestDist = UINT32_MAX;
|
||||
|
||||
for (auto& targ : NPCManager::RespawnPoints) {
|
||||
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
|
||||
best = &targ;
|
||||
bestDist = curDist;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
void PlayerManager::init() {
|
||||
|
@ -31,6 +31,7 @@ namespace PlayerManager {
|
||||
CNSocket *getSockFromID(int32_t iID);
|
||||
CNSocket *getSockFromName(std::string firstname, std::string lastname);
|
||||
CNSocket *getSockFromAny(int by, int id, int uid, std::string firstname, std::string lastname);
|
||||
WarpLocation *getRespawnPoint(Player *plr);
|
||||
|
||||
void sendToViewable(CNSocket *sock, void* buf, uint32_t type, size_t size);
|
||||
|
||||
|
@ -58,10 +58,15 @@ static void racingCancel(CNSocket* sock, CNPacketData* data) {
|
||||
if (EPRaces.find(sock) == EPRaces.end())
|
||||
return; // race not found
|
||||
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
EPRaces.erase(sock);
|
||||
|
||||
INITSTRUCT(sP_FE2CL_REP_EP_RACE_CANCEL_SUCC, resp);
|
||||
sock->sendPacket(resp, P_FE2CL_REP_EP_RACE_CANCEL_SUCC);
|
||||
|
||||
// we have to teleport the player back after this, otherwise they are unable to move
|
||||
WarpLocation* respawnLoc = PlayerManager::getRespawnPoint(plr);
|
||||
PlayerManager::sendPlayerTo(sock, respawnLoc->x, respawnLoc->y, respawnLoc->z, respawnLoc->instanceID);
|
||||
}
|
||||
|
||||
static void racingEnd(CNSocket* sock, CNPacketData* data) {
|
||||
|
Loading…
Reference in New Issue
Block a user