diff --git a/hwe/sammo/Command/General/che_임관.php b/hwe/sammo/Command/General/che_임관.php index 5861d52b..e0534c89 100644 --- a/hwe/sammo/Command/General/che_임관.php +++ b/hwe/sammo/Command/General/che_임관.php @@ -55,6 +55,9 @@ class che_임관 extends Command\GeneralCommand{ if($destGeneralID < 1){ return false; } + if($destGeneralID == $this->generalObj->getID()){ + return false; + } $this->arg = [ 'destGeneralID' => $destGeneralID diff --git a/hwe/sammo/Command/Nation/che_발령.php b/hwe/sammo/Command/Nation/che_발령.php new file mode 100644 index 00000000..0ca4eded --- /dev/null +++ b/hwe/sammo/Command/Nation/che_발령.php @@ -0,0 +1,129 @@ +arg)){ + return false; + } + if(!key_exists('destCityID', $this->arg)){ + return false; + } + if(!key_exists($this->arg['destCityID'], CityConst::all())){ + return false; + } + $destGeneralID = $this->arg['destGeneralID']; + $destCityID = $this->arg['destCityID']; + + if($destGeneralID == $this->generalObj->getID()){ + return false; + } + $this->arg = [ + 'destGeneralID'=>$destGeneralID, + 'destCityID'=>$destCityID, + ]; + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $this->setCity(); + $this->setNation(); + + $this->setDestCity($this->arg['destCityID'], null); + + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, 1); + $this->setDestGeneral($destGeneral); + + $this->runnableConstraints=[ + ConstraintHelper::BeChief(), + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::FriendlyDestGeneral(), + ConstraintHelper::OccupiedDestCity(), + ConstraintHelper::SuppliedDestCity(), + ]; + } + + public function getFailString():string{ + $commandName = $this->getName(); + $failReason = $this->testRunnable(); + if($failReason === null){ + throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집'); + } + $destGeneralName = $this->destGeneralObj->getName(); + return "{$failReason} {$destGeneralName} {$commandName} 실패."; + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 0; + } + + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + + $general = $this->generalObj; + $generalName = $general->getName(); + $date = substr($general->getVar('turntime'),11,5); + + $destCity = $this->destCity; + $destCityID = $destCity['city']; + $destCityName = $destCity['name']; + + $destGeneral = $this->destGeneralObj; + $destGeneralName = $destGeneral->getName(); + + $logger = $general->getLogger(); + + $destGeneral->setVar('city', $destCityID); + + $josaUl = JosaUtil::pick($destGeneralName, '을'); + $josaRo = JosaUtil::pick($destCityName, '로'); + $destGeneral->getLogger()->pushGeneralActionLog("{$generalName}에 의해 {$destCityName}{$josaRo} 발령됐습니다. <1>$date"); + $logger->pushGeneralActionLog("{$destGeneralName}{$josaUl} {$destCityName}{$josaRo} 발령했습니다. <1>$date"); + + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->applyDB($db); + $destGeneral->applyDB($db); + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ContraintHelper.php b/hwe/sammo/Constraint/ContraintHelper.php index b31373c5..f0c63d0d 100644 --- a/hwe/sammo/Constraint/ContraintHelper.php +++ b/hwe/sammo/Constraint/ContraintHelper.php @@ -135,6 +135,10 @@ class ConstraintHelper{ static function OccupiedCity(bool $allowNeutral=false):array{ return [__FUNCTION__, $allowNeutral]; } + + static function OccupiedDestCity():array{ + return [__FUNCTION__]; + } static function RemainCityCapacity($key, string $actionName):array{ return [__FUNCTION__, $key, $actionName]; @@ -207,6 +211,10 @@ class ConstraintHelper{ static function SuppliedCity():array{ return [__FUNCTION__]; } + + static function SuppliedDestCity():array{ + return [__FUNCTION__]; + } static function WanderingNation():array{ return [__FUNCTION__]; diff --git a/hwe/sammo/Constraint/NotOccupiedDestCity.php b/hwe/sammo/Constraint/NotOccupiedDestCity.php index fdcc2aa8..26040a50 100644 --- a/hwe/sammo/Constraint/NotOccupiedDestCity.php +++ b/hwe/sammo/Constraint/NotOccupiedDestCity.php @@ -27,7 +27,7 @@ class NotOccupiedDestCity extends Constraint{ $this->checkInputValues(); $this->tested = true; - if($this->destCity['nation'] == $this->general['nation']){ + if($this->destCity['nation'] != $this->general['nation']){ return true; } diff --git a/hwe/sammo/Constraint/OccupiedDestCity.php b/hwe/sammo/Constraint/OccupiedDestCity.php new file mode 100644 index 00000000..37506323 --- /dev/null +++ b/hwe/sammo/Constraint/OccupiedDestCity.php @@ -0,0 +1,37 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nation in general"); + } + + if(!key_exists('nation', $this->destCity)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nation in city"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->destCity['nation'] == $this->general['nation']){ + return true; + } + + $this->reason = "아국이 아닙니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/SuppliedDestCity.php b/hwe/sammo/Constraint/SuppliedDestCity.php new file mode 100644 index 00000000..21fd1ec8 --- /dev/null +++ b/hwe/sammo/Constraint/SuppliedDestCity.php @@ -0,0 +1,32 @@ +destCity)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require supply in city"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->destCity['supply']){ + return true; + } + + $this->reason = "고립된 도시입니다."; + return false; + } +} \ No newline at end of file