Artifacts fix

+Added the possibility to add WW villages to a player, in the admin
panel
+Fixed the WW villages counter
+Deleted Natars' artifacts can now be recovered from the admin panel
This commit is contained in:
iopietro
2018-07-25 15:32:14 +02:00
parent 94447708ad
commit 1f86162179
5 changed files with 76 additions and 20 deletions
+27 -7
View File
@@ -93,25 +93,30 @@ class funct
$artifactInfo = $database->getArtefactDetails($_GET['artid'], $_GET['del']);
//Check if the artifact exists
if(empty($artifactInfo) || $artifactInfo['owner'] == Artifacts::NATARS_UID) {
if(empty($artifactInfo)) {
header("location: admin.php");
exit;
}elseif($artifactInfo['owner'] == Artifacts::NATARS_UID){
$database->updateArtifactDetails($_GET['artid'], ['del' => 0]);
header("location: admin.php");
exit;
}
$artifact->returnArtifactToNatars($artifactInfo);
break;
case "addArtifacts":
$selectedArtifact = $_POST['selectedArtifact'];
$artifactQuantity = $_POST['artifactQuantity'];
$playerId = $_POST['playerId'];
$artifactQuantity = (int)$_POST['artifactQuantity'];
$playerId = (int)$_POST['playerId'];
//Check if the inputs are valid
if(!isset($selectedArtifact) || !isset($artifactQuantity) || !isset($playerId) || empty($selectedArtifact) ||
!is_numeric($artifactQuantity) || !is_numeric($playerId) || strpos($selectedArtifact, ':') === false ||
$database->getUserField($playerId, "username", 0) == "[?]"){
header("location: admin.php?p=artifacts&error=0");
!is_numeric($artifactQuantity) || $artifactQuantity <= 0 || $artifactQuantity > 999 || !is_numeric($playerId) ||
strpos($selectedArtifact, ':') === false || $database->getUserField($playerId, "username", 0) == "[?]"){
header("location: admin.php?p=natars&error=0");
exit;
}
@@ -125,7 +130,7 @@ class funct
//Check if the artifact has been found or if doesn't exist
if(empty($chosenArtifact)){
header("location: admin.php?p=artifacts&error=1");
header("location: admin.php?p=natars&error=1");
exit;
}
@@ -137,6 +142,21 @@ class funct
$artifact->addArtifactVillages($artifactArrays, $playerId);
break;
case "addWWVillages":
$numberOfVillages = (int)$_POST['numberOfVillages'];
$playerId = (int)$_POST['playerId'];
//Check if the inserted values are valid
if(!is_numeric($numberOfVillages) || $numberOfVillages <= 0 || $numberOfVillages > 999
|| !is_numeric($playerId) || $database->getUserField($playerId, "username", 0) == "[?]"){
header("location: admin.php?p=natars&error=2");
}
//Create the desired WW villages
$artifact->createWWVillages($numberOfVillages, $playerId);
break;
case "killHero":
$varray = $database->getProfileVillages($get['uid']);
$killhero = false;
+11 -5
View File
@@ -131,8 +131,14 @@ class Artifacts
* @var int The base amount of Natars' spying units, used when Natars account is created
*/
NATARS_BASE_SPY = 1500;
NATARS_BASE_SPY = 1500,
/**
* @var int the base amount of Natars' WW villages
*/
NATARS_BASE_WW_VILLAGES = 13;
public
/**
@@ -311,12 +317,12 @@ class Artifacts
*
*/
public function createWWVillages(){
public function createWWVillages($numberOfVillages = self::NATARS_BASE_WW_VILLAGES, $uid = self::NATARS_UID){
global $database;
$villageArrays = $troopArrays = $buildingArrays = $wids = [];
for($i = 1; $i <= 13; $i++){
$villageArrays[] = ['wid' => 0, 'mode' => 5, 'type' => 3, 'kid' => ($i == 13 ? rand(1, 4) : ($i % 4) + 1), 'capital' => 0, 'pop' => 233, 'name' => WWVILLAGE, 'natar' => 1];
for($i = 1; $i <= $numberOfVillages; $i++){
$villageArrays[] = ['wid' => 0, 'mode' => 5, 'type' => 3, 'kid' => ($i == $numberOfVillages ? rand(1, 4) : ($i % 4) + 1), 'capital' => 0, 'pop' => 233, 'name' => WWVILLAGE, 'natar' => 1];
$troopArrays[1][] = array_values(($this->natarsWWVillagesUnits)());
$buildingArrays[1][] = array_values(self::NATARS_WW_VILLAGES_BUILDINGS);
}
@@ -324,7 +330,7 @@ class Artifacts
$troopArrays[0] = array_keys(($this->natarsWWVillagesUnits)());
$buildingArrays[0] = array_keys(self::NATARS_WW_VILLAGES_BUILDINGS);
$wids = $database->generateVillages($villageArrays, self::NATARS_UID, TRIBE5, $troopArrays, $buildingArrays);
$wids = $database->generateVillages($villageArrays, $uid, null, $troopArrays, $buildingArrays);
}
/**