diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php new file mode 100644 index 00000000..b59c4604 --- /dev/null +++ b/hwe/sammo/Command/General/che_선양.php @@ -0,0 +1,133 @@ +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 = [ + 'destGeneralID'=>$destGeneralID + ]; + return true; + } + + protected function init(){ + + $general = $this->generalObj; + + $this->setNation(); + + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1); + $this->setDestGeneral($destGeneral); + + $this->runnableConstraints=[ + ['BeLord'], + ['ExistsDestGeneral'], + ['FriendlyDestGeneral'], + ['DisallowDiplomacyStatus', [4], '현재 통합 진행중입니다.'] + ]; + } + + 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/Constraint/DisallowDiplomacyStatus.php b/hwe/sammo/Constraint/DisallowDiplomacyStatus.php new file mode 100644 index 00000000..ae40b3b4 --- /dev/null +++ b/hwe/sammo/Constraint/DisallowDiplomacyStatus.php @@ -0,0 +1,63 @@ +arg) != 2){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require disallowDipStatusArray, message in args"); + } + + if(!is_array($this->arg[0])){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("disallowDipStatusArray must be array"); + } + + if(!is_string($this->arg[1])){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("message must be string"); + } + + $this->disallowStatus = []; + foreach($this->arg[0] as $status){ + if(!is_int($status)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("{$status} must be int"); + } + $this->disallowStatus[] = $status; + } + $this->msg = $this->arg[1]; + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $db = DB::db(); + + $disallowCnt = $db->queryFirstField( + 'SELECT count(*) FROM diplomacy WHERE me = %i AND `state` IN %li', + $this->nation['nation'], + $this->disallowStatus + ); + if($disallowCnt == 0){ + return true; + } + $this->msg = "민심이 낮아 주민들이 도망갑니다."; + return false; + } +} \ No newline at end of file