From 4adc0b7c24e3fb07e50f06943a591683074325bb Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 3 May 2020 01:33:52 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B6=88=EA=B0=80=EC=B9=A8=ED=8C=8C=EA=B8=B0?= =?UTF-8?q?=EC=A0=9C=EC=9D=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Command/Nation/che_불가침파기수락.php | 171 ++++++++++++++ .../Command/Nation/che_불가침파기제의.php | 219 ++++++++++++++++++ .../AllowDiplomacyBetweenStatus.php | 2 +- hwe/sammo/DiplomaticMessage.php | 44 ++-- hwe/sammo/GameConstBase.php | 2 +- hwe/sammo/Message.php | 4 + 6 files changed, 411 insertions(+), 31 deletions(-) create mode 100644 hwe/sammo/Command/Nation/che_불가침파기수락.php create mode 100644 hwe/sammo/Command/Nation/che_불가침파기제의.php diff --git a/hwe/sammo/Command/Nation/che_불가침파기수락.php b/hwe/sammo/Command/Nation/che_불가침파기수락.php new file mode 100644 index 00000000..ba718606 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_불가침파기수락.php @@ -0,0 +1,171 @@ +arg === null){ + return false; + } + + if(!key_exists('destNationID', $this->arg)){ + return false; + } + $destNationID = $this->arg['destNationID']; + if(!is_int($destNationID)){ + return false; + } + if($destNationID < 1){ + return false; + } + + if(!key_exists('destGeneralID', $this->arg)){ + return false; + } + $destGeneralID = $this->arg['destGeneralID']; + if(!is_int($destGeneralID)){ + return false; + } + if($destGeneralID <= 0){ + return false; + } + if($destGeneralID == $this->generalObj->getID()){ + return false; + } + + $this->arg = [ + 'destNationID'=>$destNationID, + 'destGeneralID'=>$destGeneralID, + ]; + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $env = $this->env; + $relYear = $env['year'] - $env['startyear']; + + $this->setCity(); + $this->setNation(); + + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1); + $this->setDestGeneral($destGeneral); + $this->setDestNation($this->arg['destNationID']); + + $nationID = $this->nation['nation']; + + $this->reservableConstraints = [ + ConstraintHelper::AlwaysFail('예약 불가능 커맨드') + ]; + + $this->runnableConstraints=[ + ConstraintHelper::BeChief(), + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::ExistsDestNation(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::ReqDestNationValue('nation', '소속', '==', $this->destGeneralObj->getNationID(), '제의 장수가 국가 소속이 아닙니다'), + ConstraintHelper::AllowDiplomacyBetweenStatus( + [7], + '불가침 중인 상대국에게만 가능합니다.' + ), + ]; + + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 0; + } + + public function getBrief():string{ + $commandName = $this->getName(); + $destNationName = getNationStaticInfo($this->arg['destNationID'])['name']; + return "{$destNationName}국과 불가침 파기 합의"; + } + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + $env = $this->env; + + $general = $this->generalObj; + $generalName = $general->getName(); + + $nation = $this->nation; + $nationID = $nation['nation']; + $nationName = $nation['name']; + + $destNation = $this->destNation; + $destNationID = $destNation['nation']; + $destNationName = $destNation['name']; + + $logger = $general->getLogger(); + $destLogger = $this->destGeneralObj->getLogger(); + + $db->update('diplomacy',[ + 'state'=>2, + 'term'=>0 + ], + '(me=%i AND you=%i) OR (you=%i AND me=%i)', + $nationID, $destNationID, + $nationID, $destNationID); + + $josaYiGeneral = JosaUtil::pick($generalName, '이'); + $josaYiNation = JosaUtil::pick($nationName, '이'); + + $josaWa = JosaUtil::pick($destNationName, '와'); + $logger->pushGeneralActionLog("{$destNationName}{$josaWa}의 불가침을 파기했습니다.", ActionLogger::PLAIN); + $logger->pushGeneralHistoryLog("{$destNationName}{$josaWa}의 불가침 파기 수락"); + + $logger->pushGlobalActionLog("{$generalName}{$josaYiGeneral} {$destNationName}{$josaWa}의 불가침 조약을 파기 하였습니다."); + $logger->pushGlobalHistoryLog("【종전】{$nationName}{$josaYiNation} {$destNationName}{$josaWa}의 불가침 조약을 파기 하였습니다."); + + + $josaWa = JosaUtil::pick($nationName, '와'); + $destLogger->pushGeneralActionLog("{$nationName}{$josaWa}의 불가침 파기에 성공했습니다.", ActionLogger::PLAIN); + $destLogger->pushGeneralHistoryLog("{$nationName}{$josaWa}의 불가침 파기 성공"); + + $general->applyDB($db); + $destLogger->flush(); + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Command/Nation/che_불가침파기제의.php b/hwe/sammo/Command/Nation/che_불가침파기제의.php new file mode 100644 index 00000000..6a8e3105 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_불가침파기제의.php @@ -0,0 +1,219 @@ +arg === null){ + return false; + } + //NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음 + if(!key_exists('destNationID', $this->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; + + $this->setCity(); + $this->setNation(); + + $this->setDestNation($this->arg['destNationID'], null); + + $this->runnableConstraints=[ + ConstraintHelper::BeChief(), + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::OccupiedCity(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ExistsDestNation(), + ConstraintHelper::AllowDiplomacyBetweenStatus( + [7], + '불가침 중인 상대국에게만 가능합니다.' + ), + ]; + + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 0; + } + + public function getBrief():string{ + $commandName = $this->getName(); + $destNationName = getNationStaticInfo($this->arg['destNationID'])['name']; + return "【{$destNationName}】에게 {$commandName}"; + } + + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + $env = $this->env; + + $general = $this->generalObj; + $generalName = $general->getName(); + $date = $general->getTurnTime($general::TURNTIME_HM); + + $nation = $this->nation; + $nationID = $nation['nation']; + $nationName = $nation['name']; + + $destNation = $this->destNation; + $destNationID = $destNation['nation']; + $destNationName = $destNation['name']; + + $logger = $general->getLogger(); + $destLogger = new ActionLogger(0, $destNationID, $env['year'], $env['month']); + + $logger->pushGeneralActionLog("{$destNationName}으로 불가침 파기 제의 서신을 보냈습니다.<1>$date"); + + // 상대에게 발송 + $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'] + ); + + $now = new \DateTime($date); + $validUntil = new \DateTime($date); + $validMinutes = max(30, $env['turnterm']*3); + $validUntil->add(new \DateInterval("PT{$validMinutes}M")); + + $msg = new DiplomaticMessage( + Message::MSGTYPE_DIPLOMACY, + $src, + $dest, + "{$nationName}의 불가침 파기 제의 서신", + $now, + $validUntil, + [ + 'action'=>DiplomaticMessage::TYPE_CANCEL_NA, + 'deletable'=>false, + ] + ); + $msg->send(); + + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->applyDB($db); + $destLogger->flush(); + + return true; + } + + public function getJSFiles(): array + { + return [ + 'js/defaultSelectNationByMap.js' + ]; + } + + public function getForm(): string + { + $generalObj = $this->generalObj; + $nationID = $generalObj->getNationID(); + + $db = DB::db(); + $diplomacyStatus = Util::convertArrayToDict( + $db->query('SELECT * FROM diplomacy WHERE me = %i', $nationID), + 'you' + ); + + $nationList = []; + foreach(getAllNationStaticInfo() as $destNation){ + if($destNation['nation'] == $nationID){ + continue; + } + + if($diplomacyStatus[$destNation['nation']]['state'] != 7){ + $destNation['cssBgColor'] = 'background-color:red;'; + } + else{ + $destNation['cssBgColor'] = ''; + } + + $nationList[] = $destNation; + } + + ob_start(); +?> +
+불가침중인 국가에 조약 파기를 제의합니다.
+제의할 국가를 목록에서 선택하세요.
+배경색은 현재 제의가 불가능한 국가는 붉은색으로 표시됩니다.
+
+에게 + +nationID, $this->destNationID, - array_keys($this->allowDipCodeList) + $this->allowDipCodeList ); if($state !== null){ return true; diff --git a/hwe/sammo/DiplomaticMessage.php b/hwe/sammo/DiplomaticMessage.php index 21813f7b..0d2fab83 100644 --- a/hwe/sammo/DiplomaticMessage.php +++ b/hwe/sammo/DiplomaticMessage.php @@ -98,38 +98,24 @@ class DiplomaticMessage extends Message{ } protected function cancelNA(){ - $helper = new Engine\Diplomacy($this->src->nationID, $this->dest->nationID); - $chk = $helper->cancelNA(); - if($chk[0] !== self::ACCEPTED){ - return $chk; + $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); + + $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], 1); + + $commandObj = buildNationCommandClass('che_불가침파기수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ + 'destNationID'=>$this->src->nationID, + 'destGeneralID'=>$this->src->generalID, + ]); + + $this->diplomacyDetail = $commandObj->getBrief(); + + if(!$commandObj->isRunnable()){ + return [self::DECLINED, $commandObj->getFailString()]; } - $josaYi = JosaUtil::pick($this->dest->generalName, '이'); - $josaWa = JosaUtil::pick($this->src->nationName, '와'); - $alllog[] = "●{$helper->month}월:{$this->dest->generalName}{$josaYi} {$this->src->nationName}{$josaWa} 조약 파기에 합의."; + $commandObj->run(); - $josaYi = JosaUtil::pick($this->dest->nationName, '이'); - $josaWa = JosaUtil::pick($this->src->nationName, '와'); - $history[] = "●{$helper->year}년 {$helper->month}월:【파기】{$this->dest->nationName}{$josaYi} {$this->src->nationName}{$josaWa} 불가침을 파기 하였습니다."; - - $josaWa = JosaUtil::pick($this->dest->nationName, '와'); - $youlog[] = "{$this->dest->nationName}{$josaWa} 파기에 성공했습니다."; - - $josaWa = JosaUtil::pick($this->src->nationName, '와'); - $mylog[] = "{$this->src->nationName}{$josaWa} 파기에 합의했습니다."; - - $josaWa = JosaUtil::pick($this->dest->nationName, '와'); - pushGeneralHistory($this->src->generalID, ["●{$helper->year}년 {$helper->month}월:{$this->dest->nationName}{$josaWa} 파기 성공"]); - - $josaWa = JosaUtil::pick($this->src->nationName, '와'); - pushGeneralHistory($this->dest->generalID, ["●{$helper->year}년 {$helper->month}월:{$this->src->nationName}{$josaWa} 파기 수락"]); - - pushGenLog($this->dest->generalID, $mylog); - pushGenLog($this->src->generalID, $youlog); - pushGeneralPublicRecord($alllog, $helper->year, $helper->month); - pushWorldHistory($history, $helper->year, $helper->month); - - return $chk; + return [self::ACCEPTED, '']; } protected function stopWar(){ diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index a55f0bad..11b33845 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -309,7 +309,7 @@ class GameConstBase 'che_불가침제의', 'che_선전포고', 'che_종전제의', - //'che_파기제의', + 'che_불가침파기제의', ], '특수'=>[ //'che_초토화', diff --git a/hwe/sammo/Message.php b/hwe/sammo/Message.php index 8c1b4e42..31ed50ca 100644 --- a/hwe/sammo/Message.php +++ b/hwe/sammo/Message.php @@ -286,6 +286,10 @@ class Message return '5분 이내의 메시지만 삭제할 수 있습니다.'; } + if(!($msgObj->msgOption['deletable']??true)){ + return '삭제할 수 없는 메시지입니다.'; + } + $msgOption = [ 'hide'=>true, 'silence'=>true,