Exemplo n.º 1
0
            $productions[$i] = $productions[$i] + $sectorProductions[$i];
            $spends[$i] = $spends[$i] + $sectorSpends[$i];
        }
    }
    $playerResources = $sessionPlayer->getResources();
    for ($i = 0; $i < count($productions); $i++) {
        if (isset($availableResources[$i + 1])) {
            $balances[$i] = $sectorProductions[$i] - $sectorSpends[$i];
            $totalBalances[$i] += $balances[$i];
            $playerResources[$i] = sprintf($playerResources[$i] + $balances[$i] / 3600 * ($now - $sessionPlayer->getLastUpdate()));
        }
    }
    $sessionPlayer->setBalances($totalBalances);
    $sessionPlayer->setResources($playerResources);
}
$battleCostsArr = $playerConn->getBattleCosts($sessionPlayer->getId());
foreach ($battleCostsArr as $battleCostArr) {
    $battleCosts = explode(",", $battleCostArr[3]);
    $playerResources = $sessionPlayer->getResources();
    for ($i = 0; $i < count($battleCosts); $i++) {
        if (isset($availableResources[$i + 1])) {
            $playerResources[$i] = sprintf($playerResources[$i] - $battleCosts[$i] / 3600 * ($now - $sessionPlayer->getLastUpdate()));
            $totalBalances[$i] -= $battleCosts[$i];
        }
    }
    $sessionPlayer->setBalances($totalBalances);
    $sessionPlayer->setResources($playerResources);
}
$playerConn->updatePlayerResources($sessionPlayer->getId(), implode(",", $playerResources), $now);
$sessionPlayer->setResources($playerResources);
$sessionPlayer->setLastUpdate($now);