diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index bed40760..97105ed0 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -4,7 +4,8 @@ namespace sammo\Command; use \sammo\{ Util, JosaUtil, DB, General, GameConst, - ActionLogger + ActionLogger, + LastTurn }; use function \sammo\getNationStaticInfo; @@ -124,7 +125,7 @@ abstract class BaseCommand{ return; } - $defaultArgs = ['nation', 'name', 'color', 'type', 'level', 'capital']; + $defaultArgs = ['nation', 'name', 'color', 'type', 'level', 'capital', 'gennum']; $args = array_unique(array_merge($defaultArgs, $args)); if($args == $defaultArgs){ $this->nation = $this->generalObj->getStaticNation(); @@ -293,6 +294,41 @@ abstract class BaseCommand{ } + public function getTermString():string{ + $commandName = $this->getName(); + $term = $this->getResultTurn()->getTerm(); + $termMax = $this->getPreReqTurn() + 1; + return "{$commandName} 수행중... ({$term}/{$termMax})"; + } + + public function addTermStack():bool{ + if($this->getPreReqTurn() == 0){ + return true; + } + + $lastTurn = $this->getLastTurn(); + $commandName = $this->getName(); + if($lastTurn->getCommand() != $commandName){ + $this->setResultTurn(new LastTurn( + $commandName, + $this->arg, + 1 + )); + return false; + } + + if($lastTurn->getTerm() < $this->getPreReqTurn()){ + $this->setResultTurn(new LastTurn( + $commandName, + $this->arg, + $lastTurn->getTerm() + 1 + )); + return false; + } + + return true; + } + public function isReservable():bool{ if($this->reservable !== null){ return $this->reservable; @@ -344,4 +380,16 @@ abstract class BaseCommand{ throw new \sammo\MustNotBeReachedException(); return ''; } + + public function getLastTurn():LastTurn{ + return $this->generalObj->getLastTurn(); + } + + public function setResultTurn(LastTurn $lastTurn){ + $this->generalObj->setResultTurn($lastTurn); + } + + public function getResultTurn():LastTurn{ + return $this->generalObj->getResultTurn(); + } } \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_방랑.php b/hwe/sammo/Command/General/che_방랑.php index 32b86533..3cf63e2b 100644 --- a/hwe/sammo/Command/General/che_방랑.php +++ b/hwe/sammo/Command/General/che_방랑.php @@ -44,15 +44,9 @@ class che_방랑 extends Command\GeneralCommand{ ConstraintHelper::BeLord(), ConstraintHelper::NotWanderingNation(), ConstraintHelper::NotOpeningPart($relYear), - ConstraintHelper::DisallowDiplomacyStatus($this->generalObj->getNationID(), [ - 0 => '방랑할 수 없는 외교상태입니다.', - 1 => '방랑할 수 없는 외교상태입니다.', - 3 => '방랑할 수 없는 외교상태입니다.', - 4 => '방랑할 수 없는 외교상태입니다.', - 5 => '방랑할 수 없는 외교상태입니다.', - 6 => '방랑할 수 없는 외교상태입니다.' - ]), - //TODO:diplomacy status 상수화 + ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [ + 2, 7 + ], '방랑할 수 없는 외교상태입니다.'), ]; } diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index f2a33636..d6531570 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -181,7 +181,7 @@ class che_몰수 extends Command\NationCommand{ $destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 몰수 당했습니다.", ActionLogger::PLAIN); $logger->pushGeneralActionLog("{$destGeneral->getName()}에게서 {$resName} $amountText을 몰수했습니다. <1>$date"); - $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->applyDB($db); $destGeneral->applyDB($db); diff --git a/hwe/sammo/Command/Nation/che_발령.php b/hwe/sammo/Command/Nation/che_발령.php index 0064c05f..3f02c3c0 100644 --- a/hwe/sammo/Command/Nation/che_발령.php +++ b/hwe/sammo/Command/Nation/che_발령.php @@ -133,7 +133,7 @@ class che_발령 extends Command\NationCommand{ $destGeneral->getLogger()->pushGeneralActionLog("{$generalName}에 의해 {$destCityName}{$josaRo} 발령됐습니다. <1>$date"); $logger->pushGeneralActionLog("{$destGeneralName}{$josaUl} {$destCityName}{$josaRo} 발령했습니다. <1>$date"); - $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->applyDB($db); $destGeneral->applyDB($db); diff --git a/hwe/sammo/Command/Nation/che_불가침제의.php b/hwe/sammo/Command/Nation/che_불가침제의.php index 30f6e63e..b48bff11 100644 --- a/hwe/sammo/Command/Nation/che_불가침제의.php +++ b/hwe/sammo/Command/Nation/che_불가침제의.php @@ -27,7 +27,7 @@ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; class che_불가침제의 extends Command\NationCommand{ - static protected $actionName = '불가침제의'; + static protected $actionName = '불가침 제의'; static public $reqArg = true; protected function argTest():bool{ @@ -206,7 +206,7 @@ class che_불가침제의 extends Command\NationCommand{ ); $msg->send(); - $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->applyDB($db); $destLogger->flush(); diff --git a/hwe/sammo/Command/Nation/che_선전포고.php b/hwe/sammo/Command/Nation/che_선전포고.php index 3ed07160..1fbf4bfd 100644 --- a/hwe/sammo/Command/Nation/che_선전포고.php +++ b/hwe/sammo/Command/Nation/che_선전포고.php @@ -176,7 +176,7 @@ class che_선전포고 extends Command\NationCommand{ ); $msg->send(); - $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->applyDB($db); $destLogger->flush(); diff --git a/hwe/sammo/Command/Nation/che_포상.php b/hwe/sammo/Command/Nation/che_포상.php index aa0a365e..1fc6a0a2 100644 --- a/hwe/sammo/Command/Nation/che_포상.php +++ b/hwe/sammo/Command/Nation/che_포상.php @@ -149,7 +149,7 @@ class che_포상 extends Command\NationCommand{ $destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 포상으로 받았습니다.", ActionLogger::PLAIN); $logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} $amountText을 수여했습니다. <1>$date"); - $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->applyDB($db); $destGeneral->applyDB($db); diff --git a/hwe/sammo/Command/Nation/che_필사즉생.php b/hwe/sammo/Command/Nation/che_필사즉생.php new file mode 100644 index 00000000..09c23b58 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_필사즉생.php @@ -0,0 +1,129 @@ +arg = []; + + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $env = $this->env; + + $this->setCity(); + $this->setNation(['strategic_cmd_limit']); + + $this->runnableConstraints=[ + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + /*ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [ + 0 + ], '전쟁중이 아닙니다.'),*/ + ConstraintHelper::ReqNationValue('strategic_cmd_limit', '전략기한', '==', 0, '전략기한이 남았습니다.') + ]; + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 2; + } + + public function getPostReqTurn():int{ + return 0; + } + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + + $general = $this->generalObj; + $generalID = $general->getID(); + $generalName = $general->getName(); + $date = $general->getTurnTime($general::TURNTIME_HM); + + $nationID = $general->getNationID(); + $nationName = $this->nation['name']; + + $logger = $general->getLogger(); + $logger->pushGeneralActionLog("필사즉생 발동! <1>$date"); + + $exp = 5 * ($this->getPreReqTurn() + 1); + $ded = 5 * ($this->getPreReqTurn() + 1); + + $exp = $general->onCalcStat($general, 'experience', $exp); + $ded = $general->onCalcStat($general, 'dedication', $ded); + + $josaYi = JosaUtil::pick($generalName, '이'); + + $broadcastMessage = "{$generalName}{$josaYi} 필사즉생을 발동하였습니다."; + + foreach($db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID) as $targetGeneralID){ + $targetGeneral = General::createGeneralObjFromDB($targetGeneralID, ['train', 'atmos'], 1); + $targetGeneral->getLogger()->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN); + if($targetGeneral->getVar('train') < 100){ + $targetGeneral->setVar('train', 100); + } + if($targetGeneral->getVar('atmos') < 100){ + $targetGeneral->setVar('atmos', 100); + } + + + $targetGeneral->applyDB($db); + } + + if($general->getVar('train') < 100){ + $general->setVar('train', 100); + } + if($general->getVar('atmos') < 100){ + $general->setVar('atmos', 100); + } + $logger->pushGeneralHistoryLog('필사즉생을 발동'); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} 필사즉생을 발동"); + + $genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit); + $nextTerm = Util::round(sqrt($genCount*8)*10); + + $nextTerm = $general->onCalcStrategic($this->getName(), 'delay', $nextTerm); + $db->update('nation', ['strategic_cmd_limit' => $nextTerm], 'nation=%i', $nationID); + + $general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); + $general->applyDB($db); + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/AllowDiplomacyStatus.php b/hwe/sammo/Constraint/AllowDiplomacyStatus.php new file mode 100644 index 00000000..07fca170 --- /dev/null +++ b/hwe/sammo/Constraint/AllowDiplomacyStatus.php @@ -0,0 +1,66 @@ +arg) != 3){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nationID, allowStatus, errMsg tuple"); + } + + [$this->nationID, $this->allowStatus, $this->errMsg] = $this->arg; + if(!is_int($this->nationID)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("nationID {$this->nationID} must be int"); + } + + if(!is_array($this->allowStatus)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("allowStatus {$this->allowStatus} must be array"); + } + + if(!is_string($this->errMsg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("allowStatus {$this->errMsg} must be string"); + } + + foreach($this->allowStatus as $dipCode){ + if(!is_int($dipCode)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("dipCode $dipCode must be int"); + } + } + + 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 `state` IN %li LIMIT 1', + $this->nationID, + array_keys($this->allowStatus) + ); + if($state !== null){ + return true; + } + $this->reason = $this->errMsg; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ConstraintHelper.php b/hwe/sammo/Constraint/ConstraintHelper.php index 39c337fd..0152ca51 100644 --- a/hwe/sammo/Constraint/ConstraintHelper.php +++ b/hwe/sammo/Constraint/ConstraintHelper.php @@ -7,6 +7,10 @@ class ConstraintHelper{ static function AdhocCallback(callable $callback):array{ return [__FUNCTION__, $callback]; } + + static function AllowDiplomacyStatus(int $nationID, array $disallowList, string $errMsg):array{ + return [__FUNCTION__, [$nationID, $disallowList, $errMsg]]; + } static function AllowJoinAction():array{ return [__FUNCTION__]; @@ -212,8 +216,8 @@ class ConstraintHelper{ return [__FUNCTION__, $reqRice]; } - static function ReqNationValue($key, string $keyNick, string $comp, $reqVal):array{ - return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal]]; + static function ReqNationValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{ + return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]]; } static function ReqTroopMembers():array{ diff --git a/hwe/sammo/Constraint/DisallowDiplomacyStatus.php b/hwe/sammo/Constraint/DisallowDiplomacyStatus.php index ef14bca5..6328a4d6 100644 --- a/hwe/sammo/Constraint/DisallowDiplomacyStatus.php +++ b/hwe/sammo/Constraint/DisallowDiplomacyStatus.php @@ -59,7 +59,7 @@ class DisallowDiplomacyStatus extends Constraint{ if($state === null){ return true; } - $this->msg = $this->disallowStatus[$state]; + $this->reason = $this->disallowStatus[$state]; return false; } } \ No newline at end of file diff --git a/hwe/sammo/Constraint/ReqNationValue.php b/hwe/sammo/Constraint/ReqNationValue.php index 560bc093..58b51bcf 100644 --- a/hwe/sammo/Constraint/ReqNationValue.php +++ b/hwe/sammo/Constraint/ReqNationValue.php @@ -16,14 +16,15 @@ class ReqNationValue extends Constraint{ protected $keyNick; protected $reqVal; protected $comp; + protected $errMsg; public function checkInputValues(bool $throwExeception=true):bool{ if(!parent::checkInputValues($throwExeception) && !$throwExeception){ return false; } - if(count($this->arg) == 4){ - [$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg; + if(count($this->arg) == 5){ + [$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $this->arg; if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){ if(!$throwExeception){return false; } @@ -32,7 +33,7 @@ class ReqNationValue extends Constraint{ } else{ if(!$throwExeception){return false; } - throw new \InvalidArgumentException("require key, keyNick, comp, reqVal"); + throw new \InvalidArgumentException("require key, keyNick, comp, reqVal[, errMsg]"); } $this->comp = $comp; @@ -47,7 +48,7 @@ class ReqNationValue extends Constraint{ if(is_numeric($this->reqVal)){ $this->isPercent = false; } - else if(is_str($this->reqVal)){ + else if(is_string($this->reqVal)){ $this->reqVal = Util::convPercentStrToFloat($this->reqVal); if($this->reqVal === null){ if(!$throwExeception){return false; } @@ -121,7 +122,12 @@ class ReqNationValue extends Constraint{ } $josaYi = JosaUtil::pick($keyNick, '이'); - $this->reason = "{$keyNick}{$josaYi} {$result}"; + if($this->errMsg){ + $this->reason = $this->errMsg; + } + else{ + $this->reason = "{$keyNick}{$josaYi} {$result}"; + } return false; } diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index d70cf64d..e4300752 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -280,7 +280,7 @@ class GameConstBase //'che_감축', ], '전략'=>[ - //'che_필사즉생', + 'che_필사즉생', //'che_백성동원', //'che_수몰', //'che_허보', diff --git a/hwe/sammo/LastTurn.php b/hwe/sammo/LastTurn.php index fb4d3eb3..dbab336c 100644 --- a/hwe/sammo/LastTurn.php +++ b/hwe/sammo/LastTurn.php @@ -65,4 +65,8 @@ class LastTurn{ } return Json::encode($result); } + + function duplicate():LastTurn{ + return new static($this->command, $this->arg, $this->term); + } } \ No newline at end of file diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index 21aaea88..75f3a39a 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -82,11 +82,21 @@ class TurnExecutionHelper $general->getLogger()->pushGeneralActionLog($text); break; } - + + if(!$commandObj->addTermStack()){ + $date = $general->getTurnTime($general::TURNTIME_HM); + $termString = $commandObj->getTermString(); + $text = "{$termString} <1>{$date}"; + $general->getLogger()->pushGeneralActionLog($text); + break; + } + $result = $commandObj->run(); if($result){ break; } + + $alt = $commandObj->getAlternativeCommand(); if($alt === null){ break; @@ -117,6 +127,14 @@ class TurnExecutionHelper break; } + if(!$commandObj->addTermStack()){ + $date = $general->getTurnTime($general::TURNTIME_HM); + $termString = $commandObj->getTermString(); + $text = "{$termString} <1>{$date}"; + $general->getLogger()->pushGeneralActionLog($text); + break; + } + $result = $commandObj->run(); if($result){ break; @@ -147,7 +165,7 @@ class TurnExecutionHelper $general->setVar('killturn', $killTurn); } - return $general->getResultTurn(); + return $commandObj->getResultTurn(); } function updateTurnTime(){