Artifacts fixing part 1

+Added a new table in the database, called "artefacts_chrono" which
stores the chronology of all artifacts
+Added the support for the artifacts chronology in 27_show.tpl
+Added the support for interacting with the artifacts chronology table in Database.php
+Cleaned the code in 27_show.tpl
+Some minor improovements and bug fixing
This commit is contained in:
iopietro
2018-04-23 20:28:38 +02:00
parent f810c9fe99
commit 26cb03cdb6
8 changed files with 212 additions and 93 deletions
+14 -14
View File
@@ -47,12 +47,12 @@ class Automation {
if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time()-filemtime("GameEngine/Prevention/cleardeleting.txt")>50) {
$this->clearDeleting();
}
if (! file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt")>50)
if(!file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt")>50)
{
$this->buildComplete();
}
$this->MasterBuilder();
if (! file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt")>50)
if(!file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt")>50)
{
$this->demolitionComplete();
}
@@ -2475,8 +2475,8 @@ class Automation {
//check for last village or capital
if($user_cps >= $need_cps){
if(count($varray)!='1' AND $to['capital']!='1' AND $villexp < $canconquer){
if($to['owner']!=3 OR $to['name']!='WW Buildingplan'){
if(count($varray) != 1 && $to['capital'] != 1 && $villexp < $canconquer){
if($to['owner'] != 3 || $to['name'] != 'WW Buildingplan'){
// check for standing Palace or Residence
// note: at this point, we can use cache, since we've cleared it above
if ($database->getFieldLevelInVillage($data['to'], '25, 26')) {
@@ -2518,7 +2518,7 @@ class Automation {
$info_chief = "".$chief_pic.",Inhabitants of ".$villname." village decided to join your empire.";
if ($artifact['vref'] == $data['to']){
$database->claimArtefact($data['to'], $data['to'], $database->getVillageField($data['from'],"owner"));
$database->claimArtefact($data['to'], $data['to'], $database->getVillageField($data['from'], "owner"));
}
@@ -2648,8 +2648,8 @@ class Automation {
$xp="";
$info_hero = $hero_pic.",Your hero had nothing to kill therefore gains no XP at all.";
} else {
$xp=" and gained ".$heroxp." XP from the battle.";
$info_hero = $hero_pic.",Your hero gained ".$heroxp." XP.";
$xp=" and gained <b>".$heroxp."</b> XP from the battle.";
$info_hero = $hero_pic.",Your hero gained <b>".$heroxp."</b> XP.";
}
if ($isoasis != 0) { //oasis fix by ronix
@@ -2679,14 +2679,14 @@ class Automation {
if ($heroxp == 0) {
$xp=" no XP from the battle.";
} else {
$xp=" gained ".$heroxp." XP from the battle.";
$xp=" gained <b>".$heroxp."</b> XP from the battle.";
}
$artifact = reset($database->getOwnArtefactInfo($data['to']));
if (!empty($artifact)) {
if ($type=='3') {
if ($database->canClaimArtifact($data['from'],$artifact['vref'],$artifact['size'],$artifact['type'])) {
$database->claimArtefact($data['from'],$data['to'],$database->getVillageField($data['from'],"owner"));
$info_hero = $hero_pic.",Your hero is carrying home an artefact".$xp;
if ($type == 3) {
if ($database->canClaimArtifact($data['from'], $artifact['vref'], $artifact['size'], $artifact['type'])) {
$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;
// if the defender pop is 0 with no artefact, then destroy the village
if($database->getVillageField($data['to'], "pop") == 0){
@@ -2697,7 +2697,7 @@ class Automation {
$info_hero = $hero_pic.",".$form->getError("error").$xp;
}
}else{
$info_hero = $hero_pic.",Your hero could not claim the artefact during raid".$xp;
$info_hero = $hero_pic.",Your hero could not claim an artifact during raid".$xp;
}
}
}
@@ -2705,7 +2705,7 @@ class Automation {
if ($heroxp == 0) {
$xp="";
} else {
$xp=" but gained ".$heroxp." XP from the battle.";
$xp=" but gained <b>".$heroxp."</b> XP from the battle.";
}
if ($traped11>0) {
$info_hero = $hero_pic.",Your hero was trapped".$xp;
+42 -9
View File
@@ -2471,11 +2471,8 @@ class MYSQLi_DB implements IDbConnection {
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "vdata where wref = '$wref'";
$result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);
if ($result['Total']) {
return true;
} else {
return false;
}
return $result['Total'];
}
// no need to cache this method
@@ -6953,10 +6950,10 @@ References: User ID/Message ID, Mode
}
// no need to cache this method
function getOwnArtefactInfo($vref) {
function getOwnArtefactInfo($vref, $use_cache = true) {
// load the data - type is irrelevant, since the method caches all data
// then returns the one for our type
$this->getOwnArtefactInfoByType($vref, 1);
$this->getOwnArtefactInfoByType($vref, 1, $use_cache);
// return what we've cached
return (self::$artefactInfoByTypeCache[$vref]);
@@ -7143,7 +7140,43 @@ References: User ID/Message ID, Mode
$time = time();
$q = "UPDATE " . TB_PREFIX . "artefacts SET vref = $vref, owner = $id, conquered = $time, active = 1 WHERE vref = $ovref";
return mysqli_query($this->dblink,$q);
if(mysqli_query($this->dblink, $q))
{
$artifactID = reset($this->getOwnArtefactInfo($vref, false))['id'];
return $this->addArtifactsChronology($artifactID, $id, $vref, $time);
}
else return false;
}
/**
* Retrieves the chronology of one specific artifact
*
* @param int $artefactid The id of the artifact
* @return array Returns the chronology for the passed artifact
*/
function getArtifactsChronology($artifactID){
list($artifactID) = $this->escape_input((int) $artifactID);
$q = "SELECT * FROM " . TB_PREFIX . "artefacts_chrono WHERE artefactid = $artifactID ORDER BY conqueredtime ASC";
$result = mysqli_query($this->dblink, $q);
return $this->mysqli_fetch_all($result);
}
/**
* Stores when an artifact was conquered and who had conquered it
*
* @param int $artefactid The id of the artifact
* @param int $vref The vref of the village that has conquered the artifact
* @return bool Return true if the query was successful, false otherwise
*/
function addArtifactsChronology($artifactID, $uid, $vref, $conqueredTime){
list($artifactID, $uid, $vref, $conqueredTime) = $this->escape_input((int) $artifactID, (int) $uid, (int) $vref, (int) $conqueredTime);
$q = "INSERT INTO " . TB_PREFIX . "artefacts_chrono (artefactid, uid, vref, conqueredtime) VALUES ('$artifactID', '$uid', '$vref', '$conqueredTime')";
return mysqli_query($this->dblink, $q);
}
// no need to cache this method
@@ -7224,7 +7257,7 @@ References: User ID/Message ID, Mode
}
}
// no need to cache this method
// no need to cache this method
function getArtefactDetails($id) {
list($id) = $this->escape_input((int) $id);
+1
View File
@@ -1016,6 +1016,7 @@ define("TROOPS_MAKE_SLOWEST","troops make slowest with");
define("YOU_CONSTRUCT","you can construct ");
define("CRANNY_INCREASED","cranny capacity is increased by");
define("CRANNY_DECRESE","cranny capacity is decrese by");
define("NO_PREVIOUS_OWNERS","There are no previous owners.");
define("TREASURY_DESC","The riches of your empire are kept in the treasury. The treasury has room for one treasure. After you have captured an artefact it takes 24 hours on a normal server or 12 hours on a thrice speed server to be effective.");
define("TRADEOFFICE","Trade Office");