/
Forest.php
88 lines (77 loc) · 2.81 KB
/
Forest.php
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
88
<?php
namespace App\Entity\Cell\HasWoods;
use App\Entity\Cell\Cell;
use App\Entity\Cell\CellConst;
use App\Entity\Cell\PassTurnResult;
use App\Entity\Log\Logs;
use App\Entity\Status\Status;
use App\Entity\Terrain\Terrain;
use App\Models\Island;
use App\Models\Turn;
use Illuminate\Support\Collection;
class Forest extends Cell implements IHasWoods
{
public const IMAGE_PATH = '/img/hakoniwa/hakogif/land6.gif';
public const TYPE = 'forest';
public const NAME = '森';
public const INITIAL_WOODS = 100;
private const INCREMENT_WOODS = 100;
private const MAX_WOODS = 100000;
public const WOODS_TO_RESOURCES_COEF = 0.5;
const ATTRIBUTE = [
CellConst::IS_LAND => true,
CellConst::IS_MONSTER => false,
CellConst::IS_SHIP => false,
CellConst::DESTRUCTIBLE_BY_FIRE => false,
CellConst::DESTRUCTIBLE_BY_TSUNAMI => false,
CellConst::DESTRUCTIBLE_BY_EARTHQUAKE => false,
CellConst::DESTRUCTIBLE_BY_TYPHOON => false,
CellConst::DESTRUCTIBLE_BY_METEORITE => true,
CellConst::DESTRUCTIBLE_BY_WIDE_AREA_DAMAGE_2HEX => true,
CellConst::DESTRUCTIBLE_BY_MISSILE => true,
CellConst::DESTRUCTIBLE_BY_RIOT => false,
CellConst::DESTRUCTIBLE_BY_MONSTER => true,
CellConst::PREVENTING_FIRE => true,
CellConst::PREVENTING_TYPHOON => true,
CellConst::PREVENTING_TSUNAMI => true,
];
protected string $imagePath = self::IMAGE_PATH;
protected string $type = self::TYPE;
protected string $name = self::NAME;
public function __construct(...$data)
{
parent::__construct(...$data);
if (array_key_exists('woods', $data)) {
$this->woods = $data['woods'];
} else {
$this->woods = self::INITIAL_WOODS;
}
}
public function toArray(bool $isPrivate = false, bool $withStatic = false): array
{
$arr = parent::toArray($isPrivate, $withStatic);
$arr['data']['woods'] = $this->woods;
return $arr;
}
public function getInfoString(bool $isPrivate = false): string
{
if ($isPrivate) {
return
'(' . $this->point->x . ',' . $this->point->y . ') ' . $this->getName() . PHP_EOL .
$this->woods . '本';
}
return '(' . $this->point->x . ',' . $this->point->y . ') ' . $this->getName();
}
public function passTurn(Island $island, Terrain $terrain, Status $status, Turn $turn, Collection $foreignIslandEvents): PassTurnResult
{
if ($this->woods >= self::MAX_WOODS) {
return new PassTurnResult($terrain, $status, Logs::create());
}
$this->woods += self::INCREMENT_WOODS;
return new PassTurnResult($terrain, $status, Logs::create());
}
public function getWoods(): int
{
return $this->woods;
}
}