Add place attack/claim
parent
ca722b28d1
commit
6257547a05
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
require 'required.php';
|
||||
require 'onlyloggedin.php';
|
||||
|
||||
if (is_empty($VARS['locationid'])) {
|
||||
sendError("No target!", true);
|
||||
}
|
||||
|
||||
$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("Don't attack your own kind!", true);
|
||||
}
|
||||
|
||||
// The underwhelming damage formulas :P
|
||||
$userdrain = 5 * floor($user['level']);
|
||||
$damage = 2 * $userdrain;
|
||||
|
||||
// Check if action possible
|
||||
if ($user['energy'] < $userdrain) {
|
||||
sendError("Not enough life left!", true);
|
||||
}
|
||||
|
||||
// Calculate resulting user HP
|
||||
$userhp = $user['energy'] - $userdrain;
|
||||
|
||||
// Calculate resulting place HP
|
||||
$placehp = $place['currentlife'] - $damage;
|
||||
|
||||
// No negatives plz
|
||||
if ($placehp < 0) {
|
||||
$placehp = 0;
|
||||
}
|
||||
|
||||
// Update the user's health
|
||||
// TODO: calculate XP and add to decimal portion of level
|
||||
$database->update('players', ['energy' => $userhp], ['uuid' => $_SESSION['uuid']]);
|
||||
|
||||
if ($placehp == 0) {
|
||||
// It's dead
|
||||
$database->update('locations', ['owneruuid' => null, 'teamid' => 0, 'currentlife' => 0, 'maxlife' => 0], ['locationid' => $VARS['locationid']]);
|
||||
} else {
|
||||
// or not
|
||||
$database->update('locations', ['currentlife' => $placehp], ['locationid' => $VARS['locationid']]);
|
||||
}
|
||||
|
||||
sendOK("Success!");
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require 'required.php';
|
||||
require 'onlyloggedin.php';
|
||||
|
||||
if (is_empty($VARS['locationid'])) {
|
||||
sendError("No target!", true);
|
||||
}
|
||||
|
||||
$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("Don't attack your own kind!", true);
|
||||
}
|
||||
|
||||
if ($place['currentlife'] > 0) {
|
||||
sendError("Cannot claim!", true);
|
||||
}
|
||||
|
||||
$userdrain = 5 * floor($user['level']);
|
||||
|
||||
// Calculate resulting user HP
|
||||
$userhp = $user['energy'] - $userdrain;
|
||||
// Check if action possible
|
||||
if ($userhp < 0) {
|
||||
sendError("Not enough life left!", true);
|
||||
}
|
||||
|
||||
// Update the user's health
|
||||
// TODO: calculate XP and add to decimal portion of level
|
||||
$database->update('players', ['energy' => $userhp], ['uuid' => $_SESSION['uuid']]);
|
||||
|
||||
// Update the place
|
||||
$database->update('locations', ['currentlife' => 100, 'maxlife' => 100, 'owneruuid' => $_SESSION['uuid'], 'teamid' => $user['teamid']], ['locationid' => $VARS['locationid']]);
|
||||
|
||||
sendOK("Success!");
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Get the stats for a place. Useful for reloading stats after doing something.
|
||||
*/
|
||||
require 'required.php';
|
||||
|
||||
if (is_empty($VARS['locationid'])) {
|
||||
sendError("Missing internal location ID.", true);
|
||||
}
|
||||
|
||||
$data['status'] = 'OK';
|
||||
if (!$database->has('locations', ['locationid' => $VARS['locationid']])) {
|
||||
sendError("No stats found.", true);
|
||||
}
|
||||
$gameinfo = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife'], ['locationid' => $VARS['locationid']])[0];
|
||||
|
||||
$data['stats'] = $gameinfo;
|
||||
echo json_encode($data);
|
Reference in New Issue