장수 빙의 코드 변경

This commit is contained in:
2018-05-05 21:20:15 +09:00
parent 5974028c4d
commit 3c1c339498
9 changed files with 226 additions and 376 deletions
+2 -1
View File
@@ -3,11 +3,12 @@
html, body{
background-color:black;
color:white;
line-height:1.3;
}
table { font-family:'맑은 고딕'; }
font { font-family:'맑은 고딕'; }
input { font-family:'맑은 고딕'; height:20px }
input { font-family:'맑은 고딕'; font-size:13px; }
select { font-family:'굴림'; line-height:100%; }
/* */
+17
View File
@@ -1,3 +1,8 @@
.container{
width:1000px;
margin:0 auto;
}
.card_holder{
text-align:center;
}
@@ -6,6 +11,18 @@
display:inline-block;
}
.general_card h4 {
margin:0;
}
.general_card p {
margin:0;
}
.general_card .select_btn {
width:100%;
}
.general_card label {
display: block;
+2 -10
View File
@@ -31,13 +31,10 @@ if($oldGeneral !== null){
}
list(
$year,
$month,
$maxgeneral,
$turnterm,
$genius,
$npcmode
) = $db->queryFirstList('SELECT year,month,maxgeneral,turnterm,genius,npcmode from game limit 1');
) = $db->queryFirstList('SELECT maxgeneral,turnterm,npcmode from game limit 1');
if(!$npcmode){
Json::die([
@@ -46,7 +43,6 @@ if(!$npcmode){
]);
}
$token = $db->queryFirstRow('SELECT * FROM select_npc_token WHERE `owner`=%i AND `valid_until`>=%s', $userID, $now);
$pickResult = [];
@@ -94,7 +90,7 @@ foreach($db->query('SELECT `no`, `name`, leader, power, intel, imgsvr, picture,
$general['special2'] = \sammo\SpecialityConst::WAR[$general['special2']][0]??'-';
$candidates[$general['no']] = $general + ['keepCnt'=>KEEP_CNT];
$allStat = $general['leader'] + $general['power'] + $general['intel'];
$weight[$general['no']] = pow($allStat, 1.7);
$weight[$general['no']] = pow($allStat, 1.5);
}
foreach($db->queryFirstColumn('SELECT pick_result FROM select_npc_token WHERE `owner`!=%i AND valid_until >=%s', $userID, $now) as $reserved){
@@ -124,8 +120,6 @@ $pickMoreMinute = max(PICK_MORE_MINUTE, intdiv($turnterm, 5));
$validUntil = $oNow->add(new \DateInterval(sprintf('PT%dM', $validMinute)));
$pickMoreFrom = $oNow->add(new \DateInterval(sprintf('PT%dM', $pickMoreMinute)));
$db->query('LOCK TABLES select_npc_token WRITE');
$db->delete('select_npc_token', 'valid_until < %s', $now);
$inserted = 0;
@@ -155,8 +149,6 @@ else{
}
}
$db->query('UNLOCK TABLES');
if($inserted === 0){
Json::die([
'result'=>false,
+109
View File
@@ -0,0 +1,109 @@
<?php
namespace sammo;
include "lib.php";
include "func.php";
$pick = Util::getReq('pick', 'int');
if(!$pick){
Json::die([
'result'=>false,
'reason'=>'장수를 선택하지 않았습니다'
]);
}
$session = Session::requireLogin()->setReadOnly();
$userID = Session::getUserID();
$db = DB::db();
$rootDB = RootDB::db();
$oNow = new \DateTimeImmutable();
$now = $oNow->format('Y-m-d H:i:s');
$userNick = RootDB::db()->queryFirstField('SELECT `NAME` FROM member WHERE `NO`=%i',$userID);
if(!$userNick){
Json::die([
'result'=>false,
'reason'=>'멤버 정보를 가져오지 못했습니다.'
]);
}
$pickResult = $db->queryFirstField('SELECT pick_result FROM select_npc_token WHERE `owner`=%i AND `valid_until`>=%s', $userID, $now);
if(!$pickResult){
Json::die([
'result'=>false,
'reason'=>'유효한 장수 목록이 없습니다.'
]);
}
$pickResult = Json::decode($pickResult);
if(!key_exists($pick, $pickResult)){
Json::die([
'result'=>false,
'reason'=>'선택한 장수가 목록에 없습니다.'
]);
}
$pickedNPC = $pickResult[$pick];
$gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2');
list(
$year,
$month,
$maxgeneral,
$npcmode
) = $db->queryFirstList('SELECT year,month,maxgeneral,npcmode from game limit 1');
if(!$npcmode){
Json::die([
'result'=>false,
'reason'=>'빙의 가능한 서버가 아닙니다'
]);
}
if ($gencount >= $maxgeneral) {
Json::die([
'result'=>false,
'reason'=>'더 이상 등록 할 수 없습니다.'
]);
}
//등록 시작
$db->update('general', [
'owner'=>$userID,
'npc'=>1
], 'owner <= 0 AND npc = 2 AND no = %i', $pick);
if(!$db->affectedRows()){
Json::die([
'result'=>false,
'reason'=>'장수 등록에 실패했습니다.'
]);
}
$db->delete('select_npc_token', 'owner=%i', $userID);
pushGeneralHistory($pickedNPC, "<C>●</>{$year}{$month}월:<Y>{$pickedNPC['name']}</>의 육체에 <Y>{$userNick}</>(이)가 빙의되다.");
//pushGenLog($me, $mylog);
pushGeneralPublicRecord(["<C>●</>{$month}월:<Y>{$pickedNPC['name']}</>의 육체에 <Y>{$userNick}</>(이)가 <S>빙의</>됩니다!"], $year, $month);
pushAdminLog(["가입 : {$userID} // {$session->userName} // {$pick} // ".getenv("REMOTE_ADDR")]);
$rootDB->insert('member_log', [
'member_no' => $userID,
'date'=>date('Y-m-d H:i:s'),
'action_type'=>'make_general',
'action'=>Json::encode([
'server'=>DB::prefix(),
'type'=>'npc',
'generalID'=>$npc['no'],
'generalName'=>$npc['name']
])
]);
Json::die([
'result'=>true,
'reason'=>'success'
]);
+23 -2
View File
@@ -8,6 +8,27 @@ var templateGeneralCard =
<label><input <%keepCnt?"":disabled="disabled"%> type="checkbox" value="<%no%>" name="keep[]" class="keep_select">보관(<%keepCnt%>회)</label>\
</div>';
function pickGeneral(){
$btn = $(this);
$.post({
url:'j_select_npc.php',
dataType:'json',
data:{
pick:$btn.val()
}
}).then(function(result){
if(!result.result){
alert(result.reason);
location.refresh();
}
alert('빙의에 성공했습니다.');
location.href = './';
});
return false;
}
function updatePickMoreTimer(){
var $btn = $('#btn_pick_more');
var now = Date.now();
@@ -29,18 +50,18 @@ function printGenerals(value){
$('#btn_pick_more').data('available', new Date(value.pickMoreFrom).getTime()).prop('disabled',true);
$.each(value.pick, function(idx, cardData){
cardData.iconPath = getIconPath(cardData.imgsvr, cardData.picture);
console.log(cardData);
var $card = $(TemplateEngine(templateGeneralCard, cardData));
console.log($card);
$('.card_holder').append($card);
$card.find('.select_btn').click(pickGeneral);
});
updatePickMoreTimer();
}
jQuery(function($){
$(function($){
$.post('j_get_select_npc_token.php').then(function(value){
if(!value.result){
-103
View File
@@ -1,103 +0,0 @@
<?php
namespace sammo;
include "lib.php";
include "func.php";
$session = Session::requireLogin()->setReadOnly();
$userID = Session::getUserID();
$rootDB = RootDB::db();
$db = DB::db();
//회원 테이블에서 정보확인
$member = $rootDB->queryFirstRow('select no,name,picture,grade from member where no=%i', $userID);
if(!$member) {
$session->logout();
header('location:..');
die();
}
list($npcmode, $maxgeneral) = $db->queryFirstList('SELECT npcmode,maxgeneral FROM game LIMIT 1');
if(!$npcmode) {
header('location:..');
die();
}
$gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2');
$nations = $db->queryAllLists('SELECT `name`, scoutmsg, color FROM nation');
?>
<!DOCTYPE html>
<html>
<head>
<title><?=UniqueConst::$serverName?>: NPC빙의</title>
<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<link rel='stylesheet' href='css/normalize.css' type='text/css'>
<link rel='stylesheet' href='../d_shared/common.css' type='text/css'>
<link rel='stylesheet' href='../css/config.css' type='text/css'>
<link rel='stylesheet' href='css/common.css' type='text/css'>
<link rel='stylesheet' href='css/select_npc.css' type='text/css'>
<script type="text/javascript" src="../d_shared/common_path.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../e_lib/jquery-3.2.1.min.js"></script>
<script src="js/select_npc.js"></script>
</head>
<?php
if ($gencount >= $maxgeneral) {
?>
<body>
<script>
alert('더 이상 등록할 수 없습니다.');
history.go(-1);
</script>
</body>
</html>
<?php
die();
}
?>
<body>
<div class="container">
<div class="bg0 with_border legacy_layout">장 수 선 택<br><?=backButton()?></div>
<table style="width:100%;" class="bg0 with_border">
<tr><td><?=info(0)?></td></tr>
</table>
<table style="width:100%;" class="bg0 with_border">
<thead>
<tr><th colspan=2 class="bg1">임관 권유 메세지</th></tr>
</thead>
<tbody>
<?php foreach($nations as list($name, $scoutmsg, $color)): ?>
<tr>
<td style='width:98px;color:<?=newColor($color)?>;background-color:<?=$color?>'><?=$name?></td>
<td style='color:<?=newColor($color)?>;background-color:<?=$color?>'><?=$scoutmsg?:'-'?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="bg0">
<div class="bg1 with_border legacy_layout font1" style="text-align:center;font-weight:bold;">장수 빙의</div>
<div class="with_border legacy_layout" style="text-align:center;">
<small id="valid_until">(<span id="valid_until_text"></span> 까지 유효)</small><br>
<form class="card_holder">
</form>
</div>
<div class="with_border legacy_layout" style="text-align:center">
<button id="btn_pick_more" disabled="disabled" class="with_skin with_border">다른 장수 보기</button><br>
</div>
<div class="with_border legacy_layout"><?=backButton()?></div>
<div class="with_border legacy_layout"><?=banner()?></div>
</div>
</div>
</body>
</html>
+63 -116
View File
@@ -6,141 +6,88 @@ include "func.php";
$session = Session::requireLogin()->setReadOnly();
$userID = Session::getUserID();
$rootDB = RootDB::db();
$db = DB::db();
//회원 테이블에서 정보확인
$member = $rootDB->queryFirstRow('select no,name,picture,grade from member where no=%i', $userID);
list($npcmode, $maxgeneral) = $db->queryFirstList('SELECT npcmode,maxgeneral FROM game LIMIT 1');
if(!$member) {
MessageBox("잘못된 접근입니다!!!");
echo "<script>history.go(-1);</script>";
exit(1);
}
$admin = $db->queryFirstRow('select npcmode,maxgeneral,show_img_level from game limit 1');
if($admin['npcmode'] != 1) {
header('Location:join.php');
if(!$npcmode) {
header('location:..');
die();
}
$gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2');
$connect=$db->get();
$nations = $db->queryAllLists('SELECT `name`, scoutmsg, color FROM nation');
?>
<!DOCTYPE html>
<html>
<head>
<title><?=UniqueConst::$serverName?>: NPC선택</title>
<title><?=UniqueConst::$serverName?>: NPC빙의</title>
<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<link rel='stylesheet' href='css/normalize.css' type='text/css'>
<link rel='stylesheet' href='../d_shared/common.css' type='text/css'>
<link rel='stylesheet' href='../css/config.css' type='text/css'>
<link rel='stylesheet' href='css/common.css' type='text/css'>
<link rel='stylesheet' href='css/select_npc.css' type='text/css'>
<script type="text/javascript" src="../d_shared/common_path.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../e_lib/jquery-3.2.1.min.js"></script>
<script src="js/select_npc.js"></script>
</head>
<body onLoad='changeGen()'>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr><td>장 수 선 택<br><?=backButton()?></td></tr>
</table>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr><td align=center><?=info(0)?></td></tr>
</table>
<?php
$query = "select no from general where npc<2";
$result = MYDB_query($query, $connect) or Error("join ".MYDB_error($connect),"");
$gencount = MYDB_num_rows($result);
if($gencount >= $admin['maxgeneral']) {
echo "<script>alert('더 이상 등록할 수 없습니다.');</script>";
echo "<script>history.go(-1);</script>";
exit();
}
<?php
if ($gencount >= $maxgeneral) {
?>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr><td align=center colspan=2 id=bg1>임관 권유 메세지</td></tr>
<?php
$query = "select name,scoutmsg,color from nation";
$nationresult = MYDB_query($query, $connect) or Error("join ".MYDB_error($connect),"");
$nationcount = MYDB_num_rows($nationresult);
for($i=0; $i < $nationcount; $i++) {
$nation = MYDB_fetch_array($nationresult);
if($nation['scoutmsg'] == "") {
echo "
<tr><td align=center width=98 style=color:".newColor($nation['color']).";background-color:{$nation['color']}>{$nation['name']}</td><td width=898 style=color:".newColor($nation['color']).";background-color:{$nation['color']}>-</td></tr>";
} else {
echo "
<tr><td align=center width=98 style=color:".newColor($nation['color']).";background-color:{$nation['color']}>{$nation['name']}</td><td width=898 style=color:".newColor($nation['color']).";background-color:{$nation['color']}>{$nation['scoutmsg']}</td></tr>";
}
}
?>
</table>
<form name=form1 method=post action=select_npc_post.php>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr>
<td colspan=2 align=center id=bg1>장수 선택</td>
</tr>
<?php
if($admin['show_img_level'] >= 3) {
?>
<tr>
<td width=498 align=right rowspan=2 height=64 id=bg1>장수</td>
<td width=498><img src=<?=ServConfig::$sharedIconPath?>/1001.jpg border=0 name=picture width=64 height=64></td>
</tr>
<?php
}
?>
<tr>
<td align=left colspan=2>
<select name=face size=1 style=color:white;background-color:black; value=1001 disabled>
<?php
$query = "select no,name,leader,power,intel from general where npc=2";
$result = MYDB_query($query,$connect);
$count = MYDB_num_rows($result);
for($i=0; $i < $count; $i++) {
$npc = MYDB_fetch_array($result);
$call = "{$npc['leader']} / {$npc['power']} / {$npc['intel']}";
echo "
<option value={$npc['no']}>{$npc['name']} 【{$call}】</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align=center colspan=2>
컴퓨터가 조작중이던 NPC장수를 조종하게 됩니다.<br>
80시간동안 휴식을 취하면 다시 컴퓨터가 조종하게 되고 장수의 소유권을 잃습니다.
</td>
</tr>
<tr>
<td align=center colspan=2><input type=button name=sel value=다른장수 onclick='changeGen()'><input type=submit name=join value=장수선택 onclick='return selectGen()'></td>
</tr>
</table>
</form>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr><td><?=backButton()?></td></tr>
<tr><td><?=banner()?> </td></tr>
</table>
</body>
<script type="text/javascript">
function changeGen() {
sel = Math.floor(Math.random() * <?=$count?>);
document.form1.face.selectedIndex = sel;
num = document.form1.face.value;
document.form1.picture.src="<?=ServConfig::$sharedIconPath?>" + "/"+ num +".jpg";
}
function selectGen() {
document.form1.face.disabled = false;
return true;
}
<body>
<script>
alert('더 이상 등록할 수 없습니다.');
history.go(-1);
</script>
</body>
</html>
<?php
die();
}
?>
<body>
<div class="container">
<div class="bg0 with_border legacy_layout">장 수 선 택<br><?=backButton()?></div>
<table style="width:100%;" class="bg0 with_border">
<tr><td><?=info(0)?></td></tr>
</table>
<table style="width:100%;" class="bg0 with_border">
<thead>
<tr><th colspan=2 class="bg1">임관 권유 메세지</th></tr>
</thead>
<tbody>
<?php foreach($nations as list($name, $scoutmsg, $color)): ?>
<tr>
<td style='width:98px;color:<?=newColor($color)?>;background-color:<?=$color?>'><?=$name?></td>
<td style='color:<?=newColor($color)?>;background-color:<?=$color?>'><?=$scoutmsg?:'-'?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="bg0">
<div class="bg1 with_border legacy_layout font1" style="text-align:center;font-weight:bold;">장수 빙의</div>
<div class="with_border legacy_layout" style="text-align:center;">
<small id="valid_until">(<span id="valid_until_text"></span> 까지 유효)</small><br>
<form class="card_holder">
</form>
</div>
<div class="with_border legacy_layout" style="text-align:center">
<button id="btn_pick_more" disabled="disabled" class="with_skin with_border">다른 장수 보기</button><br>
</div>
<div class="with_border legacy_layout"><?=backButton()?></div>
<div class="with_border legacy_layout"><?=banner()?></div>
</div>
</div>
</body>
</html>
-144
View File
@@ -1,144 +0,0 @@
<?php
namespace sammo;
include "lib.php";
include "func.php";
$v = new Validator($_POST);
$v
->rule('required', 'face')
->rule('integer', 'face');
if(!$v->validate()){
MessageBox($v->errorStr());
echo "<script>history.go(-1);</script>";
exit(1);
}
$session = Session::requireLogin()->setReadOnly();
$userID = Session::getUserID();
$face = (int)$_POST['face'];
$rootDB = RootDB::db();
//회원 테이블에서 정보확인
$member = $rootDB->queryFirstRow('SELECT `no`, id, picture, grade, `name` FROM member WHERE no=%i', $userID);
if(!$member) {
MessageBox("잘못된 접근입니다!!!");
echo "<script>history.go(-1);</script>";
exit(1);
}
$db = DB::db();
$npc = $db->queryFirstRow('SELECT `no`, `name`, `npc`, `level` FROM general WHERE `no`=%i', $face);
if(!$npc){
echo "<script>alert('선택한 장수가 없습니다!');</script>";
echo "<script>history.go(-1);</script>";
exit();
}
########## 동일 정보 존재여부 확인. ##########
list(
$year,
$month,
$maxgeneral,
$turnterm,
$genius,
$npcmode
) = $db->queryFirstList('SELECT year,month,maxgeneral,turnterm,genius,npcmode from game limit 1');
$gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2');
$oldGeneral = $db->queryFirstField('SELECT `no` FROM general WHERE `owner`=%i', $userID);
if($npcmode != 1) {
echo "<script>alert('잘못된 접근입니다!');</script>";
echo "<script>history.go(-1);</script>";
exit();
}
if($oldGeneral) {
echo("<script>
window.alert('이미 등록하셨습니다!')
history.go(-1)
</script>");
exit;
}
if($maxgeneral <= $gencount) {
echo("<script>
window.alert('더이상 등록할 수 없습니다!')
history.go(-1)
</script>");
exit;
}
if($npc['npc'] < 2) {
echo("<script>
window.alert('이미 선택된 장수입니다!')
history.go(-1)
</script>");
exit;
}
if($npc['npc'] != 2) {
echo("<script>
window.alert('선택할 수 없는 NPC입니다!')
history.go(-1)
</script>");
exit;
}
/*if($npc['level'] >= 5) {
echo("<script>
window.alert('수뇌부는 선택할 수 없습니다!')
history.go(-1)
</script>");
exit;
} */
$userNick = RootDB::db()->queryFirstField('SELECT `NAME` FROM member WHERE `NO`=%i',Session::getUserID());
$npcID = $npc['no'];
$db->update('general', [
'name2'=>$userNick,
'npc'=>1,
'killturn'=>6,
'mode'=>2,
'owner'=>$userID
], 'no=%i and npc=2', $npcID);
$affected = $db->affectedRows();
if(!$affected){
echo("<script>
window.alert('이미 선택된 장수입니다!')
history.go(-1)
</script>");
exit;
}
$me = [
'no'=>$npcID
];
pushGeneralHistory($me, "<C>●</>{$year}{$month}월:<Y>{$npc['name']}</>의 육체에 <Y>{$userNick}</>(이)가 빙의되다.");
//pushGenLog($me, $mylog);
pushGeneralPublicRecord(["<C>●</>{$month}월:<Y>{$npc['name']}</>의 육체에 <Y>{$userNick}</>(이)가 <S>빙의</>됩니다!"], $year, $month);
pushAdminLog(["가입 : {$userID} // {$session->userName} // {$npcID} // ".getenv("REMOTE_ADDR")]);
$rootDB->insert('member_log', [
'member_no' => $userID,
'date'=>date('Y-m-d H:i:s'),
'action_type'=>'make_general',
'action'=>Json::encode([
'server'=>DB::prefix(),
'type'=>'npc',
'generalID'=>$npc['no'],
'generalName'=>$npc['name']
])
]);
?>
<script>
window.alert('정상적으로 회원 가입되었습니다. 장수명 : <?=$npc['name']?>');
window.open('../i_other/help.php');
location.href = './';
</script>
+10
View File
@@ -118,4 +118,14 @@ var TemplateEngine = function (html, options) {
try { result = new Function('obj', code).apply(options, [options]); }
catch (err) { console.error("'" + err.message + "'", " in \n\nCode:\n", code, "\n"); }
return result;
}
function getIconPath(imgsvr, picture){
// ../d_shared/common_path.js 필요
if(!imgsvr){
return pathConfig.sharedIcon+'/'+picture;
}
else{
return pathConfig.root+'/d_pic/'+picture;
}
}