diff --git a/hwe/func_process.old.php b/hwe/func_process.old.php index d732ed6f..a0bbebd1 100644 --- a/hwe/func_process.old.php +++ b/hwe/func_process.old.php @@ -223,7 +223,7 @@ function process_domestic(array $rawGeneral, int $type){ } $cmdObj = new $cmdClass($general, $env); - if(!$cmdObj->isAvailable()){ + if(!$cmdObj->isRunnable()){ return; } $cmdObj->run(); diff --git a/hwe/func_process.php b/hwe/func_process.php index 2cbb41bf..6a2ecd68 100644 --- a/hwe/func_process.php +++ b/hwe/func_process.php @@ -233,7 +233,7 @@ function process_domestic(array $rawGeneral, int $type){ } $cmdObj = new $cmdClass($general, $env); - if(!$cmdObj->isAvailable()){ + if(!$cmdObj->isRunnable()){ return; } $cmdObj->run(); diff --git a/hwe/index.php b/hwe/index.php index 40cae3ca..c3ab5887 100644 --- a/hwe/index.php +++ b/hwe/index.php @@ -235,7 +235,14 @@ else if($session->userGrade == 4){ - + +
+
+
+ +
+
diff --git a/hwe/j_get_reserved_command.php b/hwe/j_get_reserved_command.php new file mode 100644 index 00000000..bc8cc5ae --- /dev/null +++ b/hwe/j_get_reserved_command.php @@ -0,0 +1,23 @@ +setReadOnly(); + +$db = DB::db(); + +$commandList = []; + +$generalID = $session->generalID; + +$rawTurn = $db->queryAllLists('SELECT turn_idx, action, arg FROM general_turn WHERE general_id = %i ORDER BY turn_idx ASC'); +foreach($rawTurn as [$turn_idx, $action, $arg]){ + $commandList[$turn_idx] = [ + 'action'=>$action, + 'arg'=>Json::decode($arg) + ]; +} + +Json::die($commandList); \ No newline at end of file diff --git a/hwe/j_reserve_command.php b/hwe/j_reserve_command.php new file mode 100644 index 00000000..1e17a6cd --- /dev/null +++ b/hwe/j_reserve_command.php @@ -0,0 +1,3 @@ +logger = $generalObj->getLogger(); $this->env = $env; $this->arg = $arg; + if ($this->argTest()) { + return; + } + $this->isArgValid = true; $this->init(); + } protected function resetTestCache():void{ - $this->reason = null; - $this->available = null; + $this->runnable = null; + $this->reservable = null; + + $this->reasonNotRunnable = null; + $this->reasonNotReservable = null; } protected function setCity(array $args=null){ @@ -110,6 +125,7 @@ abstract class BaseCommand{ } abstract protected function init(); + abstract protected function argTest():bool; public function getName():string { return static::$name; @@ -119,13 +135,24 @@ abstract class BaseCommand{ return $this->logger; } - public function test(bool $fullCheck):?string{ - if($this->constraints === null){ + public function testReservable():?string{ + + } + + public function testRunnable():?string{ + if(!$this->isArgValid()){ throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다'); + } + if($this->runnableConstraints === null){ + throw new \InvalidArgumentException('runnableConstraits가 제대로 설정되지 않았습니다'); } - if($this->reason){ - return $this->reason; + if(!$this->isReservable()){ + return $this->testReservable(); + } + + if($this->reasonNotRunnable){ + return $this->reasonNotRunnable; } $constraintInput = [ @@ -139,21 +166,30 @@ abstract class BaseCommand{ 'destNation'=>$this->destNation, ]; - if(!$fullCheck && $this->constraintsLight){ - return Constraint::testAll($this->constraintsLight, $constraintInput); + if(!$fullCheck && $this->reservableConstraints){ + return Constraint::testAll($this->reservableConstraints, $constraintInput); } - $this->reason = Constraint::testAll($this->constraints, $constraintInput); - $this->available = $this->reason === null; + $this->reasonNotRunnable = Constraint::testAll($this->runnableConstraints, $constraintInput); + $this->runnable = $this->reason === null; return $this->reason; } - public function isAvailable(bool $fullCheck=true):bool { - if($this->available !== null){ - return $this->available; - } - return $this->test($fullCheck) === null; + public function isReservable():bool{ + + } + + public function isArgValid():bool{ + return $this->isArgValid; + } + + public function isRunnable():bool { + if($this->runnable !== null){ + return $this->runnable; + } + + return $this->testRunnable() === null; } abstract public function getCost():array; diff --git a/hwe/sammo/Command/che_기술연구.php b/hwe/sammo/Command/che_기술연구.php index 69e84beb..17388257 100644 --- a/hwe/sammo/Command/che_기술연구.php +++ b/hwe/sammo/Command/che_기술연구.php @@ -32,7 +32,7 @@ class che_기술연구 extends che_상업투자{ $develCost = $this->env['develcost']; $reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold); - $this->constraints=[ + $this->runnableConstraints=[ ['NoNeutral'], ['NoWanderingNation'], ['OccupiedCity'], @@ -43,8 +43,12 @@ class che_기술연구 extends che_상업투자{ $this->reqGold = $reqGold; } + protected function argTest():bool{ + return true; + } + public function run():bool{ - if(!$this->isAvailable()){ + if(!$this->isRunnable()){ throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } diff --git a/hwe/sammo/Command/che_상업투자.php b/hwe/sammo/Command/che_상업투자.php index a44b9bc8..82a6c045 100644 --- a/hwe/sammo/Command/che_상업투자.php +++ b/hwe/sammo/Command/che_상업투자.php @@ -33,7 +33,7 @@ class che_상업투자 extends BaseCommand{ $develCost = $this->env['develcost']; $reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold); - $this->constraints=[ + $this->runnableConstraints=[ ['NoNeutral'], ['NoWanderingNation'], ['OccupiedCity'], @@ -45,6 +45,10 @@ class che_상업투자 extends BaseCommand{ $this->reqGold = $reqGold; } + protected function argTest():bool{ + return true; + } + protected function calcBaseScore():float{ $trust = Util::valueFit($this->city['trust'], 50); $general = $this->generalObj; @@ -71,7 +75,7 @@ class che_상업투자 extends BaseCommand{ } public function run():bool{ - if(!$this->isAvailable()){ + if(!$this->isRunnable()){ throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } diff --git a/hwe/sammo/Command/che_정착장려.php b/hwe/sammo/Command/che_정착장려.php index 6d9c1b56..1e065931 100644 --- a/hwe/sammo/Command/che_정착장려.php +++ b/hwe/sammo/Command/che_정착장려.php @@ -33,7 +33,7 @@ class che_상업투자 extends BaseCommand{ $develCost = $this->env['develcost'] * 2; $reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqRice); - $this->constraints=[ + $this->runnableConstraints=[ ['NoNeutral'], ['NoWanderingNation'], ['OccupiedCity'], @@ -45,6 +45,10 @@ class che_상업투자 extends BaseCommand{ $this->reqRice = $reqRice; } + protected function argTest():bool{ + return true; + } + protected function calcBaseScore():float{ $general = $this->generalObj; @@ -63,7 +67,7 @@ class che_상업투자 extends BaseCommand{ } public function run():bool{ - if(!$this->isAvailable()){ + if(!$this->isRunnable()){ throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } diff --git a/hwe/sammo/Command/che_주민선정.php b/hwe/sammo/Command/che_주민선정.php index d2e2ddf1..e22a6486 100644 --- a/hwe/sammo/Command/che_주민선정.php +++ b/hwe/sammo/Command/che_주민선정.php @@ -33,7 +33,7 @@ class che_주민선정 extends BaseCommand{ $develCost = $this->env['develcost'] * 2; $reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold); - $this->constraints=[ + $this->runnableConstraints=[ ['NoNeutral'], ['NoWanderingNation'], ['OccupiedCity'], @@ -45,6 +45,10 @@ class che_주민선정 extends BaseCommand{ $this->reqRice = $reqRice; } + protected function argTest():bool{ + return true; + } + protected function calcBaseScore():float{ $general = $this->generalObj; @@ -64,7 +68,7 @@ class che_주민선정 extends BaseCommand{ } public function run():bool{ - if(!$this->isAvailable()){ + if(!$this->isRunnable()){ throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } diff --git a/hwe/sammo/Command/휴식.php b/hwe/sammo/Command/휴식.php new file mode 100644 index 00000000..fe66a3ba --- /dev/null +++ b/hwe/sammo/Command/휴식.php @@ -0,0 +1,30 @@ +generalObj; + $logger = $general->getLogger(); + $date = substr($general->getVar('turntime'),11,5); + $logger->pushGeneralActionLog("아무것도 실행하지 않았습니다. <1>$date"); + + $general->increaseVar('killturn', -1); + $general->applyDB(DB::db()); + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/Constraint.php b/hwe/sammo/Constraint/Constraint.php index 1d99956e..b16d01ae 100644 --- a/hwe/sammo/Constraint/Constraint.php +++ b/hwe/sammo/Constraint/Constraint.php @@ -162,15 +162,9 @@ abstract class Constraint{ return true; } - public function reason($withTest=true):?string{ + public function reason():?string{ if(!$this->tested === false){ - if($withTest){ - $this->test(); - } - else{ - throw new \RuntimeException('test가 실행되지 않음'); - } - + throw new \RuntimeException('test가 실행되지 않음'); } return $this->reason; } diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php new file mode 100644 index 00000000..fb4f7dec --- /dev/null +++ b/hwe/sammo/TurnExecutionHelper.php @@ -0,0 +1,14 @@ +generalObj = new General(); + } +} \ No newline at end of file diff --git a/src/sammo/Session.php b/src/sammo/Session.php index b18f2413..ecf9b9c5 100644 --- a/src/sammo/Session.php +++ b/src/sammo/Session.php @@ -11,6 +11,9 @@ namespace sammo; * @property bool $reqOTP 인증 코드 필요 * @property array $acl 권한 * @property string $tokenValidUntil 로그인 토큰 길이 + * + * @property int $generalID 장수 번호 (게임 로그인 필요) + * @property string $generalName 장수 이름 (게임 로그인 필요) */ class Session {