feat,refac: GameUnitConstraint 개념 추가
- GameUnitDetail의 요구 기술, 지역, 도시, 연도를 GameUnitConstraint로 통합 - GameUnitConstraint는 조건 검사, 설명 제공 - 병종 정의를 GameUnitConstraint 이용 재정의 - test 함수에 General 객체 요구, - test 함수의 ownCities에 단순 도시 외 도시 정보 추가 - 변경된 값에 맞게 호출 함수 변경
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
|
||||
abstract class BaseGameUnitConstraint {
|
||||
public abstract function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool;
|
||||
|
||||
public abstract function getInfo(): string;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
|
||||
class Impossible extends BaseGameUnitConstraint {
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
return "불가능";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\CityConst;
|
||||
use sammo\General;
|
||||
|
||||
class ReqCities extends BaseGameUnitConstraint
|
||||
{
|
||||
|
||||
public readonly array $reqCities;
|
||||
public function __construct(...$reqCities)
|
||||
{
|
||||
$dstReqCities = [];
|
||||
if (count($reqCities) == 0) {
|
||||
$this->reqCities = [];
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($reqCities as $city) {
|
||||
$dstReqCities[CityConst::byName($city)->id] = $city;
|
||||
}
|
||||
$this->reqCities = $dstReqCities;
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
foreach ($this->reqCities as $cityID => $cityName) {
|
||||
if (key_exists($cityID, $ownCities)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
$cityNameText = implode(', ', $this->reqCities);
|
||||
return "{$cityNameText} 소유시 가능";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
|
||||
class ReqMinRelYear extends BaseGameUnitConstraint {
|
||||
|
||||
public function __construct(public readonly int $reqMinRelYear)
|
||||
{
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
return $relativeYear >= $this->reqMinRelYear;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
return "{$this->reqMinRelYear}년 경과 후 사용 가능";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\CityConst;
|
||||
use sammo\General;
|
||||
|
||||
class ReqRegions extends BaseGameUnitConstraint
|
||||
{
|
||||
|
||||
public readonly array $reqRegions;
|
||||
public function __construct(...$reqRegions)
|
||||
{
|
||||
$dstReqRegions = [];
|
||||
if (count($reqRegions) == 0) {
|
||||
$this->reqRegions = [];
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($reqRegions as $region) {
|
||||
$dstReqRegions[CityConst::$regionMap[$region]] = $region;
|
||||
}
|
||||
|
||||
$this->reqRegions = $dstReqRegions;
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
foreach ($this->reqRegions as $regionID => $regionText) {
|
||||
if (key_exists($regionID, $ownRegions)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
$regionNameText = implode(', ', $this->reqRegions);
|
||||
return "{$regionNameText} 지역 소유시 가능";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
|
||||
class ReqTech extends BaseGameUnitConstraint {
|
||||
|
||||
public function __construct(public readonly int $reqTech)
|
||||
{
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
if ($tech < $this->reqTech) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
return "기술력 {$this->reqTech} 이상 필요";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user