Compare commits

...

3 Commits

Author SHA1 Message Date
FinnHornhoover
488082cbd8
Merge f4b36b8f73 into bd0cc3c212 2023-09-12 20:50:47 -07:00
bd0cc3c212 Fix regression with /speed and /jump after previous change
Also changed the case values to use the client definitions.
2023-09-13 04:37:49 +02:00
FinnHornhoover
f4b36b8f73 added alternate racing score funcitonality 2023-07-24 00:33:19 +03:00
4 changed files with 72 additions and 21 deletions

View File

@ -69,10 +69,10 @@ static void setValuePlayer(CNSocket* sock, CNPacketData* data) {
// Handle serverside value-changes
switch (setData->iSetValueType) {
case 1:
case CN_GM_SET_VALUE_TYPE__HP:
response.iSetValue = plr->HP = setData->iSetValue;
break;
case 2:
case CN_GM_SET_VALUE_TYPE__WEAPON_BATTERY :
plr->batteryW = setData->iSetValue;
// caps
@ -81,7 +81,7 @@ static void setValuePlayer(CNSocket* sock, CNPacketData* data) {
response.iSetValue = plr->batteryW;
break;
case 3:
case CN_GM_SET_VALUE_TYPE__NANO_BATTERY:
plr->batteryN = setData->iSetValue;
// caps
@ -90,13 +90,17 @@ static void setValuePlayer(CNSocket* sock, CNPacketData* data) {
response.iSetValue = plr->batteryN;
break;
case 4:
case CN_GM_SET_VALUE_TYPE__FUSION_MATTER:
Missions::updateFusionMatter(sock, setData->iSetValue - plr->fusionmatter);
response.iSetValue = plr->fusionmatter;
break;
case 5:
case CN_GM_SET_VALUE_TYPE__CANDY:
response.iSetValue = plr->money = setData->iSetValue;
break;
case CN_GM_SET_VALUE_TYPE__SPEED:
case CN_GM_SET_VALUE_TYPE__JUMP:
response.iSetValue = setData->iSetValue;
break;
}
response.iPC_ID = setData->iPC_ID;

View File

@ -97,31 +97,47 @@ static void racingEnd(CNSocket* sock, CNPacketData* data) {
if (EPData.find(mapNum) == EPData.end() || EPData[mapNum].EPID == 0)
return; // IZ not found
uint64_t now = getTime() / 1000;
EPInfo& epInfo = EPData[mapNum];
EPRace& epRace = EPRaces[sock];
// if there are no divide-by-zero dangers, and at least one factor has been specified
// we switch over to OG scoring
bool useOGScoring = (epInfo.maxPods > 0) && (epInfo.maxTime > 0) && (
(epInfo.scaleFactor > 0.0) || (epInfo.podFactor > 0.0) || (epInfo.timeFactor > 0.0));
int timeDiff = now - EPRaces[sock].startTime;
int score = 500 * EPRaces[sock].collectedRings.size() - 10 * timeDiff;
if (score < 0) score = 0; // lol
int fm = score * plr->level * (1.0f / 36) * 0.3f;
uint64_t now = getTime() / 1000;
int timeDiff = now - epRace.startTime;
int podsCollected = epRace.collectedRings.size();
int score = 0, fm = 0;
if (useOGScoring) {
score = std::min(epInfo.maxScore, (int)std::exp(
(epInfo.podFactor * podsCollected) / epInfo.maxPods
- (epInfo.timeFactor * timeDiff) / epInfo.maxTime
+ epInfo.scaleFactor));
fm = (1.0 + std::exp(epInfo.scaleFactor - 1.0) * epInfo.podFactor * podsCollected) / epInfo.maxPods;
} else {
score = std::max(0, 500 * podsCollected - 10 * timeDiff);
fm = score * plr->level * (1.0f / 36) * 0.3f;
}
// we submit the ranking first...
Database::RaceRanking postRanking = {};
postRanking.EPID = EPData[mapNum].EPID;
postRanking.EPID = epInfo.EPID;
postRanking.PlayerID = plr->iID;
postRanking.RingCount = EPRaces[sock].collectedRings.size();
postRanking.RingCount = podsCollected;
postRanking.Score = score;
postRanking.Time = timeDiff;
postRanking.Timestamp = getTimestamp();
Database::postRaceRanking(postRanking);
// ...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(epInfo.EPID, plr->iID);
INITSTRUCT(sP_FE2CL_REP_EP_RACE_END_SUCC, resp);
// get rank scores and rewards
std::vector<int>* rankScores = &EPRewards[EPData[mapNum].EPID].first;
std::vector<int>* rankRewards = &EPRewards[EPData[mapNum].EPID].second;
std::vector<int>* rankScores = &EPRewards[epInfo.EPID].first;
std::vector<int>* rankRewards = &EPRewards[epInfo.EPID].second;
// top ranking
int topRank = 0;

View File

@ -5,7 +5,11 @@
#include "servers/CNShardServer.hpp"
struct EPInfo {
int zoneX, zoneY, EPID, maxScore, maxTime;
// available through XDT (maxScore may be updated by drops)
int zoneX, zoneY, EPID, maxScore;
// (maybe) available through drops
int maxTime = 0, maxPods = 0;
double scaleFactor = 0.0, podFactor = 0.0, timeFactor = 0.0;
};
struct EPRace {

View File

@ -572,8 +572,35 @@ static void loadDrops(json& dropData) {
continue;
}
EPInfo& epInfo = Racing::EPData[EPMap];
// time limit isn't stored in the XDT, so we include it in the reward table instead
Racing::EPData[EPMap].maxTime = race["TimeLimit"];
epInfo.maxTime = (int)race["TimeLimit"];
// update max score (if present)
if (race.find("ScoreCap") != race.end()) {
epInfo.maxScore = (int)race["ScoreCap"];
}
// update max pods (if present)
if (race.find("TotalPods") != race.end()) {
epInfo.maxPods = (int)race["TotalPods"];
}
// update scale factor (if present)
if (race.find("ScaleFactor") != race.end()) {
epInfo.scaleFactor = (double)race["ScaleFactor"];
}
// update pod factor (if present)
if (race.find("PodFactor") != race.end()) {
epInfo.podFactor = (double)race["PodFactor"];
}
// update time factor (if present)
if (race.find("TimeFactor") != race.end()) {
epInfo.timeFactor = (double)race["TimeFactor"];
}
// score cutoffs
std::vector<int> rankScores;