buildGeneralCommandClass류 구현

This commit is contained in:
2018-10-06 04:08:43 +09:00
parent b94081c45b
commit 1660e563ab
4 changed files with 15 additions and 11 deletions
+2 -4
View File
@@ -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;
}
+2 -4
View File
@@ -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;
}
+10
View File
@@ -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;
+1 -3
View File
@@ -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){