feat,game: 사전 거병 기능 추가

- 건국은 게임 개시 2턴째부터 가능
This commit is contained in:
2022-07-05 22:23:23 +09:00
parent 2b483749bc
commit e09fdefa68
6 changed files with 130 additions and 3 deletions
+11 -1
View File
@@ -6,6 +6,7 @@ include "lib.php";
include "func.php";
$showDieOnPrestartBtn = false;
$showBuildNationCandidateBtn = false;
$availableDieOnPrestart = false;
//로그인 검사
@@ -31,12 +32,16 @@ if ($myset > 0) {
$targetTime = addTurn($me->getVar('lastrefresh'), $gameStor->turnterm, 2);
if ($gameStor->turntime <= $gameStor->opentime) {
//서버 가오픈시 할 수 있는 행동
if ($me->getNPCType() == 0) {
if ($me->getNPCType() == 0 && $me->getNationID() == 0) {
$showDieOnPrestartBtn = true;
if ($targetTime <= TimeUtil::now()) {
$availableDieOnPrestart = true;
}
}
if($me->getNationID() == 0){
$showBuildNationCandidateBtn = true;
}
}
$use_treatment = $me->getAuxVar('use_treatment') ?? 10;
@@ -127,6 +132,11 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
<button type="button" id='dieOnPrestart' style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>장수 삭제</button><br><br>
<?php endif; ?>
<?php if ($showBuildNationCandidateBtn) : ?>
서버 개시 이전 거병(2턴부터 건국 가능)<br>
<button type="button" id='buildNationCandidate' style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>사전 거병</button><br><br>
<?php endif; ?>
<?php if ($gameStor->npcmode == 2 && $me->getNPCType() == 0) : ?>
다른 장수 선택 (<?= substr($me->getAuxVar('next_change') ?? TimeUtil::now(), 0, 19) ?> 부터)<br>
<a href="select_general_from_pool.php" id='select_general_from_pool'><button type="button" style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>다른 장수 선택</button></a><br><br>
@@ -0,0 +1,82 @@
<?php
namespace sammo\API\General;
use sammo\Command\General\che_거병;
use sammo\DB;
use sammo\Validator;
use sammo\Session;
use sammo\GameConst;
use sammo\General;
use sammo\JosaUtil;
use sammo\KVStorage;
use sammo\LiteHashDRBG;
use sammo\RandUtil;
use sammo\UniqueConst;
use sammo\Util;
use function sammo\increaseRefresh;
class BuildNationCandidate extends \sammo\BaseAPI
{
public function validateArgs(): ?string
{
return null;
}
public function getRequiredSessionMode(): int
{
return static::REQ_GAME_LOGIN;
}
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
{
$userID = $session->userID;
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$gameStor->cacheValues(['opentime', 'turntime']);
$general = $db->queryFirstRow('SELECT no,name,nation,owner_name,npc,lastrefresh FROM general WHERE owner=%i AND npc = 0', $userID);
if (!$general) {
return '장수가 없습니다';
}
$generalID = $general['no'];
increaseRefresh("사전 거병", 1);
if ($gameStor->turntime > $gameStor->opentime) {
return '게임이 시작되었습니다.';
}
if ($general['nation'] != 0) {
return '이미 국가에 소속되어있습니다.';
}
$env = $gameStor->getAll();
$generalObj = General::createGeneralObjFromDB($general['no']);
$cmd = new che_거병($generalObj, $env);
$failReason = $cmd->testFullConditionMet();
if ($failReason !== null) {
return $failReason;
}
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
UniqueConst::$hiddenSeed,
'BuildNationCandidate',
$generalID,
)));
$result = $cmd->run($rng);
if(!$result){
return '거병을 실패했습니다.';
}
return null;
}
}
+5 -1
View File
@@ -36,7 +36,7 @@ class DieOnPrestart extends \sammo\BaseAPI
$gameStor = KVStorage::getStorage($db, 'game_env');
$gameStor->cacheValues(['turnterm', 'opentime', 'turntime', 'year', 'month']);
$general = $db->queryFirstRow('SELECT no,name,owner_name,npc,lastrefresh FROM general WHERE owner=%i AND npc = 0', $userID);
$general = $db->queryFirstRow('SELECT no,name,nation,owner_name,npc,lastrefresh FROM general WHERE owner=%i AND npc = 0', $userID);
if (!$general) {
return '장수가 없습니다';
@@ -49,6 +49,10 @@ class DieOnPrestart extends \sammo\BaseAPI
return '게임이 시작되었습니다.';
}
if ($general['nation'] != 0){
return '이미 국가에 소속되어있습니다.';
}
//서버 가오픈시 할 수 있는 행동
$targetTime = addTurn($general['lastrefresh'], $gameStor->turnterm, 2);
if ($targetTime > TimeUtil::now()) {
+11 -1
View File
@@ -139,6 +139,16 @@ class che_건국 extends Command\GeneralCommand
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
$generalName = $general->getName();
$logger = $general->getLogger();
$initYearMonth = Util::joinYearMonth($env['init_year'], $env['init_month']);
$yearMonth = Util::joinYearMonth($env['year'], $env['month']);
if($yearMonth <= $initYearMonth){
$logger->pushGeneralActionLog("다음 턴부터 건국할 수 있습니다. <1>$date</>");
$this->alternative = new che_인재탐색($general, $this->env, null);
return false;
}
$josaYi = JosaUtil::pick($generalName, '이');
$nationName = $this->arg['nationName'];
@@ -149,7 +159,7 @@ class che_건국 extends Command\GeneralCommand
$josaUl = JosaUtil::pick($nationName, '을');
$logger = $general->getLogger();
$nationTypeClass = buildNationTypeClass($nationType);
$nationTypeName = $nationTypeClass->getName();
+1
View File
@@ -126,6 +126,7 @@ const apiRealPath = {
itemType: ItemTypeKey;
}>,
DieOnPrestart: POST as APICallT<undefined>,
BuildNationCandidate: POST as APICallT<undefined>,
},
Global: {
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
+20
View File
@@ -150,6 +150,26 @@ $(function ($) {
location.replace('..');
});
$('#buildNationCandidate').on('click', async function (e) {
e.preventDefault();
if(!confirm('거병 이후 장수를 삭제할 수 없게됩니다. 거병하시겠습니까?')){
return false;
}
try {
await SammoAPI.General.BuildNationCandidate();
}
catch (e) {
console.log(e);
alert(`실패했습니다: ${e}`);
location.reload();
return;
}
location.reload();
});
$('#vacation').on('click', async function (e) {
e.preventDefault();
if (!confirm('휴가 기능을 신청할까요?')) {