- 기존의 랜덤 코드는 deprecated 처리 - 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용 - 랜덤 생성 단위 - 월 실행 - 사령턴 실행 결과 - 커맨드 실행 결과 - 작위 보상 - 부대장 생성 - 유니크 획득 시도 - 설문 조사 - 장수 생성 - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅 - 전투 - 도시 점령 - 자율 행동 선택 - 랜덤 턴 변경 - 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
94 lines
2.6 KiB
PHP
94 lines
2.6 KiB
PHP
<?php
|
|
namespace sammo;
|
|
|
|
include "lib.php";
|
|
include "func.php";
|
|
|
|
function sortTokens(&$tokens){
|
|
usort($tokens, function($lhs, $rhs){
|
|
return array_sum($lhs['dex'])<=>array_sum($rhs['dex']);
|
|
});
|
|
}
|
|
|
|
function putInfoText(&$info){
|
|
if(key_exists('specialDomestic', $info)){
|
|
$class = buildGeneralSpecialDomesticClass($info['specialDomestic']);
|
|
$info['specialDomesticName'] = $class->getName();
|
|
$info['specialDomesticInfo'] = $class->getInfo();
|
|
}
|
|
|
|
if(key_exists('specialWar', $info)){
|
|
$class = buildGeneralSpecialDomesticClass($info['specialWar']);
|
|
$info['specialWarName'] = $class->getName();
|
|
$info['specialWarInfo'] = $class->getInfo();
|
|
}
|
|
}
|
|
|
|
$session = Session::requireLogin([])->setReadOnly();
|
|
$userID = Session::getUserID();
|
|
|
|
$oNow = new \DateTimeImmutable();
|
|
|
|
$now = $oNow->format('Y-m-d H:i:s');
|
|
|
|
$db = DB::db();
|
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
|
|
|
$npcmode = $gameStor->getValue('npcmode');
|
|
if($npcmode!=2){
|
|
Json::die([
|
|
'result'=>false,
|
|
'reason'=>'선택 가능한 서버가 아닙니다'
|
|
]);
|
|
}
|
|
|
|
$rawGeneral = $db->queryFirstRow('SELECT no, aux FROM general WHERE `owner` = %i', $userID);
|
|
if($rawGeneral){
|
|
$generalAux = Json::decode($rawGeneral['aux']);
|
|
if(key_exists('next_change', $generalAux)&& $generalAux['next_change'] > $now){
|
|
Json::die([
|
|
'result'=>false,
|
|
'reason'=>'아직 다시 고를 수 없습니다'
|
|
]);
|
|
}
|
|
}
|
|
|
|
$tokens = $db->query('SELECT unique_name, reserved_until, info FROM `select_pool` WHERE `owner`=%i AND `reserved_until`>=%s', $userID, $now);
|
|
|
|
if($tokens){
|
|
$pick = [];
|
|
$valid_until = null;
|
|
$specialInfo = [];
|
|
foreach($tokens as $token){
|
|
$valid_until = $token['reserved_until'];
|
|
$info = Json::decode($token['info']);
|
|
putInfoText($info);
|
|
$info['uniqueName'] = $token['unique_name'];
|
|
$pick[] = $info;
|
|
}
|
|
sortTokens($pick);//좀 무식하지만..
|
|
Json::die([
|
|
'result'=>true,
|
|
'pick'=>$pick,
|
|
'validUntil'=>$valid_until
|
|
]);
|
|
}
|
|
|
|
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
|
UniqueConst::$hiddenSeed, 'selectPool', $userID, $now
|
|
)));
|
|
|
|
$pick = [];
|
|
$valid_until = null;
|
|
foreach(pickGeneralFromPool($db, $rng, $userID, 14) as $pickObj){
|
|
$valid_until = $pickObj->getValidUntil();
|
|
$info = $pickObj->getInfo();
|
|
putInfoText($info);
|
|
$pick[] = $info;
|
|
}
|
|
sortTokens($pick);//좀 무식하지만..
|
|
Json::die([
|
|
'result'=>true,
|
|
'pick'=>$pick,
|
|
'validUntil'=>$valid_until
|
|
]); |