'지난 턴'을 관리하는 기능 추가

This commit is contained in:
2018-10-03 22:38:05 +09:00
parent a33a7317cc
commit e1a266e5d8
11 changed files with 114 additions and 45 deletions
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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);
}
+3 -2
View File
@@ -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;
}
+2 -1
View File
@@ -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(){
//아무것도 하지 않음
}
+16 -2
View File
@@ -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;
}
};
+23
View File
@@ -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){
+13 -1
View File
@@ -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){
+13
View File
@@ -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;
+39 -34
View File
@@ -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'];