fetchAll(); foreach ($results as $row) { /**@var UpgradeBuilding $event*/ $event = DB::convertToModel(UpgradeBuilding::class, $row); $event(); $event->dbDelete(); } # Train Units $results = DB::query(<<fetchAll(); foreach ($results as $row) { /**@var TrainUnits $event*/ $event = DB::convertToModel(TrainUnits::class, $row); $event(); $event->dbDelete(); } # Send Units $results = DB::query(<<fetchAll(); foreach ($results as $row) { /**@var SendUnits $event*/ $event = DB::convertToModel(SendUnits::class, $row); $event(); $event->dbDelete(); } // Resources $lastTick = json_decode(DB::query('select value from system where key=:key', ['key' => 'last_resource_tick'])->fetchColumn()); if ($lastTick) { $lastTick = new \DateTime($lastTick); } else { $lastTick = (new \DateTime())->modify('- 1 min'); } $diff = (new \DateTime())->diff($lastTick); $tickMultiplier = $diff->i + 60*$diff->h + 60*24*$diff->d; if ($tickMultiplier > 0) { $villages = DB::fetch(Village::class, 'select id,wood,clay,iron,food from villages'); foreach ($villages as $village) { /**@var Village $village*/ /**@var array $resourceGenerators*/ $resourceGenerators = []; /**@var Storage $storage*/ $storage = null; /**@var Building[] $buildings*/ $buildings = DB::fetch(ResourceGenerator::class, 'select level,type,village_id from village_buildings where village_id=:id', ['id' => $village->id]); foreach ($buildings as $building) { if ($building->type == 'Storage') { $storage = $building->cast(); } else if (in_array($building->type, ['WoodCutter', 'ClayPit', 'IronMine', 'Farm'])) { $resourceGenerators[] = $building->cast(); } } $resources = []; foreach ($resourceGenerators as $generator) { $village->{$generator->resourceType} = min( $village->{$generator->resourceType} + ($generator->getResourceIncrementor() * $tickMultiplier), $storage->getResourceCapacity($generator->resourceType) ); } DB::query( 'update villages set wood=:wood, clay=:clay, iron=:iron, food=:food where id=:id', ['wood' => $village->wood, 'clay' => $village->clay, 'iron' => $village->iron, 'food' => $village->food, 'id' => $village->id] ); } DB::query('delete from system where key=:key', ['key' => 'last_resource_tick']); $lastResourceTickMinute = (new \DateTime((new \DateTime())->format('Y-m-d H:i')))->format('c'); DB::query('insert into system (key,value) VALUES (:key,:value)', ['key' => 'last_resource_tick', 'value' => json_encode($lastResourceTickMinute)]); } } }