feat: UserAction 실행기

This commit is contained in:
2023-12-25 12:52:22 +00:00
parent 0f621b22a5
commit 1fe55b83bd
7 changed files with 115 additions and 13 deletions
+24 -10
View File
@@ -3,11 +3,14 @@ namespace sammo\Command;
use \sammo\Util;
abstract class UserActionCommand extends BaseCommand{
const USER_ACTION_KEY = 'user_action';
public function getNextExecuteKey():string{
//NOTE: 일반 턴 체계와 다르므로 쓸 일은 없음
$turnKey = static::$actionName;
$userActionKey = static::USER_ACTION_KEY;
$generalID = $this->getGeneral()->getID();
$executeKey = "next_execute_{$generalID}_user_action_{$turnKey}";
$executeKey = "next_execute_{$generalID}_{$userActionKey}_{$turnKey}";
return $executeKey;
}
@@ -15,23 +18,34 @@ abstract class UserActionCommand extends BaseCommand{
if($this->isArgValid && !$this->getPostReqTurn()){
return null;
}
$db = \sammo\DB::db();
$lastExecuteStor = \sammo\KVStorage::getStorage($db, 'next_execute');
return $lastExecuteStor->getValue($this->getNextExecuteKey());
$rawUserAction = $this->generalObj->getAuxVar(static::USER_ACTION_KEY);
if($rawUserAction === null){
return null;
}
$userAction = \sammo\DTO\UserAction::fromArray($rawUserAction);
$nextAvailableTurn = $userAction->nextAvailableTurn;
if($nextAvailableTurn === null){
return null;
}
$nextAvailableTurn = $nextAvailableTurn[static::$actionName] ?? null;
}
public function setNextAvailable(?int $yearMonth=null){
if(!$this->getPostReqTurn()){
return;
}
if($yearMonth === null){
$yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month'])
+ $this->getPostReqTurn() - $this->getPreReqTurn();
$rawUserAction = $this->generalObj->getAuxVar(static::USER_ACTION_KEY);
if($rawUserAction === null){
$rawUserAction = [];
}
$userAction = \sammo\DTO\UserAction::fromArray($rawUserAction);
if($userAction->nextAvailableTurn === null){
$userAction->nextAvailableTurn = [];
}
$db = \sammo\DB::db();
$lastExecuteStor = \sammo\KVStorage::getStorage($db, 'next_execute');
$lastExecuteStor->setValue($this->getNextExecuteKey(), $yearMonth);
$userAction->nextAvailableTurn[static::$actionName] = $yearMonth;
$this->generalObj->setAuxVar(static::USER_ACTION_KEY, $userAction->toArray());
}
};