Fixed a bug while reinforcing

+If you've already reinforced the target village, you'll troops will now
be merged with the present troops
This commit is contained in:
iopietro
2018-04-17 18:52:48 +02:00
parent 1dcde6675e
commit bf091c2a0c
2 changed files with 33 additions and 47 deletions
+29 -43
View File
@@ -3442,40 +3442,37 @@ class Automation {
if($data['t11'] != 0 || $troopsPresent) { 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
$check=$database->getEnforce($data['to'],$data['from']); $check = $database->getEnforce($data['to'], $data['from']);
if (!isset($check['id'])){ if (!isset($check['id'])) $database->addEnforce($data);
//no: else
$database->addEnforce($data); {
} else{
//yes //yes
$start = ($owntribe-1)*10+1; $start = ($owntribe - 1) * 10 + 1;
$end = ($owntribe*10); $end = ($owntribe * 10);
//add unit. //add unit.
$j='1'; $t_units = '';
for($i=$start;$i<=$end;$i++){ for($i = $start, $j = 1; $i <= $end; $i++, $j++)
if (!isset($t_units)) { {
$t_units = ''; $t_units .= "u".$i." = u".$i." + ".$data['t'.$j].(($j > 9) ? '' : ', ');
}
$t_units .= "u".$i."=u".$i." + ".$data['t'.$j].(($j > 9) ? '' : ', ');$j++;
} }
$q = "UPDATE ".TB_PREFIX."enforcement set $t_units where id =".(int) $check['id']; $q = "UPDATE ".TB_PREFIX."enforcement set $t_units where id =".(int) $check['id'];
$database->query($q); $database->query($q);
$database->modifyEnforce($check['id'],'hero',$data['t11'],1); $database->modifyEnforce($check['id'], 'hero', $data['t11'], 1);
} }
$data['t11']=$temphero; $data['t11'] = $temphero;
} }
//send rapport //send rapport
$unitssend_att = ''.$data['t1'].','.$data['t2'].','.$data['t3'].','.$data['t4'].','.$data['t5'].','.$data['t6'].','.$data['t7'].','.$data['t8'].','.$data['t9'].','.$data['t10'].','.$data['t11'].''; $unitssend_att = ''.$data['t1'].','.$data['t2'].','.$data['t3'].','.$data['t4'].','.$data['t5'].','.$data['t6'].','.$data['t7'].','.$data['t8'].','.$data['t9'].','.$data['t10'].','.$data['t11'].'';
$data_fail = ''.$from['wref'].','.$from['owner'].','.$owntribe.','.$unitssend_att.''; $data_fail = ''.$from['wref'].','.$from['owner'].','.$owntribe.','.$unitssend_att.'';
if($isoasis == 0){ if($isoasis == 0) $to_name = $to['name'];
$to_name=$to['name']; else $to_name = "Oasis ".$database->getVillageField($to['conqured'],"name");
}else{
$to_name="Oasis ".$database->getVillageField($to['conqured'],"name");
}
$database->addNotice($from['owner'],$from['wref'],(isset($ownally) ? $ownally : 0),8,''.addslashes($from['name']).' reinforcement '.addslashes($to_name).'',$data_fail,(isset($AttackArrivalTime) ? $AttackArrivalTime : time())); $database->addNotice($from['owner'],$from['wref'],(isset($ownally) ? $ownally : 0),8,''.addslashes($from['name']).' reinforcement '.addslashes($to_name).'',$data_fail,(isset($AttackArrivalTime) ? $AttackArrivalTime : time()));
if($from['owner'] != $to['owner']) { if($from['owner'] != $to['owner']) {
$database->addNotice($to['owner'],$to['wref'],(isset($targetally) ? $targetally : 0),8,''.addslashes($from['name']).' reinforcement '.addslashes($to_name).'',$data_fail,(isset($AttackArrivalTime) ? $AttackArrivalTime : time())); $database->addNotice($to['owner'],$to['wref'],(isset($targetally) ? $targetally : 0),8,''.addslashes($from['name']).' reinforcement '.addslashes($to_name).'',$data_fail,(isset($AttackArrivalTime) ? $AttackArrivalTime : time()));
@@ -3499,7 +3496,7 @@ class Automation {
//check empty reinforcement in rally point //check empty reinforcement in rally point
$e_units=''; $e_units='';
for ($i=1;$i<=50;$i++) { for ($i=1; $i <= 50; $i++) {
$e_units.='u'.$i.'=0 AND '; $e_units.='u'.$i.'=0 AND ';
} }
$e_units.='hero=0'; $e_units.='hero=0';
@@ -4145,34 +4142,23 @@ class Automation {
$wood *= SPEED; $wood *= SPEED;
return round($wood); return round($wood);
} }
private function bountyGetOWoodProd() { private function bountyGetOWoodProd() {
global $session; return round(SPEED * 40);
$wood = 0;
$wood += 40;
$wood *= SPEED;
return round($wood);
} }
private function bountyGetOClayProd() { private function bountyGetOClayProd() {
global $session; return round(SPEED * 40);
$clay = 0; }
$clay += 40;
$clay *= SPEED; private function bountyGetOIronProd() {
return round($clay); return round(SPEED * 40);
}private function bountyGetOIronProd() {
global $session;
$iron = 0;
$iron += 40;
$iron *= SPEED;
return round($iron);
} }
private function bountyGetOCropProd() { private function bountyGetOCropProd() {
global $session; return round(SPEED * 40);
$crop = 0;
$clay += 40;
$crop *= SPEED;
return round($crop);
} }
private function bountyGetClayProd() { private function bountyGetClayProd() {
global $bid2,$bid6,$session; global $bid2,$bid6,$session;
$clay = $brick = 0; $clay = $brick = 0;
+3 -3
View File
@@ -6170,7 +6170,7 @@ References: User ID/Message ID, Mode
// first of all, check if we should be using cache and whether the field // first of all, check if we should be using cache and whether the field
// required is already cached // required is already cached
if ($use_cache && !$array_passed && isset(self::$villageFromReinforcementsCache[$vid[0].$from[0]]) && is_array(self::$villageFromReinforcementsCache[$vid[0].$from[0]]) && !count(self::$villageFromReinforcementsCache[$vid[0].$from[0]])) { if ($use_cache && !$array_passed && isset(self::$villageFromReinforcementsCache[$vid[0].$from[0]]) && is_array(self::$villageFromReinforcementsCache[$vid[0].$from[0]]) && !count(self::$villageFromReinforcementsCache[$vid[0].$from[0]])) {
return $cachedValue; return self::$villageFromReinforcementsCache[$vid[0].$from[0]];
} else if ($use_cache && $array_passed) { } else if ($use_cache && $array_passed) {
// check what we can return from cache // check what we can return from cache
$newVIDs = []; $newVIDs = [];
@@ -6197,7 +6197,7 @@ References: User ID/Message ID, Mode
// build SELECT pairs // build SELECT pairs
$pairs = []; $pairs = [];
foreach ($vid as $index => $vidValue) { foreach ($vid as $index => $vidValue) {
$pairs[] = '(`from` = '.(int) $vidValue.' AND vref = '.(int) $from[$index].')'; $pairs[] = '(`from` = '.(int) $from[$index].' AND vref = '.(int) $vidValue.')';
} }
$q = "SELECT * FROM " . TB_PREFIX . "enforcement WHERE ".implode(' OR ', $pairs); $q = "SELECT * FROM " . TB_PREFIX . "enforcement WHERE ".implode(' OR ', $pairs);
@@ -6209,7 +6209,7 @@ References: User ID/Message ID, Mode
} else { } else {
if ($result && count($result)) { if ($result && count($result)) {
foreach ( $result as $record ) { foreach ( $result as $record ) {
self::$villageFromReinforcementsCache[ $record['from'] . $record['vref'] ] = $record; self::$villageFromReinforcementsCache[$record['vref'].$record['from']] = $record;
} }
} }