분쟁 코드를 json기반으로 변경
This commit is contained in:
+62
-63
@@ -49,6 +49,30 @@ for($i=0; $i < $nationcount; $i++) {
|
||||
$cityStr .= "속령 $citycount<br>";
|
||||
}
|
||||
|
||||
$realConflict = [];
|
||||
foreach ($db->queryAllLists('SELECT city, `name`, conflict FROM city WHERE conflict!=%s', '{}') as list(
|
||||
$cityID,
|
||||
$cityName,
|
||||
$rawConflict
|
||||
))
|
||||
{
|
||||
$conflict = Json::decode($city['conflict']);
|
||||
if (count($conflict)<2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sum = array_sum($conflict);
|
||||
|
||||
foreach ($conflict as $nationID=>$killnum) {
|
||||
$conflict['percent'] = round(100*$killnum / $sum, 1);
|
||||
$conflict['name'] = $nationname[$nationID];
|
||||
$conflict['color'] = $nationcolor[$nationID];
|
||||
}
|
||||
|
||||
$realConflict[] = [$cityID, $cityName, $conflict];
|
||||
};
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -152,78 +176,53 @@ for($i=0; $i < $nationcount; $i++) {
|
||||
?>
|
||||
<tr><td colspan=<?=$nationcount+1?> align=center>불가침 : <font color=limegreen>@</font>, 통합 : <font color=cyan>○</font>, 합병 : <font color=skyblue>◎</font>, 통상 : ㆍ, 선포 : <font color=magenta>▲</font>, 교전 : <font color=red>★</font></td></tr>
|
||||
</table>
|
||||
<?php
|
||||
$query = "select city,name,conflict,conflict2 from city where conflict like '%|%'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$citycount = MYDB_num_rows($result);
|
||||
|
||||
if($citycount != 0) {
|
||||
echo "
|
||||
<?php if ($realConflict) : ?>
|
||||
|
||||
<br>
|
||||
<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 bgcolor=magenta>분 쟁 현 황</td></tr>";
|
||||
}
|
||||
|
||||
for($i=0; $i < $citycount; $i++) {
|
||||
$city = MYDB_fetch_array($result);
|
||||
|
||||
if($city['conflict'] != "") {
|
||||
$nation = explode("|", $city['conflict']);
|
||||
$killnum = explode("|", $city['conflict2']);
|
||||
|
||||
$seq = mySort($killnum); // 큰 순서대로 순서를 구한다.
|
||||
|
||||
$sum = 0;
|
||||
for($k=0; $k < count($killnum); $k++) {
|
||||
$sum += $killnum[$k];
|
||||
}
|
||||
echo "
|
||||
<table
|
||||
align='center'
|
||||
width=1000
|
||||
border=1
|
||||
cellspacing=0
|
||||
cellpadding=0
|
||||
bordercolordark='gray'
|
||||
bordercolorlight='black'
|
||||
style='font-size:13px;word-break:break-all;'
|
||||
class='bg0'
|
||||
>
|
||||
<tr><td colspan=2 align=center bgcolor=magenta>분 쟁 현 황</td></tr>
|
||||
<?php foreach($realConflict as list($cityID, $cityName, $conflict)): ?>
|
||||
<tr>
|
||||
<td align=center width=48>{$city['name']}</td>
|
||||
<td width=948>";
|
||||
for($k=0; $k < count($nation); $k++) {
|
||||
$per = 100*$killnum[$seq[$k]] / $sum;
|
||||
$graph1 = $per / 100 * 798;
|
||||
$per = round($per, 1);
|
||||
echo "
|
||||
<table border=0 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
|
||||
<td align=center width=48><?=$cityName?></td>
|
||||
<td width=948>
|
||||
<table
|
||||
border=0
|
||||
cellspacing=0
|
||||
cellpadding=0
|
||||
bordercolordark='gray'
|
||||
bordercolorlight='black'
|
||||
style='font-size:13px;word-break:break-all;'
|
||||
class='bg0'
|
||||
>
|
||||
<?php foreach($conflict as $conflictItem): ?>
|
||||
<tr>
|
||||
<td width=98 align=right style=color:".newColor($nationcolor[$nation[$seq[$k]]]).";background-color:{$nationcolor[$nation[$seq[$k]]]};>{$nationname[$nation[$seq[$k]]]} </td>
|
||||
<td width=48 align=right>{$per}% </td>
|
||||
<td width=$graph1 style=background-color:{$nationcolor[$nation[$seq[$k]]]};></td>
|
||||
<td width=98 align=right style=color:".newColor($nationcolor[$nationID]).";background-color:<?=$conflictItem['color']?>;><?=$conflictItem['name']?> </td>
|
||||
<td width=48 align=right><?=$conflictItem['percent']?>% </td>
|
||||
<td width='<?=$conflictItem['percent']?>%' style=background-color:<?=$conflictItem['color']?>;></td>
|
||||
<td width=*></td>
|
||||
</tr>
|
||||
</table>";
|
||||
}
|
||||
echo "
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td colspan=2 height=5 id=bg1></td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
function mySort($killnum) {
|
||||
$seq = [];
|
||||
for($i=0; $i < count($killnum); $i++) {
|
||||
$seq[$i] = $i;
|
||||
}
|
||||
for($i=0; $i < count($killnum); $i++) {
|
||||
$max = 0;
|
||||
for($k=0; $k < count($killnum); $k++) {
|
||||
if($max < $killnum[$k]) {
|
||||
$max = $killnum[$k];
|
||||
$index = $k;
|
||||
}
|
||||
}
|
||||
$seq[$i] = $index;
|
||||
$killnum[$index] = 0;
|
||||
}
|
||||
return $seq;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
<tr><td colspan=2 height=5 id=bg1></td></tr>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<br>
|
||||
<table class="bg0" align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style="font-size:13px;word-break:break-all;">
|
||||
<tr>
|
||||
|
||||
@@ -382,7 +382,7 @@ function preUpdateMonthly() {
|
||||
}
|
||||
pushWorldHistory($history, $admin['year'], $admin['month']);
|
||||
//민심30이하 공백지 처리
|
||||
$query = "update city set nation='0',gen1='0',gen2='0',gen3='0',conflict='',conflict2='',term=0,front=0 where rate<='30' and supply='0'";
|
||||
$query = "update city set nation='0',gen1='0',gen2='0',gen3='0',conflict='{}',term=0,front=0 where rate<='30' and supply='0'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
// 우선 병사수/100 만큼 소비
|
||||
@@ -440,7 +440,7 @@ function preUpdateMonthly() {
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$query = "update city set term=term-1 where term>0";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$query = "update city set conflict='',conflict2='' where term=0";
|
||||
$query = "update city set conflict='{}' where term=0";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$query = "update city set state=0 where state=41";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
@@ -753,7 +753,7 @@ function checkMerge() {
|
||||
$query = "delete from nation where nation='{$me['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 아국 모든 도시들 상대국 소속으로
|
||||
$query = "update city set nation='{$you['nation']}',gen1='0',gen2='0',gen3='0',conflict='',conflict2='' where nation='{$me['nation']}'";
|
||||
$query = "update city set nation='{$you['nation']}',gen1='0',gen2='0',gen3='0',conflict='{}' where nation='{$me['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 아국 모든 장수들 일반으로 하고 상대국 소속으로, 수도로 이동
|
||||
$query = "update general set belong=1,level=1,nation='{$you['nation']}' where nation='{$me['nation']}'";
|
||||
@@ -884,7 +884,7 @@ function checkSurrender() {
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$king = MYDB_fetch_array($result);
|
||||
// 아국 모든 도시들 상대국 소속으로
|
||||
$query = "update city set nation='{$you['nation']}',gen1='0',gen2='0',gen3='0',conflict='',conflict2='' where nation='{$me['nation']}'";
|
||||
$query = "update city set nation='{$you['nation']}',gen1='0',gen2='0',gen3='0',conflict='{}' where nation='{$me['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 제의국 모든 장수들 공헌도0.95, 명성0.95
|
||||
$query = "update general set dedication=dedication*0.95,experience=experience*0.95 where nation='{$you['nation']}'";
|
||||
|
||||
@@ -935,7 +935,7 @@ function process_65(&$general) {
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
//성 공백지로
|
||||
$query = "update city set pop=pop*0.1,rate=50,agri=agri*0.1,comm=comm*0.1,secu=secu*0.1,nation='0',front='0',gen1='0',gen2='0',gen3='0',conflict='',conflict2='' where city='{$destcity['city']}'";
|
||||
$query = "update city set pop=pop*0.1,rate=50,agri=agri*0.1,comm=comm*0.1,secu=secu*0.1,nation='0',front='0',gen1='0',gen2='0',gen3='0',conflict='{}' where city='{$destcity['city']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
//경험치, 공헌치
|
||||
|
||||
@@ -604,7 +604,7 @@ function process_46(&$general) {
|
||||
$nation = getNationStaticInfo($general['nation']);
|
||||
|
||||
// 현 도시 소속지로
|
||||
$query = "update city set nation='{$nation['nation']}',conflict='',conflict2='' where city='{$general['city']}'";
|
||||
$query = "update city set nation='{$nation['nation']}',conflict='{}' where city='{$general['city']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$log[] = "<C>●</>{$admin['month']}월:<D><b>{$nation['name']}</b></>(을)를 건국하였습니다. <1>$date</>";
|
||||
@@ -685,7 +685,7 @@ function process_47(&$general) {
|
||||
$query = "update general set level=1 where nation='{$general['nation']}' and level <= 11";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 전 도시 공백지로
|
||||
$query = "update city set nation='0',front='0',gen1='0',gen2='0',gen3='0',conflict='',conflict2='' where nation='{$general['nation']}'";
|
||||
$query = "update city set nation='0',front='0',gen1='0',gen2='0',gen3='0',conflict='{}' where nation='{$general['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 외교 리셋
|
||||
$query = "update diplomacy set state='2',term='0' where me='{$general['nation']}' or you='{$general['nation']}'";
|
||||
|
||||
+42
-70
@@ -153,7 +153,7 @@ function processWar($general, $city) {
|
||||
$query = "update city set agri=agri*0.5,comm=comm*0.5,secu=secu*0.5 where city='{$city['city']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$city = addConflict($city, $general['nation'], 1);
|
||||
$city = addConflict($city, $general['nation'], 1);//NOTE: 이 경우 두 국가가 분쟁 중인 경우에는 병량패퇴의 이득이 없다.
|
||||
|
||||
ConquerCity($game, $general, $city, $nation, $destnation);
|
||||
break;
|
||||
@@ -1643,97 +1643,69 @@ function getRate($game, $type, $dtype) {
|
||||
return $game[$t];
|
||||
}
|
||||
|
||||
function addConflict($city, $nationnum, $mykillnum) {
|
||||
function addConflict($city, $nationID, $mykillnum) {
|
||||
$db = DB::db();
|
||||
$connect=$db->get();
|
||||
|
||||
$nationlist = [];
|
||||
$killnum = [0];
|
||||
|
||||
list($year, $month) = $db->queryFirstList('SELECT year, month FROM game LIMIT 1');
|
||||
|
||||
if($city['conflict']){
|
||||
$nationlist = array_map('intval', explode("|", $city['conflict']));
|
||||
$killnum = array_map('intval', explode("|", $city['conflict2']));
|
||||
$conflict = Json::decode($city['conflict']);
|
||||
|
||||
if(!$conflict || $city['def'] == 0){ // 선타, 막타 보너스
|
||||
$mykillnum *= 1.05;
|
||||
}
|
||||
|
||||
if (!$conflict) {
|
||||
$conflict[$nationID] = $mykillnum;
|
||||
}
|
||||
else if(key_exists($nationID, $conflict)){
|
||||
$conflict[$nationID] += $mykillnum;
|
||||
arsort($conflict);
|
||||
}
|
||||
else{
|
||||
$nationlist = [$nationnum];
|
||||
$killnum = [0];
|
||||
}
|
||||
|
||||
for($i=0; $i < count($nationlist); $i++) {
|
||||
if($nationlist[$i] == $nationnum) break;
|
||||
}
|
||||
if($i != 0 && $i == count($nationlist)) { // 두번째 나라부터 분쟁 가담 메시지 출력
|
||||
$nation = getNationStaticInfo($nationnum);
|
||||
$conflict[$nationID] = $mykillnum;
|
||||
arsort($conflict);
|
||||
|
||||
$nation = getNationStaticInfo($nationID);
|
||||
pushWorldHistory(["<C>●</>{$year}년 {$month}월:<M><b>【분쟁】</b></><D><b>{$nation['name']}</b></>(이)가 <G><b>{$city['name']}</b></> 공략에 가담하여 분쟁이 발생하고 있습니다."]);
|
||||
}
|
||||
|
||||
$rawConflict = Json::encode($conflict);
|
||||
$city['conflict'] = $rawConflict;
|
||||
|
||||
$nationlist[$i] = $nationnum;
|
||||
|
||||
if($i == 0 || $city['def'] == 0) { // 선타, 막타 보너스
|
||||
$killnum[$i] += Util::round($mykillnum * 1.05);
|
||||
} else {
|
||||
$killnum[$i] += $mykillnum;
|
||||
}
|
||||
$city['conflict'] = implode("|", $nationlist);
|
||||
$city['conflict2'] = implode("|", $killnum);
|
||||
|
||||
$query = "update city set conflict='{$city['conflict']}',conflict2='{$city['conflict2']}' where city='{$city['city']}'";
|
||||
MYDB_query($query, $connect) or Error("addConflict ".MYDB_error($connect),"");
|
||||
$db->update('city', [
|
||||
'conflict'=>$rawConflict
|
||||
], 'city=%i',$city['city']);
|
||||
|
||||
return $city;
|
||||
}
|
||||
|
||||
function DeleteConflict($nation) {
|
||||
$db = DB::db();
|
||||
$connect=$db->get();
|
||||
|
||||
$query = "select city,conflict,conflict2 from city where conflict!=''";
|
||||
$result = MYDB_query($query, $connect) or Error("addConflict ".MYDB_error($connect),"");
|
||||
$cityNum = MYDB_num_rows($result);
|
||||
foreach($db->queryAllLists('SELECT city, conflict FROM city WHERE conflict!=%s', '{}') as list($cityID, $rawConflict)){
|
||||
$conflict = Json::decode($rawConflict);
|
||||
|
||||
$nation = "$nation";
|
||||
for($k=0; $k < $cityNum; $k++) {
|
||||
$city = MYDB_fetch_array($result);
|
||||
|
||||
if(strpos($city['conflict'], $nation)) {
|
||||
$nationlist = explode("|", $city['conflict']);
|
||||
$killnum = explode("|", $city['conflict2']);
|
||||
|
||||
$count = count($nationlist);
|
||||
for($i=0; $i < $count; $i++) {
|
||||
if($nationlist[$i] == $nation) {
|
||||
unset($nationlist[$i]);
|
||||
unset($killnum[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$conflict = implode("|", $nationlist);
|
||||
$conflict2 = implode("|", $killnum);
|
||||
|
||||
$query = "update city set conflict='$conflict',conflict2='$conflict2' where city='{$city['city']}'";
|
||||
MYDB_query($query, $connect) or Error("addConflict ".MYDB_error($connect),"");
|
||||
if(!$conflict || !is_array($conflict)){
|
||||
continue;
|
||||
}
|
||||
if(!key_exists(!$nation)){
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($conflict[$nation]);
|
||||
|
||||
$db->update('city', [
|
||||
'conflict'=>Json::encode($conflict)
|
||||
], 'city=%i', $cityID);
|
||||
}
|
||||
}
|
||||
|
||||
function getConquerNation($city) : int {
|
||||
$db = DB::db();
|
||||
$connect=$db->get();
|
||||
|
||||
$nationlist = array_map('intval', explode("|", (string)$city['conflict']));
|
||||
$killnum = array_map('intval', explode("|", (string)$city['conflict2']));
|
||||
|
||||
$max = 0;
|
||||
for($i=0; $i < count($nationlist); $i++) {
|
||||
if($max <= $killnum[$i]) {
|
||||
$max = $killnum[$i];
|
||||
$index = $i;
|
||||
}
|
||||
}
|
||||
return $nationlist[$index];
|
||||
$conflict = Json::decode($city['conflict']);
|
||||
return array_first_key($conflict);
|
||||
}
|
||||
|
||||
function ConquerCity($game, $general, $city, $nation, $destnation) {
|
||||
@@ -1866,7 +1838,7 @@ function ConquerCity($game, $general, $city, $nation, $destnation) {
|
||||
$query = "update general set dedication=dedication*0.5,experience=experience*0.9 where nation='{$city['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 전 도시 공백지로
|
||||
$query = "update city set nation='0',gen1='0',gen2='0',gen3='0',conflict='',conflict2='',term=0 where nation='{$city['nation']}'";
|
||||
$query = "update city set nation='0',gen1='0',gen2='0',gen3='0',conflict='{}',term=0 where nation='{$city['nation']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 전 장수 소속 무소속으로, 재야로, 부대 탈퇴
|
||||
$query = "update general set nation='0',belong='0',level='0',troop='0' where nation='{$city['nation']}'";
|
||||
@@ -1984,11 +1956,11 @@ function ConquerCity($game, $general, $city, $nation, $destnation) {
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
if($city['level'] > 3) {
|
||||
// 도시 소속 변경, 태수,군사,시중 초기화
|
||||
$query = "update city set supply=1,conflict='',term=0,conflict2='',agri=agri*0.7,comm=comm*0.7,secu=secu*0.7,def=1000,wall=1000,nation='{$general['nation']}',gen1=0,gen2=0,gen3=0 where city='{$city['city']}'";
|
||||
$query = "update city set supply=1,conflict='{}',term=0,agri=agri*0.7,comm=comm*0.7,secu=secu*0.7,def=1000,wall=1000,nation='{$general['nation']}',gen1=0,gen2=0,gen3=0 where city='{$city['city']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
} else {
|
||||
// 도시 소속 변경, 태수,군사,시중 초기화
|
||||
$query = "update city set supply=1,conflict='',term=0,conflict2='',agri=agri*0.7,comm=comm*0.7,secu=secu*0.7,def=def2/2,wall=wall2/2,nation='{$general['nation']}',gen1=0,gen2=0,gen3=0 where city='{$city['city']}'";
|
||||
$query = "update city set supply=1,conflict='{}',term=0,agri=agri*0.7,comm=comm*0.7,secu=secu*0.7,def=def2/2,wall=wall2/2,nation='{$general['nation']}',gen1=0,gen2=0,gen3=0 where city='{$city['city']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
}
|
||||
//전방설정
|
||||
@@ -2011,7 +1983,7 @@ function ConquerCity($game, $general, $city, $nation, $destnation) {
|
||||
$query = [
|
||||
'supply'=>1,
|
||||
'term'=>0,
|
||||
'conflict2'=>'',
|
||||
'conflict'=>'{}',
|
||||
'agri'=>$db->sqleval('agri*0.7'),
|
||||
'comm'=>$db->sqleval('comm*0.7'),
|
||||
'secu'=>$db->sqleval('secu*0.7'),
|
||||
|
||||
+1
-2
@@ -319,8 +319,7 @@ create table city (
|
||||
state int(2) default 0,
|
||||
region int(2) default 0,
|
||||
term int(1) default 0,
|
||||
conflict char(255) default '',
|
||||
conflict2 char(255) default '',
|
||||
conflict varchar(500) default '{}'
|
||||
|
||||
PRIMARY KEY (city),
|
||||
KEY (nation)
|
||||
|
||||
Reference in New Issue
Block a user