diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2025-03-24 13:28:57 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2025-03-24 13:28:57 +0100 |
commit | a21b030abd4d5cd88f914f79574e425c7908553a (patch) | |
tree | c4eca5ff8e3dd5b12c4a151045ebb0991b211a9b /src/Model/Event/UpgradeBuilding.php | |
parent | d58f61770463aab2c71464c11f902f0074b49b62 (diff) |
Diffstat (limited to 'src/Model/Event/UpgradeBuilding.php')
-rw-r--r-- | src/Model/Event/UpgradeBuilding.php | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/Model/Event/UpgradeBuilding.php b/src/Model/Event/UpgradeBuilding.php index a3f3984..5993105 100644 --- a/src/Model/Event/UpgradeBuilding.php +++ b/src/Model/Event/UpgradeBuilding.php @@ -3,17 +3,21 @@ namespace App\Model\Event; use App\DB; +use App\Model\Village; class UpgradeBuilding extends BaseEvent { public string $type; + public int $wood; + public int $clay; + public int $iron; /** * @return void */ public function __invoke(): void { - $this->getEvent(); + $this->populateEvent(); DB::query( <<<SQL @@ -26,8 +30,44 @@ class UpgradeBuilding extends BaseEvent ); } + /*public function populateEvent(): void + { + parent::populateEvent(); + + $event = DB::fetch(UpgradeBuilding::class, 'select * from events_upgrade_building where id=:id', ['id' => $this->id])[0]; + $this->type = $event->type; + $this->wood = $event->wood; + $this->clay = $event->clay; + $this->iron = $event->iron; + }*/ + + public function create(): void + { + $this->populateEvent(); + + // remove resources + $village = Village::get($this->event->villageId); + $village->wood -= $this->wood; + $village->clay -= $this->clay; + $village->iron -= $this->iron; + $village->updateResources(); + + // add to db + $this->dbInsert(); + } + public function cancel(): void { + $this->populateEvent(); + + // add resources + $village = Village::get($this->event->villageId); + $village->wood += $this->wood; + $village->clay += $this->clay; + $village->iron += $this->iron; + $village->updateResources(); + + // remove from db $this->dbDelete(); } @@ -39,8 +79,14 @@ class UpgradeBuilding extends BaseEvent ); DB::query( - 'insert into events_upgrade_building (event_id, type) VALUES (:event_id, :type)', - ['event_id' => DB::$connection->lastInsertId(), 'type' => $this->type] + 'insert into events_upgrade_building (event_id, type, wood, clay, iron) VALUES (:event_id, :type, :wood, :clay, :iron)', + [ + 'event_id' => DB::$connection->lastInsertId(), + 'type' => $this->type, + 'wood' => $this->wood, + 'clay' => $this->clay, + 'iron' => $this->iron, + ] ); } |