fix how the custom rank is managed (it also fix no time when player disconnect)

This commit is contained in:
Beu 2023-07-12 13:13:05 +02:00
parent a97575666a
commit a641dff430

View File

@ -238,6 +238,11 @@ Race::SetRespawnBehaviour(Race::C_RespawnBehaviour_AlwaysGiveUp);
CarRank::Reset(); CarRank::Reset();
*** ***
***Match_InitRound***
***
declare Boolean ThrottleUpdate;
***
***Match_StartRound*** ***Match_StartRound***
*** ***
Scores::Clear(); Scores::Clear();
@ -310,48 +315,40 @@ foreach (Player in ShuffledPlayers) {
MalusQueue[Player.User.Login] = GetNewMalus(C_Malus_Reset, 1500); MalusQueue[Player.User.Login] = GetNewMalus(C_Malus_Reset, 1500);
} }
Net_NBPlayers = AccountIdsOfPlayers.count; UIModules_ScoresTable::DisplayOnly(AccountIdsOfPlayers);
StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]); StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]);
Race::EnableIntroDuringMatch(False); Race::EnableIntroDuringMatch(False);
UIManager.UIAll.SendChat("$<$ff3$> Stay the most time on the structure. $<$ff9GL HF!$>"); UIManager.UIAll.SendChat("$<$ff3$> Stay the most time on the structure. $<$ff9GL HF!$>");
*** ***
/***Match_InitPlayLoop***
***
MalusQueue = [];
***/
***Match_PlayLoop*** ***Match_PlayLoop***
*** ***
// Manage race events // Manage race events
declare RacePendingEvents = Race::GetPendingEvents(); declare Events::K_RaceEvent[] RacePendingEvents = Race::GetPendingEvents();
foreach (Event in RacePendingEvents) { foreach (Event in RacePendingEvents) {
Race::ValidEvent(Event); Race::ValidEvent(Event);
if (Event.Player == Null) continue;
// Waypoint // Waypoint
if (Event.Type == Events::C_Type_Waypoint) { switch (Event.Type) {
if (Event.IsEndLap) { case Events::C_Type_Waypoint: {
ThrottleUpdate = True;
Scores::UpdatePlayerBestRaceIfBetter(Event.Player);
Race::StopSkipOutro(Event.Player); Race::StopSkipOutro(Event.Player);
foreach (Player in Players) { UpdateCustomRanking(Event.Player.User, False);
CarRank::SetRank(Player, PlayersNbAlive);
Net_PlayersNbAlive = PlayersNbAlive;
} }
UpdateCustomRanking(Event.Player, Event.Type); case Events::C_Type_GiveUp: {
ThrottleUpdate = True;
UpdateCustomRanking(Event.Player.User, True);
} }
} else if (Event.Type == Events::C_Type_GiveUp) { case Events::C_Type_Eliminated: {
foreach (Player in Players) { ThrottleUpdate = True;
CarRank::SetRank(Player, PlayersNbAlive); UpdateCustomRanking(Event.Player.User, True);
Net_PlayersNbAlive = PlayersNbAlive;
} }
UpdateCustomRanking(Event.Player, Event.Type);
} else if (Event.Type == Events::C_Type_Eliminated) {
Race::StopSkipOutro(Event.Player);
foreach (Player in Players) {
CarRank::SetRank(Player, PlayersNbAlive);
Net_PlayersNbAlive = PlayersNbAlive;
}
UpdateCustomRanking(Event.Player, Event.Type);
} }
} }
@ -359,6 +356,13 @@ foreach (Event in RacePendingEvents) {
foreach (Event in PendingEvents) { foreach (Event in PendingEvents) {
if (Event.HasBeenPassed || Event.HasBeenDiscarded) continue; if (Event.HasBeenPassed || Event.HasBeenDiscarded) continue;
Events::Invalid(Event); Events::Invalid(Event);
if (Event.Type == CSmModeEvent::EType::OnPlayerRemoved) {
if (Event.User == Null ) continue;
if (!AccountIdsOfPlayers.exists(Event.User.WebServicesUserId)) continue;
ThrottleUpdate = True;
UpdateCustomRanking(Event.User, True);
}
} }
if (PlayersNbAlive <= 1 && AccountIdsOfPlayers.count >= 2) { //TODO just respawn in case of 1 player if (PlayersNbAlive <= 1 && AccountIdsOfPlayers.count >= 2) { //TODO just respawn in case of 1 player
@ -366,6 +370,18 @@ if (PlayersNbAlive <= 1 && AccountIdsOfPlayers.count >= 2) { //TODO just respawn
MB_StopRound(); MB_StopRound();
} }
if (ThrottleUpdate) {
ThrottleUpdate = False;
Net_PlayersNbAlive = PlayersNbAlive;
declare Integer Points = Net_NBPlayers - Net_PlayersNbAlive;
foreach (Player in Players) {
CarRank::SetRank(Player, PlayersNbAlive);
if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned) {
Scores::SetPlayerRoundPoints(Player.Score, Points);
}
}
}
// Update the map duration setting // Update the map duration setting
if (Map_TimeBeforeMalus != S_TimeBeforeMalus || Map_TimeBeforeMalus != S_TimeBeforeNightmare || Map_MalusEveryNSecs != S_MalusEveryNSecs || Map_NextMalusPreparationTime != S_NextMalusPreparationTime || Map_MalusDuration != S_MalusDuration || Map_RoundsPerMap != S_RoundsPerMap) { if (Map_TimeBeforeMalus != S_TimeBeforeMalus || Map_TimeBeforeMalus != S_TimeBeforeNightmare || Map_MalusEveryNSecs != S_MalusEveryNSecs || Map_NextMalusPreparationTime != S_NextMalusPreparationTime || Map_MalusDuration != S_MalusDuration || Map_RoundsPerMap != S_RoundsPerMap) {
@ -474,7 +490,6 @@ PendingMalus = False;
ActiveMalus = False; ActiveMalus = False;
Net_TimeBeforeMalus = -1; Net_TimeBeforeMalus = -1;
Net_NextMalus = -1; Net_NextMalus = -1;
RankInitialized = False;
CustomTimes.clear(); CustomTimes.clear();
Race::StopSkipOutroAll(); Race::StopSkipOutroAll();
@ -557,32 +572,19 @@ if (Round_ForceEndRound || Round_SkipPauseRound) {
/** Update the Scores Table with hidden custom points /** Update the Scores Table with hidden custom points
* *
* @param _EliminatedPlayer The Player who is eliminated * @param _User The User who is eliminated
* @param _EventType Type of event that led to the update (EndRace or GiveUp) * @param _OverrideTime Compute time because it not ended the Map
*/ */
Void UpdateCustomRanking(CSmPlayer _EliminatedPlayer, Integer _EventType) { Void UpdateCustomRanking(CUser _User, Boolean _OverrideTime) {
declare Integer[Text] CustomTimes for This; if (_User == Null) return;
declare Text[] AccountIdsOfPlayers for This;
foreach (Score in Scores) {
if (Score == Null) continue;
declare CSmPlayer Player = GetPlayer(Score.User.Login);
if (Player == Null) continue;
if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned) {
Scores::UpdatePlayerBestRaceIfBetter(Player); if (_OverrideTime) {
if (_EliminatedPlayer != Null && _EliminatedPlayer == Player) { declare Integer[Text] CustomTimes for This = [];
if (_EventType == Events::C_Type_GiveUp || _EventType == Events::C_Type_Eliminated) { CustomTimes[_User.WebServicesUserId] = Now - StartTime;
CustomTimes[Score.User.WebServicesUserId] = Now - StartTime;
}
UIManager.UIAll.SendChat("""$<$ff3$> Player $<$ff9{{{Player.User.Name}}}$> is eliminated""");
}
} else {
Scores::SetPlayerRoundPoints(Score,PlayersNbDead);
}
}
UIModules_ScoresTable::DisplayOnly(AccountIdsOfPlayers);
UIModules_ScoresTable::SetCustomTimes(CustomTimes); UIModules_ScoresTable::SetCustomTimes(CustomTimes);
} }
UIManager.UIAll.SendChat("""$<$ff3$> Player $<$ff9{{{_User.Name}}}$> is eliminated""");
}
/** Update the scores table footer text /** Update the scores table footer text
* *