diff --git a/hwe/sammo/Command/General/che_방랑.php b/hwe/sammo/Command/General/che_방랑.php index 11e7c8b0..1d66a826 100644 --- a/hwe/sammo/Command/General/che_방랑.php +++ b/hwe/sammo/Command/General/che_방랑.php @@ -44,7 +44,14 @@ class che_방랑 extends Command\GeneralCommand{ ConstraintHelper::BeLord(), ConstraintHelper::NotWanderingNation(), ConstraintHelper::NotOpeningPart($relYear), - ConstraintHelper::DisallowDiplomacyStatus([0, 1, 3, 4, 5, 6], '방랑할 수 없는 외교상태입니다.'), + ConstraintHelper::DisallowDiplomacyStatus($this->generalObj->getNationID(), [ + 0 => '방랑할 수 없는 외교상태입니다.', + 1 => '방랑할 수 없는 외교상태입니다.', + 3 => '방랑할 수 없는 외교상태입니다.', + 4 => '방랑할 수 없는 외교상태입니다.', + 5 => '방랑할 수 없는 외교상태입니다.', + 6 => '방랑할 수 없는 외교상태입니다.' + ]), //TODO:diplomacy status 상수화 ]; } diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php index eafde5cc..ea29d9ef 100644 --- a/hwe/sammo/Command/General/che_선양.php +++ b/hwe/sammo/Command/General/che_선양.php @@ -59,7 +59,10 @@ class che_선양 extends Command\GeneralCommand{ ConstraintHelper::BeLord(), ConstraintHelper::ExistsDestGeneral(), ConstraintHelper::FriendlyDestGeneral(), - ConstraintHelper::DisallowDiplomacyStatus([4], '현재 통합 진행중입니다.') + ConstraintHelper::DisallowDiplomacyStatus( + $this->generalObj->getNationID(), + [4 => '현재 통합 진행중입니다.'] + ) ]; } diff --git a/hwe/sammo/Command/General/che_화계.php b/hwe/sammo/Command/General/che_화계.php index 1d1ab888..4bfe7543 100644 --- a/hwe/sammo/Command/General/che_화계.php +++ b/hwe/sammo/Command/General/che_화계.php @@ -116,7 +116,10 @@ class che_화계 extends Command\GeneralCommand{ ConstraintHelper::NotNeutralDestCity(), ConstraintHelper::ReqGeneralGold($reqGold), ConstraintHelper::ReqGeneralRice($reqRice), - ConstraintHelper::DisallowDiplomacyStatus([7], '불가침국입니다.'), + ConstraintHelper::DisallowDiplomacyStatus( + $this->generalObj->getNationID(), + [7 => '불가침국입니다.'] + ), ]; } diff --git a/hwe/sammo/Command/Nation/che_선전포고.php b/hwe/sammo/Command/Nation/che_선전포고.php new file mode 100644 index 00000000..1c3dbeda --- /dev/null +++ b/hwe/sammo/Command/Nation/che_선전포고.php @@ -0,0 +1,170 @@ +arg)){ + return false; + } + $destNationID = $this->arg['destNationID']; + + if(!is_int($destNationID)){ + return false; + } + if($destNationID < 1){ + return false; + } + + $this->arg = [ + 'destNationID'=>$destNationID + ]; + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $env = $this->env; + $relYear = $env['year'] - $env['startyear']; + + $this->setCity(); + $this->setNation(); + + $this->setDestNation($this->arg['destNationID'], null); + + if($relYear < 3 - 2){ + $this->runnableConstraints = [ + ConstraintHelper::AlwaysFail('초반제한 해제 2년전부터 가능합니다.') + ]; + return; + } + + $this->runnableConstraints=[ + ConstraintHelper::BeChief(), + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestNation(), + ConstraintHelper::DisallowDiplomacyBetweenStatus([ + 0 => '아국과 이미 교전중입니다.', + 1 => '아국과 이미 선포중입니다.', + 7 => '아국과 불가침중입니다.', + ]), + ConstraintHelper::DisallowDiplomacyStatus($this->destNation['nation'], [ + 3 => '상대국이 외교 진행중입니다.', + 5 => '상대국이 외교 진행중입니다.' + ]), + ]; + + } + + 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(); + $env = $this->env; + + $general = $this->generalObj; + $generalName = $general->getName(); + $date = substr($general->getVar('turntime'),11,5); + + $nation = $this->nation; + $nationID = $nation['nation']; + $nationName = $nation['name']; + + $destNation = $this->destNation; + $destNationID = $destNation['nation']; + $destNationName = $destNation['name']; + + $josaYi = JosaUtil::pick($generalName, '이'); + $josaYiNation = JosaUtil::pick($nationName, '이'); + + + $logger = $general->getLogger(); + $destLogger = new ActionLogger(0, $destNationID, $env['year'], $env['month']); + + $logger->pushGeneralActionLog("{$destNationName}으로 선전 포고 했습니다.<1>$date"); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} {$destNationName}에 선전 포고"); + $destLogger->pushNationalHistoryLog("{$nationName}{$generalName}{$josaYi} 아국에 선전 포고"); + + $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$destNationName}선전 포고 하였습니다."); + $logger->pushGlobalHistoryLog("【선포】{$nationName}{$josaYiNation} {$destNationName}에 선전 포고 하였습니다."); + + $db->update('diplomacy', [ + 'state'=>1, + 'term'=>24 + ], '(me=%i AND you=%i) OR (me=%i AND you=%i)', $nationID, $destNationID, $destNationID, $nationID); + + //국메로 저장 + $text = "【외교】{$env['year']}년 {$env['month']}월:{$nationNation}에서 {$destNationName}에 선전포고"; + + $src = new MessageTarget( + $general->getID(), + $general->getName(), + $nationID, + $nationName, + $nation['color'], + GetImageURL($general->getVar('imgsvr'), $general->getVar('picture')) + ); + $dest = new MessageTarget( + 0, + '', + $destNationID, + $destNationName, + $destNation['color'] + ); + $msg = new Message( + Message::MSGTYPE_NATIONAL, + $src, + $dest, + $text, + new \DateTime($general->getVar('turntime')), + new \DateTime('9999-12-31'), + [] + ); + $msg->send(); + + $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 f0c63d0d..0307d3ff 100644 --- a/hwe/sammo/Constraint/ContraintHelper.php +++ b/hwe/sammo/Constraint/ContraintHelper.php @@ -64,8 +64,12 @@ class ConstraintHelper{ return [__FUNCTION__]; } - static function DisallowDiplomacyStatus(array $disallowStatus, string $failMessage):array{ - return [__FUNCTION__, $disallowStatus, $failMessage]; + static function DisallowDiplomacyBetweenStatus(array $disallowList):array{ + return [__FUNCTION__, $disallowList]; + } + + static function DisallowDiplomacyStatus(int $nationID, array $disallowList):array{ + return [__FUNCTION__, $nationID, $disallowList]; } static function ExistsAllowJoinNation(int $relYear, array $excludeNationList):array{ diff --git a/hwe/sammo/Constraint/DisallowDiplomacyBetweenStatus.php b/hwe/sammo/Constraint/DisallowDiplomacyBetweenStatus.php new file mode 100644 index 00000000..f4611db0 --- /dev/null +++ b/hwe/sammo/Constraint/DisallowDiplomacyBetweenStatus.php @@ -0,0 +1,55 @@ +nationID = $this->nation['nation']; + $this->destNationID = $this->destNation['nation']; + $this->disallowStatus = $this->arg; + + foreach($this->disallowStatus as $dipCode => $errMsg){ + if(!is_int($dipCode)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("dipCode $dipCode must be int"); + } + if(!is_string($errMsg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("dipCode $errMsg must be string"); + } + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $db = DB::db(); + + $state = $db->queryFirstField( + 'SELECT state FROM diplomacy WHERE me = %i AND you = %i AND `state` IN %li LIMIT 1', + $this->nationID, + $this->destNationID, + array_keys($this->disallowStatus) + ); + if($state === null){ + return true; + } + $this->msg = $this->disallowStatus[$state]; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/DisallowDiplomacyStatus.php b/hwe/sammo/Constraint/DisallowDiplomacyStatus.php index ae40b3b4..54097d0c 100644 --- a/hwe/sammo/Constraint/DisallowDiplomacyStatus.php +++ b/hwe/sammo/Constraint/DisallowDiplomacyStatus.php @@ -4,11 +4,11 @@ namespace sammo\Constraint; use \sammo\JosaUtil; use \sammo\DB; -class NotDiplomacyStatus extends Constraint{ - const REQ_VALUES = Constraint::REQ_ARG|Constraint::REQ_NATION; +class DisallowDiplomacyStatus extends Constraint{ + const REQ_VALUES = Constraint::REQ_ARRAY_ARG; - protected $disallowStatus; - protected $msg; + protected $nationID; + protected $disallowStatus = []; public function checkInputValues(bool $throwExeception=true){ if(!parent::checkInputValues($throwExeception) && !$throwException){ @@ -17,28 +17,30 @@ class NotDiplomacyStatus extends Constraint{ if(count($this->arg) != 2){ if(!$throwExeception){return false; } - throw new \InvalidArgumentException("require disallowDipStatusArray, message in args"); + throw new \InvalidArgumentException("require nationID, disallowStatus pair"); } - if(!is_array($this->arg[0])){ + [$this->nationID, $this->disallowStatus] = $this->arg; + if(!is_int($this->nationID)){ if(!$throwExeception){return false; } - throw new \InvalidArgumentException("disallowDipStatusArray must be array"); + throw new \InvalidArgumentException("nationID {$this->nationID} must be int"); } - if(!is_string($this->arg[1])){ + if(!is_array($this->disallowStatus)){ if(!$throwExeception){return false; } - throw new \InvalidArgumentException("message must be string"); + throw new \InvalidArgumentException("disallowStatus {$this->disallowStatus} must be array"); } - $this->disallowStatus = []; - foreach($this->arg[0] as $status){ - if(!is_int($status)){ + foreach($this->disallowStatus as $dipCode => $errMsg){ + if(!is_int($dipCode)){ if(!$throwExeception){return false; } - throw new \InvalidArgumentException("{$status} must be int"); + throw new \InvalidArgumentException("dipCode $dipCode must be int"); + } + if(!is_string($errMsg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("dipCode $errMsg must be string"); } - $this->disallowStatus[] = $status; } - $this->msg = $this->arg[1]; return true; } @@ -49,15 +51,15 @@ class NotDiplomacyStatus extends Constraint{ $db = DB::db(); - $disallowCnt = $db->queryFirstField( - 'SELECT count(*) FROM diplomacy WHERE me = %i AND `state` IN %li', - $this->nation['nation'], - $this->disallowStatus + $state = $db->queryFirstField( + 'SELECT state FROM diplomacy WHERE me = %i AND `state` IN %li LIMIT 1', + $this->nationID, + array_keys($this->disallowStatus) ); - if($disallowCnt == 0){ + if($state === null){ return true; } - $this->msg = "민심이 낮아 주민들이 도망갑니다."; + $this->msg = $this->disallowStatus[$state]; return false; } } \ No newline at end of file diff --git a/hwe/sammo/Constraint/ExistsDestNation.php b/hwe/sammo/Constraint/ExistsDestNation.php index de0c4b25..407bfd4f 100644 --- a/hwe/sammo/Constraint/ExistsDestNation.php +++ b/hwe/sammo/Constraint/ExistsDestNation.php @@ -21,7 +21,7 @@ class ExistsDestNation extends Constraint{ return true; } - $this->reason = "없는 국가입니다."; + $this->reason = "멸망한 국가입니다."; return false; } } \ No newline at end of file