mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
fix: defender troops do not die during attack
This commit is contained in:
+44
-25
@@ -1048,7 +1048,7 @@ class Automation {
|
||||
|
||||
// embassy level was changed
|
||||
if ($tbgid==18){
|
||||
$info_cat .= $database->checkEmbassiesAfterBattle($data['to']);
|
||||
$info_cat .= $database->checkEmbassiesAfterBattle($data['to'], false);
|
||||
}
|
||||
|
||||
// oasis cannot be destroyed
|
||||
@@ -1110,7 +1110,7 @@ class Automation {
|
||||
|
||||
// embassy level was changed
|
||||
if ( $tbgid == 18 ) {
|
||||
$info_cat .= $database->checkEmbassiesAfterBattle( $data['to'] );
|
||||
$info_cat .= $database->checkEmbassiesAfterBattle( $data['to'], false );
|
||||
}
|
||||
|
||||
// no need to recalculate population of oasis, as there is none
|
||||
@@ -1241,7 +1241,7 @@ class Automation {
|
||||
$enforDefender = array();
|
||||
$rom = $ger = $gal = $nat = $natar = 0;
|
||||
$Defender = $database->getUnit($data['to'], false);
|
||||
$enforcementarray = $database->getEnforceVillage($data['to'],0);
|
||||
$enforcementarray = $database->getEnforceVillage($data['to'], 0, false);
|
||||
if(count($enforcementarray) > 0) {
|
||||
|
||||
foreach($enforcementarray as $enforce) {
|
||||
@@ -1261,7 +1261,7 @@ class Automation {
|
||||
for($i=1;$i<=50;$i++){
|
||||
$def_ab[$i]=0;
|
||||
if(!isset($Defender['u'.$i])){
|
||||
$Defender['u'.$i] = '0';
|
||||
$Defender['u'.$i] = 0;
|
||||
} else {
|
||||
if($Defender['u'.$i]=='' || $Defender['u'.$i] <= 0){
|
||||
$Defender['u'.$i] = 0;
|
||||
@@ -1310,7 +1310,7 @@ class Automation {
|
||||
$Attacker['uhero'] = $dataarray[$data_num]['t11'];
|
||||
$hero_pic = "hero";
|
||||
//need to set these variables.
|
||||
$def_wall = $database->getFieldLevel($data['to'],40);
|
||||
$def_wall = $database->getFieldLevel($data['to'], 40, false);
|
||||
$att_tribe = $owntribe;
|
||||
$def_tribe = $targettribe;
|
||||
$residence = "0";
|
||||
@@ -1318,7 +1318,7 @@ class Automation {
|
||||
$defpop = $toF['pop'];
|
||||
$def_ab=array();
|
||||
//get level of palace or residence
|
||||
$residence = $database->getFieldLevelInVillage($data['to'], '25, 26');
|
||||
$residence = $database->getFieldLevelInVillage($data['to'], '25, 26', false);
|
||||
|
||||
//type of attack
|
||||
if($dataarray[$data_num]['attack_type'] == 1){
|
||||
@@ -1358,7 +1358,7 @@ class Automation {
|
||||
//TODO: where did dead7 & traped7 come from??/
|
||||
if (($data['t7']/*-$dead7-$traped7*/)>0 and $type=='3') {
|
||||
$basearraywall = $to;
|
||||
if (($walllevel = $database->getFieldLevel($basearraywall['wref'],40)) > 0){
|
||||
if (($walllevel = $database->getFieldLevel($basearraywall['wref'],40, false)) > 0){
|
||||
$wallgid = $database->getFieldLevel($basearraywall['wref'],"40t");
|
||||
$wallid = 40;
|
||||
$w='4';
|
||||
@@ -1386,8 +1386,8 @@ class Automation {
|
||||
//get defence units
|
||||
$enforDefender = array();
|
||||
$rom = $ger = $gal = $nat = $natar = 0;
|
||||
$Defender = $database->getUnit($data['to']);
|
||||
$enforcementarray = $database->getEnforceVillage($data['to'],0);
|
||||
$Defender = $database->getUnit($data['to'], false);
|
||||
$enforcementarray = $database->getEnforceVillage($data['to'],0, false);
|
||||
|
||||
if(count($enforcementarray) > 0) {
|
||||
foreach($enforcementarray as $enforce) {
|
||||
@@ -1480,8 +1480,13 @@ class Automation {
|
||||
$stonemason = 0;
|
||||
}
|
||||
|
||||
$varray = $database->getProfileVillages($to['owner']);
|
||||
$varray1 = $database->getProfileVillages($from['owner']);
|
||||
$varray = $database->getProfileVillages($to['owner'], false);
|
||||
|
||||
if ($to['owner'] == $from['owner']) {
|
||||
$varray1 = $varray;
|
||||
} else {
|
||||
$varray1 = $database->getProfileVillages($from['owner'], false);
|
||||
}
|
||||
|
||||
//fix by ronix
|
||||
for ($i=1;$i<=50;$i++) {
|
||||
@@ -1491,6 +1496,7 @@ class Automation {
|
||||
|
||||
$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;
|
||||
|
||||
if(PEACE == 0 || $targettribe == 4 || $targettribe == 5){
|
||||
@@ -1503,6 +1509,7 @@ class Automation {
|
||||
}elseif($targettribe == 5){
|
||||
$def_spy = $enforDefender['u54'];
|
||||
}
|
||||
|
||||
//impossible to attack or scout NATAR Capital Village
|
||||
if ($NatarCapital) {
|
||||
for($i=1;$i<=11;$i++){
|
||||
@@ -1534,7 +1541,7 @@ class Automation {
|
||||
}
|
||||
$Attacker['uhero'] -= $traped11;
|
||||
if($totaltraped_att > 0){
|
||||
$prisoners2 = $database->getPrisoners2($data['to'],$data['from']);
|
||||
$prisoners2 = $database->getPrisoners2($data['to'],$data['from'], false);
|
||||
if(empty($prisoners2)){
|
||||
$database->addPrisoners($data['to'],$data['from'],$traped1,$traped2,$traped3,$traped4,$traped5,$traped6,$traped7,$traped8,$traped9,$traped10,$traped11);
|
||||
}else{
|
||||
@@ -1613,7 +1620,7 @@ class Automation {
|
||||
for($i=1;$i<=11;$i++){
|
||||
//MUST TO BE FIX : This is only for defender and still not properly coded
|
||||
if (isset($battlepart['casualties_attacker']) && isset($battlepart['casualties_attacker'][$i]) && $battlepart['casualties_attacker'][$i] <= 0) {
|
||||
${'dead'.$i} = 0;
|
||||
${'dead'.$i} = 0;
|
||||
} else if (isset($data['t'.$i]) && isset($battlepart['casualties_attacker']) && isset($battlepart['casualties_attacker'][$i]) && $battlepart['casualties_attacker'][$i] > $data['t'.$i]) {
|
||||
${'dead'.$i}=$data['t'.$i];
|
||||
} else {
|
||||
@@ -1650,7 +1657,22 @@ class Automation {
|
||||
$start = ($targettribe-1)*10+1;
|
||||
$end = ($targettribe*10);
|
||||
|
||||
if($targettribe == 1){ $u = ""; $rom='1'; } else if($targettribe == 2){ $u = "1"; $ger='1'; } else if($targettribe == 3){$u = "2"; $gal='1'; }else if($targettribe == 4){ $u = "3"; $nat='1'; } else { $u = "4"; $natar='1'; } //FIX
|
||||
if ( $targettribe == 1 ) {
|
||||
$u = "";
|
||||
$rom = '1';
|
||||
} else if ( $targettribe == 2 ) {
|
||||
$u = "1";
|
||||
$ger = '1';
|
||||
} else if ( $targettribe == 3 ) {
|
||||
$u = "2";
|
||||
$gal = '1';
|
||||
} else if ( $targettribe == 4 ) {
|
||||
$u = "3";
|
||||
$nat = '1';
|
||||
} else {
|
||||
$u = "4";
|
||||
$natar = '1';
|
||||
} //FIX
|
||||
|
||||
$unitModifications_units = [];
|
||||
$unitModifications_amounts = [];
|
||||
@@ -1661,7 +1683,7 @@ class Automation {
|
||||
}
|
||||
|
||||
if($unitlist){
|
||||
$owndead[$i] = round($battlepart[2] * (isset($unitlist[0]) ? $unitlist[0]['u'.$i] : 0));
|
||||
$owndead[$i] = round($battlepart[2] * $unitlist['u'.$i]);
|
||||
$unitModifications_units[] = $i;
|
||||
$unitModifications_amounts[] = $owndead[$i];
|
||||
$unitModifications_modes[] = 0;
|
||||
@@ -2071,7 +2093,7 @@ class Automation {
|
||||
}
|
||||
}
|
||||
if ($herosend_att>0){
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit');
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit', false);
|
||||
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
|
||||
}
|
||||
|
||||
@@ -2251,6 +2273,9 @@ class Automation {
|
||||
if (!$catapults2WillNotShoot) {
|
||||
$this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget2, true, true, $catp_pic, $can_destroy, $isoasis, $village_destroyed);
|
||||
}
|
||||
|
||||
// clear resource levels cache, since we might have destroyed buildings/fields by now
|
||||
$database->clearResourseLevelsCache();
|
||||
}
|
||||
}
|
||||
} elseif (($data['t7']-$traped7)>0) {
|
||||
@@ -2486,7 +2511,7 @@ class Automation {
|
||||
|
||||
if ($isoasis != 0) { //oasis fix by ronix
|
||||
if ($to['owner']!=$from['owner']) {
|
||||
$troopcount = $database->countOasisTroops($data['to']);
|
||||
$troopcount = $database->countOasisTroops($data['to'], false);
|
||||
$canqured=$database->canConquerOasis($data['from'],$data['to']);
|
||||
if ($canqured==1 && $troopcount==0) {
|
||||
$database->conquerOasis($data['from'],$data['to']);
|
||||
@@ -2678,10 +2703,7 @@ class Automation {
|
||||
}
|
||||
|
||||
if ($prisoner['t11']>0){
|
||||
$p_qh = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $p_owner." AND dead = 0";
|
||||
$p_resulth = $database->query($p_qh);
|
||||
$p_hero_f=mysqli_fetch_array($p_resulth);
|
||||
$p_hero_unit=$p_hero_f['unit'];
|
||||
$p_hero_unit = $database->getHeroField($p_owner, 'unit', false)['unit'];
|
||||
$p_speeds[] = $GLOBALS['u'.$p_hero_unit]['speed'];
|
||||
}
|
||||
|
||||
@@ -2862,10 +2884,7 @@ class Automation {
|
||||
}
|
||||
}
|
||||
if ($herosend_att>0){
|
||||
$qh = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $from['owner']." AND dead = 0";
|
||||
$resulth = mysqli_query($GLOBALS['link'],$qh);
|
||||
$hero_f=mysqli_fetch_array($resulth);
|
||||
$hero_unit=$hero_f['unit'];
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit', false)['unit'];
|
||||
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
|
||||
}
|
||||
$artefact = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,3,0));
|
||||
|
||||
@@ -311,7 +311,10 @@ class Battle {
|
||||
foreach($DefendersAll as $defenders) {
|
||||
for ($i=1;$i<=50;$i++) {$def_ab[$i]=0;}
|
||||
$fromvillage = $defenders['from'];
|
||||
$enforcetribe = $database->getUserArray($database->getVillageField($fromvillage,"owner"), 1)["tribe"];
|
||||
|
||||
$userdataCache[$fromvillage] = $database->getUserArray($database->getVillageField($fromvillage,"owner"), 1);
|
||||
|
||||
$enforcetribe = $userdataCache[$fromvillage]["tribe"];
|
||||
$ud=($enforcetribe-1)*10;
|
||||
if($defenders['from']>0) { //don't check nature tribe
|
||||
$armory = $database->getABTech($defenders['from']); // Armory level every village enforcement
|
||||
|
||||
+25
-13
@@ -659,7 +659,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
$arrayVariable[$arrayStructure] = [];
|
||||
}
|
||||
|
||||
if (isset($arrayVariable[$arrayStructure]) && !is_null($arrayVariable[$arrayStructure])) {
|
||||
if (isset($arrayVariable[$arrayStructure]) && count($arrayVariable[$arrayStructure])) {
|
||||
return $arrayVariable[$arrayStructure];
|
||||
} else {
|
||||
return null;
|
||||
@@ -1789,7 +1789,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
function getOasisField($ref, $field, $use_cache = true) {
|
||||
// return all data, don't waste time by selecting fields one by one
|
||||
$oasisArray = $this->getOasisV($ref, $use_cache);
|
||||
$result = (isset($oasisArray[$field]) ? $oasisArray[$field] : null);
|
||||
return (isset($oasisArray[$field]) ? $oasisArray[$field] : null);
|
||||
|
||||
/*list($ref, $field) = $this->escape_input((int) $ref, $field);
|
||||
|
||||
@@ -1817,7 +1817,13 @@ class MYSQLi_DB implements IDbConnection {
|
||||
|
||||
$pairs = [];
|
||||
foreach ($field as $index => $fieldValue) {
|
||||
$pairs[] = $this->escape($fieldValue).' = '.((Math::isInt($value[$index]) || Math::isFloat($value[$index])) ? $value[$index] : '"'.$this->escape($value[$index]).'"');
|
||||
$newValue = ((Math::isInt($value[$index]) || Math::isFloat($value[$index])) ? $value[$index] : '"'.$this->escape($value[$index]).'"');
|
||||
$pairs[] = $this->escape($fieldValue).' = '.$newValue;
|
||||
|
||||
// update cache
|
||||
if (isset(self::$villageFieldsCache[$ref])) {
|
||||
self::$villageFieldsCache[$ref][$fieldValue] = $newValue;
|
||||
}
|
||||
}
|
||||
|
||||
$q = "UPDATE " . TB_PREFIX . "vdata SET ".implode(', ', $pairs)." WHERE wref = ".(int) $ref;
|
||||
@@ -1872,6 +1878,11 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return self::$resourceLevelsCache[$vid];
|
||||
}
|
||||
|
||||
public function clearResourseLevelsCache() {
|
||||
self::$resourceLevelsCache = [];
|
||||
self::$fieldLevelsInVillageSearchCache = [];
|
||||
}
|
||||
|
||||
function getAdminLog() {
|
||||
$q = "SELECT id,user,log,time from " . TB_PREFIX . "admin_log where id != 0 ORDER BY id DESC";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
@@ -4216,12 +4227,12 @@ class MYSQLi_DB implements IDbConnection {
|
||||
* 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, $use_cache = true) {
|
||||
// TODO: refactor this and break it into more smaler methods
|
||||
global $session;
|
||||
|
||||
// check whether this player is an alliance owner
|
||||
$isOwner = ($userData['alliance'] && $this->isAllianceOwner($userData['id']) == $userData['alliance']);
|
||||
$isOwner = ($userData['alliance'] && $this->isAllianceOwner($userData['id'], $use_cache) == $userData['alliance']);
|
||||
|
||||
// for demolition, the Embassy was already destroyed, so we need at least 1
|
||||
// Embassy still standing... for battle, the Embassy is still standing
|
||||
@@ -4233,7 +4244,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
// at lvl 1+ standing somewhere
|
||||
if (!$isOwner) {
|
||||
// TODO: replace magic numbers by constants (18 = Embassy)
|
||||
if ($this->getSingleFieldTypeCount($userData['id'], 18, '>=', 1) < $minimumExistingEmbassyRecords) {
|
||||
if ($this->getSingleFieldTypeCount($userData['id'], 18, '>=', 1, $use_cache) < $minimumExistingEmbassyRecords) {
|
||||
|
||||
// the player has no more Embassies, evict them from the alliance
|
||||
mysqli_query($this->dblink, 'UPDATE '.TB_PREFIX.'users SET alliance = 0 WHERE id = '.$userData['id']);
|
||||
@@ -4278,7 +4289,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
}
|
||||
} else {
|
||||
// the player IS an alliance owner, check if we need to take any action
|
||||
$membersCount = $this->countAllianceMembers($userData['alliance']);
|
||||
$membersCount = $this->countAllianceMembers($userData['alliance'], $use_cache);
|
||||
$minAllianceEmbassyLevel = $this->getMinEmbassyLevel($membersCount);
|
||||
|
||||
// in this case, the minimum Embassy level cannot go below 3,
|
||||
@@ -4294,7 +4305,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
&&
|
||||
// check for standing Embassies with sufficient level
|
||||
// TODO: replace magic numbers by constants (18 = Embassy)
|
||||
($this->getSingleFieldTypeCount($userData['id'], 18, '>=', $minAllianceEmbassyLevel) < $minimumExistingEmbassyRecords)
|
||||
($this->getSingleFieldTypeCount($userData['id'], 18, '>=', $minAllianceEmbassyLevel, false, $use_cache) < $minimumExistingEmbassyRecords)
|
||||
);
|
||||
|
||||
// the Embassy got damaged below a sufficient level and there are no more Embassies
|
||||
@@ -4302,7 +4313,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
if ($takeAction) {
|
||||
|
||||
// load all alliance members
|
||||
$members = $this->getAllMember($userData['alliance']);
|
||||
$members = $this->getAllMember($userData['alliance'], 0, $use_cache);
|
||||
|
||||
// if we come from demolition, we need to evict all new members
|
||||
// that accepted an invitation while level 3 of the last
|
||||
@@ -4410,7 +4421,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
} else {
|
||||
// let's determine whether to keep currently attacked player
|
||||
// in the alliance or not
|
||||
if ($userData['lvl'] > 0 || $this->getSingleFieldTypeCount($member['id'], 18, '>=', 1) >= $minimumExistingEmbassyRecords) {
|
||||
if ($userData['lvl'] > 0 || $this->getSingleFieldTypeCount($member['id'], 18, '>=', 1, $use_cache) >= $minimumExistingEmbassyRecords) {
|
||||
$keepCurrentPlayer = true;
|
||||
} else {
|
||||
$keepCurrentPlayer = false;
|
||||
@@ -4483,7 +4494,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkEmbassiesAfterBattle($vid) {
|
||||
function checkEmbassiesAfterBattle($vid, $use_cache = true) {
|
||||
$userData = $this->getUserArray($this->getVillageField($vid,"owner"), 1);
|
||||
|
||||
Automation::updateMax($this->getVillageField($vid,"owner"));
|
||||
@@ -4492,7 +4503,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
'alliance' => $userData["alliance"],
|
||||
'username' => $userData["username"],
|
||||
'lvl' => $totallvl
|
||||
]);
|
||||
], false, $use_cache);
|
||||
|
||||
if ($allianceStatus === false) {
|
||||
return ' This player\'s alliance has been dispersed.';
|
||||
@@ -5081,6 +5092,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
}
|
||||
|
||||
if (!is_array($vid)) {
|
||||
$singleVillage = true;
|
||||
$vid = [$vid];
|
||||
}
|
||||
|
||||
@@ -5114,7 +5126,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
}
|
||||
}
|
||||
|
||||
return ($vidCount > 1 ? $returnArray : reset($returnArray));
|
||||
return (!isset($singleVillage) ? $returnArray : reset($returnArray));
|
||||
}
|
||||
|
||||
// no need to cache this method
|
||||
|
||||
@@ -175,7 +175,9 @@ class Technology {
|
||||
$holder['amt'] = $unitarray['u'.$i];
|
||||
array_push($listArray,$holder);
|
||||
}
|
||||
}if($unitarray['hero'] != 0 && $unitarray['hero'] != "") {
|
||||
}
|
||||
|
||||
if($unitarray['hero'] != 0 && $unitarray['hero'] != "") {
|
||||
$holder['id'] = "hero";
|
||||
$holder['name'] = $this->unarray[$i];
|
||||
$holder['amt'] = $unitarray['hero'];
|
||||
|
||||
Reference in New Issue
Block a user