Game server and admin dashboard for TerranQuest.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

placeact.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. $player = new Player(getRequestUser());
  8. $place = new Place($VARS["id"] * 1);
  9. if ($place->isClaimed()) {
  10. if ($place->getTeamID() == $player->getTeamID()) {
  11. // Same teams, player is defending
  12. if ($place->energy->getEnergy() == $place->energy->getMaxEnergy()) {
  13. sendJsonResp($Strings->get("Nothing happened.", false));
  14. }
  15. $place->doDefend(10);
  16. $player->changeEnergy(-5);
  17. $player->addExp();
  18. $player->stats->updateStat(PlayerStats::DEFENDS, 1);
  19. $place->save();
  20. $player->save();
  21. sendJsonResp($Strings->get("Defending...", false));
  22. } else {
  23. // Different teams, player is attacking
  24. $place->doAttack(10);
  25. $player->changeEnergy(-5);
  26. $player->addExp();
  27. $player->stats->updateStat(PlayerStats::ATTACKS, 1);
  28. $place->save();
  29. $player->save();
  30. sendJsonResp($Strings->get("Attacking...", false));
  31. }
  32. } else {
  33. // Place unclaimed, player is claiming
  34. $place->claim($player);
  35. $player->addExp();
  36. $player->stats->updateStat(PlayerStats::CLAIMS, 1);
  37. $place->save();
  38. $player->save();
  39. sendJsonResp($Strings->get("Control established.", false));
  40. }