diff --git a/artifactplace.php b/artifactplace.php new file mode 100644 index 0000000..5c1c0b1 --- /dev/null +++ b/artifactplace.php @@ -0,0 +1,99 @@ +has('inventory', ["AND" => ['itemuuid' => $itemuuid, 'playeruuid' => $_SESSION['uuid']]])) { + sendError(INVALID_ITEMID . " 1.5", true); +} + +$item = $database->select( + 'items', [ + '[>]inventory' => ['itemid' => 'itemid'], + '[>]itemclasses' => ['classid', 'classid'] + ], [ + 'inventory.itemuuid', + 'inventory.itemid', + 'inventory.itemjson', + 'items.itemname', + 'items.itemcode', + 'itemclasses.classid', + 'itemclasses.classname' + ], [ + "AND" => [ + 'itemuuid' => $itemuuid, + 'playeruuid' => $_SESSION['uuid'] + ] + ] + )[0]; + +$place = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife'], ['locationid' => $VARS['locationid']])[0]; +$user = $database->select('players', ['level', 'teamid', 'energy', 'maxenergy', 'latitude', 'longitude'], ['uuid' => $_SESSION['uuid']])[0]; + +// This (probably) shouldn't happen in normal play +if ($place['teamid'] != $user['teamid']) { + sendError(PLACE_OWNED_BY_WRONG_TEAM, true); +} + +$userdrain = 2 * floor($user['level']); + +// Calculate resulting user HP +$userhp = $user['energy'] - $userdrain; +// Check if action possible +if ($userhp < 0) { + sendError(PLAYER_NO_LIFE_LEFT, true); +} + + +$item['itemcode'] = json_decode($item['itemcode'], true); +if ($item['itemjson'] == "[]" || $item['itemjson'] == "") { + $itemusesjson = json_encode(['uses' => $item['itemcode']['uses']]); + $database->update('inventory', ['itemjson' => $itemusesjson], ['itemuuid' => $itemuuid]); +} +$itemusedata = json_decode($database->select('inventory', ['itemjson'], ['itemuuid' => $itemuuid])[0]['itemjson'], true); + +switch ($item['classname']) { + case "artifact": { + if ($itemusedata['uses'] <= 1) { + $database->delete('inventory', ["AND" => ['itemuuid' => $itemuuid, 'playeruuid' => $_SESSION['uuid']]]); + } else if ($itemusedata['uses'] > 1) { + $itemusedata['uses'] -= 1; + $database->update('inventory', ['itemjson' => json_encode($itemusedata)], ['itemuuid' => $itemuuid]); + } + break; + } + default: + sendError(INVALID_ITEMID . " 2", true); +} + +// Update the user's health and level +$exp = pow(pow(floor($user['level']) + 1, 2), -1.2); +$userlevel = $user['level'] + $exp; +// If the new level is a whole int bigger than the current +$dolevelup = false; +if (floor($userlevel) > floor($user['level'])) { + $dolevelup = true; + $newmaxhp = floor($userlevel) * 100; + $database->update('players', ['energy' => $newmaxhp, 'maxenergy' => $newmaxhp, 'level' => $userlevel], ['uuid' => $_SESSION['uuid']]); +} else { + $database->update('players', ['energy' => $userhp, 'level' => $userlevel], ['uuid' => $_SESSION['uuid']]); +} + +$placelife = $place['currentlife'] + $item['itemcode']['amount']; + +$placemax = $place['maxlife'] + $item['itemcode']['amount']; + +// Update the place +$database->update('locations', ['currentlife' => $placelife, 'maxlife' => $placemax, 'owneruuid' => $_SESSION['uuid'], 'teamid' => $user['teamid']], ['locationid' => $VARS['locationid']]); + +echo json_encode(["status" => "OK", "message" => ($dolevelup ? PLAYER_LEVEL_UP : PLACE_ARTIFACT_ADDED), "levelup" => ($dolevelup ? true : false)]); diff --git a/database.mwb b/database.mwb index ddc47e0..990f950 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/inventory.php b/inventory.php index 47dafde..234c867 100644 --- a/inventory.php +++ b/inventory.php @@ -4,8 +4,9 @@ require 'required.php'; require 'onlyloggedin.php'; -if (is_empty($VARS['user'])) { - sendError("Missing data.", true); +$where = ['inventory.playeruuid' => $_SESSION['uuid']]; +if (!is_empty($VARS['classname'])) { + $where = ["AND" => ['inventory.playeruuid' => $_SESSION['uuid'], 'itemclasses.classname' => $VARS['classname']]]; } $inv = $database->select( @@ -21,9 +22,13 @@ $inv = $database->select( 'items.itemcode', 'itemclasses.classid', 'itemclasses.classname' - ], ['inventory.playeruuid' => $_SESSION['uuid']] + ], $where ); +if ($inv == FALSE) { + $inv = []; +} + $out['status'] = 'OK'; $out['items'] = $inv; echo json_encode($out); diff --git a/lang/en_us.php b/lang/en_us.php index 6a33125..983ee60 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -4,7 +4,7 @@ * Strings for i18n. */ /* - * attackplace.php, claimplace.php, refillplace.php + * attackplace.php, claimplace.php, refillplace.php, artifactplace.php */ define("PLACE_ID_NOT_SENT", "No target!"); define("PLACE_OWNED_BY_SAME_TEAM", "Cannot attack!"); @@ -16,6 +16,7 @@ define("PLACE_OWNED_BY_WRONG_TEAM", "Wrong team!"); define("PLACE_OWNED_BY_PLAYER_TEAM", "Don't attack your own kind!"); define("PLACE_HEALTH_IS_FULL", "Full!"); define("PLACE_HEALTH_REFILLED", "Refilled!"); +define("PLACE_ARTIFACT_ADDED", "Added!"); /* * buyitem.php diff --git a/login.php b/login.php index 337c84e..a12b8ec 100644 --- a/login.php +++ b/login.php @@ -15,7 +15,7 @@ $VARS['user'] = strtolower(str_replace(" ", "", $VARS['user'])); /* Insert code to check login here */ /* ------------------------------- */ -$loginok = file_get_contents("https://sso.netsyms.com/api/simplehashauth.php?get=1&user=" . urlencode($VARS['user']) . "&pass=" . hash('sha1', $VARS['pass'])); +$loginok = file_get_contents("https://sso.netsyms.com/api/simpleauth.php?get=1&user=" . urlencode($VARS['user']) . "&pass=" . $VARS['pass']); if ($loginok != "OK") { sendError(str_replace("Error: ", "", $loginok), true); diff --git a/placestats.php b/placestats.php index a2b9e3f..d2f430b 100644 --- a/placestats.php +++ b/placestats.php @@ -20,5 +20,15 @@ if ($gameinfo['owneruuid'] == null) { } $gameinfo['owneruuid'] = ""; + +// calculate artifact score +$gameinfo['artifact'] = 0; + +$templife = $gameinfo['currentlife']; +while ($templife > 100) { + $gameinfo['artifact']++; + $templife -= 75; +} + $data['stats'] = $gameinfo; echo json_encode($data); \ No newline at end of file diff --git a/refillplace.php b/refillplace.php index 7c2aa91..0ed9aaf 100644 --- a/refillplace.php +++ b/refillplace.php @@ -42,11 +42,11 @@ if (floor($userlevel) > floor($user['level'])) { } $placelife = $place['currentlife'] + 10; -if ($placelife > 100) { - $placelife = 100; +if ($placelife > $place['maxlife']) { + $placelife = $place['maxlife']; } // Update the place -$database->update('locations', ['currentlife' => $placelife, 'maxlife' => 100, 'owneruuid' => $_SESSION['uuid'], 'teamid' => $user['teamid']], ['locationid' => $VARS['locationid']]); +$database->update('locations', ['currentlife' => $placelife, 'owneruuid' => $_SESSION['uuid'], 'teamid' => $user['teamid']], ['locationid' => $VARS['locationid']]); echo json_encode(["status" => "OK", "message" => ($dolevelup ? PLAYER_LEVEL_UP : PLACE_HEALTH_REFILLED), "levelup" => ($dolevelup ? true : false)]);