mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-25 04:27:15 +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() {
|
private function sendreinfunitsComplete() {
|
||||||
global $bid23,$database,$battle,$session,$autoprefix;
|
global $bid23,$database,$battle,$session,$autoprefix;
|
||||||
|
|
||||||
|
|||||||
@@ -7882,58 +7882,6 @@ References:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************
|
|
||||||
Function checkAttack
|
|
||||||
Made by: Shadow
|
|
||||||
***************************/
|
|
||||||
// no need to cache this method
|
|
||||||
function checkAttack($wref, $toWref) {
|
|
||||||
list($wref, $toWref) = $this->escape_input((int) $wref, (int) $toWref);
|
|
||||||
|
|
||||||
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and (" . TB_PREFIX . "attacks.attack_type = 3 or " . TB_PREFIX . "attacks.attack_type = 4) ORDER BY endtime ASC";
|
|
||||||
$result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);
|
|
||||||
|
|
||||||
if ($result['Total']) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************
|
|
||||||
Function checkEnforce
|
|
||||||
Made by: Shadow
|
|
||||||
***************************/
|
|
||||||
// no need to cache this method
|
|
||||||
function checkEnforce($wref, $toWref) {
|
|
||||||
list($wref, $toWref) = $this->escape_input((int) $wref, (int) $toWref);
|
|
||||||
|
|
||||||
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and " . TB_PREFIX . "attacks.attack_type = 2 ORDER BY endtime ASC";
|
|
||||||
$result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);
|
|
||||||
if($result['Total']) {
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************
|
|
||||||
Function checkScout
|
|
||||||
Made by: yi12345
|
|
||||||
***************************/
|
|
||||||
// no need to cache this method
|
|
||||||
function checkScout($wref, $toWref) {
|
|
||||||
list($wref, $toWref) = $this->escape_input((int) $wref, (int) $toWref);
|
|
||||||
|
|
||||||
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and " . TB_PREFIX . "attacks.attack_type = 1 ORDER BY endtime ASC";
|
|
||||||
$result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);
|
|
||||||
if($result['Total']) {
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// database is not needed if we're displaying static pages
|
// database is not needed if we're displaying static pages
|
||||||
|
|||||||
+26
-8
@@ -363,7 +363,7 @@ class Units {
|
|||||||
if ( $data['u11'] < 0 ) {
|
if ( $data['u11'] < 0 ) {
|
||||||
$form->addError( "error", "You can't send negative units." );
|
$form->addError( "error", "You can't send negative units." );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $form->returnErrors() > 0 ) {
|
if ( $form->returnErrors() > 0 ) {
|
||||||
$_SESSION['errorarray'] = $form->getErrors();
|
$_SESSION['errorarray'] = $form->getErrors();
|
||||||
$_SESSION['valuearray'] = $_POST;
|
$_SESSION['valuearray'] = $_POST;
|
||||||
@@ -505,6 +505,28 @@ class Units {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$validBuildings = [23, 31, 32, 33, 34, 36];
|
||||||
|
|
||||||
|
if(isset($post['ctar1']) && $post['ctar1'] != 0){
|
||||||
|
// check if the player have selected a valid building
|
||||||
|
if($data['u8'] == 0 || in_array($post['ctar1'], $validBuildings) || $post['ctar1'] < 0 || $post['ctar1'] > 40){
|
||||||
|
$post['ctar1'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($post['ctar2']) && $post['ctar2'] != 0){
|
||||||
|
// check if there are atleast 20 catapults
|
||||||
|
if($data['u8'] < 20){
|
||||||
|
$post['ctar2'] = 0;
|
||||||
|
}else{
|
||||||
|
// check if the player has selected a valid building
|
||||||
|
if(in_array($post['ctar2'], $validBuildings) || ($post['ctar2'] < 0 || $post['ctar2'] > 40 && $post['ctar2'] != 99)){
|
||||||
|
$post['ctar2'] = 99;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: check those instructions, i think that they're wrong
|
||||||
if ( isset( $post['ctar1'] ) ) {
|
if ( isset( $post['ctar1'] ) ) {
|
||||||
if ( $artefact_2 > 0 or $artefact1_2 > 0 or $artefact2_2 > 0 or $good_artefact == 1 ) {
|
if ( $artefact_2 > 0 or $artefact1_2 > 0 or $artefact2_2 > 0 or $good_artefact == 1 ) {
|
||||||
if ( $post['ctar1'] != 40 or $post['ctar1'] != 27 and $iswwvilla == 1 ) {
|
if ( $post['ctar1'] != 40 or $post['ctar1'] != 27 and $iswwvilla == 1 ) {
|
||||||
@@ -512,12 +534,11 @@ class Units {
|
|||||||
} else {
|
} else {
|
||||||
$post['ctar1'] = 99;
|
$post['ctar1'] = 99;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$post['ctar1'] = $post['ctar1'];
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$post['ctar1'] = 0;
|
$post['ctar1'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $post['ctar2'] ) ) {
|
if ( isset( $post['ctar2'] ) ) {
|
||||||
if ( $artefact_2 > 0 or $artefact1_2 > 0 or $artefact2_2 > 0 or $good_artefact == 1 ) {
|
if ( $artefact_2 > 0 or $artefact1_2 > 0 or $artefact2_2 > 0 or $good_artefact == 1 ) {
|
||||||
if ( $post['ctar2'] != 40 or $post['ctar2'] != 27 and $iswwvilla == 1 ) {
|
if ( $post['ctar2'] != 40 or $post['ctar2'] != 27 and $iswwvilla == 1 ) {
|
||||||
@@ -525,15 +546,12 @@ class Units {
|
|||||||
} else {
|
} else {
|
||||||
$post['ctar2'] = 99;
|
$post['ctar2'] = 99;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$post['ctar2'] = $post['ctar2'];
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$post['ctar2'] = 0;
|
$post['ctar2'] = 0;
|
||||||
}
|
}
|
||||||
if ( isset( $post['spy'] ) ) {
|
|
||||||
$post['spy'] = $post['spy'];
|
if (!isset($post['spy'])) {
|
||||||
} else {
|
|
||||||
$post['spy'] = 0;
|
$post['spy'] = 0;
|
||||||
}
|
}
|
||||||
$abdata = $database->getABTech( $village->wid );
|
$abdata = $database->getABTech( $village->wid );
|
||||||
|
|||||||
Reference in New Issue
Block a user