feat: chiefCenter 500px 재구현
- API: 사령턴 관련 - TopBackBar에 갱신 추가
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationCommand;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
use sammo\TimeUtil;
|
||||
|
||||
use function sammo\checkLimit;
|
||||
use function sammo\checkSecretPermission;
|
||||
use function sammo\cutTurn;
|
||||
use function sammo\getChiefCommandTable;
|
||||
use function sammo\getNationChiefLevel;
|
||||
use function sammo\getOfficerLevelText;
|
||||
use function sammo\increaseRefresh;
|
||||
|
||||
class GetReservedCommand extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
increaseRefresh("사령부", 1);
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$userID = $session->userID;
|
||||
|
||||
$me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,penalty,permission FROM general WHERE owner=%i', $userID);
|
||||
|
||||
$nationLevel = $db->queryFirstField('SELECT level FROM nation WHERE nation = %i', $me['nation']);
|
||||
$nationID = $me['nation'];
|
||||
$con = checkLimit($me['con']);
|
||||
if ($con >= 2) {
|
||||
return "접속 제한중입니다. 1턴 이내에 너무 많은 갱신을 하셨습니다. (다음 갱신 가능 시각 : {$me['turntime']})";
|
||||
}
|
||||
|
||||
$permission = checkSecretPermission($me);
|
||||
if ($permission < 0) {
|
||||
return '국가에 소속되어있지 않습니다.';
|
||||
} else if ($permission < 1) {
|
||||
return '수뇌부가 아니거나 사관년도가 부족합니다.';
|
||||
}
|
||||
|
||||
[$turnTerm, $year, $month, $lastExecute] = $gameStor->getValuesAsArray(['turnterm', 'year', 'month', 'turntime']);
|
||||
|
||||
$generals = [];
|
||||
foreach ($db->query('SELECT no,name,turntime,npc,city,nation,officer_level FROM general WHERE nation = %i AND officer_level >= 5', $nationID) as $rawGeneral) {
|
||||
$generals[$rawGeneral['officer_level']] = new General($rawGeneral, null, null, null, $year, $month, false);
|
||||
}
|
||||
|
||||
$nationTurnList = [];
|
||||
foreach ($db->queryAllLists(
|
||||
'SELECT officer_level, turn_idx, action, arg, brief FROM nation_turn WHERE nation_id = %i ORDER BY officer_level DESC, turn_idx ASC',
|
||||
$me['nation']
|
||||
) as [$officer_level, $turn_idx, $action, $arg, $brief]) {
|
||||
if (!key_exists($officer_level, $nationTurnList)) {
|
||||
$nationTurnList[$officer_level] = [];
|
||||
}
|
||||
$nationTurnList[$officer_level][$turn_idx] = [
|
||||
'action' => $action,
|
||||
'brief' => $brief,
|
||||
'arg' => Json::decode($arg)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$nationChiefList = [];
|
||||
foreach ($nationTurnList as $officer_level => $turnBrief) {
|
||||
if (!key_exists($officer_level, $generals)) {
|
||||
$nationChiefList[$officer_level] = [
|
||||
'name' => null,
|
||||
'turnTime' => null,
|
||||
'officerLevelText' => getOfficerLevelText($officer_level, $nationLevel),
|
||||
'npcType' => null,
|
||||
'turn' => $turnBrief
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$general = $generals[$officer_level];
|
||||
$nationChiefList[$officer_level] = [
|
||||
'name' => $general->getName(),
|
||||
'turnTime' => $general->getTurnTime($general::TURNTIME_FULL),
|
||||
'officerLevel' => $general->getVar('officer_level'),
|
||||
'officerLevelText' => getOfficerLevelText($general->getVar('officer_level'), $nationLevel),
|
||||
'npcType' => $general->getNPCType(),
|
||||
'turn' => $turnBrief,
|
||||
];
|
||||
}
|
||||
|
||||
$generalObj = General::createGeneralObjFromDB($session->generalID);
|
||||
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'lastExecute' => $lastExecute,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'turnTerm' => $turnTerm,
|
||||
'date' => TimeUtil::now(true),
|
||||
'chiefList' => $nationChiefList,
|
||||
'isChief'=>($me['officer_level'] > 4),
|
||||
'autorun_limit' => $generalObj->getAuxVar('autorun_limit'),
|
||||
'officerLevel' => $me['officer_level'],
|
||||
'commandList' => getChiefCommandTable($generalObj),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationCommand;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\Validator;
|
||||
|
||||
use function sammo\cutTurn;
|
||||
use function sammo\pushNationCommand;
|
||||
|
||||
class PushCommand extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'amount',
|
||||
])
|
||||
->rule('integer', 'amount')
|
||||
->rule('min', 'amount', -12)
|
||||
->rule('max', 'amount', 12);
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$amount = $this->args['amount'];
|
||||
if($amount == 0){
|
||||
return '0은 불가능합니다';
|
||||
}
|
||||
$db = DB::db();
|
||||
$me = $db->queryFirstRow('SELECT officer_level, nation FROM general WHERE no = %i', $session->generalID);
|
||||
if(!$me){
|
||||
return '올바르지 않은 장수입니다.';
|
||||
}
|
||||
|
||||
if(!$me['nation']){
|
||||
return '국가에 소속되어 있지 않습니다.';
|
||||
}
|
||||
|
||||
if($me['officer_level'] < 5){
|
||||
return '수뇌가 아닙니다.';
|
||||
}
|
||||
|
||||
pushNationCommand($me['nation'], $me['officer_level'], $amount);
|
||||
|
||||
return [
|
||||
'result'=>true
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationCommand;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\Validator;
|
||||
|
||||
use function sammo\cutTurn;
|
||||
use function sammo\repeatGeneralCommand;
|
||||
use function sammo\repeatNationCommand;
|
||||
|
||||
class RepeatCommand extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'amount',
|
||||
])
|
||||
->rule('integer', 'amount')
|
||||
->rule('min', 'amount', 1)
|
||||
->rule('max', 'amount', 12);
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
|
||||
$amount = $this->args['amount'];
|
||||
|
||||
$db = DB::db();
|
||||
$me = $db->queryFirstRow('SELECT officer_level, nation FROM general WHERE no = %i', $session->generalID);
|
||||
if(!$me){
|
||||
return '올바르지 않은 장수입니다.';
|
||||
}
|
||||
|
||||
if(!$me['nation']){
|
||||
return '국가에 소속되어 있지 않습니다.';
|
||||
}
|
||||
|
||||
if($me['officer_level'] < 5){
|
||||
return '수뇌가 아닙니다.';
|
||||
}
|
||||
|
||||
repeatNationCommand($me['nation'], $me['officer_level'], $amount);
|
||||
|
||||
return [
|
||||
'result'=>true
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationCommand;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\GameConst;
|
||||
use sammo\Util;
|
||||
use sammo\Validator;
|
||||
|
||||
use function sammo\setNationCommand;
|
||||
|
||||
class ReserveCommand extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'action',
|
||||
'turnList'
|
||||
])
|
||||
->rule('lengthMin', 'action', 1)
|
||||
->rule('integerArray', 'turnList');
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$action = $this->args['action'];
|
||||
$turnList = $this->args['turnList'];
|
||||
$arg = $this->args['arg']??[];
|
||||
|
||||
if(!$turnList){
|
||||
return '턴이 입력되지 않았습니다';
|
||||
}
|
||||
|
||||
if(!in_array($action, Util::array_flatten(GameConst::$availableChiefCommand))){
|
||||
return '사용할 수 없는 커맨드입니다.';
|
||||
}
|
||||
|
||||
if(!is_array($arg)){
|
||||
'올바른 arg 형태가 아닙니다.';
|
||||
}
|
||||
|
||||
return setNationCommand($session->generalID, $turnList, $action, $arg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user