From 6257547a058b37f5d590c16983b5aee36b047bb8 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 6 Aug 2016 17:46:42 -0600 Subject: [PATCH] Add place attack/claim --- attackplace.php | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ claimplace.php | 38 +++++++++++++++++++++++++++++++++++++ placestats.php | 19 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 attackplace.php create mode 100644 claimplace.php create mode 100644 placestats.php diff --git a/attackplace.php b/attackplace.php new file mode 100644 index 0000000..a416b2d --- /dev/null +++ b/attackplace.php @@ -0,0 +1,50 @@ +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!"); \ No newline at end of file diff --git a/claimplace.php b/claimplace.php new file mode 100644 index 0000000..fe6dd38 --- /dev/null +++ b/claimplace.php @@ -0,0 +1,38 @@ +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!"); diff --git a/placestats.php b/placestats.php new file mode 100644 index 0000000..616b181 --- /dev/null +++ b/placestats.php @@ -0,0 +1,19 @@ +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); \ No newline at end of file