Browse Source

Add place artifacts (See issue TerranQuest/1)

master
Skylar Ittner 5 years ago
parent
commit
1c557b7d83
  1. 99
      artifactplace.php
  2. BIN
      database.mwb
  3. 11
      inventory.php
  4. 3
      lang/en_us.php
  5. 2
      login.php
  6. 10
      placestats.php
  7. 6
      refillplace.php

99
artifactplace.php

@ -0,0 +1,99 @@
<?php
require 'required.php';
require 'onlyloggedin.php';
if (is_empty($VARS['locationid'])) {
sendError(PLACE_ID_NOT_SENT, true);
}
$itemuuid = $VARS['itemid'];
if (is_empty($itemuuid) || !is_numeric($itemuuid)) {
sendError(INVALID_ITEMID . " 1", true);
}
if (!$database->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)]);

BIN
database.mwb

11
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);

3
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

2
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);

10
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);

6
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)]);