General fixes

+You can no longer build WW if your and your alliance building plans
aren't active yet
+You can no longer remove the WW from the village if you remove it from
the building queue
+Spies from every tribe will now consume crop correctly, when returning
from a scouting attacks
+Spies from every tribe will now be displayed correctly, in the "Troops"
tab of dorf3.php, when returning from a scouting attack
+Building levels will now not be downgraded by 1 level, when conquering
a Natars' village
+Natars' villages with an artifact inside, will now be deleted if the
artifact is conquered (even if the pop isn't 0)
This commit is contained in:
iopietro
2018-06-09 03:03:01 +02:00
parent a8d6b9c357
commit d96259afd8
4 changed files with 74 additions and 119 deletions
+2 -2
View File
@@ -2042,7 +2042,7 @@ class Automation {
$poparray = $database->getVSumField([$AttackerID, $DefenderID] ,"pop");
$pop1 = $poparray[0]['Total'];
$pop2 = $poparray[1]['Total'];
if($pop1 > $pop2){
if($pop1 > $pop2 && $targettribe != 5){
$buildlevel = $database->getResourceLevel($data['to']);
for ($i = 1; $i <= 39; $i++){
if($buildlevel['f'.$i]!=0){
@@ -2171,7 +2171,7 @@ class Automation {
$info_hero = $hero_pic.",Your hero is carrying home the artifact <b>".$artifact['name']."</b> and".$xp;
// if the defender pop is 0 with no artefact, then destroy the village
if($database->getVillageField($data['to'], "pop") == 0){
if($database->getVillageField($data['to'], "pop") == 0 || $targettribe == 5){
$can_destroy = $village_destroyed = 1;
$info_hero .= " The village has been destroyed.";
}
+11 -70
View File
@@ -60,42 +60,15 @@ class Building {
}
}
// check if we should allow building the WW this high
if($wwHighestLevelFound >= 50) $needed_plan = 2;
else $needed_plan = 1;
// count building plans
if($needed_plan) {
$wwbuildingplan = 0;
$planFoundInOwnersVillage = false;
$villages = $database->getVillagesID( $session->uid );
foreach($villages as $village1){
$plan = count($database->getOwnArtefactInfoByType2($village1, 11));
if($plan > 0){
$wwbuildingplan = 1;
$planFoundInOwnersVillage = true;
}
}
if($session->alliance > 0) {
$alli_users = $database->getUserByAlliance($session->alliance);
foreach($alli_users as $users){
$villages = $database->getVillagesID($users['id']);
if($users['id'] != $session->uid){
foreach($villages as $village1){
$plan = count($database->getOwnArtefactInfoByType2($village1, 11 ));
if($plan > 0) $wwbuildingplan++;
}
}
}
}
if($needed_plan == 1) $cached = ($wwbuildingplan >= $needed_plan && $planFoundInOwnersVillage);
else $cached = $wwbuildingplan >= $needed_plan;
}
else $cached = true; // no need for building plans, we can still upgrade WW
//Get our WW construction plans
$userHasWWConstructionPlans = $database->getWWConstructionPlans($session->uid);
//Get ally WW construction plans
$allyHasWWConstructionPlans = $session->alliance > 0 ? $database->getWWConstructionPlans($session->uid, $session->alliance) : false;
//Check if we should allow building the WW this high
if($wwHighestLevelFound < 50) $cached = $userHasWWConstructionPlans;
else $cached = $userHasWWConstructionPlans && $allyHasWWConstructionPlans;
}
return $cached;
@@ -593,40 +566,8 @@ class Building {
// great granary can only be built with artefact or in Natar villages
case 39: return $this->getTypeLevel(15) >= 10 && (!$isBuilt || $this->getTypeLevel($id) == 20) && ($village->natar == 1 || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 1, 0)) || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 2, 0)));
case 40:
$wwlevel = $village->resarray['f99'];
if($wwlevel > 50) $needed_plan = 1;
else $needed_plan = 0;
$wwbuildingplan = 0;
$villages = $database->getVillagesID( $session->uid );
foreach($villages as $village1) {
$plan = count($database->getOwnArtefactInfoByType2($village1, 11));
if($plan > 0){
$wwbuildingplan = 1;
break;
}
}
if($session->alliance != 0) {
$alli_users = $database->getUserByAlliance($session->alliance);
foreach($alli_users as $users) {
$villages = $database->getVillagesID($users['id']);
if($users['id'] != $session->uid) {
foreach($villages as $village1) {
$plan = count($database->getOwnArtefactInfoByType2($village1, 11 ));
if($plan > 0) {
$wwbuildingplan ++;
break;
}
}
}
}
}
return $village->natar == 1 && $wwbuildingplan > $needed_plan;
case 40: return $this->allowWwUpgrade();
case 41: return $this->getTypeLevel(16) >= 10 && $this->getTypeLevel(20) == 20 && $session->tribe == 1 && !$isBuilt;
case 42: return GREAT_WKS && $this->getTypeLevel(21) == 20 && $village->capital == 0 && !$isBuilt;
default: return false;
+49 -33
View File
@@ -4549,7 +4549,7 @@ References: User ID/Message ID, Mode
if($job['id'] == $d) $jobToDelete = $job;
}
if($canBeRemoved && $jobToDelete['field'] > 18 && $jobToDelete['type'] != 99 && $jobToDelete['level'] - 1 == 0){
if($canBeRemoved && $jobToDelete['field'] > 18 && $jobToDelete['field'] != 99 && $jobToDelete['level'] - 1 == 0){
$this->setVillageLevel($wid, ["f".$jobToDelete['field']."t"], [0]);
}
@@ -6584,57 +6584,48 @@ References: User ID/Message ID, Mode
$vinfo = $this->getVillage($id);
$vtribe = $this->getUserField($vinfo['owner'], "tribe", 0);
$movingunits = array();
$movingunits = [];
$outgoingarray = $this->getMovement(3, $id, 0);
if(!empty($outgoingarray) && count($outgoingarray)) {
foreach($outgoingarray as $out) {
for($i = 1; $i <= 10; $i++) {
if (!isset($movingunits['u' . (($vtribe - 1) * 10 + $i)])) {
$movingunits['u' . (($vtribe - 1) * 10 + $i)] = 0;
if (!isset($movingunits['u'.(($vtribe - 1) * 10 + $i)])) {
$movingunits['u'.(($vtribe - 1) * 10 + $i)] = 0;
}
if (!isset($out['t' . $i])) {
$out['t' . $i] = 0;
}
$movingunits['u' . (($vtribe - 1) * 10 + $i)] += $out['t' . $i];
if (!isset($out['t'.$i])) $out['t'.$i] = 0;
$movingunits['u'.(($vtribe - 1) * 10 + $i)] += $out['t'.$i];
}
if (!isset($movingunits['hero'])) {
$movingunits['hero'] = 0;
}
if (!isset($out['t11'])) {
$out['t11'] = 0;
}
if (!isset($movingunits['hero'])) $movingunits['hero'] = 0;
if (!isset($out['t11'])) $out['t11'] = 0;
$movingunits['hero'] += $out['t11'];
}
}
$returningarray = $this->getMovement(4, $id, 1);
if(!empty($returningarray) && count($returningarray)) {
foreach($returningarray as $ret) {
if($ret['attack_type'] != 1) {
for($i = 1; $i <= 10; $i++) {
if (!isset($movingunits['u' . (($vtribe - 1) * 10 + $i)])) {
$movingunits['u' . (($vtribe - 1) * 10 + $i)] = 0;
}
$movingunits['u' . (($vtribe - 1) * 10 + $i)] += $ret['t' . $i];
}
if (!isset($movingunits['hero'])) {
$movingunits['hero'] = 0;
}
$movingunits['hero'] += $ret['t11'];
}
for($i = 1; $i <= 10; $i++) {
if (!isset($movingunits['u'.(($vtribe - 1) * 10 + $i)])) {
$movingunits['u'.(($vtribe - 1) * 10 + $i)] = 0;
}
$movingunits['u'.(($vtribe - 1) * 10 + $i)] += $ret['t' . $i];
}
if (!isset($movingunits['hero'])) $movingunits['hero'] = 0;
$movingunits['hero'] += $ret['t11'];
}
}
$settlerarray = $this->getMovement(5, $id, 0);
if(!empty($settlerarray)) {
if (!isset($movingunits['u' . ($vtribe * 10)])) {
$movingunits['u' . ($vtribe * 10)] = 0;
if (!isset($movingunits['u'.($vtribe * 10)])) {
$movingunits['u'.($vtribe * 10)] = 0;
}
$movingunits['u' . ($vtribe * 10)] += 3 * count($settlerarray);
$movingunits['u'.($vtribe * 10)] += 3 * count($settlerarray);
}
return $movingunits;
}
@@ -7251,6 +7242,31 @@ References: User ID/Message ID, Mode
return mysqli_query($this->dblink, $q);
}
function getWWConstructionPlans($uid, $alliance = 0){
list($uid, $alliance) = $this->escape_input((int) $uid, $alliance);
if(!$alliance){
$q = "SELECT
Count(*) as Total
FROM
".TB_PREFIX."artefacts
WHERE
owner = ".$uid." AND type = 11 AND active = 1";
}else{
$q = "SELECT
Count(*) as Total
FROM
".TB_PREFIX."artefacts AS artefacts
INNER JOIN ".TB_PREFIX."users AS users
ON users.id != ".$uid." AND users.alliance = ".$alliance." AND artefacts.owner = users.id AND artefacts.type = 11
WHERE
users.id > 4 AND artefacts.active = 1";
}
$result = mysqli_fetch_array(mysqli_query($this->dblink, $q), MYSQLI_ASSOC);
return $result['Total'] > 0;
}
// no need to cache this method
function getOwnArtefactInfo($vref, $use_cache = true) {
// load the data - type is irrelevant, since the method caches all data
+12 -14
View File
@@ -161,7 +161,8 @@ class Technology {
}
public function getUnitList() {
global $database,$village;
global $database, $village;
$unitarray = func_num_args() == 1 ? $database->getUnit(func_get_arg(0)) : $village->unitall;
$listArray = [];
for($i = 1; $i < count($this->unarray); $i++) {
@@ -170,15 +171,15 @@ class Technology {
$holder['id'] = $i;
$holder['name'] = $this->unarray[$i];
$holder['amt'] = $unitarray['u'.$i];
array_push($listArray,$holder);
array_push($listArray, $holder);
}
}
if($unitarray['hero'] > 0 && !empty($unitarray['hero'])) {
$holder['id'] = "hero";
$holder['name'] = $this->unarray[$i];
$holder['amt'] = $unitarray['hero'];
array_push($listArray,$holder);
$holder['id'] = "hero";
$holder['name'] = $this->unarray[$i];
$holder['amt'] = $unitarray['hero'];
array_push($listArray, $holder);
}
return $listArray;
}
@@ -235,7 +236,7 @@ class Technology {
return $ownunit;
}
function getAllUnits($base,$InVillageOnly=False,$mode=0) {
function getAllUnits($base, $InVillageOnly = false, $mode=0) {
global $database;
$ownunit = $database->getUnit($base);
@@ -285,19 +286,16 @@ class Technology {
}
}
}
if(!$InVillageOnly){
$movement = $database->getVillageMovement($base);
if(!empty($movement)){
for($i = 1; $i <= 50; $i++){
if(!isset($ownunit['u' . $i])){
$ownunit['u' . $i] = 0;
}
$ownunit['u' . $i] += (isset($movement['u' . $i]) ? $movement['u' . $i] : 0);
if(!isset($ownunit['u'.$i])) $ownunit['u'.$i] = 0;
$ownunit['u'.$i] += (isset($movement['u'.$i]) ? $movement['u'.$i] : 0);
}
if(!isset($ownunit['hero'])){
$ownunit['hero'] = 0;
}
if(!isset($ownunit['hero'])) $ownunit['hero'] = 0;
$ownunit['hero'] += (isset($movement['hero']) ? $movement['hero'] : 0);
}
}