From 9846d7f8e47fefd6ad477713787f40e6ed704eb0 Mon Sep 17 00:00:00 2001 From: hide_d Date: Tue, 16 Oct 2018 02:29:33 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=8F=99=20=EA=B5=AC=ED=98=84.=20Base?= =?UTF-8?q?Command=EC=97=90=20GeneralSource=20=EC=97=B0=EA=B2=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/b_currentCity.php | 2 +- hwe/b_genList.php | 2 +- hwe/commandlist.php | 2 +- hwe/func_process.php | 40 --------- hwe/sammo/Command/BaseCommand.php | 22 ++++- hwe/sammo/Command/General/che_이동.php | 119 +++++++++++++++++++++++++ hwe/sammo/Constraint/NearCity.php | 43 +++++++++ hwe/sammo/Constraint/NotSameCity.php | 32 +++++++ hwe/sammo/General.php | 20 +++-- hwe/sammo/TurnExecutionHelper.php | 33 ++++--- 10 files changed, 250 insertions(+), 65 deletions(-) create mode 100644 hwe/sammo/Command/General/che_이동.php create mode 100644 hwe/sammo/Constraint/NearCity.php create mode 100644 hwe/sammo/Constraint/NotSameCity.php diff --git a/hwe/b_currentCity.php b/hwe/b_currentCity.php index f09fce83..7120637d 100644 --- a/hwe/b_currentCity.php +++ b/hwe/b_currentCity.php @@ -286,7 +286,7 @@ for($j=0; $j < $gencount; $j++) { if($ourGeneral && !$isNPC){ $turnText = []; - $generalObj = new General($general, null, 0, 0, false); + $generalObj = new General($general, null, null, null, false); $turnBrief = getGeneralTurnBrief($genralObj, $generalTurnList[$generalObj->getID()]); foreach($turnBrief as $turnRawIdx=>$turn){ $turnIdx = $turnRawIdx+1; diff --git a/hwe/b_genList.php b/hwe/b_genList.php index 96ab0b03..28a46723 100644 --- a/hwe/b_genList.php +++ b/hwe/b_genList.php @@ -174,7 +174,7 @@ foreach ($generals as &$general) { if ($general['npc'] < 2) { - $generalObj = new General($general, null, 0, 0, false); + $generalObj = new General($general, null, null, null, false); $turnBrief = getGeneralTurnBrief($genralObj, $generalTurnList[$generalObj->getID()]); $turntext = []; diff --git a/hwe/commandlist.php b/hwe/commandlist.php index ee1c8768..647b02b6 100644 --- a/hwe/commandlist.php +++ b/hwe/commandlist.php @@ -83,7 +83,7 @@ function myCommandList() { echo "로그인 되어있지 않습니다."; return; } - $generalObj = new General($me, null, 0, 0, false); + $generalObj = new General($me, null, null, null, false); $turnList = $db->query('SELECT turn_idx, action, arg FROM general_turn WHERE general_id = %i ORDER BY turn_idx ASC', $generalObj->getID()); $turnBrief = getGeneralTurnBrief($generalObj, $turnList); diff --git a/hwe/func_process.php b/hwe/func_process.php index 58795f47..ae69ee44 100644 --- a/hwe/func_process.php +++ b/hwe/func_process.php @@ -551,46 +551,6 @@ function process_16(&$general) { pushGenLog($general, $log); } -function process_17(&$general) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); - - $log = []; - $alllog = []; - $history = []; - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['year', 'month']); - - if($general['crew'] == 0) { - $log[] = "●{$admin['month']}월:병사가 없습니다. 소집해제 실패. <1>$date"; - } else { - // 주민으로 돌아감 - $query = "update city set pop=pop+'{$general['crew']}' where city='{$general['city']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $query = "update general set crew='0' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $log[0] = "●{$admin['month']}월:병사들을 소집해제하였습니다. <1>$date"; - - // 경험, 공헌 상승 - $exp = 70; - $ded = 100; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - $query = "update general set resturn='SUCCESS',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $log = checkAbility($general, $log); - } - pushGenLog($general, $log); -} - function process_21(&$general) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index 11cb4ba2..1273a02f 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -37,7 +37,7 @@ abstract class BaseCommand{ protected $runnableConstraints = null; protected $reservableConstraints = null; - + protected $generalSource = null; protected $logger; @@ -54,6 +54,17 @@ abstract class BaseCommand{ } + public function setGeneralSource(?array $generalSource){ + $this->generalSource = $generalSource; + } + + protected function getGeneralObjFromGeneralSource(int $generalNo):?General{ + if($this->generalSource === null){ + return null; + } + return $this->generalSource[$generalNo]??null; + } + protected function resetTestCache():void{ $this->runnable = null; $this->reservable = null; @@ -105,7 +116,12 @@ abstract class BaseCommand{ protected function setDestCity(int $cityNo, ?array $args){ $this->resetTestCache(); $db = DB::db(); - if($args == null){ + if($args === []){ + $cityObj = \sammo\CityConst::byID($cityNo); + $this->destCity = ['city'=>$cityNo, 'name'=>$cityObj->name]; + return; + } + if($args === null){ $this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo); return; } @@ -114,7 +130,7 @@ abstract class BaseCommand{ protected function setDestNation(int $nationNo, ?array $args = null){ $this->resetTestCache(); - if($args == null){ + if($args === null || $args === []){ $this->destNation = getNationStaticInfo($nationNo); return; } diff --git a/hwe/sammo/Command/General/che_이동.php b/hwe/sammo/Command/General/che_이동.php new file mode 100644 index 00000000..c7ba80d0 --- /dev/null +++ b/hwe/sammo/Command/General/che_이동.php @@ -0,0 +1,119 @@ +generalObj; + + $this->setCity(); + $this->setNation(); + $this->setDestCity($this->arg['destCityID'], []); + + [$reqGold, $reqRice] = $this->getCost(); + + $this->runnableConstraints=[ + ['NotSameCity'], + ['NearCity', 1], + ['ReqGeneralGold', $reqGold], + ['ReqGeneralRice', $reqRice], + ]; + } + + protected function argTest():bool{ + if(!key_exists('destCityID', $this->arg)){ + return false; + } + if(!key_exists($this->arg['destCityID'], CityConst::all())){ + return false; + } + $this->arg = [ + 'destCityID'=>$this->arg['destCityID'] + ]; + return true; + } + + public function getCost():array{ + $env = $this->env; + return [$env['develcost'], 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(); + $env = $this->env; + + $general = $this->generalObj; + $date = substr($general->getVar('turntime'),11,5); + + $destCityName = $this->destCity['name']; + $destCityID = $this->destCity['city']; + $josaRo = JosaUtil::pick($destCityName, '로'); + + $logger = $general->getLogger(); + + $logger->pushGeneralActionLog("{$destCityName}{$josaRo} 이동했습니다. <1>$date"); + + $exp = 50; + + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $general->setVar('city', $destCityID); + + if($general->getVar('level') == 12 && $this->nation['level'] == 0){ + $generalList = $db->queryFirstColumn('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); + foreach($generalList as $targetRawGeneral){ + $targetGeneralID = $targetRawGeneral['no']; + $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); + if($targetGeneral === null){ + $targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false); + } + $targetGeneral->setVar('city', $destCityID); + $targetGeneral->getLogger()->pushGeneralActionLog("방랑군 세력이 {$destCityName}{$josaRo} 이동했습니다.", ActionLogger::PLAIN); + $targetGeneral = null; + } + } + + [$reqGold, $reqRice] = $this->getCost(); + $general->increaseVarWithLimit('gold', -$reqGold, 0); + $general->increaseVar('experience', $exp); + $general->increaseVar('leader2', 1); + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + $general->applyDB($db); + + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NearCity.php b/hwe/sammo/Constraint/NearCity.php new file mode 100644 index 00000000..f48cc9b9 --- /dev/null +++ b/hwe/sammo/Constraint/NearCity.php @@ -0,0 +1,43 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require city in general"); + } + if($this->arg < 1 || !is_integer($this->arg)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("arg should be >= 1 integer"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $dist = \sammo\searchDistance($this->general['city'], $this->arg, false); + if(key_exist($this->destCity['city'], $dist)){ + return true; + } + + if($this->arg == 1){ + $this->reason = "인접도시가 아닙니다."; + } + else{ + $this->reason = "거리가 너무 멉니다."; + } + + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NotSameCity.php b/hwe/sammo/Constraint/NotSameCity.php new file mode 100644 index 00000000..02d19129 --- /dev/null +++ b/hwe/sammo/Constraint/NotSameCity.php @@ -0,0 +1,32 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require city in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->destCity['city'] != $this->general['city']){ + return true; + } + + $this->reason = "같은 도시입니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 7c8662ca..44177aa4 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -38,7 +38,7 @@ class General implements iAction{ * @param int $month 게임 월 * @param bool $fullConstruct iAction, 및 ActionLogger 초기화 여부, false인 경우 no, name, city, nation, level 정도로 초기화 가능 */ - public function __construct(array $raw, ?array $city, int $year, int $month, bool $fullConstruct=true){ + public function __construct(array $raw, ?array $city, ?int $year, ?int $month, bool $fullConstruct=true){ //TODO: 밖에서 가져오도록 하면 버그 확률이 높아짐. 필요한 raw 값을 직접 구해야함. $staticNation = getNationStaticInfo($raw['nation']); @@ -51,17 +51,21 @@ class General implements iAction{ } $this->resultTurn = new LastTurn(); + if($year !== null || $month !== null){ + $this->logger = new ActionLogger( + $this->getVar('no'), + $this->getVar('nation'), + $year, + $month, + false + ); + } + if(!$fullConstruct){ return; } - $this->logger = new ActionLogger( - $this->getVar('no'), - $this->getVar('nation'), - $year, - $month, - false - ); + $nationTypeClass = getNationTypeClass($staticNation['type']); $this->nationType = new $nationTypeClass; diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index 2bbb960c..4b60b361 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -8,11 +8,12 @@ class TurnExecutionHelper * @var General $generalObj; */ protected $generalObj; + protected $generalSource = null; - public function __construct(array $rawGeneral, int $year, int $month) + public function __construct(General $general, ?array $generalSource = null) { - $this->generalObj = new General($rawGeneral, null, $year, $month); - $this->nationTurn = $nationTurn; + $this->generalObj = $general; + $this->generalSource = $generalSource; } public function __destruct() @@ -76,6 +77,7 @@ class TurnExecutionHelper $gameStor = KVStorage::getStorage($db, 'game_env'); $commandObj = buildNationCommandClass($commandClassName, $general, $gameStor->getAll(true), $commandLast, $commandArg); + $commandObj->setGeneralSource($this->generalSource); $failReason = $commandObj->testReservable(); if($failReason){ @@ -101,6 +103,7 @@ class TurnExecutionHelper $commandClass = getGeneralCommandClass($commandClassName); /** @var \sammo\Command\GeneralCommand $commandObj */ $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandArg, $commandLast); + $commandObj->setGeneralSource($this->generalSource); $failReason = $commandObj->testReservable(); if($failReason){ @@ -185,7 +188,7 @@ class TurnExecutionHelper static public function executeGeneralCommandUntil(string $date, \DateTimeInterface $limitActionTime, int $year, int $month){ $db = DB::db(); - $generalsTodo = $db->queryFirstRow( + $rawGeneralsTodo = $db->queryFirstRow( 'SELECT no,name,name2,picture,imgsvr,nation,nations,city,troop,injury,affinity, leader,leader2,power,power2,intel,intel2,weap,book,horse,item, experience,dedication,level,gold,rice,crew,crewtype,train,atmos, @@ -200,20 +203,28 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', $date ); + $generalsTodo = []; + $generalSource = []; + foreach($rawGeneralsTodo as $rawGeneral){ + $generalCommand = $rawGeneral['action']; + $generalArg = Json::decode($rawGeneral['arg'])??[]; + unset($rawGeneral['action']); + unset($rawGeneral['arg']); + $general = new General($rawGeneral, $year, $month); + + $generalsTodo[] = [$general, $generalCommand, $generalArg]; + $generalSource[$general->getID()] = $general; + } + $currentTurn = null; - foreach($generalsTodo as $generalWork){ + foreach($generalsTodo as [$general, $generalCommand, $generalArg]){ $currActionTime = new \DateTimeImmutable(); if($currActionTime > $limitActionTime){ return [true, $currentTurn]; } - $generalCommand = $generalWork['action']; - $generalArg = Json::decode($generalWork['arg'])??[]; - unset($generalWork['action']); - unset($generalWork['arg']); - - $turnObj = new static($generalWork, $year, $month); + $turnObj = new static($general, $generalSource); $hasNationTurn = false; if($generalWork['nation'] != 0 && $generalWork['level'] >= 5){