diff --git a/hwe/func_command.old.php b/hwe/func_command.old.php index 94bbc2ea..fa32226b 100644 --- a/hwe/func_command.old.php +++ b/hwe/func_command.old.php @@ -5,8 +5,7 @@ function getGeneralTurnBrief(General $generalObj, array $turnList) { $result = []; foreach($turnList as $turnIdx => [$action, $arg]){ - $commandClass = getGeneralCommandClass($action); - $commandObj = new $commandClass($generalObj, [], $arg); + $commandObj = buildGeneralCommandClass($action, $generalObj, [], $arg); $turnText = $commandObj->getBrief(); $result[$turnIdx] = $turnText; } @@ -270,8 +269,7 @@ function getNationTurnBrief(General $generalObj, array $turnList) { $tmpTurn = new LastTurn(); foreach($turnList as $turnIdx => [$action, $arg]){ - $commandClass = getNationCommandClass($action); - $commandObj = new $commandClass($generalObj, [], $tmpTurn, $arg); + $commandObj = buildNationCommandClass($action, $generalObj, [], $tmpTurn, $arg); $turnText = $commandObj->getBrief(); $result[$turnIdx] = $turnText; } diff --git a/hwe/func_command.php b/hwe/func_command.php index 7aac8dd5..101787be 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -5,8 +5,7 @@ function getGeneralTurnBrief(General $generalObj, array $turnList) { $result = []; foreach($turnList as $turnIdx => [$action, $arg]){ - $commandClass = getGeneralCommandClass($action); - $commandObj = new $commandClass($generalObj, [], $arg); + $commandObj = buildGeneralCommandClass($action, $generalObj, [], $arg); $turnText = $commandObj->getBrief(); $result[$turnIdx] = $turnText; } @@ -18,8 +17,7 @@ function getNationTurnBrief(General $generalObj, array $turnList) { $tmpTurn = new LastTurn(); foreach($turnList as $turnIdx => [$action, $arg]){ - $commandClass = getNationCommandClass($action); - $commandObj = new $commandClass($generalObj, [], $tmpTurn, $arg); + $commandObj = buildNationCommandClass($action, $generalObj, [], $tmpTurn, $arg); $turnText = $commandObj->getBrief(); $result[$turnIdx] = $turnText; } diff --git a/hwe/func_converter.php b/hwe/func_converter.php index 57aebcb4..b8f42c95 100644 --- a/hwe/func_converter.php +++ b/hwe/func_converter.php @@ -313,6 +313,11 @@ function getGeneralCommandClass(?string $type){ throw new \InvalidArgumentException("{$type}은 올바른 장수 커맨드가 아님"); } +function buildGeneralCommandClass(?string $type, General $generalObj, array $env, $arg = null):Command\GeneralCommand{ + $class = getGeneralCommandClass($type); + return new $class($generalObj, $env, $arg); +} + function getNationCommandClass(?string $type){ if($type === null){ $type = '휴식'; @@ -328,6 +333,11 @@ function getNationCommandClass(?string $type){ throw new \InvalidArgumentException("{$type}은 올바른 국가 커맨드가 아님"); } +function buildNationCommandClass(?string $type, General $generalObj, array $env, LastTurn $lastTurn, $arg = null):Command\NationCommand{ + $class = getNationCommandClass($type); + return new $class($generalObj, $env, $lastTurn, $arg); +} + function getLevel($level, $nlevel=8) { if($level >= 0 && $level <= 4) { $nlevel = 0; } $code = $nlevel * 100 + $level; diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index af0f860f..5ec36282 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -75,9 +75,7 @@ class TurnExecutionHelper $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); - $commandClass = getNationCommandClass($commandClassName); - /** @var \sammo\Command\NationCommand $commandObj */ - $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandLast, $commandArg); + $commandObj = buildNationCommandClass($commandClassName, $general, $gameStor->getAll(true), $commandLast, $commandArg); $failReason = $commandObj->testReservable(); if($failReason){