You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
PHTML
44 lines
1.4 KiB
PHTML
5 years ago
|
<?php
|
||
|
|
||
|
/*
|
||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
|
*/
|
||
|
|
||
|
$player = new Player(getRequestUser());
|
||
|
|
||
|
$place = new Place($VARS["id"] * 1);
|
||
|
|
||
|
if ($place->isClaimed()) {
|
||
|
if ($place->getTeamID() == $player->getTeamID()) {
|
||
|
// Same teams, player is defending
|
||
|
if ($place->energy->getEnergy() == $place->energy->getMaxEnergy()) {
|
||
|
sendJsonResp($Strings->get("Nothing happened.", false));
|
||
|
}
|
||
|
$place->changeEnergy(10);
|
||
|
$player->changeEnergy(-5);
|
||
|
$player->addExp();
|
||
|
$player->stats->updateStat(PlayerStats::DEFENDS, 1);
|
||
|
$place->save();
|
||
|
$player->save();
|
||
|
sendJsonResp($Strings->get("Defending...", false));
|
||
|
} else {
|
||
|
// Different teams, player is attacking
|
||
|
$place->changeEnergy(-10);
|
||
|
$player->changeEnergy(-5);
|
||
|
$player->addExp();
|
||
|
$player->stats->updateStat(PlayerStats::ATTACKS, 1);
|
||
|
$place->save();
|
||
|
$player->save();
|
||
|
sendJsonResp($Strings->get("Attacking...", false));
|
||
|
}
|
||
|
} else {
|
||
|
// Place unclaimed, player is claiming
|
||
|
$place->claim($player);
|
||
|
$player->addExp();
|
||
|
$player->stats->updateStat(PlayerStats::CLAIMS, 1);
|
||
|
$place->save();
|
||
|
$player->save();
|
||
|
sendJsonResp($Strings->get("Control established.", false));
|
||
|
}
|