0) { $output .= ""; $output .= ""; $output .= ""; $output .= ""; $output .= ""; $output .= ""; $output .= ""; $output .= ""; while (list($diff, $display, $moves, $userID, $displayColor, $wallColor, $wallEmblem, $cdate) = mysql_fetch_row($result)) { $i++; if (!isset($displayColor)) { $sql = "INSERT INTO `userData` (`userID`, `displayColor`, `wallColor`) VALUES ('$userID', '#cccccc', '#666666')"; mysql_query($sql); $displayColor = '#cccccc'; $wallColor = '#666666'; $wallEmblem = ''; } if ($_SESSION['userID'] == $userID) $output .= ""; else $output .= ""; $cdate = date("g:i A", strtotime($cdate)); $output .= ""; $output .= "
RankBadgeNameMovesTime
$i
= 1) { $unlocked = "You've unlocked: "; while (list($uType, $uName, $uValue) = mysql_fetch_row($result)) { switch ($uType) { case 1: $unlocked .= "$uName Wall Color!"; $unlocked .= "
"; break; case 2: $unlocked .= "$uName Emblem!"; $unlocked .= "
"; $unlocked .= "
"; break; case 3: $unlocked .= "
$uName Username color!
"; break; } } } // ---------- Prepare response $r = "$aName"; if ($unlocked !== '') { $r .= "
$unlocked"; $r .= ""; $r .= "Go select this now"; $r .= "
"; } $aAry = getAchievementsArray($aType); $nextLevelRequired = $aAry[($aLevel + 1)][0]; if ($nextLevelRequired >= 1) { $nextLevelRequired = number_format($nextLevelRequired); $r .= "Next level at $nextLevelRequired
"; // unavailable data? } // ---------- Mark that we have notified the user $sql = "UPDATE `achievements` SET `notified` = 1 WHERE `ID` = '$aID'"; mysql_query($sql); return $r; // ---------- Done! } //Returns true when an achievement is applied. // Usage example: applyCareerAchievement($userID); function applyCareerPathAchievements($userID) { $sql = "SELECT SUM(solutions.moves) as totalMoves FROM `solutions` WHERE userID = '$userID'"; $result = mysql_query($sql); // --------- User hasn't played yet. if (mysql_num_rows($result) != 1) return false; list($uTotalMoves) = mysql_fetch_row($result); // ------- Select the highest level they've achieved. $sql = "SELECT `level` FROM `achievements` WHERE `userID` = '$userID' AND `type` = 1 ORDER BY `level` DESC LIMIT 1"; $result = mysql_query($sql); // --------- No achievements yet? if (mysql_num_rows($result) == 1) list($aLevel) = mysql_fetch_row($result); else $aLevel = 0; $cp = getCareerPathArray(); //Is there a next level for this? $aNextLevel = $aLevel + 1; if (!isset($cp[$aNextLevel])) return false; list($required, $unlockType, $unlockValue, $unlockName) = $cp[$aNextLevel]; if ($uTotalMoves < $required) return false; $sql = "INSERT INTO `achievements` (`userID`, `type`, `level`) VALUES ('$userID', 1, '$aNextLevel')"; mysql_query($sql); $aID = mysql_insert_id(); // ------- User gets unlock. (unlocks plural is possible here) $sql = "INSERT INTO `unlocks` (`userID`, `achievementID`, `type`, `subType`, `name`, `value`) VALUES ('$userID', '$aID', '$unlockType', NULL, '$unlockName', '$unlockValue')"; mysql_query($sql); return true; } //Almost a duplicate of applyCareerPathAchievements function applyCareerMazesAchievements($userID) { $sql = "SELECT COUNT(*) as totalSolutions FROM `solutions` WHERE userID = '$userID'"; $result = mysql_query($sql); // --------- User hasn't played yet. if (mysql_num_rows($result) != 1) return false; list($uTotalSolutions) = mysql_fetch_row($result); // ------- Select the highest level they've achieved. $sql = "SELECT `level` FROM `achievements` WHERE `userID` = '$userID' AND `type` = 2 ORDER BY `level` DESC LIMIT 1"; $result = mysql_query($sql); // --------- No achievements yet? if (mysql_num_rows($result) == 1) list($aLevel) = mysql_fetch_row($result); else $aLevel = 0; $cm = getCareerMazesArray(); //Is there a next level for this? $aNextLevel = $aLevel + 1; if (!isset($cm[$aNextLevel])) return false; list($required, $unlockType, $unlockValue, $unlockName) = $cm[$aNextLevel]; if ($uTotalSolutions < $required) return false; $sql = "INSERT INTO `achievements` (`userID`, `type`, `level`) VALUES ('$userID', 2, '$aNextLevel')"; mysql_query($sql); $aID = mysql_insert_id(); // ------- User gets unlock. (unlocks plural is possible here) $sql = "INSERT INTO `unlocks` (`userID`, `achievementID`, `type`, `subType`, `name`, `value`) VALUES ('$userID', '$aID', '$unlockType', NULL, '$unlockName', '$unlockValue')"; mysql_query($sql); return true; } //Challenges including the Tutorial. function applyChallengeAchievements($userID, $challengeID, $mapID, $solution, $moves) { if ($challengeID == '1') { //echo 'challengeID'.$mapID; //echo 'moves'.$moves; if ($moves == 75 AND $mapID == 5) { //echo 'true story'; // -------- Completed the tutorial! //have they already completed he tutorial? $sql = "SELECT `level` FROM `achievements` WHERE `userID` = '$userID' AND `type` = 32 ORDER BY `level` DESC LIMIT 1"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1) return false; // -------- This is the first time they've completed the tutorial! $sql = "INSERT INTO `achievements` (`userID`, `type`, `level`) VALUES ('$userID', 32, '1')"; mysql_query($sql); $aID = mysql_insert_id(); // ------- User gets unlock. (unlocks plural is possible here) $sql = "INSERT INTO `unlocks` (`userID`, `achievementID`, `type`, `subType`, `name`, `value`) VALUES ('$userID', '$aID', '1', NULL, 'Blue', '#4444ff')"; mysql_query($sql); return true; } } } function getAchievementsArray($type) { if ($type == 1) return getCareerPathArray(); if ($type == 2) return getCareerMazesArray(); //Tutorial if ($type == 32) { $r[1] = array(1, 1, '#4444ff', 'Blue'); return $r; } return array(); } //TYPE 1 function getCareerPathArray() { //$cp[0] = array(requiredmoves, type, 'value', 'name'); $cp[1] = array(100, 1, '#229922', 'Green'); $cp[2] = array(400, 1, '#9922ff', 'Purple'); $cp[3] = array(900, 2,'CircleSmall.png','Small White Circle'); $cp[4] = array(2000, 2,'StarsR_W.png','Starry White'); $cp[5] = array(3500, 2,'StarsR_B.png','Starry Black'); $cp[6] = array(5000, 1, '#a9b1f6', 'Steel Blue'); $cp[7] = array(7500, 3, '#aafcbb', 'Green'); $cp[8] = array(10000, 3, '#ffffaa', 'Yellow'); $cp[8] = array(13000, 3, '#ffbb77', 'Orange'); return $cp; } //TYPE 2 function getCareerMazesArray() { //$cp[0] = array(requiredmazes, type, 'value', 'name'); $cm[1] = array(1, 1, '#eeeeee', 'Silver'); $cm[2] = array(5, 1, '#22aaaa', 'Teal'); $cm[3] = array(25, 1, '#ff3344', 'Red'); $cm[4] = array(50, 1, '#aaaa22', 'Chartreuse'); $cm[5] = array(75, 1, '#ff9922', 'Orange'); $cm[6] = array(100, 1, '#cc22aa', 'Magenta'); return $cm; } function apply() { } function trackMOTDstats($mapType) { // Our rather massive query to get the data we need. $sql = "SELECT users.ID as userID, SUM(solutions.moves) as Moves, timediff(MAX(dateModified), maps.dateCreated) as Timetaken FROM `maps` JOIN `solutions` ON maps.ID = solutions.mapID JOIN `users` ON solutions.userID = users.ID JOIN `mapOfTheDay` ON maps.ID = mapOfTheDay.mapID WHERE DATE_ADD(CURDATE(), INTERVAL -1 DAY) = DATE_FORMAT(solutions.dateModified,'%Y-%m-%d') AND DATE_ADD(CURDATE(), INTERVAL -1 DAY) = DATE_FORMAT(maps.dateCreated,'%Y-%m-%d') AND `mapType` = '$mapType' GROUP BY solutions.userID ORDER BY Moves DESC, MAX(dateModified) ASC "; $mainResult = mysql_query($sql); if ($mainResult) { $first = true; while (list($userID, $uMoves, $uTimeTaken) = mysql_fetch_row($mainResult)) { //echo "$first : userID: $userID uMoves: $uMoves uTimeTaken: $uTimeTaken mapType: $mapType
"; do { //If it's the rank #1 user, we need to repeat to also award him the tie stat. $repeatThis = false; $sType = $mapType; if ($first) { $bestMoves = $uMoves; $sType = 31 + $mapType; $repeatThis = true; } if ($uMoves == $bestMoves) { $sql = "SELECT `ID` FROM `statistics` WHERE `userID` = '$userID' AND `type` = '$sType'"; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { $sql = "INSERT INTO `statistics` (`userID`, `type`, `value`) VALUES ('$userID', '$sType', 1)"; $result = mysql_query($sql); if (!$result) return false; } else { $sql = "UPDATE `statistics` SET `value` = `value` + 1 WHERE `userID` = '$userID' AND `type` = '$sType'"; $result = mysql_query($sql); if (!$result) return false; } } else { break 2; } $first = false; } while ($repeatThis); } } return true; } ?>