From 3baf761b3b3b5a14edf1f3bdfc6b46353cb98504 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 10 May 2020 02:12:25 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A4=91=EC=9B=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=9E=AC=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/b_diplomacy.php | 194 +++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 101 deletions(-) diff --git a/hwe/b_diplomacy.php b/hwe/b_diplomacy.php index 16fc3dc8..da4a7bfa 100644 --- a/hwe/b_diplomacy.php +++ b/hwe/b_diplomacy.php @@ -9,39 +9,24 @@ $userID = Session::getUserID(); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); -$connect=$db->get(); increaseRefresh("중원정보", 1); $mapTheme = $gameStor->map_theme??'che'; -$query = "select no,nation from general where owner='{$userID}'"; -$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); -$me = MYDB_fetch_array($result); +$me = $db->queryFirstRow('SELECT no,nation FROM general WHERE owner=%i', $userID); +$myNationID = $me['nation']; -$query = "select nation,color,name,power,gennum from nation where level>0 order by power desc"; -$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); -$nationcount = MYDB_num_rows($result); -$nationnum = []; -$nationname = []; +$nations = array_filter(getAllNationStaticInfo(), function(array $nation){ + return $nation['level']; +}); +uasort($nations, function(array $lhs, array $rhs){ + return -($lhs['power']<=>$rhs['power']); +}); +$nationCnt = count($nations); -$nationStr = ""; -$powerStr = ""; -$genStr = ""; -$cityStr = ""; -for($i=0; $i < $nationcount; $i++) { - $nation = MYDB_fetch_array($result); - - $citycount = $db->queryFirstField('SELECT count(city) FROM city WHERE nation=%i', $nation['nation']); - - - $nationnum[] = $nation['nation']; - $nationname[$nation['nation']] = $nation['name']; - - $nationStr .= " {$nation['name']}
"; - $powerStr .= "{$nation['power']}
"; - $genStr .= "{$nation['gennum']}
"; - $cityStr .= "$citycount
"; +foreach($db->queryAllLists('SELECT nation, count(city) FROM city WHERE nation != 0 GROUP BY nation') as [$nationID, $cityCnt]){ + $nations[$nationID]['city_cnt'] = $cityCnt; } $realConflict = []; @@ -51,23 +36,51 @@ foreach ($db->queryAllLists('SELECT city, `name`, conflict FROM city WHERE confl $rawConflict ]) { - $conflict = Json::decode($rawConflict); - if (count($conflict)<2) { + $rawConflict = Json::decode($rawConflict); + if (count($rawConflict)<2) { continue; } - $sum = array_sum($conflict); + $sum = array_sum($rawConflict); - foreach ($conflict as $nationID=>$killnum) { - $conflict[$nationID] = ['killnum'=>$killnum]; - $conflict[$nationID]['percent'] = round(100*$killnum / $sum, 1); - $conflict[$nationID]['name'] = $nationname[$nationID]; - $conflict[$nationID]['color'] = getNationStaticInfo($nationID)['color']; + + $conflict = []; + foreach ($rawConflict as $nationID=>$killnum) { + $conflict[$nationID] = [ + 'killnum'=>$killnum, + 'percent'=>round(100*$killnum / $sum, 1), + 'name'=>$nations[$nationID]['name'], + 'color'=>$nations[$nationID]['color'] + ]; } $realConflict[] = [$cityID, $cityName, $conflict]; }; +$diplomacyList = []; +foreach($db->queryAllLists('SELECT me, you, state FROM diplomacy') as [$me, $you, $state]){ + if(!key_exists($me, $diplomacyList)){ + $diplomacyList[$me] = []; + } + + $diplomacyList[$me][$you] = $state; +} + +$cellWidth = intdiv(888, max(1, $nationCnt)); + + +$defaultStateChar = '?'; +$sameNationStateChar = '\'; +$infomativeStateCharMap = [ + 0=>'', + 1=>'', + 2=>'ㆍ', + 7=>'@' +]; +$neutralStateCharMap = [ + 0=>'', + 1=>'' +]; ?> @@ -100,6 +113,7 @@ $(function(){ + @@ -109,73 +123,32 @@ $(function(){
- - - "; - -if($nationcount != 0) { - $width = intdiv(888, $nationcount); + + + + + +$meNation): ?> + + + +"; +else if($me==$myNationID || $you==$myNationID || $session->userGrade >= 5){ + echo $infomativeStateCharMap[$diplomacyList[$me][$you]]??$defaultStateChar; } -echo " - "; - -$state = []; - -for($i=0; $i < $nationcount; $i++) { - $query = "select you,state from diplomacy where me='$nationnum[$i]'"; - $dipresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nationcount2 = MYDB_num_rows($dipresult); - for($k=0; $k < $nationcount2; $k++) { - $dip = MYDB_fetch_array($dipresult); - $state[$dip['you']] = $dip['state']; - } - echo " - - "; - - for($k=0; $k < $nationcount; $k++) { - if($i == $k) { - $str = "\"; - } else { - switch($state[$nationnum[$k]]) { - case 0: $str = ""; break; - case 1: $str = ""; break; - case 2: - if($nationnum[$i] == $me['nation'] || $nationnum[$k] == $me['nation'] || $session->userGrade >= 5) { $str = "ㆍ"; } - else { $str = "?"; } -// $str = "ㆍ"; - break; - case 3: $str = ""; break; - case 4: $str = ""; break; - case 5: $str = ""; break; - case 6: $str = ""; break; - case 7: - if($nationnum[$i] == $me['nation'] || $nationnum[$k] == $me['nation'] || $session->userGrade >= 5) { $str = "@"; } - else { $str = "?"; } -// $str = "@"; - break; - } - } - - if($nationnum[$i] == $me['nation'] || $nationnum[$k] == $me['nation']) { $backcolor = "style=background-color:".GameConst::$basecolor3.";"; } - else { $backcolor = ""; } - - echo " - "; - } - echo " - -"; +else{ + echo $neutralStateCharMap[$diplomacyList[$me][$you]]??$defaultStateChar; } -?> - +?> + + + +
align=center bgcolor=blue>외 교 현 황
align=center bgcolor=blue>외 교 현 황
 ;>  style='background-color:;color:'>
;color:'>>{$nationname[$nationnum[$i]]}
{$nationname[$nationnum[$i]]}$str
align=center>불가침 : @, 통상 : ㆍ, 선포 : , 교전 :
align=center>불가침 : @, 통상 : ㆍ, 선포 : , 교전 :
@@ -220,10 +193,29 @@ for($i=0; $i < $nationcount; $i++) { -
국명
-
국력
-
장수
-
속령
+ + + + + + + + + + + + + + + + + + + + + +
국명국력장수속령
;background-color:'>
+