feat(wip): GameUnitConstrint
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;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
|
||||
abstract class GameUnitConstraint {
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract function test(General $general, KVStorage $env): bool;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\CityConst;
|
||||
use sammo\General;
|
||||
|
||||
class ReqCities extends BaseGameUnitConstraint {
|
||||
|
||||
public function __construct(protected array $reqCities)
|
||||
{
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
foreach ($this->reqCities as $city) {
|
||||
if (key_exists($city, $ownCities)) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
$cityNames = [];
|
||||
foreach ($this->reqCities as $city) {
|
||||
$cityNames[] = CityConst::byID($city)->name;
|
||||
}
|
||||
|
||||
$cityNameText = implode(', ', $cityNames);
|
||||
return "{$cityNameText} 소유시 가능";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
|
||||
class ReqMinRelYear extends BaseGameUnitConstraint {
|
||||
|
||||
public function __construct(protected 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}년 경과 후 사용 가능";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
if($reqTech > 0){
|
||||
$info[] = "기술력 {$reqTech} 이상 필요";
|
||||
}
|
||||
|
||||
if($reqCities !== null){
|
||||
$reqCities = array_map(function($reqCity) use (&$info){
|
||||
$info[] = "{$reqCity} 소유시 가능";
|
||||
return CityConst::byName($reqCity)->id;
|
||||
}, $reqCities);
|
||||
}
|
||||
|
||||
if($reqRegions !== null){
|
||||
$reqRegions = array_map(function($reqRegion) use (&$info){
|
||||
$info[] = "{$reqRegion} 지역 소유시 가능";
|
||||
return CityConst::$regionMap[$reqRegion];
|
||||
}, $reqRegions);
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\CityConst;
|
||||
use sammo\General;
|
||||
|
||||
class ReqRegions extends BaseGameUnitConstraint {
|
||||
|
||||
public function __construct(protected array $reqRegions)
|
||||
{
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
foreach ($this->reqRegions as $region) {
|
||||
if (key_exists($region, $ownRegions)) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
$regionNames = [];
|
||||
foreach ($this->reqRegions as $region) {
|
||||
$regionNames[] = CityConst::$regionMap[$region];
|
||||
}
|
||||
|
||||
$regionNameText = implode(', ', $regionNames);
|
||||
return "{$regionNameText} 지역 소유시 가능";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\GameUnitConstraint;
|
||||
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
|
||||
class ReqTech extends BaseGameUnitConstraint {
|
||||
|
||||
public function __construct(protected int $reqTech)
|
||||
{
|
||||
}
|
||||
|
||||
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
|
||||
{
|
||||
if ($tech < $this->reqTech) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getInfo(): string
|
||||
{
|
||||
return "기술력 {$this->reqTech} 이상 필요";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user