mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-30 17:44:22 +00:00
Farmlist improvements and fixes
+Troops while adding/editing a raid lists are now inside of a table, this is a graphic enhancement +Reduced the X and Y textboxes size while adding/editing a raid list +Fixed a bug that didn't permit to add a raid list +Fixed a bug that did permit to insert spies in raid lists +The farmlists graphic is now more clear, "Add raid" and "Start raid" are now two general buttons, instead of having two buttons for raid list +"Select all" checkbox, will select all raid without refreshing the page (through JS) +Moved the function "getDistance" to Database.php +Removed a lot of redundant code from crop_finder.php +Removed rams, catapults, chiefs and settlers from the raid list, because the first three can't even loot resources +Removed trooplist2.tpl because of a more general unique template file (trooplist.tpl) +Some minor improvements and bug fixing IMPORTANT NOTE: if you don't want to reinstal the whole server, you can simply run this little query (where "s1_" is the prefix of your server): ALTER TABLE `s1_raidlist` DROP `t7`, DROP `t8`, DROP `t9`, DROP `t10`;
This commit is contained in:
@@ -250,7 +250,7 @@ class Battle {
|
||||
//dp = Infantry defense points
|
||||
//rap = Result attack points
|
||||
//rdp = Result defense points
|
||||
//detected = Detected or not by enemy spies
|
||||
//detected = Detected or not by defender spies
|
||||
$cap = $ap = $dp = $cdp = $rap = $rdp = 0;
|
||||
$detected = false;
|
||||
|
||||
|
||||
+54
-27
@@ -1470,6 +1470,27 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return self::$oasisTroopsCountCache[$vref];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the distance from a village to another
|
||||
*
|
||||
* @param int $coorx1 X coordinate of the first village
|
||||
* @param int $coory1 Y coordinate of the second village
|
||||
* @param int $coorx2 X coordinate of the first village
|
||||
* @param int $coory2 Y coordinate of the second village
|
||||
* @return int Returns the calculated distance
|
||||
*/
|
||||
|
||||
public function getDistance($coorx1, $coory1, $coorx2, $coory2) {
|
||||
$max = 2 * WORLD_MAX + 1;
|
||||
$x1 = intval($coorx1);
|
||||
$y1 = intval($coory1);
|
||||
$x2 = intval($coorx2);
|
||||
$y2 = intval($coory2);
|
||||
$distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1)));
|
||||
$distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1)));
|
||||
return round(sqrt(pow($distanceX, 2) + pow($distanceY, 2)), 1);
|
||||
}
|
||||
|
||||
public function canConquerOasis($vref, $wref, $use_cache = true) {
|
||||
list($vref,$wref) = $this->escape_input($vref,$wref);
|
||||
|
||||
@@ -1592,7 +1613,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
Function to retrieve if is ocuped via ID
|
||||
Function to retrieve if is occupied via ID
|
||||
References: Village ID
|
||||
*****************************************/
|
||||
function getVillageState($wref, $use_cache = true) {
|
||||
@@ -2460,15 +2481,6 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return $this->getVillageByWorldID($wref, $use_cache)['oasistype'];
|
||||
}
|
||||
|
||||
// no need to cache this method
|
||||
function getFLData($id) {
|
||||
list($id) = $this->escape_input((int) $id);
|
||||
|
||||
$q = "SELECT * FROM " . TB_PREFIX . "farmlist where id = $id LIMIT 1";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
return mysqli_fetch_array($result);
|
||||
}
|
||||
|
||||
// no need to cache this method
|
||||
function checkVilExist($wref) {
|
||||
list($wref) = $this->escape_input((int) $wref);
|
||||
@@ -7493,18 +7505,13 @@ References: User ID/Message ID, Mode
|
||||
}
|
||||
|
||||
// no need to cache this method
|
||||
function getVilFarmlist($wref) {
|
||||
list($wref) = $this->escape_input((int) $wref);
|
||||
$q = 'SELECT * FROM ' . TB_PREFIX . 'farmlist WHERE wref = ' . $wref . ' ORDER BY wref ASC LIMIT 1';
|
||||
function getVilFarmlist($uid) {
|
||||
list($uid) = $this->escape_input((int) $uid);
|
||||
|
||||
$q = 'SELECT * FROM ' . TB_PREFIX . 'farmlist WHERE owner = '.$uid.' ORDER BY wref ASC LIMIT 1';
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
$dbarray = mysqli_fetch_array($result);
|
||||
|
||||
if($dbarray['id']!=0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $dbarray['id'] > 0;
|
||||
}
|
||||
|
||||
// no need to cache this method
|
||||
@@ -7512,15 +7519,35 @@ References: User ID/Message ID, Mode
|
||||
list($id) = $this->escape_input((int) $id);
|
||||
|
||||
$q = "SELECT * FROM " . TB_PREFIX . "raidlist WHERE id = ".$id." LIMIT 1";
|
||||
$result = mysqli_query($this->dblink, $q);
|
||||
return mysqli_fetch_array($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all informations about a farm list
|
||||
*
|
||||
* @param int $id The farmlist ID
|
||||
* @return array Returns the seleted farm list informations
|
||||
*/
|
||||
|
||||
function getFLData($id) {
|
||||
list($id) = $this->escape_input((int) $id);
|
||||
|
||||
$q = "SELECT * FROM " . TB_PREFIX . "farmlist where id = $id LIMIT 1";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
return mysqli_fetch_array($result);
|
||||
}
|
||||
|
||||
|
||||
function delFarmList($id, $owner) {
|
||||
list($id, $owner) = $this->escape_input((int) $id, (int) $owner);
|
||||
|
||||
$q = "DELETE FROM " . TB_PREFIX . "farmlist where id = $id and owner = $owner";
|
||||
return mysqli_query($this->dblink,$q);
|
||||
if(mysqli_query($this->dblink, $q) && mysqli_affected_rows($this->dblink) > 0){
|
||||
$q = "DELETE FROM " . TB_PREFIX . "raidlist where lid = $id";
|
||||
return mysqli_query($this->dblink, $q);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function delSlotFarm($id, $owner, $lid) {
|
||||
@@ -7537,17 +7564,17 @@ References: User ID/Message ID, Mode
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
function addSlotFarm($lid, $owner, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
|
||||
list($lid, $owner, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->escape_input($lid, $owner, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10);
|
||||
function addSlotFarm($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6) {
|
||||
list($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6) = $this->escape_input($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6);
|
||||
|
||||
$q = "INSERT INTO " . TB_PREFIX . "raidlist (`lid`, `towref`, `x`, `y`, `distance`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`, `t7`, `t8`, `t9`, `t10`) SELECT '$lid', '$towref', '$x', '$y', '$distance', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$t8', '$t9', '$t10' WHERE EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $lid AND owner = $owner)";
|
||||
$q = "INSERT INTO " . TB_PREFIX . "raidlist (`lid`, `towref`, `x`, `y`, `distance`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`) VALUES ('$lid', '$towref', '$x', '$y', '$distance', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6')";
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
function editSlotFarm($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
|
||||
list($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->escape_input((int) $eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10);
|
||||
function editSlotFarm($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6) {
|
||||
list($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6) = $this->escape_input((int) $eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6);
|
||||
|
||||
$q = "UPDATE " . TB_PREFIX . "raidlist SET lid = '$lid', towref = '$wref', x = '$x', y = '$y', t1 = '$t1', t2 = '$t2', t3 = '$t3', t4 = '$t4', t5 = '$t5', t6 = '$t6', t7 = '$t7', t8 = '$t8', t9 = '$t9', t10 = '$t10' WHERE id = $eid AND lid = $oldLid AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $lid AND owner = $owner) AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $oldLid AND owner = $owner)";
|
||||
$q = "UPDATE " . TB_PREFIX . "raidlist SET lid = '$lid', towref = '$wref', x = '$x', y = '$y', t1 = '$t1', t2 = '$t2', t3 = '$t3', t4 = '$t4', t5 = '$t5', t6 = '$t6' WHERE id = $eid AND lid = $oldLid AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $lid AND owner = $owner) AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $oldLid AND owner = $owner)";
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
|
||||
@@ -677,6 +677,8 @@ define("NOTROOP","no troops");
|
||||
//map
|
||||
define("DETAIL","Details");
|
||||
define("ABANDVALLEY","Abandoned valley");
|
||||
define("OCCUPIED","Occupied");
|
||||
define("UNOCCUPIED","Unoccupied");
|
||||
define("UNOCCUOASIS","Unoccupied oasis");
|
||||
define("OCCUOASIS","Occupied oasis");
|
||||
define("THERENOINFO","There is no<br>information available.");
|
||||
@@ -708,6 +710,7 @@ define("WEST","West");
|
||||
define("VILLAGE","Village");
|
||||
define("OASIS","Oasis");
|
||||
define("NO_OASIS", "You do not own any oases.");
|
||||
define("NO_VILLAGES", "There are no villages.");
|
||||
define("PLAYER","Player");
|
||||
|
||||
//LOGIN.php
|
||||
|
||||
+61
-75
@@ -776,97 +776,83 @@ class Units {
|
||||
global $database, $generator, $session;
|
||||
|
||||
$slots = $post['slot'];
|
||||
$lid = $post['lid'];
|
||||
if(empty($slots)){
|
||||
header("Location: build.php?id=39&t=99");
|
||||
exit();
|
||||
}
|
||||
|
||||
$tribe = $session->tribe;
|
||||
$getFLData = $database->getFLData($lid);
|
||||
|
||||
if($getFLData['owner'] != $session->uid) {
|
||||
header("Location: build.php?id=39&t=99");
|
||||
exit();
|
||||
}
|
||||
|
||||
$sql = "SELECT id, towref, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 FROM " . TB_PREFIX . "raidlist WHERE lid = ".$database->escape((int)$lid)." order by id asc";
|
||||
$array = $database->query_return($sql);
|
||||
foreach($array as $row){
|
||||
$sql1 = mysqli_fetch_array(mysqli_query($database->dblink, "SELECT * FROM " . TB_PREFIX . "units WHERE vref = ".(int)$getFLData['wref']));
|
||||
$sid = $row['id'];
|
||||
$wref = $row['towref'];
|
||||
|
||||
for($i = 1; $i <= 10; $i++) ${'t'.$i} = $row['t'.$i];
|
||||
|
||||
foreach($slots as $slot){
|
||||
$raidList = $database->getRaidList($slot);
|
||||
$getFLData = $database->getFLData($raidList['lid']);
|
||||
|
||||
//Check if we're trying to start our raidlists or other players raidlist
|
||||
if($getFLData['owner'] != $session->uid) continue;
|
||||
|
||||
$t11 = 0;
|
||||
//Get the units in the village
|
||||
$villageUnits = $database->getUnit($getFLData['wref'], false);
|
||||
|
||||
$sid = $raidList['id'];
|
||||
$wref = $raidList['towref'];
|
||||
|
||||
for($i = 1; $i <= 6; $i++) ${'t'.$i} = $raidList['t'.$i];
|
||||
|
||||
$villageOwner = $database->getVillageField($wref, 'owner');
|
||||
$userAccess = $database->getUserField($villageOwner, 'access', 0);
|
||||
$userID = $database->getUserField($villageOwner, 'id', 0);
|
||||
|
||||
if($userAccess != 0 && !($userAccess == MULTIHUNTER && $userID == 5) && ($userAccess != ADMIN || (ADMIN_ALLOW_INCOMING_RAIDS && $userAccess == ADMIN))){
|
||||
if($tribe == 1){
|
||||
$uname = "u";
|
||||
$uname1 = "u1";
|
||||
$uname2 = "";
|
||||
}elseif($tribe == 2){
|
||||
$uname = "u1";
|
||||
$uname1 = "u2";
|
||||
$uname2 = "1";
|
||||
}elseif($tribe == 3){
|
||||
$uname = "u2";
|
||||
$uname1 = "u3";
|
||||
$uname2 = "2";
|
||||
}elseif($tribe == 4){
|
||||
$uname = "u3";
|
||||
$uname1 = "u4";
|
||||
$uname2 = "3";
|
||||
}else{
|
||||
$uname = "u4";
|
||||
$uname1 = "u5";
|
||||
$uname2 = "4";
|
||||
}
|
||||
|
||||
if($sql1[$uname.'1'] >= $t1 && $sql1[$uname.'2'] >= $t2 && $sql1[$uname.'3'] >= $t3 && $sql1[$uname.'4'] >= $t4 && $sql1[$uname.'5'] >= $t5 && $sql1[$uname.'6'] >= $t6 && $sql1[$uname.'7'] >= $t7 && $sql1[$uname.'8'] >= $t8 && $sql1[$uname.'9'] >= $t9 && $sql1[$uname1.'0'] >= $t10 && $sql1['hero'] >= $t11){
|
||||
if($post['slot'.$sid] == 'on'){
|
||||
$ckey = $generator->generateRandStr(6);
|
||||
$time_now = time();
|
||||
$id = $database->addA2b($ckey, $time_now, $wref, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, 4);
|
||||
$data = $database->getA2b($ckey, $time_now);
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($getFLData['wref'], $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
|
||||
$time = $database->getArtifactsValueInfluence($getFLData['owner'], $getFLData['wref'], 2, $troopsTime);
|
||||
|
||||
$ctar1 = $ctar2 = 0;
|
||||
$abdata = $database->getABTech($getFLData['wref']);
|
||||
$reference = $database->addAttack(($getFLData['wref']), $data['u1'], $data['u2'], $data['u3'], $data['u4'], $data['u5'], $data['u6'], $data['u7'], $data['u8'], $data['u9'], $data['u10'], $data['u11'], $data['type'], $ctar1, $ctar2, 0, $abdata['b1'], $abdata['b2'], $abdata['b3'], $abdata['b4'], $abdata['b5'], $abdata['b6'], $abdata['b7'], $abdata['b8']);
|
||||
|
||||
$troops = [];
|
||||
$amounts = [];
|
||||
$modes = [];
|
||||
|
||||
for($u = 1; $u <= 10; $u++){
|
||||
if($tribe == 1) $unitKey = $uname2 . $u;
|
||||
else $unitKey = $uname2.($u < 10 ? $u : 0);
|
||||
|
||||
$troops[] = $unitKey;
|
||||
$amounts[] = $data['u'.$u];
|
||||
$modes[] = 0;
|
||||
}
|
||||
|
||||
$troops[] = 'hero';
|
||||
$amounts[] = $data['u11'];
|
||||
$modes[] = 0;
|
||||
|
||||
$database->modifyUnit($getFLData['wref'], $troops, $amounts, $modes);
|
||||
$database->addMovement(3, $getFLData['wref'], $data['to_vid'], $reference, time(), ($time + time()));
|
||||
|
||||
// prevent re-use of the same attack via re-POSTing the same data
|
||||
$database->remA2b($id);
|
||||
//Start = the first troop of the player's tribe
|
||||
//End = the last selectable troop of the player's tribe
|
||||
$start = ($session->tribe - 1) * 10 + 1;
|
||||
$end = $start + 5;
|
||||
|
||||
//Check if we've enough troops
|
||||
$canSend = true;
|
||||
for($i = $start; $i <= $end; $i++){
|
||||
if($villageUnits['u'.$i] < ${'t'.($i - $start + 1)}){
|
||||
$canSend = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Send the attack
|
||||
if($canSend){
|
||||
$ckey = $generator->generateRandStr(6);
|
||||
$time_now = time();
|
||||
$id = $database->addA2b($ckey, $time_now, $wref, $t1, $t2, $t3, $t4, $t5, $t6, 0, 0, 0, 0, 0, 4);
|
||||
$data = $database->getA2b($ckey, $time_now);
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($getFLData['wref'], $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
|
||||
$time = $database->getArtifactsValueInfluence($getFLData['owner'], $getFLData['wref'], 2, $troopsTime);
|
||||
|
||||
$abdata = $database->getABTech($getFLData['wref']);
|
||||
$reference = $database->addAttack(($getFLData['wref']), $data['u1'], $data['u2'], $data['u3'], $data['u4'], $data['u5'], $data['u6'], 0, 0, 0, 0, 0, $data['type'], 0, 0, 0, $abdata['b1'], $abdata['b2'], $abdata['b3'], $abdata['b4'], $abdata['b5'], $abdata['b6'], $abdata['b7'], $abdata['b8']);
|
||||
|
||||
$troops = [];
|
||||
$amounts = [];
|
||||
$modes = [];
|
||||
|
||||
for($u = $start; $u <= $end; $u++){
|
||||
$troops[] = $u;
|
||||
$amounts[] = $data['u'.($u - $start + 1)];
|
||||
$modes[] = 0;
|
||||
}
|
||||
|
||||
$database->modifyUnit($getFLData['wref'], $troops, $amounts, $modes);
|
||||
$database->addMovement(3, $getFLData['wref'], $data['to_vid'], $reference, time(), ($time + time()));
|
||||
|
||||
//Prevent re-use of the same attack via re-POSTing the same data
|
||||
$database->remA2b($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
header("Location: build.php?id=39&t=99");
|
||||
exit();
|
||||
}
|
||||
};
|
||||
|
||||
$units = new Units;
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user