NationGeneralList
This commit is contained in:
@@ -0,0 +1,237 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\List;
|
||||||
|
|
||||||
|
use sammo\ActionLogger;
|
||||||
|
use sammo\CityConst;
|
||||||
|
use sammo\DB;
|
||||||
|
use sammo\GameConst;
|
||||||
|
use sammo\GameUnitConst;
|
||||||
|
use sammo\General;
|
||||||
|
use sammo\JosaUtil;
|
||||||
|
use sammo\Json;
|
||||||
|
use sammo\KVStorage;
|
||||||
|
use sammo\RootDB;
|
||||||
|
use sammo\Session;
|
||||||
|
use sammo\SpecialityHelper;
|
||||||
|
use sammo\StringUtil;
|
||||||
|
use sammo\TimeUtil;
|
||||||
|
use sammo\UserLogger;
|
||||||
|
use sammo\Util;
|
||||||
|
use sammo\Validator;
|
||||||
|
use sammo\WebUtil;
|
||||||
|
|
||||||
|
use function sammo\addTurn;
|
||||||
|
use function sammo\calcLeadershipBonus;
|
||||||
|
use function sammo\checkLimit;
|
||||||
|
use function sammo\checkSecretPermission;
|
||||||
|
use function sammo\cutTurn;
|
||||||
|
use function sammo\getDedLevelText;
|
||||||
|
use function sammo\getGenChar;
|
||||||
|
use function sammo\getGeneralSpecialDomesticName;
|
||||||
|
use function sammo\getGeneralSpecialWarName;
|
||||||
|
use function sammo\getHonor;
|
||||||
|
use function sammo\getNationStaticInfo;
|
||||||
|
use function sammo\getOfficerLevelText;
|
||||||
|
use function sammo\getRandTurn;
|
||||||
|
use function sammo\increaseRefresh;
|
||||||
|
use function sammo\pushAdminLog;
|
||||||
|
use function sammo\resetInheritanceUser;
|
||||||
|
|
||||||
|
class NationGeneral extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
|
||||||
|
private int $reqType;
|
||||||
|
private bool $reqForce;
|
||||||
|
private int $permission;
|
||||||
|
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
$v = new Validator($this->args);
|
||||||
|
$v
|
||||||
|
->rule('integer', 'req')
|
||||||
|
->rule('boolean', 'force');
|
||||||
|
|
||||||
|
|
||||||
|
if (!$v->validate()) {
|
||||||
|
return $v->errorStr();
|
||||||
|
}
|
||||||
|
$this->reqType = $this->args['req'] ?? 1;
|
||||||
|
$this->reqForce = $this->args['force'] ?? false;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getOfficerLevel($rawGeneral)
|
||||||
|
{
|
||||||
|
$level = $rawGeneral['officer_level'];
|
||||||
|
if ($level >= 5) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
if ($this->permission > 1) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||||
|
{
|
||||||
|
increaseRefresh("세력장수", 1);
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$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) {
|
||||||
|
return '접속 제한중입니다. 1턴 이내에 너무 많은 갱신을 하셨습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$nationID = $me['nation'];
|
||||||
|
$this->permission = checkSecretPermission($me, true);
|
||||||
|
if ($this->reqForce && $this->reqType > $this->permission) {
|
||||||
|
return '권한이 부족합니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->permission = min($this->reqType, $this->permission);
|
||||||
|
|
||||||
|
$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
|
||||||
|
];
|
||||||
|
|
||||||
|
$customViewColumns = [
|
||||||
|
'officerLevel' => 0,
|
||||||
|
'officerLevelText' => 0,
|
||||||
|
'lbonus' => 0,
|
||||||
|
'ownerName' => 0,
|
||||||
|
'honorText' => 0
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$specialViewFilter = [
|
||||||
|
'officerLevel' => function ($rawGeneral) {
|
||||||
|
return $this->getOfficerLevel($rawGeneral);
|
||||||
|
},
|
||||||
|
'special' => function ($rawGeneral) {
|
||||||
|
return getGeneralSpecialDomesticName($rawGeneral['special']);
|
||||||
|
},
|
||||||
|
'special2' => function ($rawGeneral) {
|
||||||
|
return getGeneralSpecialWarName($rawGeneral['special2']);
|
||||||
|
},
|
||||||
|
'personal' => function ($rawGeneral) {
|
||||||
|
return getGenChar($rawGeneral['personal']);
|
||||||
|
},
|
||||||
|
'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'];
|
||||||
|
},
|
||||||
|
'officerLevelText' => function ($rawGeneral) use ($nationArr) {
|
||||||
|
$level = $this->getOfficerLevel($rawGeneral);
|
||||||
|
return getOfficerLevelText($level, $nationArr['level']);
|
||||||
|
},
|
||||||
|
'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);
|
||||||
|
}
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
[$queryColumns, $rankColumns] = General::mergeQueryColumn(array_keys($viewColumns), 1);
|
||||||
|
|
||||||
|
$rawGeneralList = Util::convertArrayToDict($db->query('SELECT %l from general WHERE nation = %i', Util::formatListOfBackticks($queryColumns), $nationID), 'no');
|
||||||
|
|
||||||
|
$resultColumns = [];
|
||||||
|
foreach ($viewColumns as $column => $reqPermission) {
|
||||||
|
if ($reqPermission > $this->permission) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$resultColumns[] = $column;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($customViewColumns as $column => $reqPermission) {
|
||||||
|
if ($reqPermission > $this->permission) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$resultColumns[] = $column;
|
||||||
|
}
|
||||||
|
|
||||||
|
$generalList = [];
|
||||||
|
foreach ($rawGeneralList as $rawGeneral) {
|
||||||
|
//General 생성?
|
||||||
|
|
||||||
|
$item = [];
|
||||||
|
foreach ($resultColumns as $column) {
|
||||||
|
if (key_exists($column, $specialViewFilter)) {
|
||||||
|
$value = $specialViewFilter[$column]($rawGeneral);
|
||||||
|
} else {
|
||||||
|
$value = $rawGeneral[$column];
|
||||||
|
}
|
||||||
|
$item[] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$generalList[] = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'result' => true,
|
||||||
|
'column' => $resultColumns,
|
||||||
|
'list' => $generalList,
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user