refactor: 5th round of sendunitsComplete() optimizations

This commit is contained in:
Martin Ambrus
2017-11-13 17:02:58 +01:00
parent e798635ebb
commit 35512d16f0
+233 -464
View File
@@ -1035,6 +1035,125 @@ class Automation {
} }
} }
private function resolveCatapultsDestruction(&$bdo, &$battlepart, &$info_cat, &$data, $catapultTarget, $twoRowsCatapultSetup, $isSecondRow, $catp_pic, $can_destroy, $isoasis, &$village_destroyed) {
global $database;
// currently targeted building/field level
$tblevel = (int) $bdo['f'.$catapultTarget];
// currently targetet building/field GID (ID of the building/field type - woodcutter, cropland, embassy...)
$tbgid = (int) $bdo['f'.$catapultTarget.'t'];
// currently targeted building/field ID in the database (fdata, the fID field, e.g. f1, f2, f3...)
$tbid = (int) $catapultTarget;
// building/field destroyed
if ($battlepart[4]>$battlepart[3])
{
if ($isSecondRow) {
$info_cat .= "<br><tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> ".$this->procResType($tbgid,$can_destroy,$isoasis)." destroyed.</td></tr></tbody>";
} else {
$info_cat = "" . $catp_pic . ", " . $this->procResType( $tbgid, $can_destroy, $isoasis ) . " destroyed.";
}
// prepare data to be updated
$fieldsToSet = ["f".$tbid];
$fieldValuesToSet = [0];
// update $bdo, so we don't have to reselect later
$bdo['f'.$catapultTarget] = 0;
if ($tbid >= 19 && $tbid != 99) {
$fieldsToSet[] = "f".$tbid."t";
$fieldValuesToSet[] = 0;
$bdo['f'.$catapultTarget."t"] = 0;
}
// update all that needs updating
$database->setVillageLevel($data['to'], $fieldsToSet, $fieldValuesToSet);
$buildarray = $GLOBALS["bid".$tbgid];
// (great) warehouse level was changed
if ($tbgid==10 || $tbgid==38) {
$database->setMaxStoreForVillage($data['to'], $buildarray[$tblevel]['attri']);
}
// (great) granary level was changed
if ($tbgid==11 || $tbgid==39) {
$database->setMaxCropForVillage($data['to'], $buildarray[$tblevel]['attri']);
}
// embassy level was changed
if ($tbgid==18){
$info_cat .= $database->checkEmbassiesAfterBattle($villageOwners, $cachedUserData, $data['to']);
}
// oasis cannot be destroyed
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
if($pop==0 && $can_destroy==1){
$village_destroyed = 1;
}
}
}
// building/field not damaged
elseif ($battlepart[4]==0)
{
if ($isSecondRow) {
$info_cat .= "<br><tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> ".$this->procResType($tbgid,$can_destroy,$isoasis)." was not damaged.</td></tr></tbody>";
} else {
$info_cat = "" . $catp_pic . "," . $this->procResType( $tbgid, $can_destroy, $isoasis ) . " was not damaged.";
}
}
else
// building/field was damaged, let's calculate the actual damage
{
//TODO: MUST TO BE FIX This part goes also below 0 if u have a lot of catapults
$totallvl = round( sqrt( pow( ( $tblevel + 0.5 ), 2 ) - ( ( !$twoRowsCatapultSetup ? (int) $battlepart[4] : (int) $battlepart[4] / 2 ) * 8 ) ) );
// no damage to the building/field
if ( $tblevel == $totallvl ) {
$info_cata = " was not damaged.";
} else // building/field damaged, damage calculations to follow
{
// update $bdo, so we don't have to reselect later
$bdo[ 'f' . $catapultTarget ] = $totallvl;
$info_cata = " damaged from level <b>" . $tblevel . "</b> to level <b>" . $totallvl . "</b>.";
$buildarray = $GLOBALS[ "bid" . $tbgid ];
// (great) warehouse level was changed
if ( $tbgid == 10 || $tbgid == 38 ) {
$database->setMaxStoreForVillage( $data['to'], $buildarray[ $tblevel ]['attri'] );
}
// (great) granary level was changed
if ( $tbgid == 11 || $tbgid == 39 ) {
$database->setMaxCropForVillage( $data['to'], $buildarray[ $tblevel ]['attri'] );
}
// embassy level was changed
if ( $tbgid == 18 ) {
$info_cat .= $database->checkEmbassiesAfterBattle( $villageOwners, $cachedUserData, $data['to'] );
}
// no need to recalculate population of oasis, as there is none
if ( $isoasis == 0 ) {
$pop = $this->recountPop( $data['to'] );
}
}
if ($isSecondRow) {
$info_cat .= "<br><tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> ".$this->procResType($tbgid,$can_destroy,$isoasis).$info_cata."</td></tr></tbody>";
} else {
$info_cat = "" . $catp_pic . "," . $this->procResType( $tbgid, $can_destroy, $isoasis ) . $info_cata;
}
$database->setVillageLevel( $data['to'], "f" . $tbid, $totallvl );
}
}
private function sendunitsComplete() { private function sendunitsComplete() {
global $bid23,$bid34,$database,$battle,$village,$technology,$logging,$generator,$session,$units,$autoprefix; global $bid23,$bid34,$database,$battle,$village,$technology,$logging,$generator,$session,$units,$autoprefix;
@@ -1285,8 +1404,8 @@ class Automation {
} }
} }
$tblevel = '1'; $tblevel = 1;
$stonemason = "1"; $stonemason = 1;
/*-------------------------------- /*--------------------------------
// End village Battle part // End village Battle part
@@ -1392,9 +1511,9 @@ class Automation {
$att_ab1=$att_ab2=$att_ab3=$att_ab4=$att_ab5=$att_ab6=$att_ab7=$att_ab8=0; $att_ab1=$att_ab2=$att_ab3=$att_ab4=$att_ab5=$att_ab6=$att_ab7=$att_ab8=0;
$def_ab[31]=$def_ab[32]=$def_ab[33]=$def_ab[34]=$def_ab[35]=$def_ab[36]=$def_ab[37]=$def_ab[38]=0; $def_ab[31]=$def_ab[32]=$def_ab[33]=$def_ab[34]=$def_ab[35]=$def_ab[36]=$def_ab[37]=$def_ab[38]=0;
$empty='1'; $empty=1;
$tblevel = '0'; $tblevel = 0;
$stonemason = "0"; $stonemason = 0;
} }
$varray = $database->getProfileVillages($to['owner']); $varray = $database->getProfileVillages($to['owner']);
@@ -1849,7 +1968,10 @@ class Automation {
//cranny efficiency //cranny efficiency
$atk_bonus = ($owntribe == 2)? (4/5) : 1; $atk_bonus = ($owntribe == 2)? (4/5) : 1;
$def_bonus = ($targettribe == 3)? 2 : 1; $def_bonus = ($targettribe == 3)? 2 : 1;
$to_owner = $database->getVillageField($data['to'],"owner"); if (!isset($villageOwners[$data['to']])) {
$villageOwners[$data['to']] = $database->getVillageField($data['to'],"owner");
}
$to_owner = $villageOwners[$data['to']];
$artefact_2 = count($database->getOwnUniqueArtefactInfo2($to_owner,7,3,0)); $artefact_2 = count($database->getOwnUniqueArtefactInfo2($to_owner,7,3,0));
$artefact1_2 = count($database->getOwnUniqueArtefactInfo2($data['to'],7,1,1)); $artefact1_2 = count($database->getOwnUniqueArtefactInfo2($data['to'],7,1,1));
$artefact2_2 = count($database->getOwnUniqueArtefactInfo2($to_owner,7,2,0)); $artefact2_2 = count($database->getOwnUniqueArtefactInfo2($to_owner,7,2,0));
@@ -2021,24 +2143,26 @@ class Automation {
} }
if ($isoasis == 1) $can_destroy=0; if ($isoasis == 1) $can_destroy=0;
if ($type=='3'){ if ($type=='3')
{
if (($data['t7']-$traped7)>0){ if (($data['t7']-$traped7)>0){
if (isset($empty)){ if (isset($empty)){
$info_ram = "".$ram_pic.",There is no wall to destroy."; $info_ram = "".$ram_pic.",There is no wall to destroy.";
} else } else
if ($battlepart[8]>$battlepart[7]){ if ($battlepart[8]>$battlepart[7]){
$info_ram = "".$ram_pic.",Wall destroyed."; $info_ram = "".$ram_pic.",Wall destroyed.";
$database->setVillageLevel($data['to'],"f".$wallid."",'0'); $database->setVillageLevel(
$database->setVillageLevel($data['to'],"f".$wallid."t",'0'); $data['to'],
$pop=$this->recountPop($data['to']); ["f".$wallid, "f".$wallid."t"],
[0, 0]
);
$pop=$this->recountPop($data['to']);
}elseif ($battlepart[8]==0){ }elseif ($battlepart[8]==0){
$info_ram = "".$ram_pic.",Wall was not damaged."; $info_ram = "".$ram_pic.",Wall was not damaged.";
}else{ }else{
$demolish=$battlepart[8]/$battlepart[7];
$totallvl = round(sqrt(pow(($walllevel+0.5),2)-($battlepart[8]*8))); $totallvl = round(sqrt(pow(($walllevel+0.5),2)-($battlepart[8]*8)));
if($walllevel == $totallvl){ if($walllevel == $totallvl){
$info_ram = "".$ram_pic.",Wall was not damaged."; $info_ram = "".$ram_pic.",Wall was not damaged.";
@@ -2048,19 +2172,17 @@ class Automation {
} }
} }
} }
} elseif (($data['t7']-$traped7)>0){
$info_ram = "".$ram_pic.",Hint: The ram does not work during a raid.";
}
if ($type=='3')
{
if (($data['t8']-$traped8)>0) if (($data['t8']-$traped8)>0)
{ {
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
if ($isoasis != 0) { if ($isoasis != 0) {
$pop=10; //oasis cannot be destroy bt cata/ram $pop=10; //oasis cannot be destroy bt cata/ram
} }
if($pop<=0) {
if($can_destroy==1) { // village has been destroyed
if ($pop<=0) {
if ($can_destroy==1) {
$info_cat = "".$catp_pic.", Village already destroyed."; $info_cat = "".$catp_pic.", Village already destroyed.";
} else { } else {
$info_cat = "".$catp_pic.", Village can\'t be destroyed."; $info_cat = "".$catp_pic.", Village can\'t be destroyed.";
@@ -2068,480 +2190,127 @@ class Automation {
} }
else else
{ {
// village stands, let's do the damage
$basearray = $data['to']; $basearray = $data['to'];
if ($data['ctar2']==0) $bdo=mysqli_fetch_array(mysqli_query($database->dblink,"select * from " . TB_PREFIX . "fdata where vref = " . (int) $basearray), MYSQLI_ASSOC);
$catapultTarget = $data['ctar1'];
$catapultTarget2 = (isset($data['ctar2']) ? $data['ctar2'] : 0);
$catapults1TargetRandom = ($catapultTarget == 0);
$catapults2TargetRandom = ($catapultTarget2 == 99);
$catapults2WillNotShoot = ($catapultTarget2 == 0);
// we're manually targetting 1st and/or 2nd row of catapults
if (!$catapults1TargetRandom || !$catapults2TargetRandom)
{ {
$bdo2=mysqli_query($GLOBALS['link'],"select * from " . TB_PREFIX . "fdata where vref = " . (int) $basearray); $_catapultsTarget1Levels=array();
$bdo=mysqli_fetch_array($bdo2); $__catapultsTarget1AltTargets=array();
$rand=$data['ctar1']; $_catapultsTarget2Levels=array();
$__catapultsTarget2AltTargets=array();
if ($rand != 0) // calculate targets for 1st and 2nd rows of catapults
$j=0;
for ($i=1;$i<=41;$i++)
{ {
$_rand=array(); if ($i==41) $i=99;
$__rand=array();
$j=0; // 1st row of catapults pre-selected target calculations, if needed
for ($i=1;$i<=41;$i++) if (!$catapults1TargetRandom && $bdo['f'.$i.'t'] == $catapultTarget && $bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33)
{ {
if ($i==41) $i=99; $j++;
if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0 && $rand != 31 && $rand != 32 && $rand != 33) $_catapultsTarget1Levels[$j]=$bdo['f'.$i];
{ $__catapultsTarget1AltTargets[$j]=$i;
$j++;
$_rand[$j]=$bdo['f'.$i];
$__rand[$j]=$i;
}
} }
if (count($_rand)>0)
// 2nd row of catapults pre-selected target calculations, if needed
if (!$catapults2TargetRandom && !$catapults2WillNotShoot && $bdo['f'.$i.'t'] == $catapultTarget2 && $bdo['f'.$i] > 0 && $catapultTarget2 != 31 && $catapultTarget2 != 32 && $catapultTarget2 != 33)
{ {
if (max($_rand)<=0) $rand=0; $_catapultsTarget2Levels[$j]=$bdo['f'.$i];
else $__catapultsTarget2AltTargets[$j]=$i;
{
$rand=rand(1, $j);
$rand=$__rand[$rand];
}
}
else
{
$rand=0;
} }
} }
if ($rand == 0) // if we couldn't find a suitable target for 1st row of catapults,
{ // select a random target instead
$list=array(); if (!$catapults1TargetRandom) {
$j=1; if ( count( $_catapultsTarget1Levels ) > 0 ) {
for ($i=1;$i<=41;$i++) if ( max( $_catapultsTarget1Levels ) <= 0 ) {
{ $catapultTarget = 0;
if ($i==41) $i=99; } else {
if ($bdo['f'.$i] > 0 && $rand != 31 && $rand != 32 && $rand != 33) $catapultTarget = $__catapultsTarget1AltTargets[ rand( 1, $j ) ];
{
$list[$j]=$i;
$j++;
}
}
$rand=rand(1, $j);
$rand=$list[$rand];
}
$tblevel = $bdo['f'.$rand];
$tbgid = $bdo['f'.$rand.'t'];
$tbid = $rand;
if ($battlepart[4]>$battlepart[3])
{
$info_cat = "".$catp_pic.", ".$this->procResType($tbgid,$can_destroy,$isoasis)." destroyed.";
$database->setVillageLevel($data['to'],"f".$tbid."",'0');
if($tbid>=19 && $tbid!=99) { $database->setVillageLevel($data['to'],"f".$tbid."t",'0'); }
$buildarray = $GLOBALS["bid".$tbgid];
if ($tbgid==10 || $tbgid==38) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxstore=$t_sql['maxstore']-$buildarray[$tblevel]['attri'];
if ($tmaxstore<800) $tmaxstore=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`='".$tmaxstore."'*32 WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==11 || $tbgid==39) {
if (!isset($tsql)) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
}
$t_sql=mysqli_fetch_array($tsql);
$tmaxcrop=$t_sql['maxcrop']-$buildarray[$tblevel]['attri'];
if ($tmaxcrop<800) $tmaxcrop=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."'*32 WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==18){
Automation::updateMax($database->getVillageField($data['to'],'owner'));
$allianceStatus = $database->checkAllianceEmbassiesStatus([
'id' => $DefenderID,
'alliance' => $database->getUserField($DefenderID,"alliance",0),
'username' => $database->getUserField($DefenderID,"username",0),
'lvl' => 0
]);
if ($allianceStatus === false) {
$info_cat .= ' This player\'s alliance has been dispersed.';
} else if ($allianceStatus === 0) {
$info_cat .= ' Player was forced to leave their alliance.';
}
}
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
if($pop=='0' && $can_destroy==1){
$village_destroyed = 1;
} }
} else {
$catapultTarget = 0;
} }
} }
elseif ($battlepart[4]==0)
{
$info_cat = "".$catp_pic.",".$this->procResType($tbgid,$can_destroy,$isoasis)." was not damaged.";
}
else
{
//MUST TO BE FIX : Unless variable
$demolish=$battlepart[4]/$battlepart[3];
//MUST TO BE FIX This part goes also below 0 if u have a lot of catapults
$totallvl = round(sqrt(pow(($tblevel+0.5),2)-($battlepart[4]*8)));
if ($tblevel==$totallvl)
$info_cata=" was not damaged.";
else
{
$info_cata=" damaged from level <b>".$tblevel."</b> to level <b>".$totallvl."</b>.";
$buildarray = $GLOBALS["bid".$tbgid];
if ($tbgid==10 || $tbgid==38) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxstore=$t_sql['maxstore']+$buildarray[$totallvl]['attri']-$buildarray[$tblevel]['attri'];
if ($tmaxstore<800) $tmaxstore=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`='".$tmaxstore."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==11 || $tbgid==39) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxcrop=$t_sql['maxcrop']+$buildarray[$totallvl]['attri']-$buildarray[$tblevel]['attri'];
if ($tmaxcrop<800) $tmaxcrop=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==18){
Automation::updateMax($database->getVillageField($data['to'],'owner'));
$allianceStatus = $database->checkAllianceEmbassiesStatus([
'id' => $DefenderID,
'alliance' => $database->getUserField($DefenderID,"alliance",0),
'username' => $database->getUserField($DefenderID,"username",0),
'lvl' => $totallvl
]);
if ($allianceStatus === false) { // if we couldn't find a suitable target for 2nd row of catapults,
$info_cat .= ' This player\'s alliance has been dispersed.'; // select a random target instead
} else if ($allianceStatus === 0) { if (!$catapults2TargetRandom ) {
$info_cat .= ' Player was forced to leave their alliance.'; if ( count( $_catapultsTarget2Levels ) > 0 ) {
} if ( max( $_catapultsTarget2Levels ) <= 0 ) {
} $catapultTarget2 = 99;
$pop=$this->recountPop($data['to']); } else {
$catapultTarget2 = $__catapultsTarget2AltTargets[ rand( 1, $j ) ];
} }
$info_cat = "".$catp_pic.",".$this->procResType($tbgid,$can_destroy,$isoasis).$info_cata; } else {
$database->setVillageLevel($data['to'],"f".$tbid."",$totallvl); $catapultTarget2 = 99;
}
} }
} }
else
// 1st row of catapults set to target randomly
if ($catapults1TargetRandom)
{ {
$bdo2=mysqli_query($GLOBALS['link'],"select * from " . TB_PREFIX . "fdata where vref = ". (int) $basearray); $list=array();
$bdo=mysqli_fetch_array($bdo2); $j = 0;
$rand=$data['ctar1']; for ($i=1;$i<=41;$i++)
if ($rand != 0)
{ {
$_rand=array(); if ($i==41) $i=99;
$__rand=array(); if ($bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33)
$j=0;
for ($i=1;$i<=41;$i++)
{ {
if ($i==41) $i=99; $list[$j]=$i;
if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0 && $rand != 31 && $rand != 32 && $rand != 33) $j++;
{
$j++;
$_rand[$j]=$bdo['f'.$i];
$__rand[$j]=$i;
}
} }
if (count($_rand)>0) }
$catapultTarget = $list[ rand(1, $j) ];
}
// 2nd row of catapults set to target randomly
if ($catapults2TargetRandom)
{
$list=array();
$j=0;
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
if ($bdo['f'.$i] > 0)
{ {
if (max($_rand)<=0) $rand=0; $j++;
else $list[$j]=$i;
{
$rand=rand(1, $j);
$rand=$__rand[$rand];
}
}
else
{
$rand=0;
} }
} }
$catapultTarget2 = $list[ rand(1, $j) ];
}
if ($rand == 0) /**
{ * resolve 1st row of catapults
$list=array(); */
$j=0; $village_destroyed = 0;
for ($i=1;$i<=41;$i++) $this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget, !$catapults2WillNotShoot, false, $catp_pic, $can_destroy, $isoasis, $village_destroyed);
{
if ($i==41) $i=99;
if ($bdo['f'.$i] > 0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$j++;
$list[$j]=$i;
}
}
$rand=rand(1, $j);
$rand=$list[$rand];
}
$tblevel = $bdo['f'.$rand]; /**
$tbgid = $bdo['f'.$rand.'t']; * resolve 2nd row of catapults
$tbid = $rand; */
if ($battlepart[4]>$battlepart[3]) if (!$catapults2WillNotShoot) {
{ $this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget2, true, true, $catp_pic, $can_destroy, $isoasis, $village_destroyed);
$info_cat = "".$catp_pic.", ".$this->procResType($tbgid,$can_destroy,$isoasis)." destroyed.";
$database->setVillageLevel($data['to'],"f".$tbid."",'0');
if($tbid>=19 && $tbid!=99) { $database->setVillageLevel($data['to'],"f".$tbid."t",'0'); }
$buildarray = $GLOBALS["bid".$tbgid];
if ($tbgid==10 || $tbgid==38) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxstore=$t_sql['maxstore']-$buildarray[$tblevel]['attri'];
if ($tmaxstore<800) $tmaxstore=800*32;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`='".$tmaxstore."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==11 || $tbgid==39) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxcrop=$t_sql['maxcrop']-$buildarray[$tblevel]['attri'];
if ($tmaxcrop<800) $tmaxcrop=800*32;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==18){
Automation::updateMax($database->getVillageField($data['to'],'owner'));
$allianceStatus = $database->checkAllianceEmbassiesStatus([
'id' => $DefenderID,
'alliance' => $database->getUserField($DefenderID,"alliance",0),
'username' => $database->getUserField($DefenderID,"username",0),
'lvl' => 0
]);
if ($allianceStatus === false) {
$info_cat .= ' This player\'s alliance has been dispersed.';
} else if ($allianceStatus === 0) {
$info_cat .= ' Player was forced to leave their alliance.';
}
}
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
}
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
if($pop=='0'){
if($can_destroy==1){
$village_destroyed = 1;
}
}
}
}
elseif ($battlepart[4]==0)
{
$info_cat = "".$catp_pic.",".$this->procResType($tbgid,$can_destroy,$isoasis)." was not damaged.";
}
else
{
$demolish=$battlepart[4]/$battlepart[3];
$totallvl = round(sqrt(pow(($tblevel+0.5),2)-(($battlepart[4]/2)*8)));
if ($tblevel==$totallvl)
$info_cata=" was not damaged.";
else
{
$info_cata=" damaged from level <b>".$tblevel."</b> to level <b>".$totallvl."</b>.";
$buildarray = $GLOBALS["bid".$tbgid];
if ($tbgid==10 || $tbgid==38) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxstore=$t_sql['maxstore']+$buildarray[$totallvl]['attri']-$buildarray[$tblevel]['attri'];
if ($tmaxstore<800) $tmaxstore=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`='".$tmaxstore."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==11 || $tbgid==39) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxcrop=$t_sql['maxcrop']+$buildarray[$totallvl]['attri']-$buildarray[$tblevel]['attri'];
if ($tmaxcrop<800) $tmaxcrop=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid3){
Automation::updateMax($database->getVillageField($data['to'],'owner'));
$allianceStatus = $database->checkAllianceEmbassiesStatus([
'id' => $data['to'],
'alliance' => $database->getUserField($data['to'],"alliance",0),
'username' => $database->getUserField($data['to'],"username",0),
'lvl' => $totallvl
]);
var_dump($Defender, $DefenderID);
die('3');
if ($allianceStatus === false) {
$info_cat .= ' This player\'s alliance has been dispersed.';
} else if ($allianceStatus === 0) {
$info_cat .= ' Player was forced to leave their alliance.';
}
}
$pop=$this->recountPop($data['to']);
}
$info_cat = "".$catp_pic.",".$this->procResType($tbgid,$can_destroy,$isoasis).$info_cata;
$database->setVillageLevel($data['to'],"f".$tbid."",$totallvl);
}
$bdo2=mysqli_query($GLOBALS['link'],"select * from " . TB_PREFIX . "fdata where vref = " . (int) $basearray);
$bdo=mysqli_fetch_array($bdo2);
$rand=$data['ctar2'];
if ($rand != 99)
{
$_rand=array();
$__rand=array();
$j=0;
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$j++;
$_rand[$j]=$bdo['f'.$i];
$__rand[$j]=$i;
}
}
if (count($_rand)>0)
{
if (max($_rand)<=0) $rand=99;
else
{
$rand=rand(1, $j);
$rand=$__rand[$rand];
}
}
else
{
$rand=99;
}
}
if ($rand == 99)
{
$list=array();
$j=0;
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
if ($bdo['f'.$i] > 0)
{
$j++;
$list[$j]=$i;
}
}
$rand=rand(1, $j);
$rand=$list[$rand];
}
$tblevel = $bdo['f'.$rand];
$tbgid = $bdo['f'.$rand.'t'];
$tbid = $rand;
if ($battlepart[4]>$battlepart[3])
{
$info_cat .= "<br><tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> ".$this->procResType($tbgid,$can_destroy,$isoasis)." destroyed.</td></tr></tbody>";
$database->setVillageLevel($data['to'],"f".$tbid."",'0');
if($tbid>=19 && $tbid!=99) { $database->setVillageLevel($data['to'],"f".$tbid."t",'0'); }
$buildarray = $GLOBALS["bid".$tbgid];
if ($tbgid==10 || $tbgid==38) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxstore=$t_sql['maxstore']-$buildarray[$tblevel]['attri'];
if ($tmaxstore<800) $tmaxstore=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`='".$tmaxstore."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==11 || $tbgid==39) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxcrop=$t_sql['maxcrop']-$buildarray[$tblevel]['attri'];
if ($tmaxcrop<800) $tmaxcrop=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==18){
Automation::updateMax($database->getVillageField($data['to'],'owner'));
$allianceStatus = $database->checkAllianceEmbassiesStatus([
'id' => $DefenderID,
'alliance' => $database->getUserField($DefenderID,"alliance",0),
'username' => $database->getUserField($DefenderID,"username",0),
'lvl' => 0
]);
if ($allianceStatus === false) {
$info_cat .= ' This player\'s alliance has been dispersed.';
} else if ($allianceStatus === 0) {
$info_cat .= ' Player was forced to leave their alliance.';
}
}
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
}
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
if($pop=='0' && $can_destroy==1){
$village_destroyed = 1;
}
}
}
elseif ($battlepart[4]==0)
{
$info_cat .= "<br><tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> ".$this->procResType($tbgid,$can_destroy,$isoasis)." was not damaged.</td></tr></tbody>";
}
else
{
$demolish=$battlepart[4]/$battlepart[3];
$totallvl = round(sqrt(pow(($tblevel+0.5),2)-(($battlepart[4]/2)*8)));
if ($tblevel==$totallvl)
$info_cata=" was not damaged.";
else
{
$info_cata=" damaged from level <b>".$tblevel."</b> to level <b>".$totallvl."</b>.";
$buildarray = $GLOBALS["bid".$tbgid];
if ($tbgid==10 || $tbgid==38) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxstore=$t_sql['maxstore']+$buildarray[$totallvl]['attri']-$buildarray[$tblevel]['attri'];
if ($tmaxstore<800) $tmaxstore=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`='".$tmaxstore."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==11 || $tbgid==39) {
$tsql=mysqli_query($GLOBALS['link'],"select `maxstore`,`maxcrop` from ".TB_PREFIX."vdata where wref=".(int) $data['to']);
$t_sql=mysqli_fetch_array($tsql);
$tmaxcrop=$t_sql['maxcrop']+$buildarray[$totallvl]['attri']-$buildarray[$tblevel]['attri'];
if ($tmaxcrop<800) $tmaxcrop=800;
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to'];
$database->query($q);
}
if ($tbgid==18){
Automation::updateMax($database->getVillageField($data['to'],'owner'));
$allianceStatus = $database->checkAllianceEmbassiesStatus([
'id' => $DefenderID,
'alliance' => $database->getUserField($DefenderID,"alliance",0),
'username' => $database->getUserField($DefenderID,"username",0),
'lvl' => $totallvl
]);
if ($allianceStatus === false) {
$info_cat .= ' This player\'s alliance has been dispersed.';
} else if ($allianceStatus === 0) {
$info_cat .= ' Player was forced to leave their alliance.';
}
}
if ($isoasis == 0) {
$pop=$this->recountPop($data['to']);
}
}
$info_cat .= "<br><tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> ".$this->procResType($tbgid,$can_destroy,$isoasis).$info_cata."</td></tr></tbody>";
$database->setVillageLevel($data['to'],"f".$tbid."",$totallvl);
}
} }
} }
} }
} elseif (($data['t7']-$traped7)>0) {
$info_ram = "".$ram_pic.",Hint: The ram does not work during a raid.";
} }
//chiefing village //chiefing village