전략 사용 방식 변경

This commit is contained in:
2020-07-13 21:54:32 +09:00
parent a427ddff83
commit 6306dae92d
24 changed files with 4024 additions and 3910 deletions
+57 -29
View File
@@ -1,30 +1,58 @@
<?php
namespace sammo\Command;
use \sammo\General;
use \sammo\LastTurn;
abstract class NationCommand extends BaseCommand{
protected $lastTurn;
protected $resultTurn;
public function __construct(General $generalObj, array $env, LastTurn $lastTurn, $arg = null){
$this->lastTurn = $lastTurn;
$this->resultTurn = $lastTurn->duplicate();
parent::__construct($generalObj, $env, $arg);
}
public function getLastTurn():LastTurn{
return $this->lastTurn;
}
public function setResultTurn(LastTurn $lastTurn){
$this->resultTurn = $lastTurn;
}
public function getResultTurn():LastTurn{
return $this->resultTurn;
}
<?php
namespace sammo\Command;
use \sammo\General;
use sammo\KVStorage;
use \sammo\LastTurn;
use \sammo\Util;
abstract class NationCommand extends BaseCommand{
protected $lastTurn;
protected $resultTurn;
public function __construct(General $generalObj, array $env, LastTurn $lastTurn, $arg = null){
$this->lastTurn = $lastTurn;
$this->resultTurn = $lastTurn->duplicate();
parent::__construct($generalObj, $env, $arg);
}
public function getLastTurn():LastTurn{
return $this->lastTurn;
}
public function setResultTurn(LastTurn $lastTurn){
$this->resultTurn = $lastTurn;
}
public function getResultTurn():LastTurn{
return $this->resultTurn;
}
protected function getNextExecuteKey():string{
$turnKey = static::$actionName;
$executeKey = "next_execute_{$turnKey}";
return $executeKey;
}
public function getNextAvailable():?int{
if($this->isArgValid && !$this->getPostReqTurn()){
return null;
}
$db = \sammo\DB::db();
$nationStor = \sammo\KVStorage::getStorage($db, $this->getNationID(), 'nation_env');
return $nationStor->getValue($this->getNextExecuteKey());
}
public function setNextAvailable(?int $yearMonth=null){
if(!$this->getPostReqTurn()){
return;
}
if($yearMonth === null){
$yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']) + $this->getPostReqTurn();
}
$db = \sammo\DB::db();
$nationStor = \sammo\KVStorage::getStorage($db, $this->getNationID(), 'nation_env');
$nationStor->setValue($this->getNextExecuteKey(), $yearMonth);
}
};