general fixes

+Fixed a bug that didn't permit to counquer an artifact in certain
circumstances with the new automation system
This commit is contained in:
iopietro
2018-05-25 17:45:05 +02:00
parent 8605996533
commit 11c3d44168
3 changed files with 42 additions and 65 deletions
+2 -3
View File
@@ -2165,14 +2165,13 @@ class Automation {
} }
} }
} else { } else {
global $form;
if ($heroxp == 0) $xp=" no XP from the battle."; if ($heroxp == 0) $xp=" no XP from the battle.";
else $xp=" gained <b>".$heroxp."</b> XP from the battle."; else $xp=" gained <b>".$heroxp."</b> XP from the battle.";
$artifact = reset($database->getOwnArtefactInfo($data['to'])); $artifact = reset($database->getOwnArtefactInfo($data['to']));
if (!empty($artifact)) { if (!empty($artifact)) {
if ($type == 3) { if ($type == 3) {
if ($database->canClaimArtifact($data['from'], $artifact['vref'], $artifact['size'], $artifact['type'])) { if (empty($artifactError = $database->canClaimArtifact($data['from'], $artifact['vref'], $artifact['size'], $artifact['type']))) {
$database->claimArtefact($data['from'], $data['to'], $database->getVillageField($data['from'], "owner")); $database->claimArtefact($data['from'], $data['to'], $database->getVillageField($data['from'], "owner"));
$info_hero = $hero_pic.",Your hero is carrying home the artifact <b>".$artifact['name']."</b> and".$xp; $info_hero = $hero_pic.",Your hero is carrying home the artifact <b>".$artifact['name']."</b> and".$xp;
@@ -2182,7 +2181,7 @@ class Automation {
$info_hero .= " The village has been destroyed."; $info_hero .= " The village has been destroyed.";
} }
} }
else $info_hero = $hero_pic.",".$form->getError("error").$xp; else $info_hero = $hero_pic.",".$artifactError.$xp;
} }
else $info_hero = $hero_pic.",Your hero could not claim an artifact during raid".$xp; else $info_hero = $hero_pic.",Your hero could not claim an artifact during raid".$xp;
} }
+35 -47
View File
@@ -4741,7 +4741,7 @@ References: User ID/Message ID, Mode
*/ */
public function checkAllianceEmbassiesStatus($userData, $demolition = false, $use_cache = true) { public function checkAllianceEmbassiesStatus($userData, $demolition = false, $use_cache = true) {
// TODO: refactor this and break it into more smaler methods // TODO: refactor this and break it into more smaler methods
global $session; //global $session;
if ($userData['alliance']) { if ($userData['alliance']) {
// check whether this player is an alliance owner // check whether this player is an alliance owner
@@ -4760,9 +4760,9 @@ References: User ID/Message ID, Mode
// unset the alliance in session, if we're evicting // unset the alliance in session, if we're evicting
// currently logged-in player // currently logged-in player
if ($session->uid == $userData['id']) { //if ($session->uid == $userData['id']) {
$_SESSION['alliance_user'] = 0; // $_SESSION['alliance_user'] = 0;
} //}
// notify them via in-game messaging, if we come from a demolition, // notify them via in-game messaging, if we come from a demolition,
// otherwise return a result which can be used in battle reports // otherwise return a result which can be used in battle reports
@@ -6130,7 +6130,7 @@ References: User ID/Message ID, Mode
function trainUnit($vid, $unit, $amt, $pop, $each, $mode) { function trainUnit($vid, $unit, $amt, $pop, $each, $mode) {
list($vid, $unit, $amt, $pop, $each, $mode) = $this->escape_input((int) $vid, (int) $unit, (int) $amt, (int) $pop, (int) $each, $mode); list($vid, $unit, $amt, $pop, $each, $mode) = $this->escape_input((int) $vid, (int) $unit, (int) $amt, (int) $pop, (int) $each, $mode);
global $village, $building, $session, $technology; global $technology;
if(!$mode) { if(!$mode) {
$barracks = [1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44]; $barracks = [1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44];
@@ -7532,23 +7532,17 @@ References: User ID/Message ID, Mode
// no need to cache this method // no need to cache this method
public function canClaimArtifact($from, $vref, $size, $type) { public function canClaimArtifact($from, $vref, $size, $type) {
list($size,$type) = $this->escape_input((int) $size,(int) $type); list($size, $type) = $this->escape_input((int) $size, (int) $type);
//fix by Ronix
global $form;
$artifact = $this->getOwnArtefactInfo($from); $artifact = $this->getOwnArtefactInfo($from);
if (!empty($artifact)) { if (!empty($artifact)) return "Treasury is full. Your hero could not claim the artefact";
$form->addError("error", "Treasury is full. Your hero could not claim the artefact");
return false;
}
$uid = $this->getVillageField($from, "owner"); $uid = $this->getVillageField($from, "owner");
$vuid = $this->getVillageField($vref, "owner"); $vuid = $this->getVillageField($vref, "owner");
$artifact = $this->getOwnArtifactsSum($uid); $artifact = $this->getOwnArtifactsSum($uid);
if ( $artifact['totals'] < 3 || $uid == $vuid) { if ($artifact['totals'] < 3 || $uid == $vuid) {
$DefenderFields = $this->getResourceLevel( $vref ); $DefenderFields = $this->getResourceLevel( $vref );
$defcanclaim = true; $defcanclaim = true;
@@ -7557,8 +7551,7 @@ References: User ID/Message ID, Mode
$defTresuaryLevel = $DefenderFields['f'.$i]; $defTresuaryLevel = $DefenderFields['f'.$i];
if ($defTresuaryLevel > 0) { if ($defTresuaryLevel > 0) {
$defcanclaim = false; $defcanclaim = false;
$form->addError("error", "Treasury has not been destroyed. Your hero could not claim the artefact"); return "Treasury has not been destroyed. Your hero could not claim the artefact";
return false;
} }
else $defcanclaim = true; else $defcanclaim = true;
} }
@@ -7575,20 +7568,15 @@ References: User ID/Message ID, Mode
} }
if(($artifact['great'] > 0 || $artifact['unique'] > 0) && $size > 1 && $uid != $vuid) { if(($artifact['great'] > 0 || $artifact['unique'] > 0) && $size > 1 && $uid != $vuid) {
$form->addError( "error", "Max num. of great/unique artefacts. Your hero could not claim the artefact" ); return "Max num. of great/unique artefacts. Your hero could not claim the artefact";
return false;
} }
if(($size == 1 && ($villageartifact || $accountartifact)) || (($size == 2 || $size == 3) && $accountartifact)) { if(($size == 1 && ($villageartifact || $accountartifact)) || (($size == 2 || $size == 3) && $accountartifact)) {
return true; return "";
} else {
$form->addError("error", "Your level treasury is low. Your hero could not claim the artefact");
return false;
} }
} else { else return "Your level treasury is low. Your hero could not claim the artefact";
$form->addError("error", "Max num. of artefacts. Your hero could not claim the artefact"); }
return false; else return "Max num. of artefacts. Your hero could not claim the artefact";
}
} }
// no need to cache this method // no need to cache this method
@@ -7728,7 +7716,7 @@ References: User ID/Message ID, Mode
} }
function getCropProdstarv($wref, $use_cache = true) { function getCropProdstarv($wref, $use_cache = true) {
global $bid4, $bid8, $bid9, $sesion, $technology; global $bid4, $bid8, $bid9, $technology;
// 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
@@ -7841,27 +7829,27 @@ References: User ID/Message ID, Mode
// no need to cache this method // no need to cache this method
function checkFriends($uid) { function checkFriends($uid) {
list($uid) = $this->escape_input($uid); list($uid) = $this->escape_input($uid);
global $session; global $session;
$user = $this->getUserArray( $uid, 1 );
for ( $i = 0; $i <= 19; $i ++ ) { $user = $this->getUserArray($uid, 1);
if ( $user[ 'friend' . $i ] == 0 && $user[ 'friend' . $i . 'wait' ] == 0 ) { for($i = 0; $i <= 19; $i++){
for ( $j = $i + 1; $j <= 19; $j ++ ) { if($user['friend'.$i] == 0 && $user['friend'.$i.'wait'] == 0){
$k = $j - 1; for($j = $i + 1; $j <= 19; $j++){
if ( $user[ 'friend' . $j ] != 0 ) { $k = $j - 1;
$friend = $this->getUserField( $uid, "friend" . $j, 0 ); if($user['friend'.$j] != 0){
$this->addFriend( $uid, "friend" . $k, $friend ); $friend = $this->getUserField($uid, "friend".$j, 0);
$this->deleteFriend( $uid, "friend" . $j ); $this->addFriend($uid, "friend".$k, $friend);
} $this->deleteFriend($uid, "friend".$j);
}
if ( $user[ 'friend' . $j . 'wait' ] == 0 ) {
$friendwait = $this->getUserField( $uid, "friend" . $j . "wait", 0 ); if($user['friend'.$j.'wait'] == 0){
$this->addFriend( $session->uid, "friend" . $k . "wait", $friendwait ); $friendwait = $this->getUserField($uid, "friend".$j."wait", 0);
$this->deleteFriend( $uid, "friend" . $j . "wait" ); $this->addFriend($session->uid, "friend".$k."wait", $friendwait);
} $this->deleteFriend($uid, "friend".$j."wait");
} }
} }
} }
}
} }
function setVillageEvasion($vid) { function setVillageEvasion($vid) {
+5 -15
View File
@@ -24,9 +24,7 @@ class Form {
unset($_SESSION['errorarray']); unset($_SESSION['errorarray']);
unset($_SESSION['valuearray']); unset($_SESSION['valuearray']);
} }
else { else $this->errorcount = 0;
$this->errorcount = 0;
}
} }
public function addError($field,$error) { public function addError($field,$error) {
@@ -38,18 +36,14 @@ class Form {
if(array_key_exists($field,$this->errorarray)) { if(array_key_exists($field,$this->errorarray)) {
return $this->errorarray[$field]; return $this->errorarray[$field];
} }
else { else return "";
return "";
}
} }
public function getValue($field) { public function getValue($field) {
if(array_key_exists($field,$this->valuearray)) { if(array_key_exists($field,$this->valuearray)) {
return $this->valuearray[$field]; return $this->valuearray[$field];
} }
else { else return "";
return "";
}
} }
public function setValue($field, $value) { public function setValue($field, $value) {
@@ -60,18 +54,14 @@ class Form {
if(array_key_exists($field,$this->valuearray) && $this->valuearray[$field] != $cookie) { if(array_key_exists($field,$this->valuearray) && $this->valuearray[$field] != $cookie) {
return $this->valuearray[$field]; return $this->valuearray[$field];
} }
else { else return $cookie;
return $cookie;
}
} }
public function getRadio($field,$value) { public function getRadio($field,$value) {
if(array_key_exists($field,$this->valuearray) && $this->valuearray[$field] == $value) { if(array_key_exists($field,$this->valuearray) && $this->valuearray[$field] == $value) {
return "checked"; return "checked";
} }
else { else return "";
return "";
}
} }
public function returnErrors() { public function returnErrors() {