TM2020-Gamemodes/TM_SeedingTimeAttack_Online.Script.txt

857 lines
32 KiB
Plaintext
Raw Normal View History

2021-10-16 00:19:57 +02:00
/**
* Seeding Time Attack mode
*/
2023-09-25 18:24:25 +02:00
#Extends "Modes/Nadeo/Trackmania/Base/TrackmaniaBase.Script.txt"
2021-10-16 00:19:57 +02:00
#Const CompatibleMapTypes "TrackMania\\TM_Race,TM_Race"
2023-09-25 18:24:25 +02:00
#Const Version "2023-09-25"
2022-02-27 17:49:56 +01:00
#Const ScriptName "Modes/TM2020-Gamemodes/TM_SeedingTimeAttack_Online.Script.txt"
2021-10-16 00:19:57 +02:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Libraries
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Include "TextLib" as TL
#Include "MathLib" as ML
2023-09-25 18:24:25 +02:00
#Include "Libs/Nadeo/CMGame/Utils/Task.Script.txt" as Task
#Include "Libs/Nadeo/Trackmania/Modes/TimeAttack/StateManager.Script.txt" as StateMgr
#Include "Libs/Nadeo/Trackmania/Modes/TrophyRanking.Script.txt" as TrophyRanking
#Include "Libs/Nadeo/Trackmania/MainMenu/Constants.Script.txt" as MenuConsts
#Include "Libs/Nadeo/CMGame/Modes/Utils.Script.txt" as ModeUtils
#Include "Libs/Nadeo/CMGame/Utils/Semver.Script.txt" as Semver
2021-10-16 00:19:57 +02:00
// UI from Race
2023-09-25 18:24:25 +02:00
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/TimeGap_Server.Script.txt" as UIModules_TimeGap
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/BigMessage_Server.Script.txt" as UIModules_BigMessage
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/Checkpoint_Server.Script.txt" as UIModules_Checkpoint
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/ScoresTable_Server.Script.txt" as UIModules_ScoresTable
#Include "Libs/Nadeo/TMGame/Modes/Base/UIModules/PauseMenuOnline_Server.Script.txt" as UIModules_PauseMenu_Online
#Include "Libs/Nadeo/Trackmania/Modes/TimeAttack/UIModules/EndMatchTrophy_Server.Script.txt" as UIModules_EndMatchTrophy
2021-10-16 00:19:57 +02:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Setting S_UseTheWorstTimeForDNF True as ""
2021-10-16 10:20:11 +02:00
#Setting S_MalusTimeForDNF 10000 as "Time to add (or substract) in ms for who DNF"
#Setting S_MapsPerMatch 3 as _("Number of maps per match") ///< Number of maps to play before finishing the match
2021-10-16 00:19:57 +02:00
#Setting S_TimeLimit 300 as _("Time limit") ///< Time limit before going to the next map
#Setting S_WarmUpNb 0 as _("Number of warm up")
#Setting S_WarmUpDuration 0 as _("Duration of one warm up")
#Setting S_WarmUpTimeout -1 as _("Warm up timeout")
#Setting S_ForceLapsNb 0
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Constants
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Const C_ModeName "Time Attack"
//L16N [Time Attack] Description of the mode rules
#Const Description _("$zIn $<$t$6F9Time Attack$> mode, the goal is to set the $<$t$6F9best time$>.\n\nYou have as many tries as you want, and you can $<$t$6F9retry$> when you want by pressing the respawn key.\n\nWhen the time is up, the $<$t$6F9winner$> is the player with the $<$t$6F9best time$>.")
#Const C_HudModulePath "" //< Path to the hud module
2023-09-25 18:59:38 +02:00
#Const C_ManiaAppUrl "file://Media/ManiaApps/Nadeo/Trackmania/Modes/TimeAttack.Script.txt" //< Url of the mania app
2021-10-16 00:19:57 +02:00
#Const C_FakeUsersNb 0
#Const C_UploadRecord True
#Const C_DisplayRecordGhost True
#Const C_DisplayRecordMedal True
#Const C_CelebrateRecordGhost True
#Const C_CelebrateRecordMedal True
#Const C_DisplayWorldTop True
#Const C_TrophyTaskTimeout 5000
#Const C_TrophyAnimationDuration 4000
#Const C_TrophyDisplayDuration 7000
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Extends
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
***Match_LogVersions***
***
Log::RegisterScript(ScriptName, Version);
Log::RegisterScript(StateMgr::ScriptName, StateMgr::Version);
***
***Match_LoadLibraries***
***
StateMgr::Load();
***
***Match_UnloadLibraries***
***
StateMgr::Unload();
***
***Match_Settings***
***
MB_Settings_UseDefaultTimer = False;
MB_Settings_UseDefaultHud = (C_HudModulePath == "");
MB_Settings_UseDefaultPodiumSequence = False;
***
***Match_Rules***
***
ModeInfo::SetName(C_ModeName);
ModeInfo::SetType(ModeInfo::C_Type_FreeForAll);
ModeInfo::SetRules(Description);
ModeInfo::SetStatusMessage(_("TYPE: Free for all\nOBJECTIVE: Set the best time on the track."));
***
***Match_LoadHud***
***
if (C_HudModulePath != "") Hud_Load(C_HudModulePath);
***
***Match_AfterLoadHud***
***
UIManager.UIAll.ScoreTableOnlyManialink = True;
UIModules_Checkpoint::SetRankMode(UIModules_Checkpoint::C_RankMode_BestRace);
ClientManiaAppUrl = C_ManiaAppUrl;
Race::SortScores(Race::C_Sort_BestRaceTime);
UIModules_TimeGap::SetTimeGapMode(UIModules_TimeGap::C_TimeGapMode_BestRace);
UIModules_PauseMenu_Online::SetHelp(Description);
UIManager.UIAll.OverlayHideCountdown = True;
UIManager.UIAll.OverlayHideSpectatorInfos = True;
UIManager.UIAll.OverlayHideChrono = True;
SetML();
***
***Match_Yield***
***
foreach (Event in PendingEvents) {
2021-10-31 12:31:48 +01:00
switch (Event.Type) {
// Initialize players when they join the server
case CSmModeEvent::EType::OnPlayerAdded: {
StateMgr::InitializePlayer(Event.Player);
CarRank::InitializePlayer(Event.Player);
if (Event.Player != Null) {
2022-03-04 22:21:30 +01:00
Log::Log("[Match_Yield][PendingEvents] New player added: " ^ Event.Player.User.Name);
2021-10-31 12:31:48 +01:00
declare Boolean Match_CanForceTrophyRankUpdate for This;
TrophyRanking::InitializeUser(Event.Player.User, Match_CanForceTrophyRankUpdate);
if (Scores::GetPlayerMatchPoints(Event.Player.Score) == 0) {
declare Integer CumulateWorstTimeOfPreviousMaps for This;
Log::Log("[Match_Yield][PendingEvents] New Player with : " ^ CumulateWorstTimeOfPreviousMaps ^ " points");
Scores::SetPlayerMatchPoints(Event.Player.Score, CumulateWorstTimeOfPreviousMaps);
}
}
}
}
2021-10-16 00:19:57 +02:00
}
StateMgr::Yield();
TrophyRanking::Yield();
***
***Match_StartServer***
***
// Initialize mode
Clans::SetClansNb(0);
GiveUpBehaviour_RespawnAfter = True;
CrudeExtrapolation_AllowDelay = True;
Race::SetRespawnBehaviour(Race::C_RespawnBehaviour_GiveUpBeforeFirstCheckpoint);
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
WarmUp::SetAvailability(True);
Race::SetupRecord(
2021-10-31 12:31:48 +01:00
MenuConsts::C_ScopeType_Season,
MenuConsts::C_ScopeType_PersonalBest,
MenuConsts::C_GameMode_TimeAttack,
"",
C_UploadRecord,
C_DisplayRecordGhost,
C_DisplayRecordMedal,
C_CelebrateRecordGhost,
C_CelebrateRecordMedal,
C_DisplayWorldTop
2021-10-16 00:19:57 +02:00
);
CarRank::Reset();
Scores::SaveInScore(Scores::C_Points_Match);
UIModules_Record::SetSpecialVisibility(False);
***
***Match_InitMatch***
***
2023-09-25 18:24:25 +02:00
declare Task::K_Task Match_TrophyTask;
2021-10-16 00:19:57 +02:00
declare Integer Match_TrophyTaskEndTime;
declare Integer Match_MatchDuration;
declare Boolean Match_CanForceTrophyRankUpdate for This = False;
declare netwrite Text Net_ScriptEnvironment for Teams[0] = S_ScriptEnvironment;
declare netwrite Integer[Text] Net_MatchPoints for Teams[0];
Net_MatchPoints = [];
declare netwrite Integer[Text] Net_RoundPoints for Teams[0];
Net_RoundPoints = [];
declare Integer CumulateWorstTimeOfPreviousMaps for This;
CumulateWorstTimeOfPreviousMaps = 0;
declare Integer WorstTime for This;
WorstTime = 0;
***
***Match_AfterLoadMap***
***
Match_CanForceTrophyRankUpdate = True;
***
***Match_InitMap***
***
declare Integer Map_TimeLimit;
declare Integer Map_MapStartTime;
declare Integer Map_MalusTimeForDNF;
declare Integer Map_MapsPerMatch;
declare Boolean Map_UseTheWorstTimeForDNF;
***
***Match_StartMap***
***
// Add bot when necessary
2022-02-27 17:49:56 +01:00
if (S_ScriptEnvironment == "production") Users_SetNbFakeUsers(C_FakeUsersNb, 0);
2021-10-16 00:19:57 +02:00
// Warm up
UIModules_ScoresTable::SetFooterInfo(_("Warmup"));
GiveUpBehaviour_RespawnAfter = False;
MB_WarmUp(S_WarmUpNb, S_WarmUpDuration * 1000, S_WarmUpTimeout * 1000);
GiveUpBehaviour_RespawnAfter = True;
// Initialize race
SetScoresTableScoreMode(Race::IsIndependentLaps(), False);
StartTime = Now + Race::C_SpawnDuration;
// Spawn players for the race
foreach (Player in Players) {
2021-10-31 12:31:48 +01:00
Race::Start(Player, StartTime);
2021-10-16 00:19:57 +02:00
}
StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]);
CarRank::Update(CarRank::C_SortCriteria_BestRace);
Race::EnableIntroDuringMatch(True);
Race::SortScores(Race::C_Sort_BestRaceTime);
declare netwrite Integer Net_SerialNeedToUpdate for Teams[0];
Net_SerialNeedToUpdate = 0;
Map_TimeLimit = S_TimeLimit;
Map_MapStartTime = StartTime;
Map_MapsPerMatch = S_MapsPerMatch;
Map_MalusTimeForDNF = S_MalusTimeForDNF;
Map_UseTheWorstTimeForDNF = S_UseTheWorstTimeForDNF;
UpdateScoresTableFooterAndTimeLimit(StartTime, S_TimeLimit, S_MapsPerMatch);
declare Integer WorstTime for This;
WorstTime = S_TimeLimit * 1000;
UpdateCustomRanking(Null);
***
***Match_PlayLoop***
***
foreach (Event in PendingEvents) {
2021-10-16 10:20:11 +02:00
Log::Log("[PlayLoop][PendingEvents] Event.Type: " ^ Event.Type);
2021-10-16 00:19:57 +02:00
if (Event.Type == CSmModeEvent::EType::OnPlayerAdded) {
if (Event.Player != Null) {
2022-03-04 22:21:30 +01:00
Log::Log("[PlayLoop][PendingEvents] New player added: " ^ Event.Player.User.Name);
2021-10-31 12:31:48 +01:00
UpdateCustomRanking(Event.Player);
2021-10-16 00:19:57 +02:00
}
}
}
// Manage race events
declare RacePendingEvents = Race::GetPendingEvents();
foreach (Event in RacePendingEvents) {
2021-10-31 12:31:48 +01:00
Race::ValidEvent(Event);
// Waypoint
if (Event.Type == Events::C_Type_Waypoint) {
if (Event.Player != Null) {
declare Better = False;
declare OldRank = 0;
if (Event.IsEndRace) {
// Computes old rank before changing Score
foreach (Index => Score in Scores) {
if (Score.Id == Event.Player.Score.Id) {
if (Score.BestRaceTimes.count != 0) {
OldRank = Index + 1;
} else {
OldRank = -123;
}
break;
}
}
// Change Score
Better = Scores::UpdatePlayerBestRaceIfBetter(Event.Player);
declare BetterLap = Scores::UpdatePlayerBestLapIfBetter(Event.Player);
Scores::UpdatePlayerPrevRace(Event.Player);
} else if (Event.IsEndLap) {
declare BetterLap = Scores::UpdatePlayerBestLapIfBetter(Event.Player);
if (Race::IsIndependentLaps()) {
// Computes old rank before changing Score
foreach (Index => Score in Scores) {
if (Score.Id == Event.Player.Score.Id) {
if (Score.BestLapTimes.count != 0) {
OldRank = Index + 1;
} else {
OldRank = -123;
}
break;
}
}
// Change Score
Better = BetterLap;
if (Better) Scores::UpdatePlayerBestRace(Event.Player);
Scores::UpdatePlayerPrevLap(Event.Player);
}
}
if (Better) {
UpdateCustomRanking(Event.Player);
declare NewRank = 0;
foreach (Index => Score in Scores) {
if (Score.Id == Event.Player.Score.Id) {
NewRank = Index + 1;
break;
}
}
if (OldRank != NewRank) {
if (0 < NewRank && NewRank < 4) {
foreach (Player in AllPlayers) {
UIModules_DisplayMessage::SendLiveMessage_RankUpdate(Player, Event.Player.User, NewRank);
}
} else if (0 < NewRank) {
UIModules_DisplayMessage::SendLiveMessage_RankUpdate(Event.Player, Event.Player.User, NewRank);
}
}
CarRank::ThrottleUpdate(CarRank::C_SortCriteria_BestRace);
}
}
}
2021-10-16 00:19:57 +02:00
}
// Manage mode events
foreach (Event in PendingEvents) {
2021-10-31 12:31:48 +01:00
if (Event.HasBeenPassed || Event.HasBeenDiscarded) continue;
Events::Invalid(Event);
2021-10-16 00:19:57 +02:00
}
// Spawn players
if (PlayersNbDead > 0) { //< Check for unspawned players only if at least one player is unspawned
2021-10-31 12:31:48 +01:00
foreach (Player in Players) {
if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && Race::IsReadyToStart(Player)) {
Race::Start(Player);
}
}
2021-10-16 00:19:57 +02:00
}
// Update the map duration setting
if (Map_TimeLimit != S_TimeLimit || Map_MalusTimeForDNF != S_MalusTimeForDNF || Map_MapsPerMatch != S_MapsPerMatch || Map_UseTheWorstTimeForDNF != S_UseTheWorstTimeForDNF) {
2021-10-31 12:31:48 +01:00
UpdateWorstTime();
UpdateCustomRanking(Null);
Map_UseTheWorstTimeForDNF = S_UseTheWorstTimeForDNF;
Map_MalusTimeForDNF = S_MalusTimeForDNF;
Map_TimeLimit = S_TimeLimit;
Map_MapsPerMatch = S_MapsPerMatch;
UpdateScoresTableFooterAndTimeLimit(StartTime, S_TimeLimit, S_MapsPerMatch);
2021-10-16 00:19:57 +02:00
}
if (Net_ScriptEnvironment != S_ScriptEnvironment) {
Net_ScriptEnvironment = S_ScriptEnvironment;
}
// End the map when time limit is reached
if (EndTime > 0 && Now >= EndTime) {
2021-10-31 12:31:48 +01:00
MB_StopMap();
2021-10-16 00:19:57 +02:00
}
***
2022-03-04 22:21:30 +01:00
***Match_EndRound***
2021-10-16 00:19:57 +02:00
***
2022-03-04 22:21:30 +01:00
if (Semver::Compare(XmlRpc::GetApiVersion(), ">=", "2.1.1")) {
Scores::XmlRpc_SendScores(Scores::C_Section_PreEndRound, "");
}
UpdateCustomRanking(Null);
2021-10-16 00:19:57 +02:00
EndTime = -1;
2021-10-16 10:20:11 +02:00
declare Integer WorstTime for This;
declare Integer CumulateWorstTimeOfPreviousMaps for This;
CumulateWorstTimeOfPreviousMaps = CumulateWorstTimeOfPreviousMaps + WorstTime + S_MalusTimeForDNF;
2021-10-16 00:19:57 +02:00
Match_MatchDuration = ML::Max(0, Now - Map_MapStartTime);
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
Race::EnableIntroDuringMatch(False);
Race::SortScores(Race::C_Sort_BestRaceTime);
TrophyRanking::UpdateUsersRank();
CarRank::Update(CarRank::C_SortCriteria_BestRace);
Race::StopSkipOutroAll();
Scores::EndRound();
2022-03-04 22:21:30 +01:00
***
***Match_EndMap***
***
2021-10-16 00:19:57 +02:00
if (MB_GetMapCount() >= S_MapsPerMatch) {
2021-10-31 12:31:48 +01:00
Log::Log("[Match_EndMap] Stop Match");
Scores::SetPlayerWinner(Scores::GetBestPlayer(Scores::C_Sort_MatchPoints, Scores::C_Order_Ascending));
MB_StopMatch();
2021-10-16 00:19:57 +02:00
} else {
2021-10-31 12:31:48 +01:00
Scores::SetPlayerWinner(Scores::GetBestPlayer(GetLadderSortCriteria()));
2021-10-16 00:19:57 +02:00
}
***
***Match_BeforePodiumSequence***
***
UIManager.UIAll.BigMessageSound = CUIConfig::EUISound::EndRound;
UIManager.UIAll.BigMessageSoundVariant = 0;
declare CSmScore WinnerScore <=> Scores::GetPlayerWinner();
if (WinnerScore != Null) {
2022-03-31 22:32:23 +02:00
if (!MB_MatchIsRunning()) {
UIModules_BigMessage::SetMessage("$<%1$> wins the match!", WinnerScore.User.WebServicesUserId);
} else {
UIModules_BigMessage::SetMessage("$<%1$> wins the map!", WinnerScore.User.WebServicesUserId);
}
} else {
UIModules_BigMessage::SetMessage(_("|Match|Draw"));
2021-10-16 00:19:57 +02:00
}
// Compute match trophies
Trophy_LiveTimeAttackAchievement_ClearResultList();
foreach (Key => Score in Scores) {
2021-10-31 12:31:48 +01:00
if (TrophyRanking::UserIsRanked(Score.User) && Score.BestRaceTimes.count > 0 && Score.BestRaceTimes[Score.BestRaceTimes.count - 1] >= 0) {
Trophy_LiveTimeAttackAchievement_AddResult(Score.User.WebServicesUserId, Key + 1, TrophyRanking::GetUserRank(Score.User));
}
2021-10-16 00:19:57 +02:00
}
Match_TrophyTask = Task::Create(This, Trophy_LiveTimeAttackAchievement_SendResultList(Match_MatchDuration / 1000));
Match_TrophyTaskEndTime = Now + C_TrophyTaskTimeout;
UIModules_ScoresTable::ResetTrophies();
UIModules_EndMatchTrophy::ResetTrophyAnimation();
***
***Match_PodiumSequence***
***
declare CUIConfig::EUISequence PrevUISequence = UIManager.UIAll.UISequence;
UIManager.UIAll.UISequence = CUIConfig::EUISequence::Podium;
MB_Private_Sleep((S_ChatTime*1000)/2);
// Wait until the trophy task is complete
Match_TrophyTask = Task::Update(Match_TrophyTask);
while (Task::IsInitialized(Match_TrophyTask) && Task::IsRunning(Match_TrophyTask) && Now < Match_TrophyTaskEndTime) {
2021-10-31 12:31:48 +01:00
MB_Yield();
Match_TrophyTask = Task::Update(Match_TrophyTask);
2021-10-16 00:19:57 +02:00
}
if (Task::IsInitialized(Match_TrophyTask)) {
2021-10-31 12:31:48 +01:00
Match_TrophyTask = Task::Update(Match_TrophyTask);
declare Integer[Integer][Text] AccountsTrophies;
if (!Task::IsRunning(Match_TrophyTask)) {
declare CTaskResult_AccountTrophyGainList SourceTask = Task::GetSourceTask_AccountTrophyGainList(Match_TrophyTask);
if (Task::IsSuccess(Match_TrophyTask) && SourceTask != Null) {
foreach (AccountTrophyGain in SourceTask.AccountTrophyGainList) {
declare Integer[Integer] AccountTrophies = UIModules_ScoresTable::ConvertAccountTrophyGain(AccountTrophyGain);
if (AccountTrophies.count > 0) {
AccountsTrophies[AccountTrophyGain.WebServicesUserId] = AccountTrophies;
}
}
}
}
Match_TrophyTask = Task::Destroy(Match_TrophyTask);
UIModules_ScoresTable::SetTrophies(AccountsTrophies);
UIModules_EndMatchTrophy::PlayTrophyAnimation(AccountsTrophies);
StateMgr::ForcePlayersStates([StateMgr::C_State_TrophyAnimation]);
MB_Private_Sleep(C_TrophyAnimationDuration);
StateMgr::ForcePlayersStates([StateMgr::C_State_Waiting]);
2021-10-16 00:19:57 +02:00
}
UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::ForcedVisible;
MB_Private_Sleep((S_ChatTime*1000)/2);
SetScoresTableScoreMode(Race::IsIndependentLaps(), True);
MB_Private_Sleep(C_TrophyDisplayDuration);
SetScoresTableScoreMode(Race::IsIndependentLaps(), False);
UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::Normal;
UIManager.UIAll.UISequence = PrevUISequence;
***
***Match_AfterPodiumSequence***
***
2022-03-31 22:32:23 +02:00
UIModules_BigMessage::SetMessage("");
2021-10-16 00:19:57 +02:00
UIModules_ScoresTable::ResetTrophies();
***
***Match_BeforeUnloadMap***
***
Match_CanForceTrophyRankUpdate = False;
***
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Select the scores table score mode
Void SetScoresTableScoreMode(Boolean _IsIndependentLaps, Boolean _DisplayTrophies) {
2021-10-31 12:31:48 +01:00
if (_DisplayTrophies) UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_Trophy);
else if (_IsIndependentLaps) UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_LapTime);
else UIModules_ScoresTable::SetScoreMode(UIModules_ScoresTable::C_Mode_BestTime);
2021-10-16 00:19:57 +02:00
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Update the time limit
*
* @param _StartTime The starting time of the map
* @param _NewTimeLimit The time limit before going to the next map
*/
Void UpdateScoresTableFooterAndTimeLimit(Integer _StartTime, Integer _NewTimeLimit, Integer _MapsPerMatch) {
2021-10-31 12:31:48 +01:00
Log::Log("[UpdateScoresTableFooterAndTimeLimit] Update Settings Footer");
declare Text[] Parts;
declare Text Message = "";
if (_NewTimeLimit <= 0) {
if (Parts.count > 0) Message ^= "\n";
Message ^= """%{{{Parts.count + 1}}} -""";
2021-10-16 00:19:57 +02:00
//L16N [Rounds] Number of points to reach to win the match.
Parts.add(_("Time Limit : "));
2021-10-31 12:31:48 +01:00
EndTime = -1;
UIModules_ScoresTable::SetFooterInfo(TL::Compose("%1 -", _("Time Limit")));
} else {
if (Parts.count > 0) Message ^= "\n";
Message ^= """%{{{Parts.count + 1}}}{{{TL::TimeToText(_NewTimeLimit*1000)}}}""";
2021-10-16 00:19:57 +02:00
//L16N [Rounds] Number of points to reach to win the match.
Parts.add(_("Time Limit : "));
2021-10-31 12:31:48 +01:00
EndTime = _StartTime + (S_TimeLimit * 1000);
UIModules_ScoresTable::SetFooterInfo(TL::Compose("%1 "^TL::TimeToText(_NewTimeLimit*1000), _("Time Limit")));
}
if (_MapsPerMatch > 0) {
2021-10-16 00:19:57 +02:00
if (Parts.count > 0) Message ^= "\n";
Message ^= """%{{{Parts.count + 1}}}{{{MB_GetMapCount()}}}/{{{_MapsPerMatch}}}""";
//L16N [Rounds] Number of maps played during the match.
Parts.add(_("Maps : "));
}
2021-10-31 12:31:48 +01:00
switch (Parts.count) {
2021-10-16 00:19:57 +02:00
case 0: UIModules_ScoresTable::SetFooterInfo(Message);
case 1: UIModules_ScoresTable::SetFooterInfo(TL::Compose(Message, Parts[0]));
case 2: UIModules_ScoresTable::SetFooterInfo(TL::Compose(Message, Parts[0], Parts[1]));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the right sort criteria for
* the scores
*
* @return The sort criteria
*/
Integer GetScoresSortCriteria() {
2021-10-31 12:31:48 +01:00
if (Race::IsIndependentLaps()) return Race::C_Sort_BestLapTime;
return Race::C_Sort_BestRaceTime;
2021-10-16 00:19:57 +02:00
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the right sort criteria for
* the ladder
*
* @return The sort criteria
*/
Integer GetLadderSortCriteria() {
2021-10-31 12:31:48 +01:00
if (Race::IsIndependentLaps()) return Scores::C_Sort_BestLapTime;
return Scores::C_Sort_BestRaceTime;
2021-10-16 00:19:57 +02:00
}
Void UpdateWorstTime() {
2021-10-31 12:31:48 +01:00
declare Integer MaxTime;
if (S_UseTheWorstTimeForDNF) {
foreach (Score in Scores) {
MaxTime = ML::Max(MaxTime, Scores::GetPlayerBestRaceTime(Score));
}
if (MaxTime == 0) MaxTime = S_TimeLimit * 1000;
} else {
MaxTime = S_TimeLimit * 1000;
}
declare Integer WorstTime for This;
WorstTime = MaxTime;
2021-10-16 00:19:57 +02:00
}
/** Update the Scores Table with hidden custom points
*
* @param _EliminatedPlayer The Player who is eliminated
*/
Void UpdateCustomRanking(CSmPlayer _Player) {
2021-10-31 12:31:48 +01:00
/*
* FYI, it's not possible to sort the scoreboard by Matchpoint Asc
*/
declare netwrite Integer[Text] Net_MatchPoints for Teams[0];
declare netwrite Integer[Text] Net_RoundPoints for Teams[0];
declare Integer[Text] MatchPoints = Net_MatchPoints;
declare Integer[Text] RoundPoints = Net_RoundPoints;
declare Boolean SkipUpdate;
2021-10-16 00:19:57 +02:00
declare Text[][Text] CustomPoints for This;
2021-10-31 12:31:48 +01:00
declare Integer WorstTime for This;
2021-10-16 00:19:57 +02:00
foreach (Score in Scores) {
if (Score == Null) continue;
declare CSmPlayer Player = GetPlayer(Score.User.Login);
if (Player == Null) continue;
2021-10-31 12:31:48 +01:00
if (_Player == Null || _Player == Player) {
declare Text BestCurrentColor = "$ccc";
if (Score.BestRaceTimes.count > 0) {
if (S_UseTheWorstTimeForDNF && Scores::GetPlayerRoundPoints(Score) == 0 ||
(WorstTime == Scores::GetPlayerRoundPoints(Score) && Scores::GetPlayerRoundPoints(Score) != Scores::GetPlayerBestRaceTime(Score)) || // When Last
(WorstTime + S_MalusTimeForDNF == Scores::GetPlayerRoundPoints(Score) && Scores::GetPlayerRoundPoints(Score) != Scores::GetPlayerBestRaceTime(Score) + S_MalusTimeForDNF)) // When First Time registered
{
Log::Log("[UpdateCustomRanking] Update Worst Time");
UpdateWorstTime();
Scores::SetPlayerRoundPoints(Score, Scores::GetPlayerBestRaceTime(Score));
UpdateCustomRanking(Null);
SkipUpdate = True;
break;
} else {
Scores::SetPlayerRoundPoints(Score, Scores::GetPlayerBestRaceTime(Score));
}
BestCurrentColor = "$fff" ;
} else {
Scores::SetPlayerRoundPoints(Score, WorstTime + S_MalusTimeForDNF);
}
declare Text BestCurrentTime = TL::TimeToText(Scores::GetPlayerRoundPoints(Score) , True, True);
declare Text TotalTimes = TL::TimeToText(Scores::GetPlayerRoundPoints(Score) + Scores::GetPlayerMatchPoints(Score) , True, False);
RoundPoints[Score.User.WebServicesUserId] = Scores::GetPlayerRoundPoints(Score);
MatchPoints[Score.User.WebServicesUserId] = Scores::GetPlayerRoundPoints(Score) + Scores::GetPlayerMatchPoints(Score);
CustomPoints[Score.User.WebServicesUserId] = ["$<$i"^ BestCurrentColor ^ BestCurrentTime ^ "$> $<$n$i$aaa" ^ TotalTimes , ""];
2021-10-16 00:19:57 +02:00
}
}
2021-10-31 12:31:48 +01:00
if (!SkipUpdate) {
UIModules_ScoresTable::SetCustomPoints(CustomPoints);
2021-10-16 00:19:57 +02:00
2021-10-31 12:31:48 +01:00
declare netwrite Integer Net_SerialNeedToUpdate for Teams[0];
Net_SerialNeedToUpdate = Net_SerialNeedToUpdate + 1;
2021-10-16 00:19:57 +02:00
2021-10-31 12:31:48 +01:00
// Update UI
Net_MatchPoints = MatchPoints;
Net_RoundPoints = RoundPoints;
}
2021-10-16 00:19:57 +02:00
}
Void SetML() {
declare Text MLText = """
<manialink name="MatchRanking_UI" version="3">
<script><!--
#Include "TextLib" as TL
Void DevLog(Text _LogText) {
declare netread Text Net_ScriptEnvironment for Teams[0] = "production";
if (Net_ScriptEnvironment == "development") log(_LogText);
}
Void Sleep(Integer _Duration) {
declare EndTime = Now + _Duration;
while (Now < EndTime) {
yield;
}
}
Boolean InputPlayerIsSpectator() {
if (GUIPlayer != Null && InputPlayer != Null && GUIPlayer.User.Login == InputPlayer.User.Login) return False;
return True;
}
2021-10-31 12:31:48 +01:00
CUser GetUserFromAccountId(Text _AccountId) {
foreach (Score in Scores) {
if (Score.User != Null && Score.User.WebServicesUserId == _AccountId) return Score.User;
}
return Null;
}
2021-10-16 00:19:57 +02:00
Void ToggleUI() {
declare CMlFrame Frame_Global <=> (Page.GetFirstChild("frame-global") as CMlFrame);
declare CMlFrame Frame_UI <=> (Page.GetFirstChild("frame-ui") as CMlFrame);
declare CMlQuad Quad_Toggle <=> (Page.GetFirstChild("quad-toggle") as CMlQuad);
AnimMgr.Flush(Frame_Global);
AnimMgr.Flush(Frame_UI);
declare Real GlobalEndPosX;
if (Frame_UI.Visible) {
2023-09-25 19:13:06 +02:00
Quad_Toggle.ChangeImageUrl("file://Media/Manialinks/Nadeo/CMGame/Utils/Icons/128x128/ICON_ARROW_RIGHT_OBLIQUE.dds");
2021-10-16 00:19:57 +02:00
Quad_Toggle.RelativePosition_V3.X = 5.;
GlobalEndPosX = -215.;
AnimMgr.Add(Frame_UI, "<frame hidden=\"1\" />", Now, 250, CAnimManager::EAnimManagerEasing::Linear);
} else {
2023-09-25 19:13:06 +02:00
Quad_Toggle.ChangeImageUrl("file://Media/Manialinks/Nadeo/CMGame/Utils/Icons/128x128/ICON_ARROW_LEFT_OBLIQUE.dds");
2021-10-16 00:19:57 +02:00
Quad_Toggle.RelativePosition_V3.X = 0.;
GlobalEndPosX = -160.;
Frame_UI.Visible = True;
}
AnimMgr.Add(Frame_Global, "<frame pos=\"" ^GlobalEndPosX^" "^Frame_Global.RelativePosition_V3.Y^ "\" />", Now, 250, CAnimManager::EAnimManagerEasing::Linear);
}
2021-10-31 12:31:48 +01:00
Void SetPlayerEntry(Integer _Index, Integer _Rank, Text _Name, Text _Login, Vec3 _PlayerNameColor, Integer _RoundPoints, Integer _MatchPoints) {
DevLog("[SetPlayerEntry UI] Set entry for " ^ _Name ^ " at index " ^_Index);
declare CMlFrame Frame_ParentFrame <=> (Page.GetFirstChild("player-" ^ _Index) as CMlFrame);
2022-02-27 17:49:56 +01:00
declare CMlQuad Quad_Bg <=> (Frame_ParentFrame.GetFirstChild("player-bg") as CMlQuad);
2021-10-31 12:31:48 +01:00
declare CMlLabel Label_PlayerPos <=> (Frame_ParentFrame.GetFirstChild("player-pos") as CMlLabel);
declare CMlLabel Label_PlayerName <=> (Frame_ParentFrame.GetFirstChild("player-name") as CMlLabel);
declare CMlLabel Label_PlayerMapTime <=> (Frame_ParentFrame.GetFirstChild("player-maptime") as CMlLabel);
declare CMlLabel Label_PlayerTotalTimes <=> (Frame_ParentFrame.GetFirstChild("player-totaltimes") as CMlLabel);
Frame_ParentFrame.Visible = True;
declare Text User_Login for Quad_Bg = "";
User_Login = _Login;
Label_PlayerPos.Value = ""^_Rank;
Label_PlayerName.Value = _Name;
Label_PlayerName.TextColor = _PlayerNameColor;
Label_PlayerMapTime.Value = TL::TimeToText(_RoundPoints,True,True);
Label_PlayerTotalTimes.Value = TL::TimeToText(_MatchPoints,True,True);
}
Void SpectateLogin(Text _Login) {
ClientUI.Spectator_SetForcedTarget_Clear();
SetSpectateTarget(_Login);
Playground.SetWantedSpectatorCameraType(CPlaygroundClient::ESpectatorCameraType::Replay);
}
2021-10-31 12:29:41 +01:00
2021-10-16 00:19:57 +02:00
main() {
2022-02-27 17:49:56 +01:00
declare CMlQuad Quad_Sep10 <=> (Page.GetFirstChild("sep-10") as CMlQuad);
2021-10-31 12:31:48 +01:00
declare netread Integer Net_SerialNeedToUpdate for Teams[0];
declare Integer Last_SerialNeedToUpdate = -1;
declare Text Last_GUIPlayerUID;
declare Integer RetryIn3Secs;
2021-10-16 00:19:57 +02:00
while(True) {
yield;
if (InputPlayer != Null) {
// Events
foreach(Event in PendingEvents) {
DevLog("[PendingEvents] Event.Type: " ^ Event.Type);
2021-10-31 12:31:48 +01:00
if (Event.Type == CMlScriptEvent::Type::MouseClick) {
if (TL::Find("player-", Event.ControlId, True, True) && InputPlayerIsSpectator()) {
declare Text User_Login for Event.Control = "";
if (User_Login != "") {
DevLog("[PendingEvents] Spectator " ^ InputPlayer.User.Login ^" spectate " ^ User_Login);
SpectateLogin(User_Login);
}
} else if (Event.ControlId == "quad-toggle") {
DevLog("[PendingEvents] Toggle UI by " ^ InputPlayer.User.Login);
ToggleUI();
}
2022-02-27 17:49:56 +01:00
} else if (Event.Type == CMlScriptEvent::Type::MouseOver && TL::Find("player-bg", Event.ControlId, True, True) && InputPlayerIsSpectator()) {
declare Quad <=> (Event.Control as CMlQuad);
2021-10-31 12:31:48 +01:00
Quad.Opacity = 0.1;
2022-02-27 17:49:56 +01:00
} else if (Event.Type == CMlScriptEvent::Type::MouseOut && TL::Find("player-bg", Event.ControlId, True, True)) {
declare Quad <=> (Event.Control as CMlQuad);
2021-10-31 12:31:48 +01:00
Quad.Opacity = 0.;
}
2021-10-16 00:19:57 +02:00
}
}
2021-10-31 12:31:48 +01:00
if (Last_SerialNeedToUpdate != Net_SerialNeedToUpdate || (GUIPlayer != Null && Last_GUIPlayerUID != GUIPlayer.User.WebServicesUserId) || GUIPlayer == Null && Last_GUIPlayerUID != "") {
DevLog("[main] Update UI "^ Now);
Last_SerialNeedToUpdate = Net_SerialNeedToUpdate;
declare netread Integer[Text] Net_MatchPoints for Teams[0];
declare netread Integer[Text] Net_RoundPoints for Teams[0];
// Update if change spec target
if (GUIPlayer != Null) Last_GUIPlayerUID = GUIPlayer.User.WebServicesUserId;
else Last_GUIPlayerUID = "";
declare Integer[Text] PlayersMatchPoints;
PlayersMatchPoints = Net_MatchPoints.sort();
declare Integer Rank = 1;
Rank = 1;
declare Integer Index = 1;
Index = 1;
declare Boolean GUIPlayerPassed = False;
GUIPlayerPassed = False;
declare CUser PreviousUser;
declare CUser PreviousPreviousUser;
2022-02-27 17:49:56 +01:00
Quad_Sep10.Visible = False;
2021-10-31 12:31:48 +01:00
foreach (PlayerUID => Points in PlayersMatchPoints) {
declare CUser User <=> GetUserFromAccountId(PlayerUID);
if (User == Null) continue;
declare Vec3 PlayerNameColor = <1.,1.,1.>;
if (GUIPlayer != Null && PlayerUID == GUIPlayer.User.WebServicesUserId) {
PlayerNameColor = <0.922,0.855,0.42>; //Gold
GUIPlayerPassed = True;
2022-02-27 17:49:56 +01:00
if (Rank > 12 || (Rank == 12 && PlayersMatchPoints.count > 12)) Quad_Sep10.Visible = True;
2021-10-31 12:31:48 +01:00
} else if (InputPlayer != Null && PlayerUID == InputPlayer.User.WebServicesUserId) {
PlayerNameColor = <0.431,0.98,0.627>; // Green
}
if (Index < 10 || Index == 12 || GUIPlayer == Null || (GUIPlayerPassed && PlayerUID != GUIPlayer.User.WebServicesUserId) || (GUIPlayerPassed && PlayerUID == GUIPlayer.User.WebServicesUserId && Rank <= 10 )) {
DevLog("[Update UI] Normal Entry");
SetPlayerEntry(Index,Rank,User.Name,User.Login,PlayerNameColor,Net_RoundPoints[PlayerUID],Points);
Index = Index + 1;
} else if (GUIPlayerPassed && PlayerUID == GUIPlayer.User.WebServicesUserId && Rank > 10 ) {
DevLog("[Update UI] Last Entries");
if (Rank == PlayersMatchPoints.count) {
SetPlayerEntry(Index,Rank-2,PreviousPreviousUser.Name,PreviousPreviousUser.Login,<1.,1.,1.>,Net_RoundPoints[PreviousPreviousUser.WebServicesUserId],PlayersMatchPoints[PreviousPreviousUser.WebServicesUserId]);
Index = Index + 1;
}
SetPlayerEntry(Index,Rank-1,PreviousUser.Name,PreviousUser.Login,<1.,1.,1.>,Net_RoundPoints[PreviousUser.WebServicesUserId],PlayersMatchPoints[PreviousUser.WebServicesUserId]);
SetPlayerEntry(Index+1,Rank,User.Name,User.Login,PlayerNameColor,Net_RoundPoints[PlayerUID],Points);
Index = Index + 2;
} else {
DevLog("[Update UI] No Entry");
PreviousPreviousUser <=> PreviousUser;
PreviousUser <=> User;
}
if (Index > 12) break;
Rank = Rank + 1;
}
}
2021-10-16 00:19:57 +02:00
}
2021-10-31 12:31:48 +01:00
}
2021-10-16 00:19:57 +02:00
--></script>
2021-10-31 12:31:48 +01:00
<stylesheet>
<style class="text" textfont="GameFontBlack" textcolor="fff" textsize="1.5" halign="left" valign="center2" textprefix="$i$t" />
<style class="text-suffix" textfont="GameFontBlack" textcolor="ffffff" textsize="0.7" halign="center" valign="center2" textprefix="$i$t"/>
</stylesheet>
2022-02-27 17:49:56 +01:00
<framemodel id="player-model">
<quad id="player-bg" valign="center" pos="0 0" z-index="0" size="55 5" bgcolor="999" opacity="0" scriptevents="1"/>
<label id="player-pos" class="text" pos="1 0" z-index="0" size="5 6" text="1"/>
<label id="player-pos" class="text" pos="1 0" z-index="0" size="5 6" text="1"/>
<label id="player-name" class="text" pos="7 0" z-index="0" size="25 6" text=""/>
<label id="player-maptime" class="text" pos="42 0" z-index="0" size="8 6" text="--:--.---" textcolor="aaa" textsize="0.5" halign="right"/>
<label id="player-totaltimes" class="text" pos="54 0" z-index="0" size="10 6" text="--:--.---" halign="right"/>
</framemodel>
2021-10-31 12:31:48 +01:00
<frame id="frame-global" pos="-160 30">
2022-02-27 17:49:56 +01:00
<frame pos="53 -2.5" id="frame-toggle" z-index="1" >
2023-09-25 19:13:06 +02:00
<quad id="quad-toggle" pos="0 0" size="4 4" class="quad-base" z-index="3" opacity="0.9" scriptevents="1" halign="center" valign="center" image="file://Media/Manialinks/Nadeo/CMGame/Utils/Icons/128x128/ICON_ARROW_LEFT_OBLIQUE.dds" colorize="fff"/>
2021-10-31 12:31:48 +01:00
</frame>
<frame id="frame-ui" z-index="1">
2022-02-27 17:49:56 +01:00
<quad pos="0 0" z-index="0" size="55 69" bgcolor="000" opacity="0.5"/>
2021-10-31 12:31:48 +01:00
<label pos="27.5 -5" z-index="2" size="55 7" text="Match Ranking" textfont="GameFontBlack" textprefix="$i$t" valign="center2" halign="center" textcolor="fff"/>
2022-02-27 17:49:56 +01:00
<frame pos="0 -11" z-index="2">
<frameinstance pos="0 0" hidden="1" modelid="player-model" id="player-1"/>
<frameinstance pos="0 -5" hidden="1" modelid="player-model" id="player-2"/>
<frameinstance pos="0 -10" hidden="1" modelid="player-model" id="player-3"/>
<frameinstance pos="0 -15" hidden="1" modelid="player-model" id="player-4"/>
<frameinstance pos="0 -20" hidden="1" modelid="player-model" id="player-5"/>
<frameinstance pos="0 -25" hidden="1" modelid="player-model" id="player-6"/>
<frameinstance pos="0 -30" hidden="1" modelid="player-model" id="player-7"/>
<frameinstance pos="0 -35" hidden="1" modelid="player-model" id="player-8"/>
<frameinstance pos="0 -40" hidden="1" modelid="player-model" id="player-9"/>
<quad id=sep-10 pos="0 -42" hidden=1 opacity="0.8" z-index="2" size="55 0.5" bgcolor="fff" />
<frameinstance pos="0 -45" hidden="1" modelid="player-model" id="player-10"/>
<frameinstance pos="0 -50" hidden="1" modelid="player-model" id="player-11"/>
<frameinstance pos="0 -55" hidden="1" modelid="player-model" id="player-12"/>
2021-10-31 12:31:48 +01:00
</frame>
</frame>
</frame>
2021-10-16 00:19:57 +02:00
</manialink>
""";
Layers::Create("MatchRanking_UI", MLText);
Layers::SetType("MatchRanking_UI", CUILayer::EUILayerType::Normal);
Layers::Attach("MatchRanking_UI");
}