diff options
Diffstat (limited to 'src/EventRunner.php')
-rw-r--r-- | src/EventRunner.php | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/src/EventRunner.php b/src/EventRunner.php index a071d32..7dd773d 100644 --- a/src/EventRunner.php +++ b/src/EventRunner.php @@ -9,7 +9,9 @@ use App\Model\Building\IronMine; use App\Model\Building\ResourceGenerator; use App\Model\Building\Storage; use App\Model\Building\WoodCutter; -use App\Model\Event; +use App\Model\Event\SendUnits; +use App\Model\Event\TrainUnits; +use App\Model\Event\UpgradeBuilding; use App\Model\Village; class EventRunner @@ -18,28 +20,57 @@ class EventRunner { // Events - $results = DB::query('select * from events where time < now()')->fetchAll(); + # Upgrade Building + + $results = DB::query(<<<SQL + select * from events + inner join events_upgrade_building as event + on events.id = event.event_id + where events.time < now() + SQL)->fetchAll(); foreach ($results as $row) { - /**@var Event $event*/ - $event = DB::convertToModel(Event::resolveType($row['type']), $row); + /**@var UpgradeBuilding $event*/ + $event = DB::convertToModel(UpgradeBuilding::class, $row); $event(); - DB::query( - 'delete from events where id=:id', - ['id' => $event->id] - ); + $event->dbDelete(); } - # Upgrade Building + # Train Units $results = DB::query(<<<SQL select * from events - inner join event_upgrade_building as event + inner join events_train_units as event on events.id = event.event_id where events.time < now() SQL)->fetchAll(); + foreach ($results as $row) { + /**@var TrainUnits $event*/ + $event = DB::convertToModel(TrainUnits::class, $row); + $event(); + + $event->dbDelete(); + } + + # Send Units + + $results = DB::query(<<<SQL + select * from events + inner join events_send_units as event + on events.id = event.event_id + where events.time < now() + SQL)->fetchAll(); + + foreach ($results as $row) { + /**@var SendUnits $event*/ + $event = DB::convertToModel(SendUnits::class, $row); + $event(); + + $event->dbDelete(); + } + // Resources |