mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-09-23 10:26:42 +08:00
General fixes
+Fixed a bug that didn't permit to destroy the capital if the player had more than 1 village. The capital is now destroyable (if the player has more than 1 village) +Fixed a bug that updated the hero wref wrongly when reinforcing their own villages +Fixed a bug that didn't kill the hero if his village was destroyed while he was sent to another village as a reinforcement +Better indentation +General improovements
This commit is contained in:
+43
-37
@@ -1005,7 +1005,7 @@ class Automation {
|
|||||||
$toF = $database->getVillage($data['to']);
|
$toF = $database->getVillage($data['to']);
|
||||||
$conqureby = 0;
|
$conqureby = 0;
|
||||||
$NatarCapital = ($toF['owner'] == 3 && $toF['capital'] == 1);
|
$NatarCapital = ($toF['owner'] == 3 && $toF['capital'] == 1);
|
||||||
if(!isset($to['name']) || $to['name']=='') $to['name']="??";
|
if(!isset($to['name']) || $to['name'] == '') $to['name'] = "[?]";
|
||||||
|
|
||||||
$DefenderUnit = [];
|
$DefenderUnit = [];
|
||||||
$DefenderUnit = $database->getUnit($data['to']);
|
$DefenderUnit = $database->getUnit($data['to']);
|
||||||
@@ -1243,15 +1243,11 @@ class Automation {
|
|||||||
|
|
||||||
// total population of the defender
|
// total population of the defender
|
||||||
if($isoasis == 0){
|
if($isoasis == 0){
|
||||||
foreach($varray as $defenderVillage){
|
foreach($varray as $defenderVillage) $defpop += $defenderVillage['pop'];
|
||||||
$defpop += $defenderVillage['pop'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// total population of the attacker
|
// total population of the attacker
|
||||||
foreach($varray1 as $attackerVillage){
|
foreach($varray1 as $attackerVillage) $attpop += $attackerVillage['pop'];
|
||||||
$attpop += $attackerVillage['pop'];
|
|
||||||
}
|
|
||||||
|
|
||||||
//fix by ronix
|
//fix by ronix
|
||||||
for ($i = 1; $i <= 50; $i++) {
|
for ($i = 1; $i <= 50; $i++) {
|
||||||
@@ -1830,8 +1826,9 @@ class Automation {
|
|||||||
// Data for when troops return.
|
// Data for when troops return.
|
||||||
//catapults look :D
|
//catapults look :D
|
||||||
$info_cat = $info_chief = $info_ram = $info_hero = ",";
|
$info_cat = $info_chief = $info_ram = $info_hero = ",";
|
||||||
|
|
||||||
//check to see if can destroy village
|
//check to see if can destroy village
|
||||||
if (count($varray) != 1 && $to['capital'] != 1 && !$database->villageHasArtefact($DefenderWref)) {
|
if (count($varray) > 1 && !$database->villageHasArtefact($DefenderWref)) {
|
||||||
$can_destroy = 1;
|
$can_destroy = 1;
|
||||||
}
|
}
|
||||||
else $can_destroy = 0;
|
else $can_destroy = 0;
|
||||||
@@ -2044,7 +2041,7 @@ class Automation {
|
|||||||
|
|
||||||
//check for last village or capital
|
//check for last village or capital
|
||||||
if($user_cps >= $need_cps){
|
if($user_cps >= $need_cps){
|
||||||
if(count($varray) != 1 && $to['capital'] != 1 && $villexp < $canconquer){
|
if(count($varray) > 1 && $to['capital'] != 1 && $villexp < $canconquer){
|
||||||
if($to['owner'] != 3 || $to['name'] != 'WW Buildingplan'){
|
if($to['owner'] != 3 || $to['name'] != 'WW Buildingplan'){
|
||||||
// check for standing Palace or Residence
|
// check for standing Palace or Residence
|
||||||
// note: at this point, we can use cache, since we've cleared it above
|
// note: at this point, we can use cache, since we've cleared it above
|
||||||
@@ -2526,7 +2523,26 @@ class Automation {
|
|||||||
|
|
||||||
if (!isset($village_destroyed)) $village_destroyed = 0;
|
if (!isset($village_destroyed)) $village_destroyed = 0;
|
||||||
|
|
||||||
if ($village_destroyed == 1 && $can_destroy == 1) $this->DelVillage($data['to']);
|
if ($village_destroyed == 1 && $can_destroy == 1)
|
||||||
|
{
|
||||||
|
if($to['capital'] == 1){
|
||||||
|
$mostPopulatedVillage = [];
|
||||||
|
//Search for the most populated village
|
||||||
|
foreach($varray as $village){
|
||||||
|
if($village['wref'] != $data['to'] && (empty($mostPopulatedVillage) || $mostPopulatedVillage['pop'] < $village['pop'])){
|
||||||
|
$mostPopulatedVillage = $village;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Set the new capital
|
||||||
|
$database->changeCapital($mostPopulatedVillage['wref']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete the village
|
||||||
|
$this->DelVillage($data['to']);
|
||||||
|
|
||||||
|
//Reassign the hero, if dead and assigned to the deleted village
|
||||||
|
$database->reassignHero($data['to']);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
//units attack string for battleraport
|
//units attack string for battleraport
|
||||||
$unitssend_att1 = ''.$data['t1'].','.$data['t2'].','.$data['t3'].','.$data['t4'].','.$data['t5'].','.$data['t6'].','.$data['t7'].','.$data['t8'].','.$data['t9'].','.$data['t10'].'';
|
$unitssend_att1 = ''.$data['t1'].','.$data['t2'].','.$data['t3'].','.$data['t4'].','.$data['t5'].','.$data['t6'].','.$data['t7'].','.$data['t8'].','.$data['t9'].','.$data['t10'].'';
|
||||||
@@ -2808,33 +2824,7 @@ class Automation {
|
|||||||
$AttackerID = $from['owner'];
|
$AttackerID = $from['owner'];
|
||||||
$owntribe = $database->getUserField($AttackerID,"tribe",0);
|
$owntribe = $database->getUserField($AttackerID,"tribe",0);
|
||||||
|
|
||||||
//check to see if we're sending a hero between own villages and there's a Mansion at target village
|
|
||||||
$HeroTransfer = $troopsPresent = 0;
|
$HeroTransfer = $troopsPresent = 0;
|
||||||
if($data['t11'] != 0) {
|
|
||||||
if($AttackerID == $DefenderID) {
|
|
||||||
// only add hero if we're sending him alone
|
|
||||||
if (
|
|
||||||
($this->getTypeLevel(37, $data['to']) > 0) &&
|
|
||||||
($data['t1'] == 0) &&
|
|
||||||
($data['t2'] == 0) &&
|
|
||||||
($data['t3'] == 0) &&
|
|
||||||
($data['t4'] == 0) &&
|
|
||||||
($data['t5'] == 0) &&
|
|
||||||
($data['t6'] == 0) &&
|
|
||||||
($data['t7'] == 0) &&
|
|
||||||
($data['t8'] == 0) &&
|
|
||||||
($data['t9'] == 0) &&
|
|
||||||
($data['t10'] == 0)
|
|
||||||
) {
|
|
||||||
//don't reinforce, addunit instead
|
|
||||||
$database->modifyUnit($data['to'], ["hero"], [1], [1]);
|
|
||||||
$heroid = $database->getHeroField($DefenderID, 'heroid');
|
|
||||||
$database->modifyHero("wref", $data['to'], $heroid, 0);
|
|
||||||
$HeroTransfer = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for($i = 1;$i <= 10; $i++) {
|
for($i = 1;$i <= 10; $i++) {
|
||||||
if($data['t'.$i] > 0) {
|
if($data['t'.$i] > 0) {
|
||||||
$troopsPresent = 1;
|
$troopsPresent = 1;
|
||||||
@@ -2842,7 +2832,23 @@ class Automation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($data['t11'] != 0 || $troopsPresent) {
|
//check if the hero is present and we're not sending him to an occupied oasis
|
||||||
|
//only add hero if we're sending him alone
|
||||||
|
if($data['t11'] > 0 && !$isoasis && !$troopsPresent) {
|
||||||
|
//check if we're sending a hero between own villages
|
||||||
|
if($AttackerID == $DefenderID) {
|
||||||
|
//check if there's a Mansion at target village
|
||||||
|
if($this->getTypeLevel(37, $data['to']) > 0){
|
||||||
|
//don't reinforce, addunit instead
|
||||||
|
$database->modifyUnit($data['to'], ["hero"], [1], [1]);
|
||||||
|
$heroid = $database->getHeroField($DefenderID, 'heroid');
|
||||||
|
$database->modifyHero("wref", $data['to'], $heroid);
|
||||||
|
$HeroTransfer = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($data['t11'] > 0 || $troopsPresent) {
|
||||||
$temphero = $data['t11'];
|
$temphero = $data['t11'];
|
||||||
if ($HeroTransfer) $data['t11'] = 0;
|
if ($HeroTransfer) $data['t11'] = 0;
|
||||||
//check if there is defence from town in to town
|
//check if there is defence from town in to town
|
||||||
|
|||||||
+31
-4
@@ -1013,11 +1013,8 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
$vdata = $this->getProfileVillages($ref);
|
$vdata = $this->getProfileVillages($ref);
|
||||||
|
|
||||||
foreach($vdata as $village){
|
foreach($vdata as $village){
|
||||||
if ($village['capital']) {
|
if($village['capital']) return $village;
|
||||||
return $village;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7939,6 +7936,36 @@ References:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the hero to the capital village and kills it
|
||||||
|
*
|
||||||
|
* @param int $wref The village ID where the hero is registered
|
||||||
|
* @return bool Return true if the query was successful, false otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
function reassignHero($wref){
|
||||||
|
$q = "UPDATE
|
||||||
|
".TB_PREFIX."hero AS hero
|
||||||
|
INNER JOIN ".TB_PREFIX."vdata AS vdata
|
||||||
|
ON vdata.owner = hero.uid AND vdata.capital = 1
|
||||||
|
SET
|
||||||
|
hero.dead = 1, hero.health = 0, hero.wref = vdata.wref
|
||||||
|
WHERE
|
||||||
|
hero.wref = $wref";
|
||||||
|
return mysqli_query($this->dblink, $q);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changed the actual capital with a new one
|
||||||
|
*
|
||||||
|
* @param int $wref The village ID that will became the new capital
|
||||||
|
* @return bool Return true if the query was successful, false otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
function changeCapital($wref){
|
||||||
|
$q = "UPDATE ".TB_PREFIX."vdata SET capital = 1 WHERE wref = $wref";
|
||||||
|
return mysqli_query($this->dblink, $q);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// database is not needed if we're displaying static pages
|
// database is not needed if we're displaying static pages
|
||||||
|
|||||||
@@ -224,25 +224,23 @@ class Units {
|
|||||||
|
|
||||||
public function returnTroops($wref, $mode = 0) {
|
public function returnTroops($wref, $mode = 0) {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if(!$mode){
|
if(!$mode){
|
||||||
$getenforce = $database->getEnforceVillage($wref, 0);
|
$getenforce = $database->getEnforceVillage($wref, 0);
|
||||||
foreach($getenforce as $enforce) {
|
foreach($getenforce as $enforce) $this->processReturnTroops($enforce);
|
||||||
$this->processReturnTroops($enforce);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check oasis
|
// check oasis
|
||||||
$getenforce1 = $database->getOasisEnforce($wref, 1);
|
$getenforce1 = $database->getOasisEnforce($wref, 1);
|
||||||
foreach($getenforce1 as $enforce) {
|
foreach($getenforce1 as $enforce) $this->processReturnTroops($enforce);
|
||||||
$this->processReturnTroops($enforce);
|
|
||||||
}
|
|
||||||
// set oasis to default
|
// set oasis to default
|
||||||
if (count($getenforce1)>0) {
|
if(count($getenforce1) > 0) $database->regenerateOasisUnits($getenforce1[0]['vref']);
|
||||||
$database->regenerateOasisUnits($getenforce1[0]['vref']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processReturnTroops($enforce) {
|
private function processReturnTroops($enforce) {
|
||||||
global $database, $generator;
|
global $database, $generator;
|
||||||
|
|
||||||
$to = $database->getVillage($enforce['from']);
|
$to = $database->getVillage($enforce['from']);
|
||||||
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user