mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
Fixed some bugs and some clean up
Units.php: Fixed a bug which allows to select invalid buildings or not-hittable building (such as Cranny, Walls, Stonemason's lodge and Trapper) with catapults. Fixed a bug which allows to select a secondary target with less than 20 catapults. Removed some unused functions from Automation.php and Database.php.
This commit is contained in:
@@ -3335,140 +3335,6 @@ class Automation {
|
||||
}
|
||||
}
|
||||
|
||||
private function sendTroopsBack($post) {
|
||||
global $form, $database, $village, $generator, $session, $technology;
|
||||
|
||||
$enforce=$database->getEnforceArray($post['ckey'],0);
|
||||
$to = $database->getVillage($enforce['from']);
|
||||
$Gtribe = "";
|
||||
if ($database->getUserField($to['owner'],'tribe',0) == '2'){ $Gtribe = "1"; } else if ($database->getUserField($to['owner'],'tribe',0) == '3'){ $Gtribe = "2"; } else if ($database->getUserField($to['owner'],'tribe',0) == '4'){ $Gtribe = "3"; }else if ($database->getUserField($to['owner'],'tribe',0) == '5'){ $Gtribe = "4"; }
|
||||
|
||||
for($i=1; $i<10; $i++){
|
||||
if(isset($post['t'.$i])){
|
||||
if($i!=10){
|
||||
if ($post['t'.$i] > $enforce['u'.$Gtribe.$i])
|
||||
{
|
||||
$form->addError("error","You can't send more units than you have");
|
||||
break;
|
||||
}
|
||||
|
||||
if($post['t'.$i]<0)
|
||||
{
|
||||
$form->addError("error","You can't send negative units.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$post['t'.$i.'']='0';
|
||||
}
|
||||
}
|
||||
if(isset($post['t11'])){
|
||||
if ($post['t11'] > $enforce['hero'])
|
||||
{
|
||||
$form->addError("error","You can't send more units than you have");
|
||||
|
||||
}
|
||||
|
||||
if($post['t11']<0)
|
||||
{
|
||||
$form->addError("error","You can't send negative units.");
|
||||
|
||||
}
|
||||
} else {
|
||||
$post['t11']='0';
|
||||
}
|
||||
|
||||
if($form->returnErrors() > 0) {
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header("Location: a2b.php");
|
||||
exit;
|
||||
} else {
|
||||
|
||||
//change units
|
||||
$start = ($database->getUserField($to['owner'],'tribe',0)-1)*10+1;
|
||||
$end = ($database->getUserField($to['owner'],'tribe',0)*10);
|
||||
|
||||
$j='1';
|
||||
$units = [];
|
||||
$amounts = [];
|
||||
$modes = [];
|
||||
|
||||
for($i=$start;$i<=$end;$i++){
|
||||
$units[] = $i;
|
||||
$amounts[] = $post['t'.$j.''];
|
||||
$modes[] = 0;
|
||||
$j++;
|
||||
}
|
||||
$database->modifyEnforce($post['ckey'], $units, $amounts, $modes);
|
||||
|
||||
//get cord
|
||||
$from = $database->getVillage($enforce['from']);
|
||||
$fromcoor = $database->getCoor($enforce['from']);
|
||||
$tocoor = $database->getCoor($enforce['vref']);
|
||||
$fromCor = array('x'=>$tocoor['x'], 'y'=>$tocoor['y']);
|
||||
$toCor = array('x'=>$fromcoor['x'], 'y'=>$fromcoor['y']);
|
||||
|
||||
$speeds = array();
|
||||
|
||||
//find slowest unit.
|
||||
for($i=1;$i<=10;$i++){
|
||||
if (isset($post['t'.$i])){
|
||||
if( $post['t'.$i] != '' && $post['t'.$i] > 0){
|
||||
if($unitarray) { reset($unitarray); }
|
||||
$unitarray = $GLOBALS["u".(($session->tribe-1)*10+$i)];
|
||||
$speeds[] = $unitarray['speed'];
|
||||
} else {
|
||||
$post['t'.$i.'']='0';
|
||||
}
|
||||
} else {
|
||||
$post['t'.$i.'']='0';
|
||||
}
|
||||
}
|
||||
if (isset($post['t11'])){
|
||||
if( $post['t11'] != '' && $post['t11'] > 0){
|
||||
$hero_unit = getHeroField($from['owner'], 'unit');
|
||||
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
|
||||
} else {
|
||||
$post['t11']='0';
|
||||
}
|
||||
} else {
|
||||
$post['t11']='0';
|
||||
}
|
||||
$artefact = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,3,0));
|
||||
$artefact1 = count($database->getOwnUniqueArtefactInfo2($from['vref'],2,1,1));
|
||||
$artefact2 = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,2,0));
|
||||
if($artefact > 0){
|
||||
$fastertroops = 3;
|
||||
}else if($artefact1 > 0){
|
||||
$fastertroops = 2;
|
||||
}else if($artefact2 > 0){
|
||||
$fastertroops = 1.5;
|
||||
}else{
|
||||
$fastertroops = 1;
|
||||
}
|
||||
$time = round($generator->procDistanceTime($fromCor,$toCor,min($speeds),1)/$fastertroops);
|
||||
$foolartefact4 = $database->getFoolArtefactInfo(2,$from['wref'],$from['owner']);
|
||||
if(count($foolartefact4) > 0){
|
||||
foreach($foolartefact4 as $arte){
|
||||
if($arte['bad_effect'] == 1){
|
||||
$time *= $arte['effect2'];
|
||||
}else{
|
||||
$time /= $arte['effect2'];
|
||||
$time = round($endtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
$reference = $database->addAttack($enforce['from'],$post['t1'],$post['t2'],$post['t3'],$post['t4'],$post['t5'],$post['t6'],$post['t7'],$post['t8'],$post['t9'],$post['t10'],$post['t11'],2,0,0,0,0);
|
||||
$database->addMovement(4,$village->wid,$enforce['from'],$reference,$AttackArrivalTime,($time+$AttackArrivalTime));
|
||||
$technology->checkReinf($post['ckey']);
|
||||
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function sendreinfunitsComplete() {
|
||||
global $bid23,$database,$battle,$session,$autoprefix;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user