-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php namespace App\Units; | ||
|
||
/** | ||
* Class Unit | ||
* | ||
* A non-hero unit, relevant for PvE. | ||
*/ | ||
class Unit extends BaseUnit | ||
{ | ||
/** | ||
* Master set of all unitdata. | ||
* | ||
* @var object | ||
*/ | ||
protected static $master; | ||
|
||
/** | ||
* Unique unit identifier. | ||
* | ||
* @var string | ||
*/ | ||
protected $cUnitId; | ||
|
||
/** | ||
* Create the unit with an intial set of values. | ||
* | ||
* @param string $cUnitId The ID of the unit to load | ||
*/ | ||
public function __construct(string $cUnitId) | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters