refac: GeneralBase, GeneralLite, General
- GeneralLite -> General 구조는 PHP에서 경고를 안띄웟서 포기 - GeneralBase에서 각각 요청하는 형태로 변경 - 여전히 GeneralBase를 인자로 받는 함수에서 GeneralLite를 요구하거나, General을 요구하는 함수를 추가로 호출할 때 경고가 없으므로 특히 주의해야 함.
This commit is contained in:
@@ -19,7 +19,7 @@ class AutorunGeneralPolicy{
|
|||||||
static $소집해제 = '소집해제';
|
static $소집해제 = '소집해제';
|
||||||
|
|
||||||
static $출병 = '출병';
|
static $출병 = '출병';
|
||||||
|
|
||||||
//static $NPC증여 = 'NPC증여';
|
//static $NPC증여 = 'NPC증여';
|
||||||
static $NPC헌납 = 'NPC헌납';
|
static $NPC헌납 = 'NPC헌납';
|
||||||
static $NPC사망대비 = 'NPC사망대비';
|
static $NPC사망대비 = 'NPC사망대비';
|
||||||
@@ -31,12 +31,12 @@ class AutorunGeneralPolicy{
|
|||||||
static $귀환 = '귀환';
|
static $귀환 = '귀환';
|
||||||
//static $전투이동 = '전투이동';
|
//static $전투이동 = '전투이동';
|
||||||
//static $내정이동 = '내정이동';
|
//static $내정이동 = '내정이동';
|
||||||
|
|
||||||
static $국가선택 = '국가선택';
|
static $국가선택 = '국가선택';
|
||||||
static $집합 = '집합';
|
static $집합 = '집합';
|
||||||
static $건국 = '건국';
|
static $건국 = '건국';
|
||||||
static $선양 = '선양';
|
static $선양 = '선양';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static public array $default_priority = [
|
static public array $default_priority = [
|
||||||
@@ -74,7 +74,7 @@ class AutorunGeneralPolicy{
|
|||||||
public $can소집해제 = true;
|
public $can소집해제 = true;
|
||||||
|
|
||||||
public $can출병 = true;
|
public $can출병 = true;
|
||||||
|
|
||||||
//public $canNPC증여 = true;
|
//public $canNPC증여 = true;
|
||||||
public $canNPC헌납 = true;
|
public $canNPC헌납 = true;
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ class AutorunGeneralPolicy{
|
|||||||
|
|
||||||
public array $priority;
|
public array $priority;
|
||||||
|
|
||||||
function doNPCState(General $general){
|
function doNPCState(GeneralBase $general){
|
||||||
$npc = $general->getNPCType();
|
$npc = $general->getNPCType();
|
||||||
$nationID = $general->getNationID();
|
$nationID = $general->getNationID();
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ class AutorunGeneralPolicy{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){
|
function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){
|
||||||
$this->priority = static::$default_priority;
|
$this->priority = static::$default_priority;
|
||||||
|
|
||||||
if($serverPolicy && key_exists('priority', $serverPolicy)){
|
if($serverPolicy && key_exists('priority', $serverPolicy)){
|
||||||
@@ -165,7 +165,7 @@ class AutorunGeneralPolicy{
|
|||||||
$this->can전투준비 = false;
|
$this->can전투준비 = false;
|
||||||
|
|
||||||
$this->can출병 = false;
|
$this->can출병 = false;
|
||||||
|
|
||||||
//$this->canNPC증여 = false;
|
//$this->canNPC증여 = false;
|
||||||
$this->canNPC헌납 = false;
|
$this->canNPC헌납 = false;
|
||||||
|
|
||||||
@@ -194,9 +194,9 @@ class AutorunGeneralPolicy{
|
|||||||
$this->can금쌀구매 = true;
|
$this->can금쌀구매 = true;
|
||||||
$this->can상인무시 = true;
|
$this->can상인무시 = true;
|
||||||
break;
|
break;
|
||||||
case 'recruit_high':
|
case 'recruit_high':
|
||||||
$this->can모병 = true;
|
$this->can모병 = true;
|
||||||
case 'recruit':
|
case 'recruit':
|
||||||
$this->can징병 = true;
|
$this->can징병 = true;
|
||||||
$this->can소집해제 = true;
|
$this->can소집해제 = true;
|
||||||
$this->can금쌀구매 = true;
|
$this->can금쌀구매 = true;
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class AutorunNationPolicy {
|
|||||||
'cureThreshold'=>10,
|
'cureThreshold'=>10,
|
||||||
];
|
];
|
||||||
|
|
||||||
function __construct(GeneralLite $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env)
|
function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env)
|
||||||
{
|
{
|
||||||
foreach(static::$defaultPolicy as $policy=>$value){
|
foreach(static::$defaultPolicy as $policy=>$value){
|
||||||
$this->{$policy} = $value;
|
$this->{$policy} = $value;
|
||||||
|
|||||||
@@ -10,11 +10,8 @@ use sammo\Enums\InheritanceKey;
|
|||||||
use sammo\Enums\RankColumn;
|
use sammo\Enums\RankColumn;
|
||||||
use sammo\WarUnitTrigger as WarUnitTrigger;
|
use sammo\WarUnitTrigger as WarUnitTrigger;
|
||||||
|
|
||||||
class General extends GeneralLite implements iAction
|
class General extends GeneralBase implements iAction
|
||||||
{
|
{
|
||||||
protected $rawCity = null;
|
|
||||||
|
|
||||||
|
|
||||||
/** @var Map<RankColumn,int> */
|
/** @var Map<RankColumn,int> */
|
||||||
protected Map $rankVarRead;
|
protected Map $rankVarRead;
|
||||||
/** @var Map<RankColumn,int> */
|
/** @var Map<RankColumn,int> */
|
||||||
@@ -25,9 +22,6 @@ class General extends GeneralLite implements iAction
|
|||||||
/** @var Map<GeneralAccessLogColumn,int|float|string> */
|
/** @var Map<GeneralAccessLogColumn,int|float|string> */
|
||||||
protected ?Map $accessLogRead;
|
protected ?Map $accessLogRead;
|
||||||
|
|
||||||
/** @var \sammo\ActionLogger */
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
protected $activatedSkill = [];
|
protected $activatedSkill = [];
|
||||||
protected $logActivatedSkill = [];
|
protected $logActivatedSkill = [];
|
||||||
protected $isFinished = false;
|
protected $isFinished = false;
|
||||||
|
|||||||
@@ -0,0 +1,228 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
|
use Ds\Map;
|
||||||
|
use sammo\Enums\GeneralAccessLogColumn;
|
||||||
|
use sammo\Enums\GeneralQueryMode;
|
||||||
|
use sammo\Enums\RankColumn;
|
||||||
|
|
||||||
|
abstract class GeneralBase
|
||||||
|
{
|
||||||
|
use LazyVarUpdater;
|
||||||
|
|
||||||
|
protected $raw = [];
|
||||||
|
protected $rawCity = null;
|
||||||
|
|
||||||
|
/** @var Map<RankColumn,int> */
|
||||||
|
protected Map $rankVarRead;
|
||||||
|
|
||||||
|
/** @var \sammo\ActionLogger */
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
|
const TURNTIME_FULL_MS = -1;
|
||||||
|
const TURNTIME_FULL = 0;
|
||||||
|
const TURNTIME_HMS = 1;
|
||||||
|
const TURNTIME_HM = 2;
|
||||||
|
|
||||||
|
protected static $prohibitedDirectUpdateVars = [
|
||||||
|
//Reason: iAction
|
||||||
|
'leadership' => 1,
|
||||||
|
'power' => 1,
|
||||||
|
'intel' => 1,
|
||||||
|
'nation' => 2,
|
||||||
|
'officer_level' => 1,
|
||||||
|
//NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남.
|
||||||
|
'special' => 1,
|
||||||
|
'special2' => 1,
|
||||||
|
'personal' => 1,
|
||||||
|
'horse' => 1,
|
||||||
|
'weapon' => 1,
|
||||||
|
'book' => 1,
|
||||||
|
'item' => 1
|
||||||
|
];
|
||||||
|
|
||||||
|
function initLogger(int $year, int $month)
|
||||||
|
{
|
||||||
|
$this->logger = new ActionLogger(
|
||||||
|
$this->getVar('no'),
|
||||||
|
$this->getVar('nation'),
|
||||||
|
$year,
|
||||||
|
$month,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string
|
||||||
|
{
|
||||||
|
if(!key_exists('turntime', $this->raw)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
self::TURNTIME_FULL_MS => function ($turntime) {
|
||||||
|
return $turntime;
|
||||||
|
},
|
||||||
|
self::TURNTIME_FULL => function ($turntime) {
|
||||||
|
return substr($turntime, 0, 19);
|
||||||
|
},
|
||||||
|
self::TURNTIME_HMS => function ($turntime) {
|
||||||
|
return substr($turntime, 11, 8);
|
||||||
|
},
|
||||||
|
self::TURNTIME_HM => function ($turntime) {
|
||||||
|
return substr($turntime, 11, 5);
|
||||||
|
},
|
||||||
|
][$short]($this->getVar('turntime'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNPCType(): int
|
||||||
|
{
|
||||||
|
return $this->raw['npc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getName(): string
|
||||||
|
{
|
||||||
|
return $this->raw['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getID(): int
|
||||||
|
{
|
||||||
|
return $this->raw['no'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRawCity(): ?array
|
||||||
|
{
|
||||||
|
return $this->rawCity;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRawCity(?array $city)
|
||||||
|
{
|
||||||
|
$this->rawCity = $city;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCityID(): int
|
||||||
|
{
|
||||||
|
return $this->raw['city'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNationID(): int
|
||||||
|
{
|
||||||
|
return $this->raw['nation'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStaticNation(): array
|
||||||
|
{
|
||||||
|
return getNationStaticInfo($this->raw['nation']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLogger(): ?ActionLogger
|
||||||
|
{
|
||||||
|
return $this->logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDex(GameUnitDetail $crewType)
|
||||||
|
{
|
||||||
|
$armType = $crewType->armType;
|
||||||
|
|
||||||
|
if ($armType == GameUnitConst::T_CASTLE) {
|
||||||
|
$armType = GameUnitConst::T_SIEGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getVar("dex{$armType}");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRankVar(RankColumn $key, $defaultValue = null): int
|
||||||
|
{
|
||||||
|
if (!$this->rankVarRead->hasKey($key)) {
|
||||||
|
if ($defaultValue === null) {
|
||||||
|
throw new \RuntimeException('인자가 없음 : ' . $key->value);
|
||||||
|
}
|
||||||
|
return $defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->rankVarRead[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract function applyDB($db): bool;
|
||||||
|
|
||||||
|
static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array
|
||||||
|
{
|
||||||
|
$minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city'];
|
||||||
|
$defaultEventColumn = [
|
||||||
|
'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city',
|
||||||
|
'special', 'special2', 'personal',
|
||||||
|
'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime',
|
||||||
|
];
|
||||||
|
$fullColumn = [
|
||||||
|
'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity',
|
||||||
|
'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item',
|
||||||
|
'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime',
|
||||||
|
'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong',
|
||||||
|
'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg',
|
||||||
|
'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray',
|
||||||
|
'recent_war', 'last_turn', 'myset',
|
||||||
|
'specage', 'specage2', 'aux', 'permission', 'penalty',
|
||||||
|
];
|
||||||
|
$fullAcessLogColumn = [
|
||||||
|
GeneralAccessLogColumn::refreshScore,
|
||||||
|
GeneralAccessLogColumn::refreshScoreTotal,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($reqColumns === null) {
|
||||||
|
switch ($queryMode) {
|
||||||
|
case GeneralQueryMode::Core:
|
||||||
|
return [$minimumColumn, [], []];
|
||||||
|
case GeneralQueryMode::Lite:
|
||||||
|
return [$defaultEventColumn, [], []];
|
||||||
|
case GeneralQueryMode::FullWithoutIAction:
|
||||||
|
case GeneralQueryMode::Full:
|
||||||
|
return [$fullColumn, RankColumn::cases(), []];
|
||||||
|
case GeneralQueryMode::FullWithAccessLog:
|
||||||
|
return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var RankColumn[] */
|
||||||
|
$rankColumn = [];
|
||||||
|
$subColumn = [];
|
||||||
|
$accessLogColumn = [];
|
||||||
|
foreach ($reqColumns as $column) {
|
||||||
|
if ($column instanceof RankColumn) {
|
||||||
|
$rankColumn[] = $column;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($column instanceof GeneralAccessLogColumn) {
|
||||||
|
$accessLogColumn[] = $column;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$enumKey = RankColumn::tryFrom($column);
|
||||||
|
if ($enumKey !== null) {
|
||||||
|
$rankColumn[] = $enumKey;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$enumKey = GeneralAccessLogColumn::tryFrom($column);
|
||||||
|
if ($enumKey !== null) {
|
||||||
|
$accessLogColumn[] = $enumKey;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$subColumn[] = $column;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($queryMode) {
|
||||||
|
case GeneralQueryMode::Core:
|
||||||
|
return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn];
|
||||||
|
case GeneralQueryMode::Lite:
|
||||||
|
return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn];
|
||||||
|
case GeneralQueryMode::FullWithoutIAction:
|
||||||
|
case GeneralQueryMode::Full:
|
||||||
|
return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn];
|
||||||
|
case GeneralQueryMode::FullWithAccessLog:
|
||||||
|
return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))];
|
||||||
|
default:
|
||||||
|
throw new \RuntimeException('invalid query mode');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-221
@@ -3,49 +3,11 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
use Ds\Map;
|
use Ds\Map;
|
||||||
use sammo\Command\GeneralCommand;
|
|
||||||
use sammo\Enums\GeneralAccessLogColumn;
|
|
||||||
use sammo\Enums\GeneralQueryMode;
|
use sammo\Enums\GeneralQueryMode;
|
||||||
use sammo\Enums\InheritanceKey;
|
|
||||||
use sammo\Enums\RankColumn;
|
use sammo\Enums\RankColumn;
|
||||||
use sammo\WarUnitTrigger as WarUnitTrigger;
|
|
||||||
|
|
||||||
class GeneralLite
|
class GeneralLite extends GeneralBase
|
||||||
{
|
{
|
||||||
use LazyVarUpdater;
|
|
||||||
|
|
||||||
protected $raw = [];
|
|
||||||
protected $rawCity = null;
|
|
||||||
|
|
||||||
/** @var Map<RankColumn,int> */
|
|
||||||
protected Map $rankVarRead;
|
|
||||||
|
|
||||||
/** @var \sammo\ActionLogger */
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
const TURNTIME_FULL_MS = -1;
|
|
||||||
const TURNTIME_FULL = 0;
|
|
||||||
const TURNTIME_HMS = 1;
|
|
||||||
const TURNTIME_HM = 2;
|
|
||||||
|
|
||||||
protected static $prohibitedDirectUpdateVars = [
|
|
||||||
//Reason: iAction
|
|
||||||
'leadership' => 1,
|
|
||||||
'power' => 1,
|
|
||||||
'intel' => 1,
|
|
||||||
'nation' => 2,
|
|
||||||
'officer_level' => 1,
|
|
||||||
//NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남.
|
|
||||||
'special' => 1,
|
|
||||||
'special2' => 1,
|
|
||||||
'personal' => 1,
|
|
||||||
'horse' => 1,
|
|
||||||
'weapon' => 1,
|
|
||||||
'book' => 1,
|
|
||||||
'item' => 1
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $raw DB row값.
|
* @param array $raw DB row값.
|
||||||
* @param null|array $city DB city 테이블의 row값
|
* @param null|array $city DB city 테이블의 row값
|
||||||
@@ -72,108 +34,6 @@ class GeneralLite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initLogger(int $year, int $month)
|
|
||||||
{
|
|
||||||
$this->logger = new ActionLogger(
|
|
||||||
$this->getVar('no'),
|
|
||||||
$this->getVar('nation'),
|
|
||||||
$year,
|
|
||||||
$month,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string
|
|
||||||
{
|
|
||||||
if(!key_exists('turntime', $this->raw)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
self::TURNTIME_FULL_MS => function ($turntime) {
|
|
||||||
return $turntime;
|
|
||||||
},
|
|
||||||
self::TURNTIME_FULL => function ($turntime) {
|
|
||||||
return substr($turntime, 0, 19);
|
|
||||||
},
|
|
||||||
self::TURNTIME_HMS => function ($turntime) {
|
|
||||||
return substr($turntime, 11, 8);
|
|
||||||
},
|
|
||||||
self::TURNTIME_HM => function ($turntime) {
|
|
||||||
return substr($turntime, 11, 5);
|
|
||||||
},
|
|
||||||
][$short]($this->getVar('turntime'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNPCType(): int
|
|
||||||
{
|
|
||||||
return $this->raw['npc'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getName(): string
|
|
||||||
{
|
|
||||||
return $this->raw['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getID(): int
|
|
||||||
{
|
|
||||||
return $this->raw['no'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRawCity(): ?array
|
|
||||||
{
|
|
||||||
return $this->rawCity;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setRawCity(?array $city)
|
|
||||||
{
|
|
||||||
$this->rawCity = $city;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCityID(): int
|
|
||||||
{
|
|
||||||
return $this->raw['city'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNationID(): int
|
|
||||||
{
|
|
||||||
return $this->raw['nation'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStaticNation(): array
|
|
||||||
{
|
|
||||||
return getNationStaticInfo($this->raw['nation']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLogger(): ?ActionLogger
|
|
||||||
{
|
|
||||||
return $this->logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDex(GameUnitDetail $crewType)
|
|
||||||
{
|
|
||||||
$armType = $crewType->armType;
|
|
||||||
|
|
||||||
if ($armType == GameUnitConst::T_CASTLE) {
|
|
||||||
$armType = GameUnitConst::T_SIEGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getVar("dex{$armType}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRankVar(RankColumn $key, $defaultValue = null): int
|
|
||||||
{
|
|
||||||
if (!$this->rankVarRead->hasKey($key)) {
|
|
||||||
if ($defaultValue === null) {
|
|
||||||
throw new \RuntimeException('인자가 없음 : ' . $key->value);
|
|
||||||
}
|
|
||||||
return $defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->rankVarRead[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \MeekroDB $db
|
* @param \MeekroDB $db
|
||||||
*/
|
*/
|
||||||
@@ -201,86 +61,6 @@ class GeneralLite
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array
|
|
||||||
{
|
|
||||||
$minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city'];
|
|
||||||
$defaultEventColumn = [
|
|
||||||
'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city',
|
|
||||||
'special', 'special2', 'personal',
|
|
||||||
'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime',
|
|
||||||
];
|
|
||||||
$fullColumn = [
|
|
||||||
'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity',
|
|
||||||
'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item',
|
|
||||||
'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime',
|
|
||||||
'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong',
|
|
||||||
'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg',
|
|
||||||
'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray',
|
|
||||||
'recent_war', 'last_turn', 'myset',
|
|
||||||
'specage', 'specage2', 'aux', 'permission', 'penalty',
|
|
||||||
];
|
|
||||||
$fullAcessLogColumn = [
|
|
||||||
GeneralAccessLogColumn::refreshScore,
|
|
||||||
GeneralAccessLogColumn::refreshScoreTotal,
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($reqColumns === null) {
|
|
||||||
switch ($queryMode) {
|
|
||||||
case GeneralQueryMode::Core:
|
|
||||||
return [$minimumColumn, [], []];
|
|
||||||
case GeneralQueryMode::Lite:
|
|
||||||
return [$defaultEventColumn, [], []];
|
|
||||||
case GeneralQueryMode::FullWithoutIAction:
|
|
||||||
case GeneralQueryMode::Full:
|
|
||||||
return [$fullColumn, RankColumn::cases(), []];
|
|
||||||
case GeneralQueryMode::FullWithAccessLog:
|
|
||||||
return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var RankColumn[] */
|
|
||||||
$rankColumn = [];
|
|
||||||
$subColumn = [];
|
|
||||||
$accessLogColumn = [];
|
|
||||||
foreach ($reqColumns as $column) {
|
|
||||||
if ($column instanceof RankColumn) {
|
|
||||||
$rankColumn[] = $column;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($column instanceof GeneralAccessLogColumn) {
|
|
||||||
$accessLogColumn[] = $column;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$enumKey = RankColumn::tryFrom($column);
|
|
||||||
if ($enumKey !== null) {
|
|
||||||
$rankColumn[] = $enumKey;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$enumKey = GeneralAccessLogColumn::tryFrom($column);
|
|
||||||
if ($enumKey !== null) {
|
|
||||||
$accessLogColumn[] = $enumKey;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$subColumn[] = $column;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($queryMode) {
|
|
||||||
case GeneralQueryMode::Core:
|
|
||||||
return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn];
|
|
||||||
case GeneralQueryMode::Lite:
|
|
||||||
return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn];
|
|
||||||
case GeneralQueryMode::FullWithoutIAction:
|
|
||||||
case GeneralQueryMode::Full:
|
|
||||||
return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn];
|
|
||||||
case GeneralQueryMode::FullWithAccessLog:
|
|
||||||
return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))];
|
|
||||||
default:
|
|
||||||
throw new \RuntimeException('invalid query mode');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ?int[] $generalIDList
|
* @param ?int[] $generalIDList
|
||||||
* @param null|array<string|RankColumn> $column
|
* @param null|array<string|RankColumn> $column
|
||||||
|
|||||||
Reference in New Issue
Block a user