<?php
include_once $PATH_TO_CODE."/script/tick/allincludefortick.php";
class MoneyTick extends TickRunnable {
public function getName() {
return "Income";
}
public function run() {
global $gloObjectManager;
//TODO : we can improve that with sum all in a map and next addCash to player
$res = executer("SELECT playerId, ".DungeonConstante::$INCOME_LORD_BEING." FROM player");
$this->addCashIncomeWithRes($res);
$res = executer("SELECT playerId, 20 FROM player");
$this->addCashIncomeWithRes($res, true);
//FIXME : change all of this !
/*
$res = DungeonPlayer::selectIncomeForBlock();
$this->addCashIncomeWithRes($res);
$res = DungeonPlayer::selectIncomeForBarrack();
$this->addCashIncomeWithRes($res);
no more gold in this version
$res = DungeonPlayer::selectIncomeForGoldMine();
while($row = mysql_fetch_array($res)) {
$locPlayerId = $row[0];
$locPlayer = $gloObjectManager->getPlayer($locPlayerId);
$locPlayer->addCash($row[1]/10);
}
*/
$res = DungeonPlayer::selectIncomeForPopulation();
$this->addCashIncomeWithRes($res);
$res = DungeonPlayer::selectIncomeTroopUpkeep();
$this->addCashIncomeWithRes($res);
$res = DungeonPlayer::selectIncomeForUpToNullCash();
$this->addCashIncomeWithRes($res);
$res = DungeonPlayer::selectIncomeForShame();
$this->addCashIncomeWithRes($res);
DungeonPlayer::updateShame();
}
protected function addCashIncomeWithRes($res, $parIsForCash2=false) {
global $gloObjectManager;
while($row=mysql_fetch_array($res))
{
$locPlayerId = $row[0];
$locMoney = $row[1];
if($locMoney <> 0) {
$locPlayer = $gloObjectManager->getPlayer($locPlayerId);
if($parIsForCash2) {
$locPlayer->addCash2($locMoney);
} else {
$locPlayer->addCash($locMoney);
}
}
}
}
}
?>