This repository has been archived on 2024-07-18. You can view files and clone it, but cannot push or open issues or pull requests.
lwb5/scripts/game/beta5/bq/library/flush.inc

33 lines
779 B
PHP
Raw Normal View History

2016-01-10 11:01:49 +01:00
<?php
class beta5_bq_flush {
function beta5_bq_flush($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Flush a planet's build queue
function run($id) {
$q = $this->db->query("SELECT owner FROM planet WHERE id = $id");
list($uid) = dbFetchArray($q);
if (is_null($uid)) {
return;
}
$ru = $this->rules->call('get', $uid);
$sum = 0;
$q = $this->db->query("SELECT item,quantity FROM buildqueue WHERE planet = $id");
while ($r = dbFetchArray($q)) {
$sum += $r[1] * $ru['build_cost_'.$this->lib->mainClass->types[$r[0]]];
}
$this->db->query("DELETE FROM buildqueue WHERE planet = $id");
$this->db->query("UPDATE player SET cash = cash + $sum WHERE id = $uid");
}
}
?>