From df6b2bd0e8663bb5b0dea99749ad695f7c83cbc8 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 2 Sep 2018 13:17:26 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B4=88=EA=B8=B0=20constraint=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Constraint/Constraint.php | 157 ++++++++++++++++++++ hwe/sammo/Constraint/NoFullCityCapacity.php | 47 ++++++ hwe/sammo/Constraint/NoNeutral.php | 32 ++++ hwe/sammo/Constraint/NoOpeningPart.php | 31 ++++ hwe/sammo/Constraint/NoWanderingNation.php | 32 ++++ hwe/sammo/GameConstBase.php | 3 + 6 files changed, 302 insertions(+) create mode 100644 hwe/sammo/Constraint/Constraint.php create mode 100644 hwe/sammo/Constraint/NoFullCityCapacity.php create mode 100644 hwe/sammo/Constraint/NoNeutral.php create mode 100644 hwe/sammo/Constraint/NoOpeningPart.php create mode 100644 hwe/sammo/Constraint/NoWanderingNation.php diff --git a/hwe/sammo/Constraint/Constraint.php b/hwe/sammo/Constraint/Constraint.php new file mode 100644 index 00000000..d34095a0 --- /dev/null +++ b/hwe/sammo/Constraint/Constraint.php @@ -0,0 +1,157 @@ +general = $general; + $this->tested = false; + $this->reason = null; + } + public function city(array $city){ + $this->city = $city; + $this->tested = false; + $this->reason = null; + } + public function nation(array $nation){ + $this->nation = $nation; + $this->tested = false; + $this->reason = null; + } + public function arg($arg){ + $this->arg = $arg; + $this->tested = false; + $this->reason = null; + } + + public function destGeneral(array $general){ + $this->destGeneral = $general; + $this->tested = false; + $this->reason = null; + } + public function destCity(array $city){ + $this->destCity = $city; + $this->tested = false; + $this->reason = null; + } + public function destNation(array $nation){ + $this->destNation = $nation; + $this->tested = false; + $this->reason = null; + } + + static public function build(array $input):this{ + $self = new static(); + foreach($input as $key=>$value){ + switch($key){ + case 'general': $self->general($value); break; + case 'city': $self->city($value); break; + case 'nation': $self->nation($value); break; + case 'arg': $self->arg($value); break; + + case 'destGeneral': $self->destGeneral($value); break; + case 'destCity': $self->destCity($value); break; + case 'destNation': $self->destNation($value); break; + } + } + + return $self; + } + + public function checkInputValues(bool $throwExeception=true):bool{ + $valueType = static::requiredValueType(); + + if(($valueType&REQ_GENERAL) && $this->general === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require general'); + } + + if(($valueType&REQ_CITY) && $this->city === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require city'); + } + + if(($valueType&REQ_NATION) && $this->nation === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require nation'); + } + + if (!($valueType&REQ_ARG)) { + return true; + } + + if($valueType === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require arg'); + } + + if(($valueType&REQ_STRING_ARG) && !is_string($this->arg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require string arg'); + } + + if(($valueType&REQ_INT_ARG) && !is_int($this->arg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require int arg'); + } + + if(($valueType&REQ_NUMERIC_ARG) && !is_numeric($this->arg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require numeric arg'); + } + + if(!($valueType&REQ_ARRAY_ARG) && !is_array($this->arg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require array arg'); + } + + return true; + } + + public function reason($withTest=true):?string{ + if(!$this->tested === false){ + if($withTest){ + $this->test(); + } + else{ + throw new \RuntimeException('test가 실행되지 않음'); + } + + } + return $this->reason; + } + +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NoFullCityCapacity.php b/hwe/sammo/Constraint/NoFullCityCapacity.php new file mode 100644 index 00000000..c565a9aa --- /dev/null +++ b/hwe/sammo/Constraint/NoFullCityCapacity.php @@ -0,0 +1,47 @@ +key, $this->keyNick] = $this->arg; + $this->maxKey = $this->key.'2'; + + if(!key_exists($this->key, $this->city)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require {$this->key} in city"); + } + + if(!key_exists($this->maxKey, $this->city)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require {$this->maxKey} in city"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->city[$this->key] < $this->city[$this->maxKey]){ + return true; + } + + $josaUn = JosaUtil::pick($keyNick, '은'); + $this->reason = "{$keyNick}{$josaUn} 충분합니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NoNeutral.php b/hwe/sammo/Constraint/NoNeutral.php new file mode 100644 index 00000000..7d86c0d3 --- /dev/null +++ b/hwe/sammo/Constraint/NoNeutral.php @@ -0,0 +1,32 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require level in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->general['level'] != 0){ + return true; + } + + $this->reason = "재야입니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NoOpeningPart.php b/hwe/sammo/Constraint/NoOpeningPart.php new file mode 100644 index 00000000..db7da18a --- /dev/null +++ b/hwe/sammo/Constraint/NoOpeningPart.php @@ -0,0 +1,31 @@ +relYear = $this->arg; + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($relYear >= GameConst::$openingPartYear){ + return true; + } + + $this->reason = "초반 제한 중에는 불가능합니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NoWanderingNation.php b/hwe/sammo/Constraint/NoWanderingNation.php new file mode 100644 index 00000000..69628e17 --- /dev/null +++ b/hwe/sammo/Constraint/NoWanderingNation.php @@ -0,0 +1,32 @@ +nation)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require level in nation"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->nation['level'] != 0){ + return true; + } + + $this->reason = "방랑군은 불가능합니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index bfe8755b..ade62feb 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -90,4 +90,7 @@ class GameConstBase public static $maxTurn = 24; public static $statGradeLevel = 5; + + /** @var int 초반 제한 기간 */ + public static $openingPartYear = 3; }