Skip to content

Commit

Permalink
Artifacts fixes part 3
Browse files Browse the repository at this point in the history
+Fixed the artifact of the fool, it will now work and reduce/increase
troops speed
+Optimized some templates file and deleted some useless files
+Added a method to Database.php which permits to calculate things
related to artifacts (it's not general yet, it only works for troops
speed)
-Removed artifact of the fool "Account" type, because it shouldn't exist
  • Loading branch information
iopietro committed Apr 25, 2018
1 parent c15f8d4 commit 8e731dd
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 1,850 deletions.
96 changes: 23 additions & 73 deletions GameEngine/Automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,7 @@ private function sendunitsComplete() {
}

//cranny efficiency
//TODO: Needs to be connected to a function
$atk_bonus = ($owntribe == 2)? (4/5) : 1;
$def_bonus = ($targettribe == 3)? 2 : 1;
$to_owner = $database->getVillageField($data['to'],"owner");
Expand Down Expand Up @@ -2922,31 +2923,9 @@ private function sendunitsComplete() {
//to here
// If the dead units not equal the ammount sent they will return and report
if($totalsend_att - ($totaldead_att + (isset($totaltraped_att) ? $totaltraped_att : 0)) > 0)
{
$artefact = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,3,0));
$artefact1 = count($database->getOwnUniqueArtefactInfo2($from['wref'],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;
}
$endtime = round($this->procDistanceTime($from,$to,min($speeds),1)/$fastertroops);
$foolartefact2 = $database->getFoolArtefactInfo(2,$from['wref'],$from['owner']);
if(count($foolartefact2) > 0){
foreach($foolartefact2 as $arte){
if($arte['bad_effect'] == 1){
$endtime *= $arte['effect2'];
}else{
$endtime /= $arte['effect2'];
$endtime = round($endtime);
}
}
}
{
$troopsTime = $this->procDistanceTime($from, $to, min($speeds), 1);
$endtime = $database->getTroopsWalkingTime($from['owner'], $from['wref'], 2, $troopsTime);
$endtime += $AttackArrivalTime;
if($type == 1) {
if($from['owner'] == 3) { //fix natar report by ronix
Expand Down Expand Up @@ -3026,54 +3005,29 @@ private function sendunitsComplete() {
$herosend_att = $data['t11'];
$unitssend_att= $unitssend_att1.','.$herosend_att;

$speeds = array();
$speeds = [];

//find slowest unit.
for($i=1;$i<=10;$i++)
//TODO: Needs to be made as a function
for($i = 1; $i <= 10; $i++)
{
if ($data['t'.$i] > 0) {
if($unitarray) { reset($unitarray); }
$unitarray = $GLOBALS["u".(($owntribe-1)*10+$i)];
$speeds[] = $unitarray['speed'];
}
}

if ($herosend_att>0){
if ($herosend_att > 0){
$hero_unit = $database->getHeroField($from['owner'], 'unit');
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
}

$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;
}

$endtime = round($this->procDistanceTime($from,$to,min($speeds),1)/$fastertroops);
$foolartefact3 = $database->getFoolArtefactInfo(2,$from['wref'],$from['owner']);

if(count($foolartefact3) > 0){
foreach($foolartefact3 as $arte){
if($arte['bad_effect'] == 1){
$endtime *= $arte['effect2'];
}else{
$endtime /= $arte['effect2'];
$endtime = round($endtime);
}
}
}
$troopsTime = $this->procDistanceTime($from, $to, min($speeds), 1);
$endtime = $database->getTroopsWalkingTime($from['owner'], $from['wref'], 2, $troopsTime);
$endtime += $AttackArrivalTime;
//$endtime += microtime(true);

$database->setMovementProc($data['moveid']);
$database->addMovement(4,$to['wref'],$from['wref'],$data['ref'],$AttackArrivalTime,$endtime);
$database->addMovement(4, $to['wref'], $from['wref'], $data['ref'], $AttackArrivalTime, $endtime);
$peace = PEACE;
$data2 = $from['owner'].','.$from['wref'].','.$to['owner'].','.$owntribe.','.$unitssend_att.','.$peace;
$time = time();
Expand Down Expand Up @@ -5863,37 +5817,33 @@ function medals(){
private function artefactOfTheFool() {
global $database;
$time = time();
$q = "SELECT id, size FROM " . TB_PREFIX . "artefacts where type = 8 and active = 1 and lastupdate <= ".($time - 86400);
$q = "SELECT id, size FROM " . TB_PREFIX . "artefacts where type = 8 AND active = 1 AND lastupdate <= ".($time - (86400 / (SPEED == 2 ? 1.5 : (SPEED == 3 ? 2 : SPEED))));
$array = $database->query_return($q);
if ($array) {
foreach($array as $artefact) {
$kind = rand(1,7);
$kind = rand(1, 7);
while($kind == 6){
$kind = rand(1,7);
}
if($artefact['size'] != 3){
$bad_effect = rand(0,1);
}else{
$bad_effect = 0;
$kind = rand(1, 7);
}
if($artefact['size'] != 3) $bad_effect = rand(0, 1);
else $bad_effect = 0;

switch($kind) {
case 1:
$effect = rand(1,5);
$effect = rand(1, 5);
break;
case 2:
$effect = rand(1,3);
$effect = rand(1, 3);
break;
case 3:
$effect = rand(3,10);
$effect = rand(3, 10);
break;
case 4:
$effect = rand(2,4);
break;
case 5:
$effect = rand(2,4);
$effect = rand(2, 4);
break;
case 7:
$effect = rand(1,6);
$effect = rand(1, 6);
break;
}
mysqli_query($database->dblink,"UPDATE ".TB_PREFIX."artefacts SET kind = ". (int) $kind. ", bad_effect = $bad_effect, effect2 = $effect, lastupdate = $time WHERE id = ".(int) $artefact['id']);
Expand Down
58 changes: 53 additions & 5 deletions GameEngine/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3504,7 +3504,11 @@ function getFieldLevelInVillage($vid, $fieldType, $use_cache = true) {
IF(
f40t IN ($fieldType),
f40,
0
IF(
f99t IN ($fieldType),
f99,
0
)
)
)
)
Expand Down Expand Up @@ -3635,7 +3639,7 @@ function getFieldLevelInVillage($vid, $fieldType, $use_cache = true) {
OR
f40t IN ($fieldType)
OR
f99 IN ($fieldType))
f99t IN ($fieldType))
LIMIT 1
");
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
Expand Down Expand Up @@ -6942,6 +6946,50 @@ public function getAvailableExpansionTraining() {
return $slots;
}

/**
* Calculates how much time troops spend to walk from a village to another, counting artifacts
*
* @param int $uid The User ID
* @param int $vid The village ID
* @param int $time The old time, without multipliers
* @return int Returns the new time, multiplied or divided by artifacts bonus or malus
*/

function getTroopsWalkingTime($uid, $vid, $kind, $time){
list($uid, $vid, $time) = $this->escape_input((int) $uid,(int) $vid, $time);

$artefacts = $foolArefacts = [];
$multiplier = [2, 3, 1.5];

$artefacts[] = count($this->getOwnUniqueArtefactInfo2($vid, $kind, 1, 1)); //Village effect
$artefacts[] = count($this->getOwnUniqueArtefactInfo2($uid, $kind, 3, 0)); //Unique effect
$artefacts[] = count($this->getOwnUniqueArtefactInfo2($uid, $kind, 2, 0)); //Account effect

$fasterTroops = 1;
for($i = 0; $i < count($artefacts); $i++)
{
if($artefacts[$i] > 0) {
$fasterTroops = $multiplier[$i];
break;
}
}

$foolArefacts[] = $this->getOwnUniqueArtefactInfo2($vid, 8, 1, 1); //Village effect
$foolArefacts[] = $this->getOwnUniqueArtefactInfo2($uid, 8, 3, 0); //Unique effect

$foolEffect = 1;
for($i = 0; $i < count($foolArefacts); $i++)
{
if(count($foolArefacts[$i]) > 0 && $foolArefacts[$i]['kind'] == $kind)
{
$foolEffect = $foolArefacts[$i]['bad_effect'] == 1 ? $foolArefacts[$i]['effect2'] : 1 / $foolArefacts[$i]['effect2'];
break;
}
}

return round(($time / $fasterTroops) * $foolEffect);
}

function addArtefact($vref, $owner, $type, $size, $name, $desc, $effect, $img) {
list($vref, $owner, $type, $size, $name, $desc, $effect, $img) = $this->escape_input($vref, $owner, $type, $size, $name, $desc, $effect, $img);

Expand Down Expand Up @@ -7067,8 +7115,8 @@ function getOwnUniqueArtefactInfo2($id, $type, $size, $mode, $use_cache = true)
return (isset(self::$artefactDataCache[$id.$mode][$size.$type]) ? self::$artefactDataCache[$id.$mode][$size.$type] : []);
}

function getFoolArtefactInfo($type,$vid,$uid, $use_cache = true) {
list($type,$vid,$uid) = $this->escape_input((int) $type,(int) $vid,(int) $uid);
function getFoolArtefactInfo($type, $vid, $uid, $use_cache = true) {
list($type, $vid, $uid) = $this->escape_input((int) $type, (int) $vid, (int) $uid);

// first of all, check if we should be using cache and whether the field
// required is already cached
Expand Down Expand Up @@ -7199,7 +7247,7 @@ function areArtifactsSpawned(){
function getInactiveArtifacts($time){
list($time) = $this->escape_input($time);

$q = "SELECT * FROM ".TB_PREFIX."artefacts WHERE active = 0 AND owner > 5 AND conquered < $time ORDER BY conquered ASC, size ASC";
$q = "SELECT * FROM ".TB_PREFIX."artefacts WHERE active = 0 AND owner > 5 AND conquered <= $time ORDER BY conquered ASC, size ASC";
$result = mysqli_query($this->dblink, $q);
return $this->mysqli_fetch_all($result);
}
Expand Down
Loading

4 comments on commit 8e731dd

@Shadowss
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So , after this update will remail Forbiden Manuscript ?
I understand you modify the effect from account to village. It's correct ?

@velhbxtyrj
Copy link
Collaborator

@velhbxtyrj velhbxtyrj commented on 8e731dd Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attack with the leaders on the village with an artifact.

Fatal error: Uncaught Error: Call to a member function getOwnArtifactsSum() on null in /home/u997437127/public_html/GameEngine/Database.php:7322 Stack trace: #0 /home/u997437127/public_html/GameEngine/Automation.php(2691): MYSQLi_DB->canClaimArtifact('21816', '7321', 1, 8) #1 /home/u997437127/public_html/GameEngine/Automation.php(78): Automation->sendunitsComplete() #2 /home/u997437127/public_html/GameEngine/Automation.php(5854): Automation->__construct() #3 /home/u997437127/public_html/GameEngine/Village.php(341): include_once('/home/u99743712...') #4 /home/u997437127/public_html/dorf1.php(16): include_once('/home/u99743712...') #5 {main} thrown in /home/u997437127/public_html/GameEngine/Database.php on line 7322

@velhbxtyrj
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually:

default

@iopietro
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shadowss, Yep, I only removed the "Account effect" fools artifacts.
@velhbxtyrj Fixed in 6394707.

Please sign in to comment.