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
+192 -182
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,200 +2269,201 @@ class Automation {
} else { } else {
$can_destroy=0; $can_destroy=0;
} }
if ($isoasis == 1) $can_destroy=0;
if ($type=='3') if($isoasis == 0)
{ {
if (($data['t7']-$traped7)>0){ if ($type=='3')
if (isset($empty)){ {
$info_ram = "".$ram_pic.",There is no wall to destroy."; if (($data['t7']-$traped7)>0){
} else if (isset($empty)){
$info_ram = "".$ram_pic.",There is no wall to destroy.";
if ($battlepart[8]>$battlepart[7]){ } else
$info_ram = "".$ram_pic.",Wall destroyed.";
$database->setVillageLevel( if ($battlepart[8]>$battlepart[7]){
$data['to'], $info_ram = "".$ram_pic.",Wall destroyed.";
["f".$wallid, "f".$wallid."t"], $database->setVillageLevel(
[0, 0] $data['to'],
); ["f".$wallid, "f".$wallid."t"],
$pop=$this->recountPop($data['to']); [0, 0]
);
}elseif ($battlepart[8]==0){ $pop=$this->recountPop($data['to']);
$info_ram = "".$ram_pic.",Wall was not damaged."; }elseif ($battlepart[8]==0){
}else{
$totallvl = round(sqrt(pow(($walllevel+0.5),2)-($battlepart[8]*8)));
if($walllevel == $totallvl){
$info_ram = "".$ram_pic.",Wall was not damaged."; $info_ram = "".$ram_pic.",Wall was not damaged.";
}else{ }else{
$info_ram = "".$ram_pic.",Wall damaged from level <b>".$walllevel."</b> to level <b>".$totallvl."</b>."; $totallvl = round(sqrt(pow(($walllevel+0.5),2)-($battlepart[8]*8)));
$database->setVillageLevel($data['to'],"f".$wallid."",$totallvl); if($walllevel == $totallvl){
$info_ram = "".$ram_pic.",Wall was not damaged.";
}else{
$info_ram = "".$ram_pic.",Wall damaged from level <b>".$walllevel."</b> to level <b>".$totallvl."</b>.";
$database->setVillageLevel($data['to'],"f".$wallid."",$totallvl);
}
} }
} }
}
if (($data['t8']-$traped8)>0)
if (($data['t8']-$traped8)>0)
{
$pop=$this->recountPop($data['to']);
if ($isoasis != 0) {
$pop=10; //oasis cannot be destroy bt cata/ram
}
// village has been destroyed
if ($pop<=0) {
if ($can_destroy==1) {
$info_cat = "".$catp_pic.", Village already destroyed.";
} else {
$info_cat = "".$catp_pic.", Village can\'t be destroyed.";
}
}
else
{ {
// village stands, let's do the damage $pop=$this->recountPop($data['to']);
/**
* FIRST CATAPULTS ROW // village has been destroyed
*/ if ($pop<=0) {
$basearray = $data['to']; if ($can_destroy==1) {
$bdo = $database->getResourceLevel($basearray, false); $info_cat = "".$catp_pic.", Village already destroyed.";
$catapultTarget = $data['ctar1']; } else {
$catapultTarget2 = (isset($data['ctar2']) ? $data['ctar2'] : 0); $info_cat = "".$catp_pic.", Village can\'t be destroyed.";
$catapults1TargetRandom = ($catapultTarget == 0);
$catapults2WillNotShoot = ($catapultTarget2 == 0);
$catapults2TargetRandom = ($catapults2WillNotShoot || $catapultTarget2 == 99);
// we're manually targetting 1st and/or 2nd row of catapults
if (!$catapults1TargetRandom)
{
$_catapultsTarget1Levels=array();
$__catapultsTarget1AltTargets=array();
// calculate targets for 1st rows of catapults
$j=0;
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
// 1st row of catapults pre-selected target calculations, if needed
if (!$catapults1TargetRandom && $bdo['f'.$i.'t'] == $catapultTarget && $bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33)
{
$j++;
$_catapultsTarget1Levels[$j]=$bdo['f'.$i];
$__catapultsTarget1AltTargets[$j]=$i;
}
} }
}
// if we couldn't find a suitable target for 1st row of catapults, else
// select a random target instead {
if (!$catapults1TargetRandom) { // village stands, let's do the damage
if ( count( $_catapultsTarget1Levels ) > 0 ) { /**
if ( max( $_catapultsTarget1Levels ) <= 0 ) { * FIRST CATAPULTS ROW
*/
$basearray = $data['to'];
$bdo = $database->getResourceLevel($basearray, false);
$catapultTarget = $data['ctar1'];
$catapultTarget2 = (isset($data['ctar2']) ? $data['ctar2'] : 0);
$catapults1TargetRandom = ($catapultTarget == 0);
$catapults2WillNotShoot = ($catapultTarget2 == 0);
$catapults2TargetRandom = ($catapults2WillNotShoot || $catapultTarget2 == 99);
// we're manually targetting 1st and/or 2nd row of catapults
if (!$catapults1TargetRandom)
{
$_catapultsTarget1Levels=array();
$__catapultsTarget1AltTargets=array();
// calculate targets for 1st rows of catapults
$j=0;
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
// 1st row of catapults pre-selected target calculations, if needed
if (!$catapults1TargetRandom && $bdo['f'.$i.'t'] == $catapultTarget && $bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33)
{
$j++;
$_catapultsTarget1Levels[$j]=$bdo['f'.$i];
$__catapultsTarget1AltTargets[$j]=$i;
}
}
// if we couldn't find a suitable target for 1st row of catapults,
// select a random target instead
if (!$catapults1TargetRandom) {
if ( count( $_catapultsTarget1Levels ) > 0 ) {
if ( max( $_catapultsTarget1Levels ) <= 0 ) {
$catapultTarget = 0;
} else {
$catapultTarget = $__catapultsTarget1AltTargets[ rand( 1, $j ) ];
}
} else {
$catapultTarget = 0; $catapultTarget = 0;
} else { $catapults1TargetRandom = true;
$catapultTarget = $__catapultsTarget1AltTargets[ rand( 1, $j ) ];
} }
} else {
$catapultTarget = 0;
$catapults1TargetRandom = true;
} }
} }
}
// 1st row of catapults set to target randomly
// 1st row of catapults set to target randomly if ($catapults1TargetRandom)
if ($catapults1TargetRandom)
{
$list=array();
for ($i=1;$i<=41;$i++)
{ {
if ($i==41) $i=99; $list=array();
if ($bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33) for ($i=1;$i<=41;$i++)
{ {
$list[] = $i; if ($i==41) $i=99;
if ($bdo['f'.$i] > 0 && $catapultTarget != 31 && $catapultTarget != 32 && $catapultTarget != 33)
{
$list[] = $i;
}
} }
$catapultTarget = $list[ rand(0, count($list) - 1) ];
} }
$catapultTarget = $list[ rand(0, count($list) - 1) ];
} /**
* resolve 1st row of catapults
/** */
* resolve 1st row of catapults $village_destroyed = 0;
*/ $this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget, !$catapults2WillNotShoot, false, $catp_pic, $can_destroy, $isoasis, $village_destroyed);
$village_destroyed = 0;
$this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget, !$catapults2WillNotShoot, false, $catp_pic, $can_destroy, $isoasis, $village_destroyed); /**
* SECOND CATAPULTS ROW
/** */
* SECOND CATAPULTS ROW
*/ // we're manually targetting 2nd row of catapults
if (!$catapults2TargetRandom)
// we're manually targetting 2nd row of catapults
if (!$catapults2TargetRandom)
{
$_catapultsTarget2Levels=array();
$__catapultsTarget2AltTargets=array();
// calculate targets for 2nd rows of catapults
$j=0;
for ($i=1;$i<=41;$i++)
{ {
if ($i==41) $i=99; $_catapultsTarget2Levels=array();
$__catapultsTarget2AltTargets=array();
// 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) // calculate targets for 2nd rows of catapults
$j=0;
for ($i=1;$i<=41;$i++)
{ {
$j++; if ($i==41) $i=99;
$_catapultsTarget2Levels[$j]=$bdo['f'.$i];
$__catapultsTarget2AltTargets[$j]=$i; // 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)
{
$j++;
$_catapultsTarget2Levels[$j]=$bdo['f'.$i];
$__catapultsTarget2AltTargets[$j]=$i;
}
} }
}
// if we couldn't find a suitable target for 2nd row of catapults,
// if we couldn't find a suitable target for 2nd row of catapults, // select a random target instead
// select a random target instead if (!$catapults2TargetRandom ) {
if (!$catapults2TargetRandom ) { if ( count( $_catapultsTarget2Levels ) > 0 ) {
if ( count( $_catapultsTarget2Levels ) > 0 ) { if ( max( $_catapultsTarget2Levels ) <= 0 ) {
if ( max( $_catapultsTarget2Levels ) <= 0 ) { $catapultTarget2 = 99;
} else {
$catapultTarget2 = $__catapultsTarget2AltTargets[ rand( 1, $j ) ];
}
} else {
$catapultTarget2 = 99; $catapultTarget2 = 99;
} else { $catapults2TargetRandom = true;
$catapultTarget2 = $__catapultsTarget2AltTargets[ rand( 1, $j ) ];
} }
} else {
$catapultTarget2 = 99;
$catapults2TargetRandom = true;
} }
} }
}
// 2nd row of catapults set to target randomly
// 2nd row of catapults set to target randomly if ($catapults2TargetRandom && !$catapults2WillNotShoot)
if ($catapults2TargetRandom && !$catapults2WillNotShoot)
{
$list=array();
for ($i=1;$i<=41;$i++)
{ {
if ($i==41) $i=99; $list=array();
if ($bdo['f'.$i] > 0) for ($i=1;$i<=41;$i++)
{ {
$list[] = $i; if ($i==41) $i=99;
if ($bdo['f'.$i] > 0)
{
$list[] = $i;
}
} }
$catapultTarget2 = $list[ rand(0, count($list) - 1) ];
} }
$catapultTarget2 = $list[ rand(0, count($list) - 1) ];
/**
* resolve 2nd row of catapults
*/
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
call_user_func(get_class($database).'::clearResourseLevelsCache');
} }
/**
* resolve 2nd row of catapults
*/
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
call_user_func(get_class($database).'::clearResourseLevelsCache');
} }
} elseif (($data['t7']-$traped7)>0) {
$info_ram = "".$ram_pic.",Hint: The ram does not work during a raid.";
} }
} elseif (($data['t7']-$traped7)>0) { }else{
$info_ram = "".$ram_pic.",Hint: The ram does not work during a raid."; $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,10 +3062,8 @@ 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
+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);
} }