This commit is contained in:
2022-07-14 22:48:03 +09:00
parent 857038cb50
commit 11a8efac85
+33 -53
View File
@@ -3,9 +3,15 @@
namespace sammo\API\Nation; namespace sammo\API\Nation;
use sammo\DB; use sammo\DB;
use sammo\GameConst;
use sammo\General;
use sammo\KVStorage;
use sammo\LastTurn;
use sammo\Session; use sammo\Session;
use sammo\Util;
use sammo\Validator; use sammo\Validator;
use function sammo\buildNationCommandClass;
use function sammo\checkLimit; use function sammo\checkLimit;
use function sammo\checkSecretPermission; use function sammo\checkSecretPermission;
use function sammo\getBattleDetailLogMore; use function sammo\getBattleDetailLogMore;
@@ -42,67 +48,41 @@ class GetNationInfo extends \sammo\BaseAPI
]; ];
} }
$generalObj = General::createGeneralObjFromDB($session->generalID, null, 1);
$gameStor = KVStorage::getStorage($db, 'game_env');
$gameEnv = $gameStor->getValues(['year', 'month', 'startyear']);
$nation = $db->queryFirstRow(
'SELECT nation, `name`, color, capital, gennum, gold, rice, bill, rate, secretlimit, chief_set, scout, war, strategic_cmd_limit, surlimit, tech, `power`, `level`, `type` FROM nation WHERE id = %i',
$nationID
);
$nationStor = \sammo\KVStorage::getStorage($db, $nationID, 'nation_env');
$nationStor->cacheAll();
$targetGeneralID = $this->getTargetGeneralID($session); //전략 정보를 매번 읽어와야하나?
$reqType = $this->args['type']; $impossibleStrategicCommandLists = [];
$reqTo = $this->args['reqTo'] ?? null; $strategicCommandLists = GameConst::$availableChiefCommand['전략'];
$yearMonth = Util::joinYearMonth($gameEnv['year'], $gameEnv['month']);
foreach ($strategicCommandLists as $command) {
$me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,permission,penalty from general where owner=%i', $userID); $cmd = buildNationCommandClass($command, $generalObj, $gameEnv, new LastTurn());
$nextAvailableTurn = $cmd->getNextAvailableTurn();
$con = checkLimit($me['con']); if ($nextAvailableTurn > $yearMonth) {
if ($con >= 2) { $impossibleStrategicCommandLists[] = [$cmd->getName(), $nextAvailableTurn - $yearMonth];
return '접속 제한입니다.'; }
} }
$permissionResult = $this->checkPermission($me); $troopName = [];
if ($permissionResult !== null) { foreach ($db->queryAllLists('SELECT troop_leader, name FROM troop WHERE nation=%i', $nationID) as [$troopID, $tName]) {
return $permissionResult; $troopName[$troopID] = $tName;
} }
if ($reqType == static::GENERAL_HISTORY) {
return [ return [
'result' => true, 'result' => true,
'reqType' => $reqType, 'nation' => $nation,
'generalID' => $targetGeneralID, 'impossibleStrategicCommandLists' => $impossibleStrategicCommandLists,
'log' => getGeneralHistoryLogAll($targetGeneralID) 'troops' => $troopName,
]; ];
} }
if ($reqType == static::GENERAL_ACTION) {
return [
'result' => true,
'reqType' => $reqType,
'generalID' => $targetGeneralID,
'log' => $reqTo === null
? getGeneralActionLogRecent($targetGeneralID, 30)
: getGeneralActionLogMore($targetGeneralID, $reqTo, 30)
];
}
if ($reqType == static::BATTLE_RESULT) {
return [
'result' => true,
'reqType' => $reqType,
'generalID' => $targetGeneralID,
'log' => $reqTo === null
? getBattleResultRecent($targetGeneralID, 30)
: getBattleResultMore($targetGeneralID, $reqTo, 30)
];
}
if ($reqType == static::BATTLE_DETAIL) {
return [
'result' => true,
'reqType' => $reqType,
'generalID' => $targetGeneralID,
'log' => $reqTo === null
? getBattleResultRecent($targetGeneralID, 30)
: getBattleDetailLogMore($targetGeneralID, $reqTo, 30)
];
}
return '잘못된 요청입니다: ' . $reqType;
}
} }