Fixed an hero bug

The experience was distributed incorrectly if the defender(s)/attacker had more than 1 hero
This commit is contained in:
Pietro
2018-04-03 01:44:27 +02:00
committed by GitHub
parent 09ec695997
commit a749d74dfb
2 changed files with 193 additions and 183 deletions
+36 -26
View File
@@ -1675,6 +1675,30 @@ class Automation {
} }
} }
} }
// we need to save the attacker heroid before the battle
if(isset($Attacker['uhero']) && $Attacker['uhero'] > 0){
$AttackerHeroID = $database->getHeroField($from['owner'],"heroid");
}
// and the defender(s) heroid
$DefendersHeroID = array();
// check if our hero is defending the village, if so, add it to the list
if (isset($Defender['hero']) && $Defender['hero'] > 0) {
$DefendersHeroID[] = $database->getHeroField($DefenderID, "heroid");
}
// check if there are other heroes defending the village
if(count($enforcementarray) > 0){
foreach($enforcementarray as $enforcement){
if($enforcement['hero'] > 0){
$heroOwner = $database->getVillageField($enforcement['from'],"owner");
$DefendersHeroID[] = $database->getHeroField($heroOwner, "heroid");
}
}
}
//to battle.php //to battle.php
//fix by ronix //fix by ronix
//MUST TO BE FIX : You need to filter these values //MUST TO BE FIX : You need to filter these values
@@ -1693,25 +1717,12 @@ class Automation {
}else{ }else{
$unitssend_att_check=$unitssend_att; $unitssend_att_check=$unitssend_att;
} }
//units defence string for battleraport
$DefenderHero=array();
$d=0;
if (isset($Defender['hero'])) {
if ($Defender['hero']>0) {
$d=1;
$DefenderHero[$d]=$DefenderID;
}
}
// our reinforcements count could have changed at this point, thus the re-select // our reinforcements count could have changed at this point, thus the re-select
$enforcementarray2 = $database->getEnforceVillage($data['to'],0); $enforcementarray2 = $database->getEnforceVillage($data['to'],0);
if(count($enforcementarray2) > 0) { if(count($enforcementarray2) > 0) {
foreach($enforcementarray2 as $enforce2) { foreach($enforcementarray2 as $enforce2) {
$Defender['hero'] += $enforce2['hero']; $Defender['hero'] += $enforce2['hero'];
if ($enforce2['hero']>0) {
$d++;
$DefenderHero[$d] = $database->getVillageField($enforce2['from'],"owner");
}
for ($i=1;$i<=50;$i++) { for ($i=1;$i<=50;$i++) {
$Defender['u'.$i]+= $enforce2['u'.$i]; $Defender['u'.$i]+= $enforce2['u'.$i];
} }
@@ -2026,7 +2037,7 @@ class Automation {
if ($Attacker['uhero'] != 0){ if ($Attacker['uhero'] != 0){
$heroxp = $totalpoint_att; $heroxp = $totalpoint_att;
$database->modifyHeroXp("experience",$heroxp,$from['owner']); $database->modifyHeroXp("experience",$heroxp,$AttackerHeroID);
} }
for($i=1;$i<=10;$i++){ for($i=1;$i<=10;$i++){
@@ -2042,12 +2053,12 @@ class Automation {
$totalpoint_def = 0; $totalpoint_def = 0;
} }
$totalpoint_def += $dead11*6; $totalpoint_def += $dead11*6;
if($Defender['hero'] > 0){ if($Defender['hero'] > 0){
//counting heroxp //counting heroxp
$defheroxp=intval($totalpoint_def/count($DefenderHero)); $defheroxp=intval($totalpoint_def/count($DefendersHeroID));
for ($i=1;$i<=count($DefenderHero);$i++){ foreach($DefendersHeroID as $HeroID){
$reinfheroxp = $defheroxp; $database->modifyHeroXp("experience",$defheroxp,$HeroID);
$database->modifyHeroXp("experience",$reinfheroxp,$DefenderHero[$i]);
} }
} }
@@ -2258,8 +2269,9 @@ class Automation {
} else { } else {
$can_destroy=0; $can_destroy=0;
} }
if ($isoasis == 1) $can_destroy=0;
if($isoasis == 0)
{
if ($type=='3') if ($type=='3')
{ {
if (($data['t7']-$traped7)>0){ if (($data['t7']-$traped7)>0){
@@ -2293,9 +2305,6 @@ class Automation {
if (($data['t8']-$traped8)>0) if (($data['t8']-$traped8)>0)
{ {
$pop=$this->recountPop($data['to']); $pop=$this->recountPop($data['to']);
if ($isoasis != 0) {
$pop=10; //oasis cannot be destroy bt cata/ram
}
// village has been destroyed // village has been destroyed
if ($pop<=0) { if ($pop<=0) {
@@ -2448,10 +2457,13 @@ class Automation {
} elseif (($data['t7']-$traped7)>0) { } elseif (($data['t7']-$traped7)>0) {
$info_ram = "".$ram_pic.",Hint: The ram does not work during a raid."; $info_ram = "".$ram_pic.",Hint: The ram does not work during a raid.";
} }
}else{
$can_destroy = 0;
}
//chiefing village //chiefing village
//there are senators //there are senators
if(($data['t9']-$dead9-$traped9)>0){ if(($data['t9']-$dead9-$traped9)>0 && $isoasis==0){
if ($type=='3') { if ($type=='3') {
$palacelevel = $database->getResourceLevel($from['wref']); $palacelevel = $database->getResourceLevel($from['wref']);
@@ -3050,11 +3062,9 @@ class Automation {
$village_destroyed = 0; $village_destroyed = 0;
} }
if ($village_destroyed == 1) { if ($village_destroyed == 1 && $can_destroy==1) {
if($can_destroy==1){
$this->DelVillage($data['to']); $this->DelVillage($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'].'';
+1 -1
View File
@@ -5883,7 +5883,7 @@ References: User ID/Message ID, Mode
function modifyHeroXp($column,$value,$heroid) { function modifyHeroXp($column,$value,$heroid) {
list($column,$value,$heroid) = $this->escape_input($column,(int) $value,(int) $heroid); list($column,$value,$heroid) = $this->escape_input($column,(int) $value,(int) $heroid);
$q = "UPDATE ".TB_PREFIX."hero SET $column = $column + $value WHERE uid=$heroid"; $q = "UPDATE ".TB_PREFIX."hero SET $column = $column + $value WHERE heroid=$heroid";
return mysqli_query($this->dblink,$q); return mysqli_query($this->dblink,$q);
} }