feat(wip): 세력장수에서 암행부, 랭크 값 모두 불러옴

This commit is contained in:
2022-04-07 03:03:38 +09:00
parent 09fb96d9b3
commit c104fbcf58
5 changed files with 207 additions and 117 deletions
+163 -93
View File
@@ -25,8 +25,84 @@ class GeneralList extends \sammo\BaseAPI
{
private int $permission;
static $viewColumns = [
'no' => 0,
'name' => 0,
'nation' => 0,
'npc' => 0,
'injury' => 0,
'leadership' => 0,
'strength' => 0,
'intel' => 0,
'explevel' => 0,
'dedlevel' => 0,
'gold' => 0,
'rice' => 0,
'killturn' => 0,
'picture' => 0,
'imgsvr' => 0,
'age' => 0,
'special' => 0,
'special2' => 0,
'personal' => 0,
'belong' => 0,
'connect' => 0,
'city' => 1,
'experience' => 1,
'dedication' => 1,
'officer_level' => 2,
'officer_city' => 2,
'defence_train' => 2,
'troop' => 2,
'crewtype' => 2,
'crew' => 2,
'train' => 2,
'atmos' => 2,
'turntime' => 2,
'horse' => 2,
'weapon' => 2,
'book' => 2,
'item' => 2,
'aux' => 2,
'owner_name' => 9,//안씀.
//RANK
'warnum' => 2,
'killnum' => 2,
'deathnum' => 2,
'killcrew' => 2,
'deathcrew' => 2,
'firenum' => 2,
];
static $columnRemap = [
'special' => 'specialDomestic',
'special2' => 'specialWar',
'aux' => null,
];
static $customViewColumns = [
'officerLevel' => 0,
'officerLevelText' => 0,
'lbonus' => 0,
'ownerName' => 0,
'honorText' => 0,
'dedLevelText' => 0,
'bill' => 0,
'reservedCommand' => 2,
'autorun_limit' => 2,
];
public function validateArgs(): ?string
{
//TODO: 장기적으로는 요청에 따라 반환해야...
return null;
}
@@ -53,6 +129,9 @@ class GeneralList extends \sammo\BaseAPI
$db = DB::db();
$gameStor = \sammo\KVStorage::getStorage($db, 'game_env');
$env = $gameStor->getValues(['year', 'month', 'turntime', 'turnterm']);
$me = $db->queryFirstRow('SELECT con, turntime, belong, nation, officer_level, permission, penalty FROM general WHERE owner=%i', $session->getUserID());
$con = checkLimit($me['con']);
if ($con >= 2) {
@@ -64,112 +143,99 @@ class GeneralList extends \sammo\BaseAPI
$nationArr = getNationStaticInfo($nationID);
$viewColumns = [
'no' => 0,
'name' => 0,
'owner_name' => 9,
'nation' => 0,
'city' => 1,
'officer_level' => 2,
'officer_city' => 2,
'npc' => 0,
'defence_train' => 2,
'troop' => 2,
'injury' => 0,
'leadership' => 0,
'strength' => 0,
'intel' => 0,
'experience' => 1,
'explevel' => 0,
'dedication' => 1,
'dedlevel' => 0,
'gold' => 0,
'rice' => 0,
'crewtype' => 2,
'crew' => 2,
'train' => 2,
'atmos' => 2,
'killturn' => 0,
'turntime' => 2,
'picture' => 0,
'imgsvr' => 0,
'age' => 0,
'special' => 0,
'special2' => 0,
'personal' => 0,
'belong' => 0,
'horse' => 2,
'weapon' => 2,
'book' => 2,
'item' => 2,
'connect' => 0
];
$columnRemap = [
'special' => 'specialDomestic',
'special2' => 'specialWar',
];
$customViewColumns = [
'officerLevel' => 0,
'officerLevelText' => 0,
'lbonus' => 0,
'ownerName' => 0,
'honorText' => 0,
'dedLevelText' => 0,
'bill' => 0,
];
$specialViewFilter = [
'officerLevel' => function ($rawGeneral) {
return $this->getOfficerLevel($rawGeneral);
},
'officerLevelText' => function ($rawGeneral) use ($nationArr) {
$level = $this->getOfficerLevel($rawGeneral);
return getOfficerLevelText($level, $nationArr['level']);
},
'lbonus' => function ($rawGeneral) use ($nationArr) {
return calcLeadershipBonus($rawGeneral['officer_level'], $nationArr['level']);
},
'ownerName' => function ($rawGeneral) {
if ($rawGeneral['npc'] != 1) {
return null;
}
return $rawGeneral['owner_name'];
},
'honorText' => function ($rawGeneral) {
return getHonor($rawGeneral['experience']);
},
'dedLevelText' => function ($rawGeneral) {
return getDedLevelText($rawGeneral['dedlevel']);
},
'turntime' => function ($rawGeneral) {
//'0000-00-00 11:23';
return substr($rawGeneral['turntime'], 11, 5);
},
'bill' => fn($rawGeneral) => getBillByLevel($rawGeneral['dedlevel'])
];
[$queryColumns, $rankColumns] = General::mergeQueryColumn(array_keys($viewColumns), 1);
[$queryColumns, $rankColumns] = General::mergeQueryColumn(array_keys(static::$viewColumns), 1);
$rawGeneralList = Util::convertArrayToDict($db->query('SELECT %l from general WHERE nation = %i', Util::formatListOfBackticks($queryColumns), $nationID), 'no');
$reservedCommand = [];
if ($this->permission >= 2) {
$nonNPCGeneralIDList = [];
foreach ($rawGeneralList as $rawGeneral) {
if ($rawGeneral['npc'] < 2) {
$nonNPCGeneralIDList[] = $rawGeneral['no'];
}
}
$rawTurnList = $db->query(
'SELECT general_id, turn_idx, action, arg, brief FROM general_turn WHERE general_id IN %li AND turn_idx < 5 ORDER BY general_id asc, turn_idx asc',
$nonNPCGeneralIDList
);
foreach ($rawTurnList as $rawTurn) {
[
'general_id' => $generalID,
'action' => $action,
'arg' => $arg,
'brief' => $brief,
] = $rawTurn;
if (!key_exists($generalID, $reservedCommand)) {
$reservedCommand[$generalID] = [];
}
$reservedCommand[$generalID][] = [
'action' => $action,
'arg' => $arg,
'brief' => $brief
];
}
}
$rankList = [];
if ($rankColumns) {
$rawRankList = $db->query('SELECT general_id, `type`, `value` FROM rank_data WHERE nation_id = %i AND `type` IN %ls', $nationID, $rankColumns);
foreach ($rawRankList as $rawRank) {
[
'general_id' => $generalID,
'type' => $type,
'value' => $value
] = $rawRank;
if (!key_exists($generalID, $rankList)) {
$rankList[$generalID] = [];
}
$rankList[$generalID][$type] = $value;
}
}
$getRankVar = fn ($key) => (fn ($rawGeneral) => (($rankList[$rawGeneral['no']] ?? [])[$key] ?? 0));
$specialViewFilter = [
'officerLevel' => fn ($rawGeneral) => $this->getOfficerLevel($rawGeneral),
'officerLevelText' => fn ($rawGeneral) => getOfficerLevelText($this->getOfficerLevel($rawGeneral), $nationArr['level']),
'lbonus' => fn ($rawGeneral) => calcLeadershipBonus($rawGeneral['officer_level'], $nationArr['level']),
'ownerName' => fn ($rawGeneral) => ($rawGeneral['npc'] != 1) ? null : $rawGeneral['owner_name'],
'honorText' => fn ($rawGeneral) => getHonor($rawGeneral['experience']),
'dedLevelText' => fn ($rawGeneral) => getDedLevelText($rawGeneral['dedlevel']),
//'0000-00-00 11:23';
'turntime' => fn ($rawGeneral) => substr($rawGeneral['turntime'], 0, 19),
'bill' => fn ($rawGeneral) => getBillByLevel($rawGeneral['dedlevel']),
'reservedCommand' => fn ($rawGeneral) => $reservedCommand[$rawGeneral['no']] ?? null,
'autorun_limit' => fn ($rawGeneral) => ($rawGeneral['aux'] ?? [])['autorun_limit'] ?? 0,
];
foreach ($rankColumns as $rankKey) {
$specialViewFilter[$rankKey] = $getRankVar($rankKey);
}
$resultColumns = [];
foreach ($viewColumns as $column => $reqPermission) {
foreach (static::$viewColumns as $column => $reqPermission) {
if ($reqPermission > $this->permission) {
continue;
}
if(key_exists($column, $columnRemap)){
$resultColumns[$columnRemap[$column]] = $column;
}
else{
if (key_exists($column, static::$columnRemap)) {
$newColumn = static::$columnRemap[$column];
if($newColumn !== null){
$resultColumns[$newColumn] = $column;
}
} else {
$resultColumns[$column] = $column;
}
}
foreach ($customViewColumns as $column => $reqPermission) {
foreach (static::$customViewColumns as $column => $reqPermission) {
if ($reqPermission > $this->permission) {
continue;
}
@@ -179,6 +245,9 @@ class GeneralList extends \sammo\BaseAPI
$generalList = [];
foreach ($rawGeneralList as $rawGeneral) {
//General 생성?
if (key_exists('aux', $rawGeneral)) {
$rawGeneral['aux'] = \sammo\JSON::decode($rawGeneral['aux']);
}
$item = [];
foreach ($resultColumns as $column) {
@@ -198,6 +267,7 @@ class GeneralList extends \sammo\BaseAPI
'permission' => $this->permission,
'column' => array_keys($resultColumns),
'list' => $generalList,
'env' => $env,
];
return $result;