refactor: alliance and Embassy mechanics refactoring, stage 3 of 3

Battle results logic now accounts for Embassy destruction as per new
alliance and Embassies game mechanics.
This commit is contained in:
Martin Ambrus
2017-11-01 21:37:09 +01:00
parent 041726fbd2
commit 8a3591a8b0
3 changed files with 4692 additions and 4547 deletions
+2 -26
View File
@@ -382,7 +382,7 @@ class Alliance {
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $session->alliance.""; $q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $session->alliance."";
$database->query($q); $database->query($q);
$database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1); $database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1);
$this->updateMax($newleader); Automation::updateMax($newleader);
} }
} }
}else{ }else{
@@ -470,7 +470,7 @@ class Alliance {
$_SESSION['alliance_user'] = 0; $_SESSION['alliance_user'] = 0;
$database->query($q); $database->query($q);
$database->createAlliPermissions($newleader, $session->alliance, 'Alliance Leader', 1, 1, 1, 1, 1, 1, 1, 1); $database->createAlliPermissions($newleader, $session->alliance, 'Alliance Leader', 1, 1, 1, 1, 1, 1, 1, 1);
$this->updateMax($newleader); Automation::updateMax($newleader);
// send the new founder an in-game message, notifying them of their election // send the new founder an in-game message, notifying them of their election
$database->sendMessage( $database->sendMessage(
@@ -537,30 +537,6 @@ class Alliance {
exit; exit;
} }
} }
private function updateMax($leader) {
global $bid18, $database;
$leader = $database->escape((int) $leader);
$q = mysqli_query($GLOBALS['link'],"SELECT * FROM " . TB_PREFIX . "alidata where leader = $leader");
if(mysqli_num_rows($q) > 0){
$villages = $database->getVillagesID2($leader);
$max = 0;
foreach($villages as $village){
$field = $database->getResourceLevel($village['wref']);
for($i=19;$i<=40;$i++){
if($field['f'.$i.'t'] == 18){
$level = $field['f'.$i];
$attri = $bid18[$level]['attri'];
}
}
if($attri > $max){
$max = $attri;
}
}
$q = "UPDATE ".TB_PREFIX."alidata set max = ".(int) $max." where leader = ".(int) $leader;
$database->query($q);
}
}
} }
$alliance = new Alliance; $alliance = new Alliance;
+149 -34
View File
@@ -16,7 +16,6 @@
## ## ## ##
################################################################################# #################################################################################
class Automation { class Automation {
private $bountyresarray = array(); private $bountyresarray = array();
@@ -151,7 +150,7 @@ class Automation {
$dataarray = $$name; $dataarray = $$name;
for ($i = 0; $i <= $lvl; $i++) { for ($i = 0; $i <= $lvl; $i++) {
$popT += $dataarray[$i]['pop']; $popT += ((isset($dataarray[$i]) && isset($dataarray[$i]['pop'])) ? $dataarray[$i]['pop'] : 0);
} }
return $popT; return $popT;
} }
@@ -163,7 +162,7 @@ class Automation {
$dataarray = $$name; $dataarray = $$name;
for ($i = 0; $i <= $lvl; $i++) { for ($i = 0; $i <= $lvl; $i++) {
$popT += $dataarray[$i]['cp']; $popT += ((isset($dataarray[$i]) && $dataarray[$i]['cp']) ? $dataarray[$i]['cp'] : 0);
} }
return $popT; return $popT;
} }
@@ -447,7 +446,7 @@ class Automation {
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $alliance.""; $q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $alliance."";
$database->query($q); $database->query($q);
$database->updateAlliPermissions($newleader, $alliance, "Leader", 1, 1, 1, 1, 1, 1, 1); $database->updateAlliPermissions($newleader, $alliance, "Leader", 1, 1, 1, 1, 1, 1, 1);
$this->updateMax($newleader); Automation::updateMax($newleader);
} }
$database->deleteAlliance($alliance); $database->deleteAlliance($alliance);
$q = "DELETE FROM ".TB_PREFIX."hero where uid = ".(int) $need['uid']; $q = "DELETE FROM ".TB_PREFIX."hero where uid = ".(int) $need['uid'];
@@ -684,7 +683,7 @@ class Automation {
} }
if($indi['type'] == 18){ if($indi['type'] == 18){
$this->updateMax($database->getVillageField($indi['wid'],"owner")); Automation::updateMax($database->getVillageField($indi['wid'],"owner"));
} }
if($indi['type'] == 26 && $level=='1'){ if($indi['type'] == 26 && $level=='1'){
@@ -1086,11 +1085,13 @@ class Automation {
$cannotsend = 0; $cannotsend = 0;
$movements = $database->getMovement("34",$data['to'],1); $movements = $database->getMovement("34",$data['to'],1);
for($y=0;$y < count($movements);$y++){ for($y=0;$y < count($movements);$y++){
if (property_exists($units, $y)) {
$returntime = $units->$y['endtime']-time(); $returntime = $units->$y['endtime']-time();
if($units->$y['sort_type'] == 4 && $units->$y['from'] != 0 && $returntime <= 10){ if($units->$y['sort_type'] == 4 && $units->$y['from'] != 0 && $returntime <= 10){
$cannotsend = 1; $cannotsend = 1;
} }
} }
}
if($evasion == 1 && $maxevasion > 0 && $gold > 1 && $cannotsend == 0 && $dataarray[$data_num]['attack_type'] > 2){ if($evasion == 1 && $maxevasion > 0 && $gold > 1 && $cannotsend == 0 && $dataarray[$data_num]['attack_type'] > 2){
$totaltroops = 0; $totaltroops = 0;
for($i=1;$i<=10;$i++){ for($i=1;$i<=10;$i++){
@@ -1230,7 +1231,7 @@ class Automation {
//rams attack //rams attack
//TODO: where did dead7 & traped7 come from??/ //TODO: where did dead7 & traped7 come from??/
if(($data['t7']-$dead7-$traped7)>0 and $type=='3'){ if(($data['t7']/*-$dead7-$traped7*/)>0 and $type=='3'){
$basearraywall = $database->getMInfo($data['to']); $basearraywall = $database->getMInfo($data['to']);
if($database->getFieldLevel($basearraywall['wref'],40)>'0'){ if($database->getFieldLevel($basearraywall['wref'],40)>'0'){
for ($w=1; $w<2; $w++){ for ($w=1; $w<2; $w++){
@@ -1366,7 +1367,13 @@ class Automation {
$stonemason = "0"; $stonemason = "0";
} }
//fix by ronix //fix by ronix
for ($i=1;$i<=50;$i++) $enforDefender['u'.$i]+=$Defender['u'.$i]; for ($i=1;$i<=50;$i++) {
if (!isset($enforDefender['u'.$i])) {
$enforDefender['u'.$i] = 0;
}
$enforDefender['u'.$i] += (isset($Defender['u'.$i]) ? $Defender['u'.$i] : 0);
}
$defspy=($enforDefender['u4']>0 || $enforDefender['u14']>0 || $enforDefender['u23']>0 || $enforDefender['u44']>0)? true:false; $defspy=($enforDefender['u4']>0 || $enforDefender['u14']>0 || $enforDefender['u23']>0 || $enforDefender['u44']>0)? true:false;
if(PEACE == 0 || $targettribe == 4 || $targettribe == 5){ if(PEACE == 0 || $targettribe == 4 || $targettribe == 5){
@@ -1382,9 +1389,9 @@ class Automation {
//impossible to attack or scout NATAR Capital Village //impossible to attack or scout NATAR Capital Village
if ($NatarCapital) { if ($NatarCapital) {
for($i=1;$i<=11;$i++){ for($i=1;$i<=11;$i++){
${traped.$i}=$data['t'.$i]; ${'traped'.$i}=$data['t'.$i];
} }
}elseif(!$scout || $def_spy >0){ }elseif(!empty($scout) || $def_spy >0){
$traps = $Defender['u99']-$Defender['u99o']; $traps = $Defender['u99']-$Defender['u99o'];
if ($traps<1) $traps=0; if ($traps<1) $traps=0;
for($i=1;$i<=11;$i++){ for($i=1;$i<=11;$i++){
@@ -1392,16 +1399,21 @@ class Automation {
if($data['t'.$i] < $traps1){ if($data['t'.$i] < $traps1){
$traps1 = $data['t'.$i]; $traps1 = $data['t'.$i];
} }
${traped.$i}=$traps1; ${'traped'.$i}=$traps1;
$traps -= $traps1; $traps -= $traps1;
} }
} }
if(!$scout || $def_spy >0 || $NatarCapital){ if(!empty($scout) || $def_spy >0 || $NatarCapital){
for ($i = 1; $i <= 11; $i++) {
if (!isset(${'trapped'.$i})) {
${'trapped'.$i} = 0;
}
}
$totaltraped_att = $traped1+$traped2+$traped3+$traped4+$traped5+$traped6+$traped7+$traped8+$traped9+$traped10+$traped11; $totaltraped_att = $traped1+$traped2+$traped3+$traped4+$traped5+$traped6+$traped7+$traped8+$traped9+$traped10+$traped11;
$database->modifyUnit($data['to'],array("99o"),array($totaltraped_att),array(1)); $database->modifyUnit($data['to'],array("99o"),array($totaltraped_att),array(1));
for($i=$start;$i<=$end;$i++) { for($i=$start;$i<=$end;$i++) {
$j = $i-$start+1; $j = $i-$start+1;
$Attacker['u'.$i] -= ${traped.$j}; $Attacker['u'.$i] -= ${'traped'.$j};
} }
$Attacker['uhero'] -= $traped11; $Attacker['uhero'] -= $traped11;
if($totaltraped_att > 0){ if($totaltraped_att > 0){
@@ -1478,12 +1490,12 @@ class Automation {
for($i=1;$i<=11;$i++){ for($i=1;$i<=11;$i++){
//MUST TO BE FIX : This is only for defender and still not properly coded //MUST TO BE FIX : This is only for defender and still not properly coded
if($battlepart['casualties_attacker'][$i] <= 0) { ${dead.$i} = 0; }elseif($battlepart['casualties_attacker'][$i] > $data['t'.$i]){ if($battlepart['casualties_attacker'][$i] <= 0) { ${'dead'.$i} = 0; }elseif($battlepart['casualties_attacker'][$i] > $data['t'.$i]){
${dead.$i}=$data['t'.$i]; ${'dead'.$i}=$data['t'.$i];
}else { ${dead.$i} = $battlepart['casualties_attacker'][$i]; } }else { ${'dead'.$i} = (isset($battlepart['casualties_attacker'][$i]) ? $battlepart['casualties_attacker'][$i] : 0); }
} }
//if the defender does not have spies, the attacker will not die spies. FIXED BY Armando //if the defender does not have spies, the attacker will not die spies. FIXED BY Armando
if($scout){ if(!empty($scout) && $scout){
$spy_def_Detect=0; $spy_def_Detect=0;
for($i=1;$i<=(50);$i++) { for($i=1;$i<=(50);$i++) {
if($i == 4 || $i == 14 || $i == 23 || $i == 34 || $i == 44){ if($i == 4 || $i == 14 || $i == 23 || $i == 34 || $i == 44){
@@ -1522,7 +1534,7 @@ class Automation {
} }
$owndead['hero']='0'; $owndead['hero']='0';
if($unitlist){ if($unitlist){
$owndead['hero']=$battlepart['deadherodef']; $owndead['hero'] = (isset($battlepart['deadherodef']) ? $battlepart['deadherodef'] : '');
$database->modifyUnit($data['to'],array("hero"),array($owndead['hero']),array(0)); $database->modifyUnit($data['to'],array("hero"),array($owndead['hero']),array(0));
} }
//kill other defence in village //kill other defence in village
@@ -1586,6 +1598,9 @@ class Automation {
} }
$totalsend_att = $data['t1']+$data['t2']+$data['t3']+$data['t4']+$data['t5']+$data['t6']+$data['t7']+$data['t8']+$data['t9']+$data['t10']+$data['t11']; $totalsend_att = $data['t1']+$data['t2']+$data['t3']+$data['t4']+$data['t5']+$data['t6']+$data['t7']+$data['t8']+$data['t9']+$data['t10']+$data['t11'];
for ($i=1;$i<=50;$i++) { for ($i=1;$i<=50;$i++) {
if (!isset($alldead[$i])) {
$alldead[$i] = 0;
}
$alldead[$i] += $owndead[$i]; $alldead[$i] += $owndead[$i];
} }
$unitsdead_def[1] = ''.$alldead['1'].','.$alldead['2'].','.$alldead['3'].','.$alldead['4'].','.$alldead['5'].','.$alldead['6'].','.$alldead['7'].','.$alldead['8'].','.$alldead['9'].','.$alldead['10'].''; $unitsdead_def[1] = ''.$alldead['1'].','.$alldead['2'].','.$alldead['3'].','.$alldead['4'].','.$alldead['5'].','.$alldead['6'].','.$alldead['7'].','.$alldead['8'].','.$alldead['9'].','.$alldead['10'].'';
@@ -1598,6 +1613,15 @@ class Automation {
$unitsdead_deff[3] = '?,?,?,?,?,?,?,?,?,?,'; $unitsdead_deff[3] = '?,?,?,?,?,?,?,?,?,?,';
$unitsdead_deff[4] = '?,?,?,?,?,?,?,?,?,?,'; $unitsdead_deff[4] = '?,?,?,?,?,?,?,?,?,?,';
$unitsdead_deff[5] = '?,?,?,?,?,?,?,?,?,?,'; $unitsdead_deff[5] = '?,?,?,?,?,?,?,?,?,?,';
if (!isset($alldead['hero'])) {
$alldead['hero'] = 0;
}
if (!isset($owndead['hero'])) {
$owndead['hero'] = 0;
}
$deadhero = $alldead['hero']+$owndead['hero']; $deadhero = $alldead['hero']+$owndead['hero'];
$totaldead_alldef_tmp[1] = $alldead['1']+$alldead['2']+$alldead['3']+$alldead['4']+$alldead['5']+$alldead['6']+$alldead['7']+$alldead['8']+$alldead['9']+$alldead['10']; $totaldead_alldef_tmp[1] = $alldead['1']+$alldead['2']+$alldead['3']+$alldead['4']+$alldead['5']+$alldead['6']+$alldead['7']+$alldead['8']+$alldead['9']+$alldead['10'];
@@ -1614,8 +1638,16 @@ class Automation {
$t_units = []; $t_units = [];
$p_units = []; $p_units = [];
for ($i=1;$i<=11;$i++) { for ($i=1;$i<=11;$i++) {
$t_units[] = "t".$i."=t".$i." - ".${dead.$i}; if (!isset(${'dead'.$i})) {
$p_units[] = "t".$i."=t".$i." - ".${traped.$i}; ${'dead'.$i} = 0;
}
if (!isset(${'traped'.$i})) {
${'traped'.$i} = 0;
}
$t_units[] = "t".$i."=t".$i." - ".${'dead'.$i};
$p_units[] = "t".$i."=t".$i." - ".${'traped'.$i};
} }
$database->modifyAttack3($data['ref'],implode(',', $t_units)); $database->modifyAttack3($data['ref'],implode(',', $t_units));
@@ -1646,14 +1678,20 @@ class Automation {
$troopsdead10 = $dead10; $troopsdead10 = $dead10;
$troopsdead11 = $dead11; $troopsdead11 = $dead11;
for($i=1;$i<=50;$i++) { for($i=1;$i<=50;$i++) {
if($unitarray) { reset($unitarray); } if(!empty($unitarray)) { reset($unitarray); }
$unitarray = $GLOBALS["u".$i]; $unitarray = $GLOBALS["u".$i];
if (!isset($totaldead_def)) {
$totaldead_def = 0;
}
$totaldead_def += $alldead[''.$i.'']; $totaldead_def += $alldead[''.$i.''];
if (!isset($totalpoint_att)) {
$totalpoint_att = 0;
}
$totalpoint_att += ($alldead[''.$i.'']*$unitarray['pop']); $totalpoint_att += ($alldead[''.$i.'']*$unitarray['pop']);
} }
$totalpoint_att += ($alldead['hero']*6); $totalpoint_att += ((isset($alldead['hero']) ? $alldead['hero'] : 0)*6);
if ($Attacker['uhero'] != 0){ if ($Attacker['uhero'] != 0){
$heroxp = $totalpoint_att; $heroxp = $totalpoint_att;
@@ -1663,7 +1701,11 @@ class Automation {
for($i=1;$i<=10;$i++){ for($i=1;$i<=10;$i++){
if($unitarray) { reset($unitarray); } if($unitarray) { reset($unitarray); }
$unitarray = $GLOBALS["u".(($att_tribe-1)*10+$i)]; $unitarray = $GLOBALS["u".(($att_tribe-1)*10+$i)];
$totalpoint_def += (${dead.$i}*$unitarray['pop']); $totalpoint_def += (${'dead'.$i}*$unitarray['pop']);
}
if (!isset($totalpoint_def)) {
$totalpoint_def = 0;
} }
$totalpoint_def += $dead11*6; $totalpoint_def += $dead11*6;
if($Defender['hero'] > 0){ if($Defender['hero'] > 0){
@@ -1710,7 +1752,7 @@ class Automation {
}else{ }else{
$artefact_bouns = 1; $artefact_bouns = 1;
} }
$foolartefact = $database->getFoolArtefactInfo(7,$vid,$session->uid); $foolartefact = $database->getFoolArtefactInfo(7,(isset($vid) ? $vid : 0),$session->uid);
if(count($foolartefact) > 0){ if(count($foolartefact) > 0){
foreach($foolartefact as $arte){ foreach($foolartefact as $arte){
if($arte['bad_effect'] == 1){ if($arte['bad_effect'] == 1){
@@ -1995,8 +2037,19 @@ class Automation {
$database->query($q); $database->query($q);
} }
if ($tbgid==18){ if ($tbgid==18){
$this->updateMax($database->getVillageField($data['to'],'owner')); Automation::updateMax($database->getVillageField($data['to'],'owner'));
//$p_alliance = $database->getUserField($data['to'],"alliance",0); $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) { if ($isoasis == 0) {
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
@@ -2039,7 +2092,19 @@ class Automation {
$database->query($q); $database->query($q);
} }
if ($tbgid==18){ if ($tbgid==18){
$this->updateMax($database->getVillageField($data['to'],'owner')); 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.';
}
} }
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
} }
@@ -2125,7 +2190,19 @@ class Automation {
$database->query($q); $database->query($q);
} }
if ($tbgid==18){ if ($tbgid==18){
$this->updateMax($database->getVillageField($data['to'],'owner')); 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) { if ($isoasis == 0) {
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
@@ -2169,8 +2246,22 @@ class Automation {
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to']; $q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`='".$tmaxcrop."' WHERE wref=".(int) $data['to'];
$database->query($q); $database->query($q);
} }
if ($tbgid==18){ if ($tbgid3){
$this->updateMax($database->getVillageField($data['to'],'owner')); 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']); $pop=$this->recountPop($data['to']);
} }
@@ -2254,7 +2345,19 @@ class Automation {
$database->query($q); $database->query($q);
} }
if ($tbgid==18){ if ($tbgid==18){
$this->updateMax($database->getVillageField($data['to'],'owner')); 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) { if ($isoasis == 0) {
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
@@ -2298,7 +2401,19 @@ class Automation {
$database->query($q); $database->query($q);
} }
if ($tbgid==18){ if ($tbgid==18){
$this->updateMax($database->getVillageField($data['to'],'owner')); 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) { if ($isoasis == 0) {
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
@@ -4114,7 +4229,7 @@ $wallimg = "<img src=\"".GP_LOCATE."img/g/g3".$targettribe."Icon.gif\" height=\"
$database->query($q); $database->query($q);
} }
if ($type==18){ if ($type==18){
$this->updateMax($database->getVillageField($vil['vref'],'owner')); Automation::updateMax($database->getVillageField($vil['vref'],'owner'));
} }
if ($level==1) { $clear=",f".$vil['buildnumber']."t=0"; } else { $clear=""; } if ($level==1) { $clear=",f".$vil['buildnumber']."t=0"; } else { $clear=""; }
if ($village->natar==1 && $type==40) $clear=""; //fix by ronix if ($village->natar==1 && $type==40) $clear=""; //fix by ronix
@@ -4751,7 +4866,7 @@ $wallimg = "<img src=\"".GP_LOCATE."img/g/g3".$targettribe."Icon.gif\" height=\"
} }
} }
public function updateMax($leader) { public static function updateMax($leader) {
global $bid18, $database; global $bid18, $database;
$q = mysqli_query($GLOBALS['link'],"SELECT * FROM " . TB_PREFIX . "alidata where leader = ". (int) $leader); $q = mysqli_query($GLOBALS['link'],"SELECT * FROM " . TB_PREFIX . "alidata where leader = ". (int) $leader);
if(mysqli_num_rows($q) > 0){ if(mysqli_num_rows($q) > 0){
@@ -4769,7 +4884,7 @@ $wallimg = "<img src=\"".GP_LOCATE."img/g/g3".$targettribe."Icon.gif\" height=\"
$max = $attri; $max = $attri;
} }
} }
$q = "UPDATE ".TB_PREFIX."alidata set max = $max where leader = $leader"; $q = "UPDATE ".TB_PREFIX."alidata set max = ".(int) $max." where leader = ".(int) $leader;
$database->query($q); $database->query($q);
} }
} }
+71 -17
View File
@@ -2963,11 +2963,14 @@ class MYSQLi_DB implements IDbConnection {
* *
* @return boolean Returns TRUE if there was no change * @return boolean Returns TRUE if there was no change
* to the player-alliance relationship * to the player-alliance relationship
* FALSE otherwise. * FALSE if the player was an alliance
* leader and the alliance was destroyed
* and 0 when the player was evicted from
* the alliance due to Embassy damage.
*/ */
public function checkAllianceEmbassiesStatus($userData, $demolition = false) { public function checkAllianceEmbassiesStatus($userData, $demolition = false) {
// TODO: refactor this and break it into more smaler methods // TODO: refactor this and break it into more smaler methods
global $session, $automation; global $session;
// check whether this player is an alliance owner // check whether this player is an alliance owner
$isOwner = ($userData['alliance'] && $this->isAllianceOwner($userData['id']) == $userData['alliance']); $isOwner = ($userData['alliance'] && $this->isAllianceOwner($userData['id']) == $userData['alliance']);
@@ -3000,7 +3003,7 @@ class MYSQLi_DB implements IDbConnection {
$userData['id'], $userData['id'],
2, 2,
'You left the alliance', 'You left the alliance',
"Hi, ".$userData['username']."!\n\nThis is to inform you that due to a finished demolition of your last Embassy, you have now successfully left your alliance.\n\nYours sincerely,\n<i>Server Robot :)</i>", $this->escape("Hi, ".$userData['username']."!\n\nThis is to inform you that due to a finished demolition of your last Embassy, you have now successfully left your alliance.\n\nYours sincerely,\n<i>Server Robot :)</i>"),
0, 0,
0, 0,
0, 0,
@@ -3009,7 +3012,19 @@ class MYSQLi_DB implements IDbConnection {
true); true);
} else { } else {
// player has been removed from the alliance // player has been removed from the alliance
return false; $this->sendMessage(
$userData['id'],
2,
'An attack has forced you to leave the alliance',
$this->escape("Hi, ".$userData['username']."!\n\nThis is to inform you that due to a successful attack and destruction of your last Embassy, you have been forced to leave your alliance.\n\nTo re-establish your position in this alliance, you will need to build a new Embassy and ask the leader to send you an invite again.\n\nYours sincerely,\n<i>Server Robot :)</i>"),
0,
0,
0,
0,
0,
true);
return 0;
} }
} }
@@ -3059,9 +3074,9 @@ class MYSQLi_DB implements IDbConnection {
( (
($member['id'] == $userData['id']) ($member['id'] == $userData['id'])
? ?
"Hi, ".$userData['username']."!\n\nThis is to inform you that due to a finished demolition of your last Embassy at level 3, and the fact that you were the leader of your alliance, this alliance has been disbanded.\n\nIn order to found a new alliance, please build a level 3 Embassy again in one of your villages.\n\nYours sincerely,\n<i>Server Robot :)</i>" $this->escape("Hi, ".$userData['username']."!\n\nThis is to inform you that due to a finished demolition of your last Embassy at level 3, and the fact that you were the leader of your alliance, this alliance has been disbanded.\n\nIn order to found a new alliance, please build a level 3 Embassy again in one of your villages.\n\nYours sincerely,\n<i>Server Robot :)</i>")
: :
"Hi, ".$userData['username']."!\n\nThis is to inform you that due to a demolition of your alliance founder's last Embassy below level 3, this alliance has been disbanded.\n\n\You can now accept invitations from other alliances or found a new alliance yourself.\n\nYours sincerely,\n<i>Server Robot :)</i>" $this->escape("Hi, ".$member['username']."!\n\nThis is to inform you that due to a demolition of your alliance founder's last Embassy below level 3, this alliance has been disbanded.\n\n\You can now accept invitations from other alliances or found a new alliance yourself.\n\nYours sincerely,\n<i>Server Robot :)</i>")
), ),
0, 0,
0, 0,
@@ -3079,15 +3094,18 @@ class MYSQLi_DB implements IDbConnection {
// we'll collect them inside this foeach loop // we'll collect them inside this foeach loop
$memberIDs = []; $memberIDs = [];
foreach ($member as $member) { // no need for this whole foreach loop if this player is the lone
if (!$newLeaderFound && $this->getSingleFieldTypeCount($member['id'], 18, '>=', $minAllianceEmbassyLevel) >= $minimumExistingEmbassyRecords) { // founder and member of their alliance
if ($membersCount > 1) {
foreach ($members as $member) {
if (!$newLeaderFound && $this->getSingleFieldTypeCount($member['id'], 18, '>=', $minAllianceEmbassyLevel) >= 1) {
// found a new leader for the alliance // found a new leader for the alliance
$newLeaderFound = true; $newLeaderFound = true;
$newleader = $member['id']; $newleader = $member['id'];
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $userData['alliance']; $q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $userData['alliance'];
$this->query($q); $this->query($q);
$this->updateAlliPermissions($newleader, $userData['alliance'], "Leader", 1, 1, 1, 1, 1, 1, 1); $this->updateAlliPermissions($newleader, $userData['alliance'], "Leader", 1, 1, 1, 1, 1, 1, 1);
$automation->updateMax($newleader); Automation::updateMax($newleader);
// update permissions for the old leader // update permissions for the old leader
$this->updateAlliPermissions($userData['id'], $userData['alliance'], "Former Leader", 0, 0, 0, 0, 0, 0, 0); $this->updateAlliPermissions($userData['id'], $userData['alliance'], "Former Leader", 0, 0, 0, 0, 0, 0, 0);
@@ -3096,8 +3114,8 @@ class MYSQLi_DB implements IDbConnection {
$this->sendMessage( $this->sendMessage(
$newleader, $newleader,
2, 2,
'You are now an alliance leader', 'You are now the alliance leader',
"Hi, ".$userData['username']."!\n\nThis is to inform you that there was a successful attack on player <a href=\"spieler.php?uid=".$userData['id']."\">".$userData['username']."</a> which has damaged their Embassy badly enough that they are no longer able to sustain the leadership of your alliance.\n\nSince your Embassy level is of a sufficient level, you have been auto-elected to the position of a new leader of your alliance with all duties and responsibilities thereof.\n\nYours sincerely,\n<i>Server Robot :)</i>", $this->escape("Hi, ".$member['username']."!\n\nThis is to inform you that there was a successful attack on player <a href=\"spieler.php?uid=".$userData['id']."\">".$userData['username']."</a> which has damaged their Embassy badly enough that they are no longer able to sustain the leadership of your alliance.\n\nSince your Embassy level is of a sufficient level, you have been auto-elected to the position of a new leader of your alliance with all duties and responsibilities thereof.\n\nYours sincerely,\n<i>Server Robot :)</i>"),
0, 0,
0, 0,
0, 0,
@@ -3108,6 +3126,10 @@ class MYSQLi_DB implements IDbConnection {
$memberIDs[] = $member['id']; $memberIDs[] = $member['id'];
} }
} else {
// if there is only 1 member and it's the actual founder
$memberIDs[] = $userData['id'];
}
// if there wasn't anyone with a sufficient level of Embassy // if there wasn't anyone with a sufficient level of Embassy
// among the existing members, disperse this alliance // among the existing members, disperse this alliance
@@ -3117,17 +3139,17 @@ class MYSQLi_DB implements IDbConnection {
mysqli_query($this->dblink, 'UPDATE '.TB_PREFIX.'users SET alliance = 0 WHERE id IN('.implode(',', $memberIDs).")"); mysqli_query($this->dblink, 'UPDATE '.TB_PREFIX.'users SET alliance = 0 WHERE id IN('.implode(',', $memberIDs).")");
// notify all of them via in-game messaging // notify all of them via in-game messaging
foreach ($memberIDs as $id) { foreach ($members as $member) {
$this->sendMessage( $this->sendMessage(
$id, $member['id'],
2, 2,
'Your alliance was dispersed', 'Your alliance was dispersed',
( (
($id == $userData['id']) ($member['id'] == $userData['id'])
? ?
"Hi, ".$userData['username']."!\n\nThis is to inform you that due to a successful attack that has degraded your last Embassy to a level which is unable to hold all ".$membersCount." alliance members, and because there was no other alliance member with an Embassy on a high enough level to overtake the leadership, your alliance has been dispersed.\n\nYours sincerely,\n<i>Server Robot :)</i>" $this->escape("Hi, ".$userData['username']."!\n\nThis is to inform you that due to a successful attack that has degraded your last Embassy to a level ".($membersCount > 1 ? "which is unable to hold all ".$membersCount." alliance members, and because there was no other alliance member with an Embassy on a high enough level to overtake the leadership," : "lower then 3 - which is required to found and hold your own alliance - ")." your alliance has been dispersed.\n\nYours sincerely,\n<i>Server Robot :)</i>")
: :
"Hi, ".$userData['username']."!\n\nThis is to inform you that due to a successful attack on your alliance leader's Embassy by another player that degraded it below threshold allowed to hold all ".$membersCount." alliance members, and because there was no other alliance member with an Embassy on a high enough level to overtake the leadership, your alliance has been dispersed.\n\nYours sincerely,\n<i>Server Robot :)</i>" $this->escape("Hi, ".$member['username']."!\n\nThis is to inform you that due to a successful attack on your alliance leader's Embassy by another player that degraded it below threshold allowed to hold all ".$membersCount." alliance members, and because there was no other alliance member with an Embassy on a high enough level to overtake the leadership, your alliance has been dispersed.\n\nYours sincerely,\n<i>Server Robot :)</i>")
), ),
0, 0,
0, 0,
@@ -3136,6 +3158,31 @@ class MYSQLi_DB implements IDbConnection {
0, 0,
true); true);
} }
} else {
// if a new leader was found, notify all alliance member of this change
// notify all of them via in-game messaging
foreach ($members as $member) {
// don't send duplicate messages to the new leader
if ($member['id'] != $newleader) {
$this->sendMessage(
$member['id'],
2,
'Your alliance has a new leader',
(
($member['id'] == $userData['id'])
?
$this->escape("Hi, ".$userData['username']."!\n\nThis is to inform you that due to a successful attack that has degraded your last Embassy to a level which is unable to hold all ".$membersCount." alliance members, another alliance member who meets these criteria has been auto-elected as a new alliance leader.\n\nAdditionally - due to the Embassy destruction - you have been forcefuly evicted from your alliance.\n\nPlease re-establish the connection with your alliance by building a new Embassy and contacting <a href=\"spieler.php?uid=".$newleader."\">the new leader</a> for an invitation.\n\nYours sincerely,\n<i>Server Robot :)</i>")
:
$this->escape("Hi, ".$member['username']."!\n\nThis is to inform you that due to a successful attack on your alliance leader's Embassy by another player, <a href=\"spieler.php?uid=".$newleader."\">another alliance member</a> with enough Embassy capacity has been auto-elected as the new alliance leader.\n\nYours sincerely,\n<i>Server Robot :)</i>")
),
0,
0,
0,
0,
0,
true);
}
}
} }
} }
@@ -3149,7 +3196,7 @@ class MYSQLi_DB implements IDbConnection {
$_SESSION['alliance_user'] = 0; $_SESSION['alliance_user'] = 0;
} }
return false; return ((isset($newLeaderFound) && $newLeaderFound === true) ? true : false);
} }
} }
@@ -4006,8 +4053,15 @@ class MYSQLi_DB implements IDbConnection {
if(!empty($outgoingarray)) { if(!empty($outgoingarray)) {
foreach($outgoingarray as $out) { foreach($outgoingarray as $out) {
for($i = 1; $i <= 10; $i++) { 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)] += $out['t' . $i]; $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $out['t' . $i];
} }
if (!isset($movingunits['hero'])) {
$movingunits['hero'] = 0;
}
$movingunits['hero'] += $out['t11']; $movingunits['hero'] += $out['t11'];
} }
} }