fix: villages with artifacts must not be destroyed

#425
This commit is contained in:
Martin Ambrus
2017-12-26 19:58:34 +01:00
parent ed916d8994
commit 765914d863
2 changed files with 47 additions and 4 deletions
+29 -4
View File
@@ -2246,9 +2246,14 @@ class Automation {
//catapults look :D
$info_cat = $info_chief = $info_ram = $info_hero = ",";
//check to see if can destroy village
if(count($varray)!='1' AND $to['capital']!='1'){
$hasArtefact = false;
if (count($varray) != 1 && $to['capital'] != 1 && !$database->villageHasArtefact($DefenderWref)) {
$can_destroy=1;
}else{
} else {
if ($database->villageHasArtefact($DefenderWref)) {
$hasArtefact = true;
}
$can_destroy=0;
}
if ($isoasis == 1) $can_destroy=0;
@@ -2304,6 +2309,20 @@ class Automation {
/**
* FIRST CATAPULTS ROW
*/
// first of all, update data if we're targetting a Treasury in village with an artefact,
// since such village (and its Treasury) cannot be destroyed until that artefact is
// removed... don't worry about Treasury levels here either, that can be taken care of
// once the artefact is gone
if ($hasArtefact && $data['ctar1'] == 27) {
$data['ctar1'] = 0;
}
if (isset($data['ctar2']) && $hasArtefact && $data['ctar2'] == 27) {
$data['ctar2'] = 0;
}
// on to targetting
$basearray = $data['to'];
$bdo = $database->getResourceLevel($basearray, false);
$catapultTarget = $data['ctar1'];
@@ -2359,7 +2378,10 @@ class Automation {
if ($i==41) $i=99;
if ($bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33)
{
$list[]=$i;
// don't allow to randomly select Treasury if there's an artefact in it
if (!$hasArtefact || ($hasArtefact && $bdo['f'.$i.'t'] != 27)) {
$list[] = $i;
}
}
}
$catapultTarget = $list[ rand(0, count($list) - 1) ];
@@ -2421,7 +2443,10 @@ class Automation {
if ($i==41) $i=99;
if ($bdo['f'.$i] > 0)
{
$list[]=$i;
// don't allow to randomly select Treasury if there's an artefact in it
if (!$hasArtefact || ($hasArtefact && $bdo['f'.$i.'t'] != 27)) {
$list[] = $i;
}
}
}
$catapultTarget2 = $list[ rand(0, count($list) - 1) ];
+18
View File
@@ -7130,6 +7130,24 @@ References: User ID/Message ID, Mode
}
}
function villageHasArtefact($vref) {
// this is a somewhat non-ideal, externally non-changeable way of caching
// but since we're only ever going to be calling this from a single point of Automation,
// this will more than suffice
static $cachedData = [];
$vref = (int) $vref;
if (isset($cachedData[$vref])) {
return $cachedData[$vref];
}
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "artefacts WHERE vref = $vref";
$result = mysqli_fetch_array(mysqli_query($this->dblink, $q), MYSQLI_ASSOC);
$cachedData[$vref] = $result['Total'];
return $cachedData[$vref];
}
function claimArtefact($vref, $ovref, $id) {
list($vref, $ovref, $id) = $this->escape_input((int) $vref, (int) $ovref, (int) $id);