From e1a266e5d8810eab9702b3b877b2facf9742e934 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 3 Oct 2018 22:38:05 +0900 Subject: [PATCH] =?UTF-8?q?'=EC=A7=80=EB=82=9C=20=ED=84=B4'=EC=9D=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= 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_command.php | 4 +- hwe/sammo/Command/General/휴식.php | 5 +- hwe/sammo/Command/Nation/휴식.php | 3 +- hwe/sammo/Command/NationCommand.php | 18 ++++++- hwe/sammo/General.php | 23 +++++++++ hwe/sammo/LastTurn.php | 14 +++++- hwe/sammo/LazyVarUpdater.php | 13 +++++ hwe/sammo/TurnExecutionHelper.php | 73 +++++++++++++++-------------- 11 files changed, 114 insertions(+), 45 deletions(-) diff --git a/hwe/b_currentCity.php b/hwe/b_currentCity.php index c468b797..3098109b 100644 --- a/hwe/b_currentCity.php +++ b/hwe/b_currentCity.php @@ -186,7 +186,7 @@ if($city['trade'] == 0) { $city['trade'] = "- "; } -$query = "select npc,mode,no,picture,imgsvr,name,injury,leader,power,intel,level,nation,crewtype,crew,train,atmos,term,turn0,turn1,turn2,turn3,turn4,turn5 from general where city='{$city['city']}' order by dedication desc"; // 장수 목록 +$query = "select npc,mode,no,picture,imgsvr,name,injury,leader,power,intel,level,nation,crewtype,crew,train,atmos,turn0,turn1,turn2,turn3,turn4,turn5 from general where city='{$city['city']}' order by dedication desc"; // 장수 목록 $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $gencount = MYDB_num_rows($genresult); diff --git a/hwe/b_genList.php b/hwe/b_genList.php index 6829d2f7..e7c136fb 100644 --- a/hwe/b_genList.php +++ b/hwe/b_genList.php @@ -97,7 +97,7 @@ switch ($type) { case 8: $orderSQL = "order by troop desc"; break; } -$generals = $db->query('SELECT npc,mode,no,level,troop,city,injury,leader,power,intel,experience,name,gold,rice,crewtype,crew,train,atmos,killturn,turntime,term,turn0,turn1,turn2,turn3,turn4 from general WHERE nation = %i %l', $me['nation'], $orderSQL); +$generals = $db->query('SELECT npc,mode,no,level,troop,city,injury,leader,power,intel,experience,name,gold,rice,crewtype,crew,train,atmos,killturn,turntime,turn0,turn1,turn2,turn3,turn4 from general WHERE nation = %i %l', $me['nation'], $orderSQL); foreach ($generals as &$general) { $general['cityText'] = CityConst::byID($general['city'])->name; diff --git a/hwe/commandlist.php b/hwe/commandlist.php index c4a49c37..da752c23 100644 --- a/hwe/commandlist.php +++ b/hwe/commandlist.php @@ -78,7 +78,7 @@ function myCommandList() { // 명령 목록 $admin = $gameStor->getValues(['year','month','turnterm','turntime']); - $me = $db->queryFirstRow("SELECT `no`,turntime,term,turn0,turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9,turn10,turn11,turn12,turn13,turn14,turn15,turn16,turn17,turn18,turn19,turn20,turn21,turn22,turn23 FROM general WHERE `owner`=%s", $userID); + $me = $db->queryFirstRow("SELECT `no`,turntime,last_turn,turn0,turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9,turn10,turn11,turn12,turn13,turn14,turn15,turn16,turn17,turn18,turn19,turn20,turn21,turn22,turn23 FROM general WHERE `owner`=%s", $userID); if(!$me){ echo "로그인 되어있지 않습니다."; return; diff --git a/hwe/func_command.php b/hwe/func_command.php index bfada0fd..9b0e3afe 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -471,7 +471,7 @@ function processCommand($no) { $gameStor = KVStorage::getStorage($db, 'game_env'); $connect=$db->get(); - $query = "select npc,no,name,picture,imgsvr,nation,nations,city,troop,injury,affinity,leader,leader2,power,power2,intel,intel2,experience,dedication,level,gold,rice,crew,crewtype,train,atmos,weap,book,horse,item,turntime,makenation,makelimit,killturn,block,dedlevel,explevel,age,belong,personal,special,special2,term,turn0,dex0,dex10,dex20,dex30,dex40,warnum,killnum,deathnum,killcrew,deathcrew,recwar from general where no='$no'"; + $query = "select npc,no,name,picture,imgsvr,nation,nations,city,troop,injury,affinity,leader,leader2,power,power2,intel,intel2,experience,dedication,level,gold,rice,crew,crewtype,train,atmos,weap,book,horse,item,turntime,makenation,makelimit,killturn,block,dedlevel,explevel,age,belong,personal,special,special2,last_turn,turn0,dex0,dex10,dex20,dex30,dex40,warnum,killnum,deathnum,killcrew,deathcrew,recwar from general where no='$no'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $general = MYDB_fetch_array($result); @@ -533,7 +533,7 @@ function processCommand($no) { } //장수정보 재로드 - $query = "select npc,no,name,picture,imgsvr,nation,nations,city,troop,injury,affinity,leader,leader2,power,power2,intel,intel2,experience,dedication,level,gold,rice,crew,crewtype,train,atmos,weap,book,horse,item,turntime,makenation,makelimit,killturn,block,dedlevel,explevel,age,belong,personal,special,special2,term,turn0,dex0,dex10,dex20,dex30,dex40,warnum,killnum,deathnum,killcrew,deathcrew,recwar from general where no='$no'"; + $query = "select npc,no,name,picture,imgsvr,nation,nations,city,troop,injury,affinity,leader,leader2,power,power2,intel,intel2,experience,dedication,level,gold,rice,crew,crewtype,train,atmos,weap,book,horse,item,turntime,makenation,makelimit,killturn,block,dedlevel,explevel,age,belong,personal,special,special2,last_turn,turn0,dex0,dex10,dex20,dex30,dex40,warnum,killnum,deathnum,killcrew,deathcrew,recwar from general where no='$no'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $general = MYDB_fetch_array($result); } diff --git a/hwe/sammo/Command/General/휴식.php b/hwe/sammo/Command/General/휴식.php index 10b519d9..dc8d7065 100644 --- a/hwe/sammo/Command/General/휴식.php +++ b/hwe/sammo/Command/General/휴식.php @@ -5,7 +5,7 @@ use \sammo\Command; use \sammo\Util; use \sammo\JosaUtil; -class 휴식 extends GeneralCommand{ +class 휴식 extends Command\GeneralCommand{ protected function init(){ //아무것도 하지 않음 } @@ -32,7 +32,8 @@ class 휴식 extends GeneralCommand{ $date = substr($general->getVar('turntime'),11,5); $logger->pushGeneralActionLog("아무것도 실행하지 않았습니다. <1>$date"); - $general->increaseVar('killturn', -1); + $general->setResultTurn(new LastTurn()); + $general->applyDB(DB::db()); return true; } diff --git a/hwe/sammo/Command/Nation/휴식.php b/hwe/sammo/Command/Nation/휴식.php index dbead4c4..54981391 100644 --- a/hwe/sammo/Command/Nation/휴식.php +++ b/hwe/sammo/Command/Nation/휴식.php @@ -4,8 +4,9 @@ namespace sammo\Command\Nation; use \sammo\Command; use \sammo\Util; use \sammo\JosaUtil; +use sammo\LastTurn; -class 휴식 extends NationCommand{ +class 휴식 extends Command\NationCommand{ protected function init(){ //아무것도 하지 않음 } diff --git a/hwe/sammo/Command/NationCommand.php b/hwe/sammo/Command/NationCommand.php index d65e1380..0ecab883 100644 --- a/hwe/sammo/Command/NationCommand.php +++ b/hwe/sammo/Command/NationCommand.php @@ -3,12 +3,26 @@ namespace sammo\Command; abstract class NationCommand extends BaseCommand{ protected $lastTurn; + protected $resultTurn; - public function setLast($lastTurn){ + public function __construct(General $generalObj, array $env, LastTurn $lastTurn, $arg = null){ $this->lastTurn = $lastTurn; + $this->resultTurn = new LastTurn(); + parent::__construct($generalObj, $env, $arg); } - public function getLast():array{ + public function getLastTurn():LastTurn{ return $this->lastTurn; } + + public function setResultTurn(LastTurn $lastTurn){ + $this->resultTurn = $lastTurn; + } + + public function getResultTurn():LastTurn{ + return $this->resultTurn; + } + + + }; \ No newline at end of file diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 7a771cad..d84aa6fc 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -28,6 +28,9 @@ class General implements iAction{ protected $personalityObj = null; protected $itemObjs = []; + protected $lastTurn = null; + protected $resultTurn = null; + public function __construct(array $raw, ?array $city, int $year, int $month){ //TODO: 밖에서 가져오도록 하면 버그 확률이 높아짐. 필요한 raw 값을 직접 구해야함. @@ -36,6 +39,11 @@ class General implements iAction{ $this->raw = $raw; $this->rawCity = $city; + if(key_exists('last_turn', $this->raw)){ + $this->lastTurn = LastTurn::fromJson($this->raw['last_turn']); + } + $this->resultTurn = new LastTurn(); + $this->logger = new ActionLogger( $this->getVar('no'), @@ -61,6 +69,18 @@ class General implements iAction{ //TODO: $specialItemClass 설정 } + function getLastTurn():LastTurn{ + return $this->lastTurn; + } + + function setResultTurn(LastTurn $resultTurn){ + $this->resultTurn = $resultTurn; + } + + function getResultTurn():LastTurn{ + return $this->resultTurn; + } + function clearActivatedSkill(){ foreach ($this->activatedSkill as $skillName=>$state) { if (!$state) { @@ -234,6 +254,9 @@ class General implements iAction{ * @param \MeekroDB $db */ function applyDB($db):bool{ + if($this->lastTurn && $this->getLastTurn() != $this->getResultTurn()){ + $this->setVar('last_turn', $this->getResultTurn()->toJson()); + } $updateVals = $this->getUpdatedValues(); if(!$updateVals){ diff --git a/hwe/sammo/LastTurn.php b/hwe/sammo/LastTurn.php index 5db76647..f95de1bd 100644 --- a/hwe/sammo/LastTurn.php +++ b/hwe/sammo/LastTurn.php @@ -6,9 +6,21 @@ class LastTurn{ protected $arg = null; protected $term = null; - function __construct(string $json) + function __construct(?string $command=null, ?array $arg=null, ?int $term=null) { + $this->setCommand($command); + $this->setArg($arg); + $this->setTerm($term); + } + + static function fromJson(string $json):self{ $values = Json::decode($json); + $obj = new static( + $values['command']??null, + $values['arg']??null, + $values['term']??null + ); + return $obj; } function setCommand(?string $command){ diff --git a/hwe/sammo/LazyVarUpdater.php b/hwe/sammo/LazyVarUpdater.php index 0d1bfb4a..37bf885c 100644 --- a/hwe/sammo/LazyVarUpdater.php +++ b/hwe/sammo/LazyVarUpdater.php @@ -13,6 +13,19 @@ trait LazyVarUpdater{ return $this->raw[$key]; } + function touchVar(string $key):bool{ + if(key_exists($key, $this->raw)){ + return false; + } + $this->raw[$key] = null; + + return true; + } + + function setVar(string $key, $value){ + return $this->updateVar($key, $value); + } + function updateVar(string $key, $value){ if($this->raw[$key] === $value){ return; diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index 075544df..6251ba56 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -10,9 +10,8 @@ class TurnExecutionHelper protected $generalObj; protected $turn = null; protected $nationTurn = null; - protected $lastNationTurn = null; - public function __construct(array $rawGeneral, array $turn, ?array $nationTurn, int $year, int $month) + public function __construct(array $rawGeneral, int $year, int $month) { $this->generalObj = new General($rawGeneral, null, $year, $month); $this->turn = $turn; @@ -70,7 +69,7 @@ class TurnExecutionHelper return true; } - public function processNationCommand():array{ + public function processNationCommand(string $commandClassName, array $commandArg, LastTurn $commandLast):LastTurn{ if(!$this->nationTurn){ throw new \InvalidArgumentException('nationTurn이 없음'); } @@ -79,21 +78,9 @@ class TurnExecutionHelper $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); - [$commandClassName, $commandArg, $commandLast] = $this->nationTurn; - - if(!$commandLast){ - //doNothing - } - else if($commandLast['command'] != $commandClassName){ - $commandLast = []; - } - else if($commandLast['arg'] != $commandArg){ - $commandLast = []; - } - $commandClass = getNationCommandClass($commandClassName); /** @var \sammo\Command\NationCommand $commandObj */ - $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandArg); + $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandLast, $commandArg); $failReason = $commandObj->testReservable(); if($failReason){ @@ -101,26 +88,24 @@ class TurnExecutionHelper $commandName = $commandObj->getName(); $text = "{$failReason} {$commandName} 실패. <1>{$date}"; $general->getLogger()->pushGeneralActionLog($text); - - $commandLast = []; } else{ $commandObj->run(); - $commandLast = $commandObj->getLast(); } - return $commandLast; + return $commandObj->getResultTurn(); } - public function processCommand(){ + public function processCommand(string $commandClassName, array $commandArg){ + + $general = $this->getGeneral(); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); - [$commandClassName, $commandArg] = $this->turn; $commandClass = getGeneralCommandClass($commandClassName); /** @var \sammo\Command\GeneralCommand $commandObj */ - $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandArg); + $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandArg, $commandLast); $failReason = $commandObj->testReservable(); if($failReason){ @@ -134,17 +119,32 @@ class TurnExecutionHelper } $general->clearActivatedSkill(); + return $general->getResultTurn(); } - function updateTurnTime(){ + function updateTurnTime($commandClassName){ $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); - $general = $this->generalObj; + $general = $this->getGeneral(); $generalID = $general->getRaw('no'); $logger = $general->getLogger(); $generalName = $general->getName(); + $killTurn = $gameStor->killturn; + + if($general->getVar('npc') >= 2){ + $general->increaseVarWithLimit('killturn', -1); + } + else if($general->getVar('killturn') > $killTurn){ + $general->increaseVarWithLimit('killturn', -1); + } + else if($commandClassName == '휴식'){ + $general->increaseVarWithLimit('killturn', -1); + } + else{ + $general->setVar('killturn', $killTurn); + } // 삭턴장수 삭제처리 if($general->getVar('killturn') <= 0){ @@ -196,7 +196,7 @@ turntime,makenation,makelimit,killturn,block,dedlevel,explevel, age,belong,personal,special,special2,term, npc,npc_org,npcid,deadyear, dex0,dex10,dex20,dex30,dex40, -warnum,killnum,deathnum,killcrew,deathcrew,recwar, +warnum,killnum,deathnum,killcrew,deathcrew,recwar,last_turn general_turn.`action` AS `action`, general_turn.arg AS arg FROM general LEFT JOIN general_turn ON general.`no` = general_turn.general_id AND turn_idx = 0 WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', @@ -211,7 +211,8 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', return [true, $currentTurn]; } - $turn = [$generalWork['action'], Json::decode($generalWork['arg'])]; + $generalCommand = $generalWork['action']; + $generalArg = $generalWork['arg']; unset($generalWork['action']); unset($generalWork['arg']); @@ -219,7 +220,7 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', processAI($generalID); // npc AI 처리 } - $nationTurn = null; + $hasNationTurn = false; if($generalWork['nation'] != 0 && $generalWork['level'] >= 5){ $nationStor = KVStorage::getStorage($db, 'nation_env'); $lastNationTurnKey = "turn_last_{$generalWork['nation']}_{$generalWork['level']}"; @@ -230,21 +231,25 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', $generalWork['nation'], $generalWork['level'] ); - $nationTurn = [$rawNationTurn['action'], Json::decode($rawNationTurn['arg']), $lastNationTurn]; + $hasNationTurn = true; } $turnObj = new static($generalWork, $turn, $nationTurn, $year, $month); if(!$turnObj->processBlocked()){ $turnObj->preprocessCommand(); - if($nationTurn){ - $lastNationTurn = $turnObj->processNationCommand(); - $nationStor->setValue($lastNationTurnKey, $lastNationTurn); + if($hasNationTurn){ + $resultNationTurn = $turnObj->processNationCommand( + $rawNationTurn['action'], + Json::decode($rawNationTurn['arg']), + $lastNationTurn + ); + $nationStor->setValue($lastNationTurnKey, $resultNationTurn->toJson()); } - $turnObj->processCommand(); + $turnObj->processCommand($generalCommand, $generalArg); } pullNationCommand($generalWork['nation'], $generalWork['level']); pullGeneralCommand($generalWork['no']); - $turnObj->updateTurntime(); + $turnObj->updateTurnTime(); $turnObj->applyDB(); $currentTurn = $generalWork['turntime'];