diff --git a/hwe/func_converter.php b/hwe/func_converter.php index 85f991e5..e16d74cf 100644 --- a/hwe/func_converter.php +++ b/hwe/func_converter.php @@ -291,6 +291,40 @@ function buildScenarioEffectClass(?string $type):iAction{ return $obj; } +function getBuffClass(?string $type){ + if($type === null || $type === ''){ + $type = 'None'; + } + + static $basePath = __NAMESPACE__.'\\ActionBuff\\'; + $classPath = ($basePath.$type); + + if(class_exists($classPath)){ + return $classPath; + } + + $classPath = ($basePath.'che_'.$type); + if(class_exists($classPath)){ + return $classPath; + } + + throw new \InvalidArgumentException("{$type}은 버프 클래스가 아님"); +} +function buildBuffClass(?string $type):iAction{ + static $cache = []; + if($type === null){ + $type = 'None'; + } + if(key_exists($type, $cache)){ + return $cache[$type]; + } + $class = getBuffClass($type); + + $obj = new $class(); + $cache[$type]= $obj; + return $obj; +} + function getGeneralSpecialDomesticClass(?string $type){ if($type === null || $type === ''){ $type = GameConst::$defaultSpecialDomestic; diff --git a/hwe/sammo/API/Command/ReserveUserAction.php b/hwe/sammo/API/Command/ReserveUserAction.php index 81299564..e661b887 100644 --- a/hwe/sammo/API/Command/ReserveUserAction.php +++ b/hwe/sammo/API/Command/ReserveUserAction.php @@ -76,7 +76,7 @@ class ReserveUserAction extends \sammo\BaseAPI $item = buildUserActionCommandClass($action, $general, $gameStor->getAll()); $userActions->reserved[$turnIdx] = new UserActionItem( $item->getRawClassName(), - $item->getCommandDetailTitle(), + $item->getBrief(), null, ); diff --git a/hwe/sammo/ActionBuff/g65_사기40.php b/hwe/sammo/ActionBuff/g65_사기40.php new file mode 100644 index 00000000..1eaa263b --- /dev/null +++ b/hwe/sammo/ActionBuff/g65_사기40.php @@ -0,0 +1,19 @@ +getPostReqTurn(); + return "3턴간 사기 +40(재사용 대기 {$postReqTurn})"; + } + + protected function init(){ + //아무것도 하지 않음 + $this->fullConditionConstraints=[]; + + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 60; + } + + public function getCost():array{ + return [0, 0]; + } + + public function run(\Sammo\RandUtil $rng):bool{ + + $this->generalObj->addInstantBuff(new g65_사기40(), 3); + $logger = $this->generalObj->getLogger(); + $logger->pushGeneralActionLog("병사에게 연회를 열어 3턴간 사기가 40 상승합니다."); + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Command/UserActionCommand.php b/hwe/sammo/Command/UserActionCommand.php index 25f45a99..98e4fc06 100644 --- a/hwe/sammo/Command/UserActionCommand.php +++ b/hwe/sammo/Command/UserActionCommand.php @@ -1,11 +1,15 @@ isArgValid && !$this->getPostReqTurn()){ + public function getNextAvailableTurn(): ?int + { + if ($this->isArgValid && !$this->getPostReqTurn()) { return null; } $rawUserAction = $this->generalObj->getAuxVar(static::USER_ACTION_KEY); - if($rawUserAction === null){ + if ($rawUserAction === null) { return null; } $userAction = \sammo\DTO\UserAction::fromArray($rawUserAction); $nextAvailableTurn = $userAction->nextAvailableTurn; - if($nextAvailableTurn === null){ + if ($nextAvailableTurn === null) { return null; } $nextAvailableTurn = $nextAvailableTurn[static::$actionName] ?? null; + return $nextAvailableTurn; } - public function setNextAvailable(?int $yearMonth=null){ - if(!$this->getPostReqTurn()){ + public function setNextAvailable(?int $yearMonth = null) + { + if (!$this->getPostReqTurn()) { return; } $rawUserAction = $this->generalObj->getAuxVar(static::USER_ACTION_KEY); - if($rawUserAction === null){ + if ($rawUserAction === null) { $rawUserAction = []; } $userAction = \sammo\DTO\UserAction::fromArray($rawUserAction); - if($userAction->nextAvailableTurn === null){ + if ($userAction->nextAvailableTurn === null) { $userAction->nextAvailableTurn = []; } + if ($yearMonth === null) { + $yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']) + + $this->getPostReqTurn() - $this->getPreReqTurn(); + } $userAction->nextAvailableTurn[static::$actionName] = $yearMonth; $this->generalObj->setAuxVar(static::USER_ACTION_KEY, $userAction->toArray()); } - -}; \ No newline at end of file +}; diff --git a/hwe/sammo/DTO/InstantBuff.php b/hwe/sammo/DTO/InstantBuff.php new file mode 100644 index 00000000..019e4a3f --- /dev/null +++ b/hwe/sammo/DTO/InstantBuff.php @@ -0,0 +1,13 @@ + [ '휴식', - /*'che_병사연회', - 'che_내정집중', - 'che_즉시치료',*/ + 'g65_병사연회', + /*'g65_철야내정', + 'g65_의원소환',*/ ] ]; diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index cb6d115e..a33ce880 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -5,7 +5,9 @@ namespace sammo; use Ds\Map; use sammo\Command\GeneralCommand; use sammo\Command\UserActionCommand; +use sammo\DTO\InstantBuff; use sammo\Enums\GeneralAccessLogColumn; +use sammo\Enums\GeneralAuxKey; use sammo\Enums\GeneralQueryMode; use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; @@ -46,6 +48,9 @@ class General extends GeneralBase implements iAction /** @var ?iAction */ protected $scenarioEffect = null; + /** @var iAction[] */ + protected $instantBuffList = []; + /** @var ?GameUnitDetail */ protected $crewType = null; @@ -54,6 +59,9 @@ class General extends GeneralBase implements iAction protected $calcCache = []; + /** @var int */ + protected $yearMonth; + /** * @param array $raw DB row값. * @param null|Map $rawRank @@ -73,6 +81,8 @@ class General extends GeneralBase implements iAction $this->raw = $raw; $this->rawCity = $city; + $this->yearMonth = Util::joinYearMonth($year, $month); + $this->resultTurn = new LastTurn(); if (key_exists('last_turn', $this->raw)) { $this->lastTurn = LastTurn::fromJson($this->raw['last_turn']); @@ -116,6 +126,47 @@ class General extends GeneralBase implements iAction if(GameConst::$scenarioEffect){ $this->scenarioEffect = buildScenarioEffectClass(GameConst::$scenarioEffect); } + + $this->refreshInstantBuff(Util::joinYearMonth($year, $month)); + } + + function refreshInstantBuff(){ + $this->instantBuffList = []; + $rawBuffList = $this->getAuxVar(GeneralAuxKey::instantBuffList); + if($rawBuffList === null){ + return; + } + + $newRawBuffList = []; + $reqUpdate = false; + + foreach($rawBuffList as $rawBuff){ + $buffItem = InstantBuff::fromArray($rawBuff); + if($buffItem->untilYearMonth < $this->yearMonth){ + $reqUpdate = true; + continue; + } + + $newRawBuffList[] = $rawBuff; + $this->instantBuffList[] = buildBuffClass($buffItem->buffName); + } + + if($reqUpdate){ + $this->setAuxVar(GeneralAuxKey::instantBuffList, $newRawBuffList); + } + } + + function addInstantBuff(iAction $buffObj, int $month){ + $this->instantBuffList[] = $buffObj; + + $untilYearMonth = $this->yearMonth + $month - 1; + $buffItem = new InstantBuff(Util::getClassName($buffObj::class), $untilYearMonth); + $rawBuffList = $this->getAuxVar(GeneralAuxKey::instantBuffList); + if($rawBuffList === null){ + $rawBuffList = []; + } + $rawBuffList[] = $buffItem->toArray(); + $this->setAuxVar(GeneralAuxKey::instantBuffList, $rawBuffList); } function setItem(string $itemKey = 'item', ?string $itemCode) @@ -810,7 +861,7 @@ class General extends GeneralBase implements iAction $this->crewType, $this->inheritBuffObj, $this->scenarioEffect - ], $this->itemObjs); + ], $this->itemObjs, $this->instantBuffList); } public function getPreTurnExecuteTriggerList(General $general): ?GeneralTriggerCaller