summaryrefslogtreecommitdiffstats
path: root/includes/datas.php
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2012-03-19 19:18:29 -0700
committerPatrick Davison <snapwilliam@gmail.com>2012-03-19 19:18:29 -0700
commit0a36018c7dd4e45fb4e64b14ac67badc0011c43c (patch)
treec4e7964246d686730116b216f5389d411160dde1 /includes/datas.php
parent92e3e9165f7c7bcd2d95c0f09d42e55fc566f975 (diff)
downloadpathery-0a36018c7dd4e45fb4e64b14ac67badc0011c43c.tar.xz
Some achievements set, and notifications adjusted.
Diffstat (limited to 'includes/datas.php')
-rw-r--r--includes/datas.php391
1 files changed, 278 insertions, 113 deletions
diff --git a/includes/datas.php b/includes/datas.php
index f29f60e..19337e1 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -28,124 +28,154 @@ function topScores($mapid, $top = 5) {
";
$result = mysql_query($sql);
- if (mysql_num_rows($result) > 0) {
- $output .= "<table class='score'>";
- $output .= "<tr>";
- $output .= "<th>Rank</th>";
- $output .= "<th>Badge</th>";
- $output .= "<th>Name</th>";
- $output .= "<th>Moves</th>";
- $output .= "<th title='Time since map generation'>Time</th>";
- $output .= "</tr>";
- 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 .= "<tr style='background-color: #356;'>";
- else
- $output .= "<tr>";
-
- $cdate = date("g:i A", strtotime($cdate));
-
- $output .= "<td>$i</td>";
- $output .= "<td><div class='grid_td' style='width:35px; height:35px; ";
- $output .= "background:$wallColor";
- if ($wallEmblem != '')
- $output .= " url(images/marks/$wallEmblem)";
- $output .= ";'><div style='background-color:transparent;' class='grid_td_inner grid_td_rocks'></div></td>";
- $output .= "<td><span title='UserID: $userID'><a href='achievements?id=$userID' style='color:$displayColor'>$display</a></span></td>";
- $output .= "<td>$moves</td>";
- $output .= "<td title='Improved $cdate (EST)'>$diff</td>";
- $output .= "</tr>";
+ $output .= "<table class='score'>";
+ $output .= "<tr>";
+ $output .= "<th>Rank</th>";
+ $output .= "<th>Badge</th>";
+ $output .= "<th>Name</th>";
+ $output .= "<th>Moves</th>";
+ //$output .= "<th title='Time since map generation'>Time</th>";
+ $output .= "</tr>";
+ 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 = 'blank.png';
}
- $output .= "</table>";
+
+ $cdate = date("g:i A", strtotime($cdate));
+
+ if ($_SESSION['userID'] == $userID)
+ $output .= "<tr style='background-color: #356;' ";
+ else
+ $output .= "<tr ";
+ $output .= "title='Scored $cdate (EST)'>";
+
+
+ $output .= "<td>$i</td>
+<td>
+ <div class='grid_td' style='width:35px; height:35px; background:$wallColor url(images/marks/$wallEmblem);'>
+ <div style='background-color:transparent;' class='grid_td_inner grid_td_rocks'>
+ </div>
+ </div>
+</td>
+<td><span title='UserID: $userID'><a href='achievements?id=$userID' style='color:$displayColor'>$display</a></span></td>
+<td>$moves</td>\n";
+ //$output .= "<td >$diff</td>";
+ $output .= "</tr>";
}
+ $output .= "</table>";
return $output;
}
-
//Returns text refering to any notifications.
function getNotified($userID) {
+
+ $r = '';
+
$sql = "SELECT `ID`, `type`, `level`
FROM `achievements`
WHERE `notified` = false
AND userID = '$userID'
- LIMIT 1";
+ LIMIT 25";
- $result = mysql_query($sql);
- if (mysql_num_rows($result) !== 1)
+ $resultA = mysql_query($sql);
+ if (mysql_num_rows($resultA) <= 0)
return false;
// --------- We found an achievement they don't know they got!
- list($aID, $aType, $aLevel) = mysql_fetch_row($result);
+ while (list($aID, $aType, $aLevel) = mysql_fetch_row($resultA)) {
+
+ if ($r != '')
+ $r .= '<br /><hr />';
+
+ $aTypeNames[1] = "Path Career Level $aLevel!";
+ $aTypeNames[2] = "Mazes Career Level $aLevel!";
+ $aTypeNames[3] = "Maze Mastery Level $aLevel!";
+ $aTypeNames[4] = "Champion Level $aLevel!";
+ $aTypeNames[32] = 'Tutorial Complete!';
+
+ $aTypeCurrency[1] = "total moves mazed";
+ $aTypeCurrency[2] = "mazes played";
+ $aTypeCurrency[3] = "mazes with (tied) top score";
+ $aTypeCurrency[4] = "maze wins";
- $aTypeNames[1] = "Path Career Level $aLevel!";
- $aTypeNames[2] = "Mazes Career Level $aLevel!";
- $aTypeNames[32] = 'Tutorial Complete!';
-
- $aName = $aTypeNames[$aType];
-
- // --------- Any unlocks for this achievement?
- $sql = "SELECT `type`, `name`, `value`
- FROM `unlocks`
- WHERE `achievementID` = '$aID'";
- $result = mysql_query($sql);
- $unlocked = '';
- if (mysql_num_rows($result) >= 1) {
- $unlocked = "You've unlocked: ";
- while (list($uType, $uName, $uValue) = mysql_fetch_row($result)) {
- switch ($uType) {
- case 1:
- $unlocked .= "$uName Wall Color!";
- $unlocked .= "<table><tr><td onclick='changeWallColor(\"$uValue\")' style='background-color:$uValue;' class='grid_td_rocks'></td></tr></table>";
- break;
- case 2:
- $unlocked .= "$uName Emblem!";
- $unlocked .= "<div class='grid_td_rocks' title='' onClick='emblemclick(this,\"$uValue\", \"0\")' style='background: #999 url(../images/marks/$uValue);' >";
- $unlocked .= "<div class='grid_inner grid_td_walls'></div></div>";
- break;
- case 3:
- $unlocked .= "<br /><span style='color:$uValue;'>$uName Username color!</span><br />";
- break;
+ $aName = $aTypeNames[$aType];
+ $currency = $aTypeCurrency[$aType];
+
+ // --------- Any unlocks for this achievement?
+ $sql = "SELECT `type`, `name`, `value`
+ FROM `unlocks`
+ WHERE `achievementID` = '$aID'";
+ $result = mysql_query($sql);
+ $unlocked = '';
+ if (mysql_num_rows($result) >= 1) {
+ $unlocked = "You've unlocked: ";
+ while (list($uType, $uName, $uValue) = mysql_fetch_row($result)) {
+ switch ($uType) {
+ case 1:
+ $unlocked .= "$uName Wall Color!";
+ $unlocked .= "<table><tr><td onclick='changeWallColor(\"$uValue\")' style='background-color:$uValue;' class='grid_td_rocks'></td></tr></table>";
+ break;
+ case 2:
+ $unlocked .= "$uName Emblem!";
+ $unlocked .= "<div class='grid_td_rocks' title='' onClick='emblemclick(this,\"$uValue\", \"0\")' style='background: #999 url(../images/marks/$uValue);' >";
+ $unlocked .= "<div class='grid_inner grid_td_walls'></div></div>";
+ break;
+ case 3:
+ $unlocked .= "<br /><span style='color:$uValue;'>$uName Username color!</span><br />";
+ break;
+ }
}
}
+ // ---------- Prepare response
+
+ $r .= "<strong>$aName</strong>";
+ if ($unlocked !== '') {
+ $r .= "<center>$unlocked";
+ //$r .= "<div style='width:300px;height:75px;overflow:auto;'>";
+ $r .= "</center>";
+ }
+ $aAry = getAchievementsArray($aType);
+ $nextLevelRequired = $aAry[($aLevel + 1)][0];
+ $currentLevelRequired = $aAry[($aLevel)][0];
+
+ if ($currency) {
+ $currentLevelRequired = number_format($currentLevelRequired);
+ $r .= "You have $currentLevelRequired $currency <br />";
+ }
+ if ($nextLevelRequired >= 1) {
+ $nextLevelRequired = number_format($nextLevelRequired);
+ $r .= "Next level at $nextLevelRequired <br />";
+ }
+
+
+
+
+ // Item ID List
+ $aIDList[] = "'$aID'";
}
- // ---------- Prepare response
+ $r .= "<br /><a href='achievements?id=$userID'>Go select unlocks now</a>";
- $r = "<strong>$aName</strong>";
- if ($unlocked !== '') {
- $r .= "<center>$unlocked";
- $r .= "<a href='achievements'>";
- $r .= "Go select this now</a>";
- $r .= "</center>";
- }
- $aAry = getAchievementsArray($aType);
- $nextLevelRequired = $aAry[($aLevel + 1)][0];
- if ($nextLevelRequired >= 1) {
- $nextLevelRequired = number_format($nextLevelRequired);
- $r .= "Next level at $nextLevelRequired <br />"; // unavailable data?
- }
+ // ---------- Mark that we have notified the user
+ $aIDListStr = implode(',', $aIDList);
+ $sql = "UPDATE `achievements`
+ SET `notified` = 1
+ WHERE `ID` IN ($aIDListStr)";
+ mysql_query($sql);
- // ---------- 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);
+// !! DEPRECIATED
function applyCareerPathAchievements($userID) {
$sql = "SELECT
SUM(solutions.moves) as totalMoves
@@ -192,13 +222,14 @@ function applyCareerPathAchievements($userID) {
// ------- User gets unlock. (unlocks plural is possible here)
$sql = "INSERT INTO `unlocks`
- (`userID`, `achievementID`, `type`, `subType`, `name`, `value`)
+ (`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
VALUES ('$userID', '$aID', '$unlockType', NULL, '$unlockName', '$unlockValue')";
mysql_query($sql);
return true;
}
//Almost a duplicate of applyCareerPathAchievements
+// !! DEPRECIATED
function applyCareerMazesAchievements($userID) {
$sql = "SELECT
COUNT(*) as totalSolutions
@@ -245,7 +276,7 @@ function applyCareerMazesAchievements($userID) {
// ------- User gets unlock. (unlocks plural is possible here)
$sql = "INSERT INTO `unlocks`
- (`userID`, `achievementID`, `type`, `subType`, `name`, `value`)
+ (`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
VALUES ('$userID', '$aID', '$unlockType', NULL, '$unlockName', '$unlockValue')";
mysql_query($sql);
return true;
@@ -280,20 +311,114 @@ function applyChallengeAchievements($userID, $challengeID, $mapID, $solution, $m
// ------- 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')";
+ (`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
+ VALUES ('$userID', '$aID', '1', 0, 'Blue', '#4444ff')";
mysql_query($sql);
return true;
}
}
}
+function applyAchievements($userID, $aType) {
+
+ $amount = getAchievementCurrency($userID, $aType);
+
+ $aLevel = getAchievementLevel($userID, $aType);
+
+ $aArray = getAchievementsArray($aType);
+
+ //Is there a next level for this?
+ $aNextLevel = $aLevel + 1;
+ if (!isset($aArray[$aNextLevel]))
+ return false;
+ list($required, $unlockType, $unlockValue, $unlockName, $unlockSubtype) = $aArray[$aNextLevel];
+ if ($amount < $required)
+ return false;
+
+ $sql = "INSERT INTO `achievements`
+ (`userID`, `type`, `level`)
+ VALUES ('$userID', $aType, '$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', '$unlockSubtype', '$unlockName', '$unlockValue')";
+ mysql_query($sql);
+ return true;
+
+}
+
+function getAchievementCurrency($userID, $aType) {
+
+// 1, Total Moves "Path Career" //Backdated
+// 2, Total Solutions (Total maps played) "Mazes Career" //Backdated
+// 3, Tie Top-Score on a map "Maze Mastery" //Tracked (no backdate)
+// 4, Rank#1 Win Top-Score on a map "Wins" //Tracked
+ $r = 0;
+ $sql = '';
+ switch ($aType) {
+ case 1:
+ $sql = "SELECT
+ SUM(solutions.moves) as t
+ FROM `solutions`
+ WHERE userID = '$userID'";
+ break;
+ case 2:
+ $sql = "SELECT
+ COUNT(*) as t
+ FROM `solutions`
+ WHERE userID = '$userID'";
+ break;
+ case 3:
+ $sql = "SELECT
+ SUM(`value`) as t
+ FROM `statistics`
+ WHERE `userID` = '$userID'
+ AND `type` IN (1, 2, 3, 4)";
+ break;
+ case 4:
+ $sql = "SELECT
+ SUM(`value`) as t
+ FROM `statistics`
+ WHERE `userID` = '$userID'
+ AND `type` IN (32, 33, 34, 35)";
+ break;
+ }
+ if ($sql == '')
+ return false;
+ $result = mysql_query($sql);
+ if (mysql_num_rows($result) == 1)
+ list($r) = mysql_fetch_row($result);
+
+ return $r;
+}
+
+function getAchievementLevel($userID, $aType) {
+ // ------- Select the highest level they've achieved.
+ $r = 0;
+ $sql = "SELECT `level`
+ FROM `achievements`
+ WHERE `userID` = '$userID'
+ AND `type` = '$aType'
+ ORDER BY `level` DESC
+ LIMIT 1";
+ $result = mysql_query($sql);
+ if (mysql_num_rows($result) == 1)
+ list($r) = mysql_fetch_row($result);
+ return $r;
+}
function getAchievementsArray($type) {
if ($type == 1)
return getCareerPathArray();
if ($type == 2)
return getCareerMazesArray();
+ if ($type == 3)
+ return getMazeMasteryArray();
+ if ($type == 4)
+ return getWinsArray();
//Tutorial
if ($type == 32) {
$r[1] = array(1, 1, '#4444ff', 'Blue');
@@ -305,41 +430,81 @@ function getAchievementsArray($type) {
//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');
+ // Note that the description is followed by " wall color"
+ $cp[1] = array(100, 1, '#229922', 'Green');
+ $cp[2] = array(1000, 1, '#9922ff', 'Purple');
+ $cp[3] = array(5000, 2, 'CircleSmall_W.png', 'Light Small Circle', 0);
+ $cp[4] = array(10000, 2, 'DiamondSmall_B.png', 'Dark Small Diamond', 0);
+ $cp[5] = array(20000, 3, '#a9b1f6', 'Steel Blue');
+ $cp[6] = array(32000, 2, 'DiagonalCover_W.png', 'Light Diagonal Cover', 0);
+ $cp[7] = array(50000, 2, 'DiamondLargeDonut_B_I.png', 'Dark Annulated Diamond', 0);
+ $cp[8] = array(75000, 3, '#ffffaa', 'Yellow');
+ $cp[9] = array(100000, 3, '#ffbb77', 'Orange');
+ $cp[10] = array(130000, 2, 'OffsetStripesVertical_W.png', 'Light Vertical Stripes', 0);
+ $cp[11] = array(165000, 2, 'CircleSmall_B.png', 'Dark Small Circle', 0);
+ $cp[12] = array(200000, 3, '#ee77ff', 'Purple');
+ $cp[13] = array(250000, 1, '#ffff22', 'Yellow', 1);
+ $cp[14] = array(300000, 2, 'DiagonalCover_B_I.png', 'Inverted Dark Diagonal Cover', 0);
+ $cp[15] = array(350000, 1, '#333377', 'Navy Blue', 0);
+ $cp[16] = array(400000, 2, 'RacingStripes_W.png', 'Light Racing Stripes', 0);
+
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[1] = array(5, 1, '#eeeeee', 'Silver', 1);
+ $cm[2] = array(15, 1, '#ff9922', 'Orange', 1);
+ $cm[3] = array(30, 2, 'DiamondLargeDonut_W.png', 'Light Annulated Diamond', 0);
$cm[4] = array(50, 1, '#aaaa22', 'Chartreuse');
- $cm[5] = array(75, 1, '#ff9922', 'Orange');
- $cm[6] = array(100, 1, '#cc22aa', 'Magenta');
-
+ $cm[5] = array(85, 2, 'CrossXL_W.png', 'Light Large Present', 0);
+ $cm[6] = array(150, 1, '#cc22aa', 'Magenta', 0);
+ $cm[7] = array(250, 1, '#ff3344', 'Red');
+ $cm[8] = array(375, 1, '#ffdd88', 'Gold');
+ $cm[9] = array(550, 2, 'ConvexCover_W.png', 'Light Dome Cover', 0);
+ $cm[10] = array(750, 2, 'OffsetStripesVertical_B.png', 'Dark Vertical Stripes', 0);
+ $cm[11] = array(1000, 3, '#ff95b0', 'Pink');
+ $cm[12] = array(1400, 1, '#ff95b0', 'Pink', 1);
+ $cm[13] = array(2000, 2, 'StarsR_W.png', 'Bright Stars', 0);
+ $cm[14] = array(2750, 2, 'Stars1_B.png', 'Dark Single Star', 0);
+ $cm[15] = array(3500, 2, 'CircleSmall_B_I.png', 'Inverted Dark Small Circle', 0);
+
return $cm;
}
+//TYPE 3
+function getMazeMasteryArray() {
+ //$cp[0] = array(requiredmazestied, type, 'value', 'name');
+ $r[1] = array(1, 2, 'OffsetStripesDiagonal_W.png', 'Light Diagonal Stripes', 0);
+ $r[2] = array(5, 2, 'OffsetStripesVertical_B_I.png', 'Inverted Dark Vertical Stripes', 0);
+ $r[3] = array(15, 2, 'DiagonalCover_W_I.png', 'Inverted Light Diagonal Cover', 0);
+ $r[4] = array(30, 3, '#aafcbb', 'Green');
+ $r[5] = array(50, 2, 'DiamondLarge_W.png', 'Light Large Diamond', 0);
+ $r[6] = array(75, 2, 'CrossXL_B.png', 'Dark Large Present', 0);
+ $r[7] = array(100, 2, 'CircleLargeDonut_W.png', 'Light Annulated Circle', 0);
+ $r[8] = array(150, 2, 'CrossXL_W_I.png', 'Inverted Bright Large Present', 0);
+ return $r;
+}
+//TYPE 4
+function getWinsArray() {
+ //$cp[0] = array(requiredmazewins, type, 'value', 'name');
+ $r[1] = array(1, 2, 'DiagonalCover_B.png', 'Light Diagnol Cover', 0);
+ $r[2] = array(5, 1, '#22aaaa', 'Teal');
+ $r[3] = array(15, 2, 'OffsetStripesDiagonal_B.png', 'Dark Diagonal Stripes', 0);
+ $r[4] = array(30, 2, 'DiamondLargeDonut_W_I.png', 'Inverted Light Annulated Diamond', 0);
+ $r[5] = array(50, 2, 'StarsR_B.png', 'Dark Stars', 0);
+ $r[6] = array(75, 2, 'CrossXL_B_I.png', 'Inverted Dark Large Present', 0);
+ $r[7] = array(75, 2, 'CircleSmall_W_I.png', 'Inverted Bright Small Circle', 0);
-function apply() {
-
-
+ return $r;
}
-
+//Used to track statistics on who wins or ties maps at the end of a day.
function trackMOTDstats($mapType) {
// Our rather massive query to get the data we need.
$sql = "SELECT