diff --git a/app/Commands/Simulate.php b/app/Commands/Simulate.php index 3856164..27f2c80 100644 --- a/app/Commands/Simulate.php +++ b/app/Commands/Simulate.php @@ -1,6 +1,7 @@ schedule()->timelimit = 20; diff --git a/app/Controllers/Simulate.php b/app/Controllers/Simulate.php index 42d7811..80ad561 100644 --- a/app/Controllers/Simulate.php +++ b/app/Controllers/Simulate.php @@ -1,6 +1,7 @@ setCrit(0); diff --git a/app/Units/Hero.php b/app/Units/Hero.php index 1a7a9be..b17be14 100644 --- a/app/Units/Hero.php +++ b/app/Units/Hero.php @@ -108,7 +108,6 @@ public function name(): string /** * Add each talent to the list of selected talents. - * WIP - probably needs to check for talent removal or something * * @param string $nameId nameId of the target talent * diff --git a/app/Units/Unit.php b/app/Units/Unit.php new file mode 100644 index 0000000..e737707 --- /dev/null +++ b/app/Units/Unit.php @@ -0,0 +1,87 @@ +cUnitId = $cUnitId; + } + + /** + * Lazy load data from the source. + */ + protected function ensureData(): void + { + // If the data is there then all is well + if ($this->data) + { + return; + } + + // Make sure the data is loaded from file + if (self::$master === null) + { + $path = $this->getPath('unitdata_*.json'); + $json = file_get_contents($path); + self::$master = json_decode($json); + } + + // Clone the master data to the current set + /* + * WIP - `clone` doesn't dereference sub-objects, hack it with serializing for now + * $this->data = clone self::$master->{$this->cHeroId}; + */ + $this->data = unserialize(serialize(self::$master->{$this->cUnitId})); + } + + /** + * Resets data to their defaults and clears all statuses. + * + * @return $this + */ + public function reset() + { + $this->data = unserialize(serialize(self::$master->{$this->cUnitId})); + + foreach ($this->statuses as $statusId => $status) + { + $this->removeStatus($statusId); + } + + return $this; + } + + /** + * Returns this unit's cUnitId. + * + * @return string + */ + public function name(): string + { + return $this->cUnitId; + } +} diff --git a/app/Views/simulate.php b/app/Views/simulate.php index acaf27f..ecc9a44 100644 --- a/app/Views/simulate.php +++ b/app/Views/simulate.php @@ -16,8 +16,9 @@