장수일람 API 생성

This commit is contained in:
2019-05-04 18:33:09 +09:00
parent e33d8776bc
commit e1dbc46d8d
4 changed files with 141 additions and 14 deletions
+11 -6
View File
@@ -174,13 +174,10 @@ function getGenSpecial($type) {
return $call;
}
function getSpecialInfo(?int $type):?string{
if($type === null){
return null;
}
function getSpecialTextList():array{
//앞칸은 '설명을 위해' '그냥' 적어둠
$infoText = [
return [
0 => ['-', null],
1 => ['경작', '[내정] 농지 개간 : 기본 보정 +10%, 성공률 +10%p, 비용 -20%'],
2 => ['상재', '[내정] 상업 투자 : 기본 보정 +10%, 성공률 +10%p, 비용 -20%'],
@@ -219,6 +216,14 @@ function getSpecialInfo(?int $type):?string{
74 => ['격노', '[전투] 상대방 필살 및 회피 시도시 일정 확률로 격노(필살) 발동, 공격 시 일정 확률로 진노(1페이즈 추가)'],
75 => ['척사', '[전투] 지역·도시 병종 상대로 대미지 +10%, 아군 피해 -10%']
];
}
function getSpecialInfo(?int $type):?string{
if($type === null){
return null;
}
$infoText = getSpecialTextList();
return $infoText[$type][1]??null;
}
+12 -7
View File
@@ -159,6 +159,17 @@ function CriticalRatioDomestic(&$general, $type) {
);
}
function calcLeadershipBonus($generalLevel, $nationLevel):int{
if($generalLevel == 12) {
$lbonus = $nationLevel * 2;
} elseif($generalLevel >= 5) {
$lbonus = $nationLevel;
} else {
$lbonus = 0;
}
return $lbonus;
}
/**
* 수뇌직 통솔 보너스 계산
*
@@ -168,13 +179,7 @@ function CriticalRatioDomestic(&$general, $type) {
* @return int 계산된 $general['lbonus'] 값
*/
function setLeadershipBonus(&$general, $nationLevel){
if($general['level'] == 12) {
$lbonus = $nationLevel * 2;
} elseif($general['level'] >= 5) {
$lbonus = $nationLevel;
} else {
$lbonus = 0;
}
$lbonus = calcLeadershipBonus($general['level'], $nationLevel);
$general['lbonus'] = $lbonus;
return $lbonus;
}
+108
View File
@@ -0,0 +1,108 @@
<?php
namespace sammo;
include "lib.php";
include "func.php";
//로그인 검사
$session = Session::requireLogin();
$userID = Session::getUserID();
$db = DB::db();
$withToken = Util::getReq('with_token', 'bool', false);
$gameStor = KVStorage::getStorage($db, 'game_env');
if($session->isGameLoggedIn()){
increaseRefresh("장수일람", 2);
$me = $db->queryFirstRow('SELECT con, turntime FROM general WHERE owner=%i', $userID);
$con = checkLimit($me['con']);
if ($con >= 2) {
Json::die([
'result'=>false,
'reason'=>'접속 제한중입니다. 1턴 이내에 너무 많은 갱신을 하셨습니다.'
]);
}
}
else{
$availableNextCall = $session->availableNextCallGetGeneralList??'2000-01-01 00:00:00';
$now = new \DateTimeImmutable();
if($now <= new \DateTimeImmutable($availableNextCall) && $session->userGrade < 5){
Json::die([
'result'=>false,
'reason'=>"장수 리스트는 10초에 한번 갱신 가능합니다.\n다음 시간 : ".$availableNextCall
]);
}
$availableNextCall = $now->add(new \DateInterval('PT1S'))->format('Y-m-d H:i:s');
$session->availableNextCallGetGeneralList = $availableNextCall;
}
$session->setReadOnly();
$rawGeneralList = $db->queryAllLists('SELECT owner,no,picture,imgsvr,npc,age,nation,special,special2,personal,name,name2,injury,leader,power,intel,experience,dedication,level,killturn,connect from general');
$ownerNameList = [];
if($gameStor->isunited){
foreach(RootDB::db()->queryAllLists('SELECT no, name FROM member') as [$ownerID, $ownerName]){
$ownerNameList[$ownerID] = $ownerName;
}
}
$generalList = [];
foreach($rawGeneralList as $rawGeneral){
[$owner,$no,$picture,$imgsvr,$npc,$age,$nation,$special,$special2,$personal,$name,$name2,$injury,$leader,$power,$intel,$experience,$dedication,$level,$killturn,$connect] = $rawGeneral;
if(key_exists($owner, $ownerNameList)){
$name2 = $ownerNameList[$owner];
}
$nationArr = getNationStaticInfo($nation);
$lbonus = calcLeadershipBonus($level, $nationArr['level']);
$generalList[] = [
$no,
$picture,
$imgsvr,
$npc,
$age,
$nationArr['name'],
SpecCall($special),
SpecCall($special2),
getGenChar($personal),
$name,
$name2,
$leader,
$lbonus,
$power,
$intel,
getHonor($experience),
getDed($dedication),
getLevel($level, $nationArr['level']),
$killturn,
$connect
];
}
$result = [
'result'=>'true',
'list'=>$generalList,
];
if($withToken){
$result['list'][] ='aserasdrgtlkjsdrgltjsrdt1!!!!!!!!!!!!!!!!!!';
$now = (new \DateTimeImmutable())->format('Y-m-d H:i:s');
$tokens = [];
foreach($db->query('SELECT * FROM select_npc_token WHERE `valid_until`>=%s', $now) as $token){
$validUntil = $token['valid_until'];
foreach(Json::decode($token['pick_result']) as $pickResult){
$tokens[$pickResult['no']]=$pickResult['keepCnt'];
}
}
$result['token'] = $tokens;
}
Json::die($result);
+10 -1
View File
@@ -50,7 +50,16 @@ foreach (SpecialityConst::WAR as $id=>$values) {
$specialAll['-'] = '없음';
echo Json::encode($specialAll);
?>
;
;
var characterInfo =
<?php
$characterAll = [];
foreach(getCharacterList() as $id=>[$name, $info]){
$characterAll[$name] = $info;
}
echo Json::encode($characterAll);
?>
;
</script>
<?=WebUtil::printJS('../d_shared/common_path.js')?>