feat: g65_병사연회 구현

This commit is contained in:
2023-12-25 13:43:46 +00:00
parent 1fe55b83bd
commit 53474ab3d2
10 changed files with 204 additions and 19 deletions
+34
View File
@@ -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;
+1 -1
View File
@@ -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,
);
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace sammo\ActionBuff;
use sammo\General;
use \sammo\iAction;
class g65_사기40 implements iAction
{
use \sammo\DefaultAction;
function onCalcStat(General $general, string $statName, $value, $aux = null)
{
if ($statName == 'bonusAtmos') {
return $value + 40;
}
return $value;
}
}
@@ -0,0 +1,53 @@
<?php
namespace sammo\Command\UserAction;
use sammo\ActionBuff\g65_사기40;
use \sammo\Command;
use \sammo\Util;
use \sammo\JosaUtil;
use sammo\LastTurn;
class g65_병사연회 extends Command\UserActionCommand{
static protected $actionName = '병사연회';
protected function argTest():bool{
return true;
}
public function getBrief(): string
{
return '병사 연회';
}
public function getCommandDetailTitle(): string
{
$postReqTurn = $this->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;
}
}
+22 -12
View File
@@ -1,11 +1,15 @@
<?php
namespace sammo\Command;
use \sammo\Util;
abstract class UserActionCommand extends BaseCommand{
abstract class UserActionCommand extends BaseCommand
{
const USER_ACTION_KEY = 'user_action';
public function getNextExecuteKey():string{
public function getNextExecuteKey(): string
{
//NOTE: 일반 턴 체계와 다르므로 쓸 일은 없음
$turnKey = static::$actionName;
$userActionKey = static::USER_ACTION_KEY;
@@ -14,38 +18,44 @@ abstract class UserActionCommand extends BaseCommand{
return $executeKey;
}
public function getNextAvailableTurn():?int{
if($this->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());
}
};
};
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace sammo\DTO;
use LDTO\DTO;
class InstantBuff extends DTO{
public function __construct(
public readonly string $buffName,
public readonly int $untilYearMonth,
){
}
}
-2
View File
@@ -19,8 +19,6 @@ class UserAction extends \LDTO\DTO
#[Convert(MapConverter::class, [UserActionItem::class])]
public ?array $reserved,
#[Convert(ArrayConverter::class, [UserActionItem::class])]
public ?array $active,
#[Convert(MapConverter::class, ['int'])]
public ?array $nextAvailableTurn,
) {
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace sammo\Enums;
enum GeneralAuxKey: string{
case instantBuffList = 'instantBuffList';
}
+3 -3
View File
@@ -400,9 +400,9 @@ class GameConstBase
public static $availableUserActionCommand = [
'개인 전략' => [
'휴식',
/*'che_병사연회',
'che_내정집중',
'che_즉시치료',*/
'g65_병사연회',
/*'g65_철야내정',
'g65_의원소환',*/
]
];
+52 -1
View File
@@ -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<RankColumn,int|float> $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