lwb5-in-2025/scripts/game/beta5/bq/library/flush.inc

33 lines
776 B
PHP
Raw Normal View History

2016-01-10 11:01:49 +01:00
<?php
class beta5_bq_flush {
2024-12-31 10:42:58 +01:00
function __construct($lib) {
2016-01-10 11:01:49 +01:00
$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");
}
}
?>