diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-11-29 11:03:15 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-11-29 11:03:15 +0100 |
commit | fa9096c0ab521aae45cab6c48a54290d14a221b9 (patch) | |
tree | 61466b792c2714848cfea00594456ac06c259c94 /src/EventRunner.php | |
parent | 3afcaef927391db23fe23c6c8c26b8960e8dae32 (diff) |
event tables
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 |