mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-25 22:40:16 +00:00
Fix indentation in RacingManager.cpp and compilation on Linux
This commit is contained in:
parent
8a2073d081
commit
322e354f5b
@ -1825,8 +1825,4 @@ void Database::postRaceRanking(Database::RaceRanking ranking) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,155 +12,155 @@ std::map<CNSocket*, EPRace> RacingManager::EPRaces;
|
|||||||
std::map<int32_t, std::pair<std::vector<int>, std::vector<int>>> RacingManager::EPRewards;
|
std::map<int32_t, std::pair<std::vector<int>, std::vector<int>>> RacingManager::EPRewards;
|
||||||
|
|
||||||
void RacingManager::init() {
|
void RacingManager::init() {
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_RACE_START, racingStart);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_RACE_START, racingStart);
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_GET_RING, racingGetPod);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_GET_RING, racingGetPod);
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_RACE_CANCEL, racingCancel);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_RACE_CANCEL, racingCancel);
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_RACE_END, racingEnd);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_EP_RACE_END, racingEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RacingManager::racingStart(CNSocket* sock, CNPacketData* data) {
|
void RacingManager::racingStart(CNSocket* sock, CNPacketData* data) {
|
||||||
if (data->size != sizeof(sP_CL2FE_REQ_EP_RACE_START))
|
if (data->size != sizeof(sP_CL2FE_REQ_EP_RACE_START))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
|
|
||||||
sP_CL2FE_REQ_EP_RACE_START* req = (sP_CL2FE_REQ_EP_RACE_START*)data->buf;
|
sP_CL2FE_REQ_EP_RACE_START* req = (sP_CL2FE_REQ_EP_RACE_START*)data->buf;
|
||||||
|
|
||||||
if (NPCManager::NPCs.find(req->iStartEcomID) == NPCManager::NPCs.end())
|
if (NPCManager::NPCs.find(req->iStartEcomID) == NPCManager::NPCs.end())
|
||||||
return; // starting line agent not found
|
return; // starting line agent not found
|
||||||
|
|
||||||
int mapNum = MAPNUM(NPCManager::NPCs[req->iStartEcomID]->instanceID);
|
int mapNum = MAPNUM(NPCManager::NPCs[req->iStartEcomID]->instanceID);
|
||||||
if (EPData.find(mapNum) == EPData.end() || EPData[mapNum].EPID == 0)
|
if (EPData.find(mapNum) == EPData.end() || EPData[mapNum].EPID == 0)
|
||||||
return; // IZ not found
|
return; // IZ not found
|
||||||
|
|
||||||
// make ongoing race entry
|
// make ongoing race entry
|
||||||
EPRace race = { 0, req->iEPRaceMode, req->iEPTicketItemSlotNum, getTime() / 1000 };
|
EPRace race = { 0, req->iEPRaceMode, req->iEPTicketItemSlotNum, getTime() / 1000 };
|
||||||
EPRaces[sock] = race;
|
EPRaces[sock] = race;
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_EP_RACE_START_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_EP_RACE_START_SUCC, resp);
|
||||||
resp.iStartTick = 0; // ignored
|
resp.iStartTick = 0; // ignored
|
||||||
resp.iLimitTime = EPData[mapNum].maxTime;
|
resp.iLimitTime = EPData[mapNum].maxTime;
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_RACE_START_SUCC, sizeof(sP_FE2CL_REP_EP_RACE_START_SUCC));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_RACE_START_SUCC, sizeof(sP_FE2CL_REP_EP_RACE_START_SUCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RacingManager::racingGetPod(CNSocket* sock, CNPacketData* data) {
|
void RacingManager::racingGetPod(CNSocket* sock, CNPacketData* data) {
|
||||||
if (data->size != sizeof(sP_CL2FE_REQ_EP_GET_RING))
|
if (data->size != sizeof(sP_CL2FE_REQ_EP_GET_RING))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
|
|
||||||
if (EPRaces.find(sock) == EPRaces.end())
|
if (EPRaces.find(sock) == EPRaces.end())
|
||||||
return; // race not found
|
return; // race not found
|
||||||
|
|
||||||
sP_CL2FE_REQ_EP_GET_RING* req = (sP_CL2FE_REQ_EP_GET_RING*)data->buf;
|
sP_CL2FE_REQ_EP_GET_RING* req = (sP_CL2FE_REQ_EP_GET_RING*)data->buf;
|
||||||
|
|
||||||
// without an anticheat system, we really don't have a choice but to honor the request
|
// without an anticheat system, we really don't have a choice but to honor the request
|
||||||
EPRaces[sock].ringCount++;
|
EPRaces[sock].ringCount++;
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_EP_GET_RING_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_EP_GET_RING_SUCC, resp);
|
||||||
|
|
||||||
resp.iRingLID = req->iRingLID; // could be used to check for proximity in the future
|
resp.iRingLID = req->iRingLID; // could be used to check for proximity in the future
|
||||||
resp.iRingCount_Get = EPRaces[sock].ringCount;
|
resp.iRingCount_Get = EPRaces[sock].ringCount;
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_GET_RING_SUCC, sizeof(sP_FE2CL_REP_EP_GET_RING_SUCC));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_GET_RING_SUCC, sizeof(sP_FE2CL_REP_EP_GET_RING_SUCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RacingManager::racingCancel(CNSocket* sock, CNPacketData* data) {
|
void RacingManager::racingCancel(CNSocket* sock, CNPacketData* data) {
|
||||||
if (data->size != sizeof(sP_CL2FE_REQ_EP_RACE_CANCEL))
|
if (data->size != sizeof(sP_CL2FE_REQ_EP_RACE_CANCEL))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
|
|
||||||
if (EPRaces.find(sock) == EPRaces.end())
|
if (EPRaces.find(sock) == EPRaces.end())
|
||||||
return; // race not found
|
return; // race not found
|
||||||
|
|
||||||
EPRaces.erase(sock);
|
EPRaces.erase(sock);
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_EP_RACE_CANCEL_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_EP_RACE_CANCEL_SUCC, resp);
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_RACE_CANCEL_SUCC, sizeof(sP_FE2CL_REP_EP_RACE_CANCEL_SUCC));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_RACE_CANCEL_SUCC, sizeof(sP_FE2CL_REP_EP_RACE_CANCEL_SUCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RacingManager::racingEnd(CNSocket* sock, CNPacketData* data) {
|
void RacingManager::racingEnd(CNSocket* sock, CNPacketData* data) {
|
||||||
if (data->size != sizeof(sP_CL2FE_REQ_EP_RACE_END))
|
if (data->size != sizeof(sP_CL2FE_REQ_EP_RACE_END))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
|
|
||||||
if (EPRaces.find(sock) == EPRaces.end())
|
if (EPRaces.find(sock) == EPRaces.end())
|
||||||
return; // race not found
|
return; // race not found
|
||||||
|
|
||||||
sP_CL2FE_REQ_EP_RACE_END* req = (sP_CL2FE_REQ_EP_RACE_END*)data->buf;
|
sP_CL2FE_REQ_EP_RACE_END* req = (sP_CL2FE_REQ_EP_RACE_END*)data->buf;
|
||||||
Player* plr = PlayerManager::getPlayer(sock);
|
Player* plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
if (NPCManager::NPCs.find(req->iEndEcomID) == NPCManager::NPCs.end())
|
if (NPCManager::NPCs.find(req->iEndEcomID) == NPCManager::NPCs.end())
|
||||||
return; // finish line agent not found
|
return; // finish line agent not found
|
||||||
|
|
||||||
int mapNum = MAPNUM(NPCManager::NPCs[req->iEndEcomID]->instanceID);
|
int mapNum = MAPNUM(NPCManager::NPCs[req->iEndEcomID]->instanceID);
|
||||||
if (EPData.find(mapNum) == EPData.end() || EPData[mapNum].EPID == 0)
|
if (EPData.find(mapNum) == EPData.end() || EPData[mapNum].EPID == 0)
|
||||||
return; // IZ not found
|
return; // IZ not found
|
||||||
|
|
||||||
uint64_t now = getTime() / 1000;
|
uint64_t now = getTime() / 1000;
|
||||||
|
|
||||||
int timeDiff = now - EPRaces[sock].startTime;
|
int timeDiff = now - EPRaces[sock].startTime;
|
||||||
int score = 500 * EPRaces[sock].ringCount - 10 * timeDiff;
|
int score = 500 * EPRaces[sock].ringCount - 10 * timeDiff;
|
||||||
if (score < 0) score = 0; // lol
|
if (score < 0) score = 0; // lol
|
||||||
int fm = score * plr->level * (1.0f / 36) * 0.3f;
|
int fm = score * plr->level * (1.0f / 36) * 0.3f;
|
||||||
|
|
||||||
// we submit the ranking first...
|
// we submit the ranking first...
|
||||||
Database::RaceRanking postRanking = {};
|
Database::RaceRanking postRanking = {};
|
||||||
postRanking.EPID = EPData[mapNum].EPID;
|
postRanking.EPID = EPData[mapNum].EPID;
|
||||||
postRanking.PlayerID = plr->iID;
|
postRanking.PlayerID = plr->iID;
|
||||||
postRanking.RingCount = EPRaces[sock].ringCount;
|
postRanking.RingCount = EPRaces[sock].ringCount;
|
||||||
postRanking.Score = score;
|
postRanking.Score = score;
|
||||||
postRanking.Time = timeDiff;
|
postRanking.Time = timeDiff;
|
||||||
postRanking.Timestamp = getTimestamp();
|
postRanking.Timestamp = getTimestamp();
|
||||||
Database::postRaceRanking(postRanking);
|
Database::postRaceRanking(postRanking);
|
||||||
|
|
||||||
// ...then we get the top ranking, which may or may not be what we just submitted
|
// ...then we get the top ranking, which may or may not be what we just submitted
|
||||||
Database::RaceRanking topRankingPlayer = Database::getTopRaceRanking(EPData[mapNum].EPID, plr->iID);
|
Database::RaceRanking topRankingPlayer = Database::getTopRaceRanking(EPData[mapNum].EPID, plr->iID);
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_EP_RACE_END_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_EP_RACE_END_SUCC, resp);
|
||||||
|
|
||||||
// get rank scores and rewards
|
// get rank scores and rewards
|
||||||
std::vector<int>* rankScores = &EPRewards[EPData[mapNum].EPID].first;
|
std::vector<int>* rankScores = &EPRewards[EPData[mapNum].EPID].first;
|
||||||
std::vector<int>* rankRewards = &EPRewards[EPData[mapNum].EPID].second;
|
std::vector<int>* rankRewards = &EPRewards[EPData[mapNum].EPID].second;
|
||||||
|
|
||||||
// top ranking
|
// top ranking
|
||||||
int topRank = 0;
|
int topRank = 0;
|
||||||
while (rankScores->at(topRank) > topRankingPlayer.Score)
|
while (rankScores->at(topRank) > topRankingPlayer.Score)
|
||||||
topRank++;
|
topRank++;
|
||||||
|
|
||||||
resp.iEPTopRank = topRank + 1;
|
resp.iEPTopRank = topRank + 1;
|
||||||
resp.iEPTopRingCount = topRankingPlayer.RingCount;
|
resp.iEPTopRingCount = topRankingPlayer.RingCount;
|
||||||
resp.iEPTopScore = topRankingPlayer.Score;
|
resp.iEPTopScore = topRankingPlayer.Score;
|
||||||
resp.iEPTopTime = topRankingPlayer.Time;
|
resp.iEPTopTime = topRankingPlayer.Time;
|
||||||
|
|
||||||
// this ranking
|
// this ranking
|
||||||
int rank = 0;
|
int rank = 0;
|
||||||
while (rankScores->at(rank) > postRanking.Score)
|
while (rankScores->at(rank) > postRanking.Score)
|
||||||
rank++;
|
rank++;
|
||||||
|
|
||||||
resp.iEPRank = rank + 1;
|
resp.iEPRank = rank + 1;
|
||||||
resp.iEPRingCnt = postRanking.RingCount;
|
resp.iEPRingCnt = postRanking.RingCount;
|
||||||
resp.iEPScore = postRanking.Score;
|
resp.iEPScore = postRanking.Score;
|
||||||
resp.iEPRaceTime = postRanking.Time;
|
resp.iEPRaceTime = postRanking.Time;
|
||||||
resp.iEPRaceMode = EPRaces[sock].mode;
|
resp.iEPRaceMode = EPRaces[sock].mode;
|
||||||
resp.iEPRewardFM = fm;
|
resp.iEPRewardFM = fm;
|
||||||
|
|
||||||
MissionManager::updateFusionMatter(sock, resp.iEPRewardFM);
|
MissionManager::updateFusionMatter(sock, resp.iEPRewardFM);
|
||||||
|
|
||||||
resp.iFusionMatter = plr->fusionmatter;
|
resp.iFusionMatter = plr->fusionmatter;
|
||||||
resp.iFatigue = 50;
|
resp.iFatigue = 50;
|
||||||
resp.iFatigue_Level = 1;
|
resp.iFatigue_Level = 1;
|
||||||
|
|
||||||
sItemReward reward;
|
sItemReward reward;
|
||||||
reward.iSlotNum = ItemManager::findFreeSlot(plr);
|
reward.iSlotNum = ItemManager::findFreeSlot(plr);
|
||||||
reward.eIL = 1;
|
reward.eIL = 1;
|
||||||
sItemBase item;
|
sItemBase item;
|
||||||
item.iID = rankRewards->at(rank); // rank scores and rewards line up
|
item.iID = rankRewards->at(rank); // rank scores and rewards line up
|
||||||
item.iType = 0;
|
item.iType = 0;
|
||||||
item.iOpt = 1;
|
item.iOpt = 1;
|
||||||
reward.sItem = item;
|
reward.sItem = item;
|
||||||
|
|
||||||
if (reward.iSlotNum > -1 && reward.sItem.iID != 0) {
|
if (reward.iSlotNum > -1 && reward.sItem.iID != 0) {
|
||||||
resp.RewardItem = reward;
|
resp.RewardItem = reward;
|
||||||
plr->Inven[reward.iSlotNum] = item;
|
plr->Inven[reward.iSlotNum] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
EPRaces.erase(sock);
|
EPRaces.erase(sock);
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_RACE_END_SUCC, sizeof(sP_FE2CL_REP_EP_RACE_END_SUCC));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_EP_RACE_END_SUCC, sizeof(sP_FE2CL_REP_EP_RACE_END_SUCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ struct EPRace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
namespace RacingManager {
|
namespace RacingManager {
|
||||||
|
|
||||||
extern std::map<int32_t, EPInfo> EPData;
|
extern std::map<int32_t, EPInfo> EPData;
|
||||||
extern std::map<CNSocket*, EPRace> EPRaces;
|
extern std::map<CNSocket*, EPRace> EPRaces;
|
||||||
extern std::map<int32_t, std::pair<std::vector<int>, std::vector<int>>> EPRewards;
|
extern std::map<int32_t, std::pair<std::vector<int>, std::vector<int>>> EPRewards;
|
||||||
|
@ -547,7 +547,7 @@ void TableData::loadDrops() {
|
|||||||
|
|
||||||
// find the instance data corresponding to the EPID
|
// find the instance data corresponding to the EPID
|
||||||
int EPMap = -1;
|
int EPMap = -1;
|
||||||
for (auto& it = RacingManager::EPData.begin(); it != RacingManager::EPData.end(); it++) {
|
for (auto it = RacingManager::EPData.begin(); it != RacingManager::EPData.end(); it++) {
|
||||||
if (it->second.EPID == raceEPID) {
|
if (it->second.EPID == raceEPID) {
|
||||||
EPMap = it->first;
|
EPMap = it->first;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user