diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index 51cf6f90..f83e65a6 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -8,6 +8,7 @@ use \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; abstract class BaseCommand{ /** diff --git a/hwe/sammo/Command/General/che_NPC능동.php b/hwe/sammo/Command/General/che_NPC능동.php index 1e02e260..bf26b1d7 100644 --- a/hwe/sammo/Command/General/che_NPC능동.php +++ b/hwe/sammo/Command/General/che_NPC능동.php @@ -11,6 +11,7 @@ use \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_NPC능동 extends Command\GeneralCommand{ @@ -43,7 +44,7 @@ class che_NPC능동 extends Command\GeneralCommand{ $general = $this->generalObj; $this->runnableConstraints=[ - ['MustBeNPC'] + ConstraintHelper::MustBeNPC() ]; } diff --git a/hwe/sammo/Command/General/che_강행.php b/hwe/sammo/Command/General/che_강행.php index c9f4ff9f..6c292d8f 100644 --- a/hwe/sammo/Command/General/che_강행.php +++ b/hwe/sammo/Command/General/che_강행.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -47,10 +48,10 @@ class che_강행 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotSameDestCity'], - ['NearCity', 3], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::NotSameDestCity(), + ConstraintHelper::NearCity(3), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; } diff --git a/hwe/sammo/Command/General/che_거병.php b/hwe/sammo/Command/General/che_거병.php index cb101b6c..5a282950 100644 --- a/hwe/sammo/Command/General/che_거병.php +++ b/hwe/sammo/Command/General/che_거병.php @@ -12,6 +12,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; use function sammo\getNationTypeClass; use function sammo\refreshNationStaticInfo; @@ -44,9 +45,9 @@ class che_거병 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ - ['BeNeutral'], - ['BeOpeningPart', $relYear], - ['AllowJoinAction'], + ConstraintHelper::BeNeutral(), + ConstraintHelper::BeOpeningPart($relYear), + ConstraintHelper::AllowJoinAction(), ]; } diff --git a/hwe/sammo/Command/General/che_건국.php b/hwe/sammo/Command/General/che_건국.php index d9eadb38..83bed9f9 100644 --- a/hwe/sammo/Command/General/che_건국.php +++ b/hwe/sammo/Command/General/che_건국.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; use function sammo\getNationTypeClass; use function sammo\refreshNationStaticInfo; @@ -78,13 +79,13 @@ class che_건국 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ - ['ReqNationValue', 'gennum', '수하 장수', '>=', 2], - ['BeOpeningPart', $relYear], - ['WanderingNation'], - ['CheckNationNameDuplicate', $nationName], - ['BeLord'], - ['AllowJoinAction'], - ['ConstructableCity'] + ConstraintHelper::ReqNationValue('gennum', '수하 장수', '>=', 2), + ConstraintHelper::BeOpeningPart($relYear), + ConstraintHelper::WanderingNation(), + ConstraintHelper::CheckNationNameDuplicate($nationName), + ConstraintHelper::BeLord(), + ConstraintHelper::AllowJoinAction(), + ConstraintHelper::ConstructableCity(), ]; } diff --git a/hwe/sammo/Command/General/che_견문.php b/hwe/sammo/Command/General/che_견문.php index 58983730..13d183ce 100644 --- a/hwe/sammo/Command/General/che_견문.php +++ b/hwe/sammo/Command/General/che_견문.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use \sammo\TextDecoration\SightseeingMessage; diff --git a/hwe/sammo/Command/General/che_군량매매.php b/hwe/sammo/Command/General/che_군량매매.php index b3c0a15b..6d47029f 100644 --- a/hwe/sammo/Command/General/che_군량매매.php +++ b/hwe/sammo/Command/General/che_군량매매.php @@ -21,6 +21,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\MustNotBeReachedException; class che_군량매매 extends Command\GeneralCommand{ @@ -59,16 +60,16 @@ class che_군량매매 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['ReqCityTrader', $general->getVar('npc')], - ['OccupiedCity', true], - ['SuppliedCity'], + ConstraintHelper::ReqCityTrader($general->getVar('npc')), + ConstraintHelper::OccupiedCity(true), + ConstraintHelper::SuppliedCity(), ]; if($this->arg['buyRice']){ - $this->runnableConstraints[] = ['ReqGeneralGold', 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1); } else{ - $this->runnableConstraints[] = ['ReqGeneralRice', 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1); } } diff --git a/hwe/sammo/Command/General/che_귀환.php b/hwe/sammo/Command/General/che_귀환.php index ad8daa36..896ea20e 100644 --- a/hwe/sammo/Command/General/che_귀환.php +++ b/hwe/sammo/Command/General/che_귀환.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -38,9 +39,9 @@ class che_귀환 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['NotCapital', 1], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::NotCapital(true), ]; } diff --git a/hwe/sammo/Command/General/che_기술연구.php b/hwe/sammo/Command/General/che_기술연구.php index 55120960..27d18ff1 100644 --- a/hwe/sammo/Command/General/che_기술연구.php +++ b/hwe/sammo/Command/General/che_기술연구.php @@ -18,6 +18,7 @@ use function sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_기술연구 extends che_상업투자{ @@ -40,12 +41,12 @@ class che_기술연구 extends che_상업투자{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['SuppliedCity'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice) ]; $this->reqGold = $reqGold; diff --git a/hwe/sammo/Command/General/che_단련.php b/hwe/sammo/Command/General/che_단련.php index 487ba8e5..bea5765d 100644 --- a/hwe/sammo/Command/General/che_단련.php +++ b/hwe/sammo/Command/General/che_단련.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; @@ -37,12 +38,12 @@ class che_단련 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['ReqGeneralCrew'], - ['ReqGeneralValue', 'train', '훈련', GameConst::$defaultTrainHigh], - ['ReqGeneralValue', 'atmos', '사기', GameConst::$defaultAtmosHigh], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::ReqGeneralCrew(), + ConstraintHelper::ReqGeneralValue('train', '훈련', '<', GameConst::$defaultTrainHigh), + ConstraintHelper::ReqGeneralValue('atmos', '사기', '<', GameConst::$defaultAtmosHigh), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; } diff --git a/hwe/sammo/Command/General/che_등용.php b/hwe/sammo/Command/General/che_등용.php index 7659e9ab..d265dde4 100644 --- a/hwe/sammo/Command/General/che_등용.php +++ b/hwe/sammo/Command/General/che_등용.php @@ -20,6 +20,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_등용 extends Command\GeneralCommand{ @@ -57,17 +58,18 @@ class che_등용 extends Command\GeneralCommand{ $this->setDestGeneral($destGeneral); [$reqGold, $reqRice] = $this->getCost(); + $relYear = $this->env['year'] - $this->env['startyear']; $this->runnableConstraints=[ - ['ReqEnvValue', 'join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'], - ['NotBeNeutral'], - ['NotOpeningPart'], - ['OccupiedCity'], - ['SuppliedCity'], - ['ExistsDestGeneral'], - ['DifferentNationDestGeneral'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::ReqEnvValue('join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'), + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotOpeningPart($relYear), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::DifferentNationDestGeneral(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; if($this->destGeneralObj->getVar('level') == 12){ diff --git a/hwe/sammo/Command/General/che_랜덤임관.php b/hwe/sammo/Command/General/che_랜덤임관.php index 997d1560..f275b5ec 100644 --- a/hwe/sammo/Command/General/che_랜덤임관.php +++ b/hwe/sammo/Command/General/che_랜덤임관.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; use sammo\MustNotBeReachedException; @@ -61,10 +62,10 @@ class che_랜덤임관 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ - ['BeNeutral'], - ['ExistsDestNation'], - ['AllowJoinAction'], - ['ExistsAllowJoinNation', $relYear, [$this->arg['destNationIDList']]], + ConstraintHelper::BeNeutral(), + ConstraintHelper::ExistsDestNation(), + ConstraintHelper::AllowJoinAction(), + ConstraintHelper::ExistsAllowJoinNation($relYear, $this->arg['destNationIDList']), ]; } diff --git a/hwe/sammo/Command/General/che_모반.php b/hwe/sammo/Command/General/che_모반.php new file mode 100644 index 00000000..c3482448 --- /dev/null +++ b/hwe/sammo/Command/General/che_모반.php @@ -0,0 +1,119 @@ +arg = null; + return true; + } + + protected function init(){ + + $general = $this->generalObj; + + $this->setNation(); + + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1); + $this->setDestGeneral($destGeneral); + + $this->runnableConstraints=[ + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::BeChief(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::NotLord(), + ConstraintHelper::AllowRebellion(), + ]; + } + + 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; + $date = substr($general->getVar('turntime'),11,5); + + $destGeneral = $this->destGeneralObj; + + $generalName = $general->getName(); + $destGeneralName = $destGeneral->getName(); + + $nationName = $this->nation['name']; + + $logger = $general->getLogger(); + $destLogger = $destGeneral->getLogger(); + + $destGeneral->setVar('level', 12); + $general->setVar('level', 1); + $general->multiplyVar('experience', 0.7); + + $db->update('city', [ + 'gen1'=>0 + ], 'gen1=%i', $destGeneral->getID()); + $db->update('city', [ + 'gen2'=>0 + ], 'gen2=%i', $destGeneral->getID()); + $db->update('city', [ + 'gen3'=>0 + ], 'gen3=%i', $destGeneral->getID()); + + $destGeneral->increaseVarWithLimit($resKey, $amount); + $general->increaseVarWithLimit($resKey, -$amount, 0); + + $josaYi = JosaUtil::pick($generalName, '이'); + $logger->pushGlobalHistoryLog("【선양】{$generalName}{$josaYi} {$nationName}의 군주 자리를 {$destGeneralName}에게 선양했습니다."); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} {$destGeneralName}에게 선양"); + + $logger->pushGeneralActionLog("{$destGeneralName}에게 군주의 자리를 물려줍니다. <1>$date"); + $destLogger->pushGeneralActionLog("{$generalName}에게서 군주의 자리를 물려받습니다."); + + $logger->pushGeneralHistoryLog("{$nationName}의 군주자리를 {$destGeneralName}에게 선양"); + $destLogger->pushGeneralHistoryLog("{$nationName}의 군주자리를 물려 받음"); + + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + $general->applyDB($db); + $destGeneral->applyDB($db); + + return true; + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_물자조달.php b/hwe/sammo/Command/General/che_물자조달.php index 3b0587e2..a5deffe9 100644 --- a/hwe/sammo/Command/General/che_물자조달.php +++ b/hwe/sammo/Command/General/che_물자조달.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_물자조달 extends Command\GeneralCommand{ @@ -37,10 +38,10 @@ class che_물자조달 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['SuppliedCity'] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity() ]; } diff --git a/hwe/sammo/Command/General/che_사기진작.php b/hwe/sammo/Command/General/che_사기진작.php index fd79fc4c..a1588615 100644 --- a/hwe/sammo/Command/General/che_사기진작.php +++ b/hwe/sammo/Command/General/che_사기진작.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_사기진작 extends Command\GeneralCommand{ @@ -36,13 +37,13 @@ class che_사기진작 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['ReqGeneralCrew'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], - ['ReqGeneralAtmosMargin', GameConst::$maxAtmosByCommand], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::ReqGeneralCrew(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::ReqGeneralAtmosMargin(GameConst::$maxAtmosByCommand), ]; } diff --git a/hwe/sammo/Command/General/che_상업투자.php b/hwe/sammo/Command/General/che_상업투자.php index 38b96890..8bb4786d 100644 --- a/hwe/sammo/Command/General/che_상업투자.php +++ b/hwe/sammo/Command/General/che_상업투자.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_상업투자 extends Command\GeneralCommand{ @@ -43,13 +44,13 @@ class che_상업투자 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['SuppliedCity'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], - ['RemainCityCapacity', [static::$cityKey, static::$actionName]] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName) ]; $this->reqGold = $reqGold; diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php index b59c4604..01d5fdd2 100644 --- a/hwe/sammo/Command/General/che_선양.php +++ b/hwe/sammo/Command/General/che_선양.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_선양 extends Command\GeneralCommand{ @@ -55,10 +56,10 @@ class che_선양 extends Command\GeneralCommand{ $this->setDestGeneral($destGeneral); $this->runnableConstraints=[ - ['BeLord'], - ['ExistsDestGeneral'], - ['FriendlyDestGeneral'], - ['DisallowDiplomacyStatus', [4], '현재 통합 진행중입니다.'] + ConstraintHelper::BeLord(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::FriendlyDestGeneral(), + ConstraintHelper::DisallowDiplomacyStatus([4], '현재 통합 진행중입니다.') ]; } diff --git a/hwe/sammo/Command/General/che_소집해제.php b/hwe/sammo/Command/General/che_소집해제.php index 8f52735b..0faff3c6 100644 --- a/hwe/sammo/Command/General/che_소집해제.php +++ b/hwe/sammo/Command/General/che_소집해제.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_소집해제 extends Command\GeneralCommand{ static protected $actionName = '소집해제'; @@ -33,7 +34,7 @@ class che_소집해제 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['ReqGeneralCrew'], + ConstraintHelper::ReqGeneralCrew(), ]; } diff --git a/hwe/sammo/Command/General/che_요양.php b/hwe/sammo/Command/General/che_요양.php index aad99faf..a148ce40 100644 --- a/hwe/sammo/Command/General/che_요양.php +++ b/hwe/sammo/Command/General/che_요양.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; diff --git a/hwe/sammo/Command/General/che_이동.php b/hwe/sammo/Command/General/che_이동.php index 42722226..18d35a59 100644 --- a/hwe/sammo/Command/General/che_이동.php +++ b/hwe/sammo/Command/General/che_이동.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -47,10 +48,10 @@ class che_이동 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotSameDestCity'], - ['NearCity', 1], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::NotSameDestCity(), + ConstraintHelper::NearCity(1), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; } diff --git a/hwe/sammo/Command/General/che_인재탐색.php b/hwe/sammo/Command/General/che_인재탐색.php index bdf29160..e8a6e6d9 100644 --- a/hwe/sammo/Command/General/che_인재탐색.php +++ b/hwe/sammo/Command/General/che_인재탐색.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_인재탐색 extends Command\GeneralCommand{ @@ -39,17 +40,17 @@ class che_인재탐색 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; $relYear = $env['year'] - $env['startyear']; if($relYear < 3 && $this->nation['gennum'] >= GameConst::$initialNationGenLimit){ $nationName = $this->nation['name']; $josaUn = JosaUtil::pick($nationName, '은'); - $this->runnableConstraints[] = ['AlwaysFail', "현재 {$nationName}{$josaUn} 탐색이 제한되고 있습니다."]; + $this->runnableConstraints[] = ConstraintHelper::AlwaysFail("현재 {$nationName}{$josaUn} 탐색이 제한되고 있습니다."); } } diff --git a/hwe/sammo/Command/General/che_임관.php b/hwe/sammo/Command/General/che_임관.php index 38548ebe..5861d52b 100644 --- a/hwe/sammo/Command/General/che_임관.php +++ b/hwe/sammo/Command/General/che_임관.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -84,11 +85,11 @@ class che_임관 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ - ['ReqEnvValue', 'join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'], - ['BeNeutral'], - ['ExistsDestNation'], - ['AllowJoinDestNation', $relYear], - ['AllowJoinAction'] + ConstraintHelper::ReqEnvValue('join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'), + ConstraintHelper::BeNeutral(), + ConstraintHelper::ExistsDestNation(), + ConstraintHelper::AllowJoinDestNation($relYear), + ConstraintHelper::AllowJoinAction() ]; } diff --git a/hwe/sammo/Command/General/che_장비매매.php b/hwe/sammo/Command/General/che_장비매매.php index 4e2c71a2..bd4865f1 100644 --- a/hwe/sammo/Command/General/che_장비매매.php +++ b/hwe/sammo/Command/General/che_장비매매.php @@ -21,6 +21,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_장비매매 extends Command\GeneralCommand{ static protected $actionName = '장비매매'; @@ -65,20 +66,20 @@ class che_장비매매 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['ReqCityTrader', $general->getVar('npc')], - ['ReqCityCapacity', 'secu', '치안 수치', $itemCode * 1000], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::ReqCityTrader($general->getVar('npc')), + ConstraintHelper::ReqCityCapacity('secu', '치안 수치', $itemCode * 1000), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; if($itemCode == 0){ - $this->runnableConstraints[] = ['ReqGeneralValue', $itemType, $itemTypeName, 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralValue($itemType, $itemTypeName, '>=', 1); } else if($itemCode == $general->getVar($itemType)){ - $this->runnableConstraints[] = ['AlwaysFail', '이미 가지고 있습니다.']; + $this->runnableConstraints[] = ConstraintHelper::AlwaysFail('이미 가지고 있습니다.'); } else if($itemType != 'item' && $general->getVar($itemType) > 6){ - $this->runnableConstraints[] = ['AlwaysFail', '이미 진귀한 것을 가지고 있습니다.']; + $this->runnableConstraints[] = ConstraintHelper::AlwaysFail('이미 진귀한 것을 가지고 있습니다.'); } } diff --git a/hwe/sammo/Command/General/che_전투태세.php b/hwe/sammo/Command/General/che_전투태세.php index c6dc627c..8a41e12f 100644 --- a/hwe/sammo/Command/General/che_전투태세.php +++ b/hwe/sammo/Command/General/che_전투태세.php @@ -17,6 +17,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_전투태세 extends Command\GeneralCommand{ @@ -37,14 +38,14 @@ class che_전투태세 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['ReqGeneralCrew'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], - ['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand - 10], - ['ReqGeneralAtmosMargin', GameConst::$maxAtmosByCommand - 10], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::ReqGeneralCrew(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::ReqGeneralTrainMargin(GameConst::$maxTrainByCommand - 10), + ConstraintHelper::ReqGeneralAtmosMargin(GameConst::$maxAtmosByCommand - 10), ]; } diff --git a/hwe/sammo/Command/General/che_정착장려.php b/hwe/sammo/Command/General/che_정착장려.php index bdccded6..27047cda 100644 --- a/hwe/sammo/Command/General/che_정착장려.php +++ b/hwe/sammo/Command/General/che_정착장려.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use function sammo\getGeneralLeadership; @@ -43,13 +44,13 @@ class che_정착장려 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['SuppliedCity'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], - ['RemainCityCapacity', [static::$cityKey, static::$actionName]] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName) ]; $this->reqRice = $reqRice; diff --git a/hwe/sammo/Command/General/che_주민선정.php b/hwe/sammo/Command/General/che_주민선정.php index 032d5e90..e1bf8f35 100644 --- a/hwe/sammo/Command/General/che_주민선정.php +++ b/hwe/sammo/Command/General/che_주민선정.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_주민선정 extends Command\GeneralCommand{ @@ -42,13 +43,13 @@ class che_주민선정 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['SuppliedCity'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], - ['RemainCityTrust', static::$actionName] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::RemainCityTrust(static::$actionName) ]; $this->reqRice = $reqRice; diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index 361cf51a..86046654 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_증여 extends Command\GeneralCommand{ @@ -73,17 +74,17 @@ class che_증여 extends Command\GeneralCommand{ $this->setDestGeneral($destGeneral); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['OccupiedCity'], - ['SuppliedCity'], - ['ExistsDestGeneral'], - ['FriendlyDestGeneral'] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::FriendlyDestGeneral() ]; if($this->arg['isGold']){ - $this->runnableConstraints[] = ['ReqGeneralGold', 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1); } else{ - $this->runnableConstraints[] = ['ReqGeneralRice', 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1); } } diff --git a/hwe/sammo/Command/General/che_집합.php b/hwe/sammo/Command/General/che_집합.php index 50d58afb..0470bd19 100644 --- a/hwe/sammo/Command/General/che_집합.php +++ b/hwe/sammo/Command/General/che_집합.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -39,11 +40,11 @@ class che_집합 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['OccupiedCity'], - ['SuppliedCity'], - ['MustBeTroopLeader'], - ['ReqTroopMembers'], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::MustBeTroopLeader(), + ConstraintHelper::ReqTroopMembers(), ]; } diff --git a/hwe/sammo/Command/General/che_징병.php b/hwe/sammo/Command/General/che_징병.php index e8e47548..824721a3 100644 --- a/hwe/sammo/Command/General/che_징병.php +++ b/hwe/sammo/Command/General/che_징병.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; @@ -92,14 +93,14 @@ class che_징병 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['OccupiedCity'], - ['ReqCityCapacity', 'pop', '주민', 30000 + $reqCrew], - ['ReqCityTrust', 20], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], - ['ReqGeneralCrewMargin', $reqCrewType->id], - ['AvailableRecruitCrewType', $reqCrewType->id] + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::ReqCityCapacity('pop', '주민', 30000 + $reqCrew), + ConstraintHelper::ReqCityTrust(20), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::ReqGeneralCrewMargin($reqCrewType->id), + ConstraintHelper::AvailableRecruitCrewType($reqCrewType->id) ]; } diff --git a/hwe/sammo/Command/General/che_첩보.php b/hwe/sammo/Command/General/che_첩보.php index 9a2fa584..52f8ea6e 100644 --- a/hwe/sammo/Command/General/che_첩보.php +++ b/hwe/sammo/Command/General/che_첩보.php @@ -17,6 +17,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -49,9 +50,9 @@ class che_첩보 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NotOccupiedDestCity'], - ['ReqGeneralGold', $reqGold], - ['ReqGeneralRice', $reqRice], + ConstraintHelper::NotOccupiedDestCity(), + ConstraintHelper::ReqGeneralGold($reqGold), + ConstraintHelper::ReqGeneralRice($reqRice), ]; } diff --git a/hwe/sammo/Command/General/che_출병.php b/hwe/sammo/Command/General/che_출병.php index a4b72125..6c1c9b9d 100644 --- a/hwe/sammo/Command/General/che_출병.php +++ b/hwe/sammo/Command/General/che_출병.php @@ -17,6 +17,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -47,16 +48,17 @@ class che_출병 extends Command\GeneralCommand{ $this->setDestNation(['nation' ,'level','name','capital','gennum','tech','type','gold','rice']); [$reqGold, $reqRice] = $this->getCost(); + $relYear = $this->env['year'] - $this->env['startyear']; $this->runnableConstraints=[ - ['NotOpeningPart'], - ['NearCity', 1], - ['NotBeNeutral'], - ['OccupiedCity'], - ['ReqGeneralCrew'], - ['ReqGeneralRice', $reqRice], - ['AllowWar'], - ['BattleGroundCity', 1], + ConstraintHelper::NotOpeningPart($relYear), + ConstraintHelper::NearCity(1), + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::ReqGeneralCrew(), + ConstraintHelper::ReqGeneralRice($reqRice), + ConstraintHelper::AllowWar(), + ConstraintHelper::BattleGroundCity(true), ]; } diff --git a/hwe/sammo/Command/General/che_하야.php b/hwe/sammo/Command/General/che_하야.php index a23111f6..189c85c5 100644 --- a/hwe/sammo/Command/General/che_하야.php +++ b/hwe/sammo/Command/General/che_하야.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; @@ -38,9 +39,9 @@ class che_하야 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotOpeningPart', $relYear], - ['NotLord'], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotOpeningPart($relYear), + ConstraintHelper::NotLord(), ]; } diff --git a/hwe/sammo/Command/General/che_해산.php b/hwe/sammo/Command/General/che_해산.php index 2554e2f1..04a5b0d6 100644 --- a/hwe/sammo/Command/General/che_해산.php +++ b/hwe/sammo/Command/General/che_해산.php @@ -12,6 +12,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; use function sammo\getNationTypeClass; use function sammo\refreshNationStaticInfo; @@ -46,8 +47,8 @@ class che_해산 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; $this->runnableConstraints=[ - ['BeLord'], - ['WanderingNation'], + ConstraintHelper::BeLord(), + ConstraintHelper::WanderingNation(), ]; } diff --git a/hwe/sammo/Command/General/che_헌납.php b/hwe/sammo/Command/General/che_헌납.php index 5d8bee9e..2c613301 100644 --- a/hwe/sammo/Command/General/che_헌납.php +++ b/hwe/sammo/Command/General/che_헌납.php @@ -19,6 +19,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; class che_헌납 extends Command\GeneralCommand{ @@ -55,15 +56,15 @@ class che_헌납 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['OccupiedCity'], - ['SuppliedCity'], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), ]; if($this->arg['isGold']){ - $this->runnableConstraints[] = ['ReqGeneralGold', 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1); } else{ - $this->runnableConstraints[] = ['ReqGeneralRice', 1]; + $this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1); } } diff --git a/hwe/sammo/Command/General/che_훈련.php b/hwe/sammo/Command/General/che_훈련.php index b3cd8171..4be8d035 100644 --- a/hwe/sammo/Command/General/che_훈련.php +++ b/hwe/sammo/Command/General/che_훈련.php @@ -16,6 +16,7 @@ use function \sammo\{ }; use \sammo\Constraint\Constraint; +use \sammo\Constraint\ConstraintHelper; @@ -35,11 +36,11 @@ class che_훈련 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['NotBeNeutral'], - ['NotWanderingNation'], - ['OccupiedCity'], - ['ReqGeneralCrew'], - ['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand], + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::NotWanderingNation(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::ReqGeneralCrew(), + ConstraintHelper::ReqGeneralTrainMargin(GameConst::$maxTrainByCommand), ]; } diff --git a/hwe/sammo/Constraint/AllowRebellion.php b/hwe/sammo/Constraint/AllowRebellion.php new file mode 100644 index 00000000..1c1a3bc1 --- /dev/null +++ b/hwe/sammo/Constraint/AllowRebellion.php @@ -0,0 +1,61 @@ +env)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require killturn in env"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $general = $this->general; + $nationID = $general['nation']; + + if($nationID == 0){ + throw new MustNotBeReachedException('재야임'); + } + + $db = DB::db(); + $lord = $db->queryFirstRow('SELECT no, killturn, npc FROM general WHERE nation = %i AND level = 12', $nationID); + + if(!$lord){ + throw new MustNotBeReachedException('군주가 없음'); + } + + if($lord['no'] == $general['no']){ + $this->reason = '이미 군주입니다.'; + return false; + } + + if($lord['killturn'] >= $this->env['killturn']){ + $this->reason = '군주가 활동중입니다.'; + return false; + } + + if(in_array($lord['npc'], [2,3,6,9])){ + $this->reason = '군주가 NPC입니다.'; + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/BattleGroundCity.php b/hwe/sammo/Constraint/BattleGroundCity.php index 9f6c8ae1..9ae63add 100644 --- a/hwe/sammo/Constraint/BattleGroundCity.php +++ b/hwe/sammo/Constraint/BattleGroundCity.php @@ -4,7 +4,7 @@ namespace sammo\Constraint; use \sammo\DB; class BattleGroundCity extends Constraint{ - const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_CITY|Contraint::REQ_INT_ARG; + const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_CITY|Constraint::REQ_BOOLEAN_ARG; public function checkInputValues(bool $throwExeception=true){ if(!parent::checkInputValues($throwExeception) && !$throwException){ diff --git a/hwe/sammo/Constraint/Constraint.php b/hwe/sammo/Constraint/Constraint.php index b16d01ae..f2c21a90 100644 --- a/hwe/sammo/Constraint/Constraint.php +++ b/hwe/sammo/Constraint/Constraint.php @@ -16,7 +16,8 @@ abstract class Constraint{ const REQ_STRING_ARG = self::REQ_ARG | 0x1000; const REQ_INT_ARG = self::REQ_ARG | 0x2000; const REQ_NUMERIC_ARG = self::REQ_ARG | 0x4000; - const REQ_ARRAY_ARG = self::REQ_ARG | 0x8000; + const REQ_BOOLEAN_ARG = self::REQ_ARG | 0x8000; + const REQ_ARRAY_ARG = self::REQ_ARG | 0x10000; const REQ_VALUES = 0; @@ -144,6 +145,11 @@ abstract class Constraint{ throw new \InvalidArgumentException('require string arg'); } + if(($valueType&static::REQ_BOOLEAN_ARG) && !is_bool($this->arg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException('require bool arg'); + } + if(($valueType&static::REQ_INT_ARG) && !is_int($this->arg)){ if(!$throwExeception){return false; } throw new \InvalidArgumentException('require int arg'); diff --git a/hwe/sammo/Constraint/ContraintHelper.php b/hwe/sammo/Constraint/ContraintHelper.php new file mode 100644 index 00000000..3386168a --- /dev/null +++ b/hwe/sammo/Constraint/ContraintHelper.php @@ -0,0 +1,186 @@ +checkInputValues(); $this->tested = true; - //특수 예외로 ARG가 지정된 경우에는 재야여도 'OccupiedCity'로 허용함 - if($this->arg && $this->general['nation'] == 0){ + //재야여도 허용하는 경우 + if($this->arg[0] && $this->general['nation'] == 0){ return true; } diff --git a/hwe/sammo/Constraint/ReqGeneralCrewMargin.php b/hwe/sammo/Constraint/ReqGeneralCrewMargin.php index 03bff532..bf0c2633 100644 --- a/hwe/sammo/Constraint/ReqGeneralCrewMargin.php +++ b/hwe/sammo/Constraint/ReqGeneralCrewMargin.php @@ -13,6 +13,11 @@ class ReqGeneralCrewMargin extends Constraint{ return false; } + if(GameUnitConst::byID($this->arg) === null){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("{$this->arg} is invalid crewtype"); + } + foreach(['leader','power','intel','crew','crewtype','nation','level'] as $key){ if(!key_exists($key, $this->general)){ if(!$throwExeception){return false; } @@ -33,6 +38,13 @@ class ReqGeneralCrewMargin extends Constraint{ //XXX: 왜 General -> obj -> General 변환을 하고 있나? $generalObj = new General($this->general, null, null, null, false); + + $reqCrewType = GameUnitConst::byID($this->arg); + + if($reqCrewType->id != $generalObj->getCrewTypeObj()->id){ + return true; + } + $leadership = $generalObj->getLeadership(); $crew = $this->general['crew']; diff --git a/hwe/sammo/Constraint/ReqGeneralValue.php b/hwe/sammo/Constraint/ReqGeneralValue.php index 75e6c210..4e4a793a 100644 --- a/hwe/sammo/Constraint/ReqGeneralValue.php +++ b/hwe/sammo/Constraint/ReqGeneralValue.php @@ -8,7 +8,7 @@ use \sammo\Util; /** * 범용으로 사용 가능한 장수 변수 검사도구 */ -class RegGeneralValue extends Constraint{ +class ReqGeneralValue extends Constraint{ const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG; protected $key;