/** * Calculates the produced ressources since the last update */ public function calculateResources($time = null) { global $game_config, $planetrow; if ($time === null) { if (class_exists('LWEventHandler')) { $time = LWEventHandler::getTime(); } else { $time = TIME_NOW; } } $this->calculateProduction(false); $timeDiff = $time - $this->last_update; $hangarSQL = $this->checkHangar($timeDiff); // production level @($prodLevel = min(100, $this->energy_max / $this->energy_used * 100) / 100); // metal $prodMetal = $timeDiff * $this->metal_perhour / 3600 * $prodLevel; if ($this->metal + $prodMetal > $this->metal_max && $this->metal < $this->metal_max) { $this->metal = $this->metal_max; } else { $this->metal += $prodMetal; } // crystal $prodCrystal = $timeDiff * $this->crystal_perhour / 3600 * $prodLevel; if ($this->crystal + $prodCrystal > $this->crystal_max && $this->crystal < $this->crystal_max) { $this->crystal = $this->crystal_max; } else { $this->crystal += $prodCrystal; } // deuterium $prodDeuterium = $timeDiff * $this->deuterium_perhour / 3600 * $prodLevel; if ($this->deuterium + $prodDeuterium > $this->deuterium_max && $this->deuterium < $this->deuterium_max) { $this->deuterium = $this->deuterium_max; } else { $this->deuterium += $prodDeuterium; } // basic income if ($this->planet_type == 1) { $this->metal += $timeDiff / 3600 * $game_config['metal_basic_income']; $this->crystal += $timeDiff / 3600 * $game_config['crystal_basic_income']; $this->deuterium += $timeDiff / 3600 * $game_config['deuterium_basic_income']; } if (is_numeric($this->planetID)) { $sql = "UPDATE ugml" . LW_N . "_planets\n\t\t\t\t\tSET metal_perhour = " . $this->metal_perhour . ",\n\t\t\t\t\t\tcrystal_perhour = " . $this->crystal_perhour . ",\n\t\t\t\t\t\tdeuterium_perhour = " . $this->deuterium_perhour . ",\n\t\t\t\t\t\tmetal = " . $this->metal . ",\n\t\t\t\t\t\tcrystal = " . $this->crystal . ",\n\t\t\t\t\t\tdeuterium = " . $this->deuterium . ",\n\t\t\t\t\t\tenergy_used = " . $this->energy_used . ",\n\t\t\t\t\t\tlast_update = " . $time . ",\n\t\t\t\t\t\t" . $hangarSQL . "\n\t\t\t\t\t\tenergy_max = " . $this->energy_max . "\n\t\t\t\t\tWHERE id = " . $this->planetID; WCF::getDB()->sendQuery($sql); /*if(WCF::getUser()->userID == 361) { echo $sql; }*/ } $this->last_update = $time; // update old ugamela vars $planetrow['metal'] = $this->metal; $planetrow['crystal'] = $this->crystal; $planetrow['deuterium'] = $this->deuterium; $planetrow['last_update'] = $this->last_update; }
/** * Updates the activity timestamp */ public function updateLastActivity() { if (!class_exists('LWEventHandler') || !is_numeric($this->planetID)) { return; } $sql = "UPDATE ugml_planets\r\n\t\t\t\tSET last_update = " . LWEventHandler::getTime() . "\r\n\t\t\t\tWHERE id = " . $this->planetID; WCF::getDB()->registerShutdownUpdate($sql); }