Skip to content

Commit

Permalink
Little refactor and changed how completion time is calculated
Browse files Browse the repository at this point in the history
- Using the moment the player clicked on "start quest button" for instance could lead to the player letting the window open until being close to a token. (Race)StartTime taken instead.
- Refactored the times formatting for the board a bit.
- URLEncoding Username.
  • Loading branch information
Harest committed Nov 24, 2019
1 parent fb256fc commit 9ab9c61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
14 changes: 2 additions & 12 deletions GetBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,8 @@
$qh = null;
// Format the players' times
foreach ($players as $key => $player) {
$tmpTime = gameTimeToDateInterval($player["firstTime"]);
if ($tmpTime->h >= 1) {
$players[$key]["firstTime"] = "more than 1 hour";
} else {
$players[$key]["firstTime"] = $tmpTime->format("%I:%S.").substr($tmpTime->f, 0, 3);
}
$tmpTime = gameTimeToDateInterval($player["bestTime"]);
if ($tmpTime->h >= 1) {
$players[$key]["bestTime"] = "more than 1 hour";
} else {
$players[$key]["bestTime"] = $tmpTime->format("%I:%S.").substr($tmpTime->f, 0, 3);
}
$players[$key]["firstTime"] = gameTimeFormatted($player["firstTime"]);
$players[$key]["bestTime"] = gameTimeFormatted($player["bestTime"]);
}
// Return the results
$playersList = array("Players" => $players,
Expand Down
15 changes: 5 additions & 10 deletions Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,12 @@
declare persistent Text[][Integer] Pe_LocalTokensIds for Map;
declare persistent Text[][Integer] Pe_PlayerPos for Map;
declare persistent Integer[Integer] P_PlayerRaceStartTime for Map;
declare persistent Integer[Integer] P_PlayerQuestStartTime for Map;
declare persistent Text[Integer] P_QuestMapUid for Map;
Per_LocalTokensCollected[G_QuestId] = [];
Pe_LocalTokensIds[G_QuestId] = [];
Pe_PlayerPos[G_QuestId] = [];
P_PlayerRaceStartTime[G_QuestId] = 0;
P_PlayerQuestStartTime[G_QuestId] = 0;
P_QuestMapUid[G_QuestId] = "";
}
Expand All @@ -208,9 +206,9 @@
if (nbPlayers >= 1) {
declare Text QuestTitleToDisplay = TextLib::Replace(QuestTitleList, "[count]", nbPlayers ^ " " ^ PluralPlayers);
Message.SetText(Message.Value ^ QuestTitleToDisplay ^ "\n");
if (CurPage == 1) Message.SetText(Message.Value ^ "$nNote: This list is cached 10 minutes, ordered by first completion date.$z\n");
if (CurPage == 1) Message.SetText(Message.Value ^ "$n$fffNote: This list is cached 10 minutes, ordered by first completion date.$z\n");
} else {
Message.SetText(Message.Value ^ QuestTitleEmptyList ^ "\n$nNote: This list is cached 10 minutes.$z");
Message.SetText(Message.Value ^ QuestTitleEmptyList ^ "\n$n$fffNote: This list is cached 10 minutes.$z");
}
for(i, StartPos, MaxLimit)
{
Expand Down Expand Up @@ -265,7 +263,6 @@
declare persistent Text[][Integer] Pe_LocalTokensIds for Map;
declare persistent Text[][Integer] Pe_PlayerPos for Map;
declare persistent Integer[Integer] P_PlayerRaceStartTime for Map;
declare persistent Integer[Integer] P_PlayerQuestStartTime for Map;
declare persistent Text[Integer] P_QuestMapUid for Map;
declare persistent Boolean DebugMode for Map;
G_QuestId = '.htmlentities($QuestId, ENT_XML1).';
Expand Down Expand Up @@ -351,7 +348,6 @@
if (P_QuestMapUid[G_QuestId] == "") P_QuestMapUid[G_QuestId] = "'.htmlentities($QuestInfo["map_uid"], ENT_XML1).'";
if (DebugMode) log("MapUid for quest " ^ TextLib::ToText(G_QuestId) ^ " set to: " ^ P_QuestMapUid[G_QuestId]);
P_PlayerRaceStartTime[G_QuestId] = GUIPlayer.'.$startTimeVar.';
P_PlayerQuestStartTime[G_QuestId] = GameTime;
// Check if the MapUid matches
if (P_QuestMapUid[G_QuestId] != Map.MapInfo.MapUid) {
Expand Down Expand Up @@ -388,7 +384,7 @@
}
else
{
Message.SetText(QuestFullDesc ^ "\n\nHave fun!\n\n$nNote: You need to complete the quest in the same race from where you started it. If you restart (e.g. by pressing del), you\'ll need to start the quest again. Several quests can be done in the same race.$z");
Message.SetText(QuestFullDesc ^ "\n\n$fffHave fun!\n\n$nNote: You need to complete the quest in the same race from where you started it. If you restart (e.g. by pressing del), you\'ll need to start the quest again. Several quests can be done in the same race.$z");
}
// Log all tokens for quest if debug activated
Expand Down Expand Up @@ -446,7 +442,6 @@
if (P_QuestMapUid[G_QuestId] == "") P_QuestMapUid[G_QuestId] = "'.htmlentities($QuestInfo["map_uid"], ENT_XML1).'";
if (DebugMode) log("MapUid for quest " ^ TextLib::ToText(G_QuestId) ^ " set to: " ^ P_QuestMapUid[G_QuestId]);
P_PlayerRaceStartTime[G_QuestId] = GUIPlayer.'.$startTimeVar.';
P_PlayerQuestStartTime[G_QuestId] = GameTime;
// Check if the MapUid matches
if (P_QuestMapUid[G_QuestId] != Map.MapInfo.MapUid) {
Expand Down Expand Up @@ -514,11 +509,11 @@
declare Text Pe_PlayerPosString = LogMissingTokens();
// Get quest completion time
declare Integer QuestCompletionTime = GameTime - P_PlayerQuestStartTime[G_QuestId];
declare Integer QuestCompletionTime = GameTime - P_PlayerRaceStartTime[G_QuestId];
declare CHttpRequest request;
if (DebugMode) log("Quest " ^ TextLib::ToText(G_QuestId) ^ " completed. Processing...");
request = Http.CreateGet("'.$urlToRequest.'UpdateQuest.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&Login=" ^ LocalUser.Login ^ "&UserName=" ^ LocalUser.Name ^ "&Positions=" ^ TextLib::URLEncode(Pe_PlayerPosString) ^ "&MapUid=" ^ P_QuestMapUid[G_QuestId] ^ "&Time=" ^ TextLib::ToText(QuestCompletionTime) ^ "&" ^ Now);
request = Http.CreateGet("'.$urlToRequest.'UpdateQuest.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&Login=" ^ LocalUser.Login ^ "&UserName=" ^ TextLib::URLEncode(LocalUser.Name) ^ "&Positions=" ^ TextLib::URLEncode(Pe_PlayerPosString) ^ "&MapUid=" ^ P_QuestMapUid[G_QuestId] ^ "&Time=" ^ TextLib::ToText(QuestCompletionTime) ^ "&" ^ Now);
clearPersistentData();
wait(request.IsCompleted);
if (DebugMode) {
Expand Down
2 changes: 1 addition & 1 deletion UpdateQuest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Get vars
$Login = filter_input(INPUT_GET, 'Login');
$QuestId = intval(filter_input(INPUT_GET, 'QuestId'));
$UserName = filter_input(INPUT_GET, 'UserName');
$UserName = urldecode(filter_input(INPUT_GET, 'UserName'));
$Positions = urldecode(filter_input(INPUT_GET, 'Positions'));
$MapUid = filter_input(INPUT_GET, 'MapUid');
$Time = intval(filter_input(INPUT_GET, 'Time'));
Expand Down
10 changes: 10 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ function gameTimeToDateInterval($time) {
$dateInterval->s = floor($seconds % 60);
$dateInterval->f = $time - ($seconds * 1000);
return $dateInterval;
}

// Return a GameTime DateInterval formatted as MM:SS.ms
function gameTimeFormatted($time) {
$tmpTime = gameTimeToDateInterval($time);
if ($tmpTime->h >= 1) {
return "more than 1 hour";
} else {
return $tmpTime->format("%I:%S.").$tmpTime->f;
}
}

0 comments on commit 9ab9c61

Please sign in to comment.