Attack strength now decreases far away from a location (closes #6)

master
Skylar Ittner 8 years ago
parent 047410610d
commit 6d13916c23

@ -3,11 +3,13 @@
require 'required.php'; require 'required.php';
require 'onlyloggedin.php'; require 'onlyloggedin.php';
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
if (is_empty($VARS['locationid'])) { if (is_empty($VARS['locationid'])) {
sendError("No target!", true); sendError("No target!", true);
} }
$place = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife'], ['locationid' => $VARS['locationid']])[0]; $place = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife', 'osmid'], ['locationid' => $VARS['locationid']])[0];
$user = $database->select('players', ['level', 'teamid', 'energy', 'maxenergy', 'latitude', 'longitude'], ['uuid' => $_SESSION['uuid']])[0]; $user = $database->select('players', ['level', 'teamid', 'energy', 'maxenergy', 'latitude', 'longitude'], ['uuid' => $_SESSION['uuid']])[0];
// This (probably) shouldn't happen in normal play // This (probably) shouldn't happen in normal play
@ -27,30 +29,57 @@ if ($type_mod == 0.5) {
$terrain_mod = 1.0; $terrain_mod = 1.0;
$weather_mod = 1.0; $weather_mod = 1.0;
$distance_mod = 1.0;
if (!is_empty($VARS['lat']) && !is_empty($VARS['long'])) { if (!is_empty($VARS['lat']) && !is_empty($VARS['long'])) {
require 'weather_inc.php'; try {
$terrain = json_decode(file_get_contents("http://gis.terranquest.net/terrain.php?key=" . GIS_API_KEY . "&lat=" . $VARS['lat'] . "&long=" . $VARS['long']), TRUE); require_once 'latlong_validate.php';
if ($terrain['status'] == 'OK') { if (!is_empty(DARKSKY_APIKEY)) {
$terraintype = $terrain['type']; require 'weather_inc.php';
$terrain_mod = $TERRAIN_GRID[$terraintype][$user['teamid'] - 1]; $weather_icon = $currently['icon'];
if ($terrain_mod == 0.5) { $weather_mod = $WEATHER_GRID[$weather_icon][$user['teamid'] - 1];
$terrain_mod = .9; if ($weather_mod == 0.5) {
} else if ($terrain_mod == 2) { $weather_mod = .9;
$terrain_mod = 1.1; } else if ($weather_mod == 2) {
} else if ($terrain_mod == 3) { $weather_mod = 1.1;
$terrain_mod = 1.3; }
} }
} catch (Exception $e) {
$weather_mod = 1.0;
} }
$weather_icon = $currently['icon'];
$weather_mod = $WEATHER_GRID[$weather_icon][$user['teamid'] - 1]; try {
if ($weather_mod == 0.5) { $terrain = json_decode(file_get_contents("http://gis.terranquest.net/terrain.php?key=" . GIS_API_KEY . "&lat=" . $VARS['lat'] . "&long=" . $VARS['long']), TRUE);
$weather_mod = .9; if ($terrain['status'] == 'OK') {
} else if ($weather_mod == 2) { $terraintype = $terrain['type'];
$weather_mod = 1.1; $terrain_mod = $TERRAIN_GRID[$terraintype][$user['teamid'] - 1];
if ($terrain_mod == 0.5) {
$terrain_mod = .9;
} else if ($terrain_mod == 2) {
$terrain_mod = 1.1;
} else if ($terrain_mod == 3) {
$terrain_mod = 1.3;
}
} }
} catch (Exception $e) {
$terrain_mod = 1.0;
}
try {
// Round to 2 digits (approx. 1.11 meters/3.6 feet)
$lat = number_format((float) $VARS['lat'], 5, '.', '');
$long = number_format((float) $VARS['long'], 5, '.', '');
$placedata = json_decode(file_get_contents("http://gis.terranquest.net/place.php?key=" . GIS_API_KEY . "&osmid=" . $place['osmid']), true);
$placelong = $placedata['features'][0]['geometry']['coordinates'][0];
$placelat = $placedata['features'][0]['geometry']['coordinates'][1];
$playerlocation = GeoLocation::fromDegrees($lat, $long);
$placelocation = GeoLocation::fromDegrees($placelat, $placelong);
$distance_mod = DISTANCE_GRID($playerlocation->distanceTo($placelocation, 'miles'));
} catch (Exception $e) {
$distance_mod = 1.0;
}
} }
$damage = pow(floor($user['level']), 0.5) * 4 * $type_mod * $terrain_mod * $weather_mod; $damage = pow(floor($user['level']), 0.5) * 4 * $type_mod * $terrain_mod * $weather_mod * $distance_mod;
//$damage = 2 * $userdrain * $TYPE_GRID[$user['teamid']][$place['teamid']]; //$damage = 2 * $userdrain * $TYPE_GRID[$user['teamid']][$place['teamid']];
// Check if action possible // Check if action possible
if ($user['energy'] < $userdrain) { if ($user['energy'] < $userdrain) {

@ -46,3 +46,25 @@ $WEATHER_GRID = [
"wind" => [1, 1, 1, 2, 1, 1], "wind" => [1, 1, 1, 2, 1, 1],
"fog" => [1, 1, 1, 1, 1, 1] "fog" => [1, 1, 1, 1, 1, 1]
]; ];
/**
* Get a multiplier for the distance between the player and place.
* @param float $d the number of miles between
* @return float The damage multiplier
*/
function DISTANCE_GRID($d) {
$distance = floor($d * 100.0);
if ($distance <= 5) { // ~250 feet
return 1;
} else if ($distance <= 10) { // ~500 feet
return 0.95;
} else if ($distance <= 20) { // ~1000 feet
return 0.8;
} else if ($distance <= 50) { // ~2500 feet
return 0.6;
} else if ($distance <= 100) { // 1 mile (5280 feet)
return 0.4;
} else { // Greater than 1 mile
return 0.2;
}
}

@ -5,7 +5,7 @@
* Get the contents of the current weather with $currently * Get the contents of the current weather with $currently
*/ */
require 'latlong_validate.php'; require_once 'latlong_validate.php';
// Round to 2 digits (approx. 1.1km) // Round to 2 digits (approx. 1.1km)
$lat = number_format((float) $VARS['lat'], 2, '.', ''); $lat = number_format((float) $VARS['lat'], 2, '.', '');