Repository navigation
Expand file tree
/
Copy pathUnit.php
More file actions
87 lines (77 loc) · 1.58 KB
/
Copy pathUnit.php
File metadata and controls
87 lines (77 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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;
}
}