From 4cf7bca399b74ab6fff6f974efbee8cb4ce31c32 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 27 Jun 2018 01:14:34 +0900 Subject: [PATCH] =?UTF-8?q?=EC=99=95=EC=A1=B0=20=EC=9D=BC=EB=9E=8C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=84=9C=EB=B2=84=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EC=99=80=20=EA=B5=AD=EA=B0=80=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=B4=EA=B4=80=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/a_emperior.php | 84 +++--- hwe/func_converter.php | 5 +- hwe/func_gamerule.php | 605 +++++++++++++++++++++-------------------- hwe/sql/schema.sql | 124 +++++---- src/sammo/Util.php | 16 +- 5 files changed, 442 insertions(+), 392 deletions(-) diff --git a/hwe/a_emperior.php b/hwe/a_emperior.php index 0127b4dd..707cf4c0 100644 --- a/hwe/a_emperior.php +++ b/hwe/a_emperior.php @@ -11,7 +11,7 @@ extractMissingPostToGlobals(); $db = DB::db(); $connect=$db->get(); -increaseRefresh("왕조일람", 2); +increaseRefresh("왕조일람", 1); ?> @@ -77,131 +77,133 @@ if ($select == 0) { {$emperior['l9name']} -"; + + + + +
+ +"; } -} else { - $query = "select * from emperior where no='$select'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), ""); - $emperior = MYDB_fetch_array($result); + die(); +} - echo " +$emperior = $db->queryFirstRow('SELECT * FROM emperior WHERE `no`=%i',$select); + +?> - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
- {$emperior['phase']} +
국 가 수
(최종 / 최대)
{$emperior['nation_count']} 장 수 수
(최종 / 최대)
{$emperior['gen_count']}
등 장 국 가{$emperior['nation_name']}
국가별 성향{$emperior['nation_hist']}
장 수 성 격{$emperior['personal_hist']}
장 수 특 기{$emperior['special_hist']}
- {$emperior['name']} ({$emperior['year']}年 {$emperior['month']}月) + ; bgcolor= colspan=6> + (月)
국 력{$emperior['power']} 성 향{$emperior['type']}
장 수{$emperior['gennum']} 속 령{$emperior['citynum']}
총 인 구{$emperior['pop']} 인 구 율{$emperior['poprate']}
국 고{$emperior['gold']} 병 량{$emperior['rice']}
황 제  {$emperior['l12name']} 승 상  {$emperior['l11name']}
위 장 군  {$emperior['l10name']} 사 공  {$emperior['l9name']}
표 기 장 군  {$emperior['l8name']} 태 위  {$emperior['l7name']}
거 기 장 군  {$emperior['l6name']} 사 도  {$emperior['l5name']}
오 호 장 군{$emperior['tiger']}
건 안 칠 자{$emperior['eagle']}
장 수 들
(공헌도 순서)
{$emperior['gen']}
역 사 기 록".ConvertLog($emperior['history'], 1)."
-"; -} -?>
- - + \ No newline at end of file diff --git a/hwe/func_converter.php b/hwe/func_converter.php index 78c98ebb..a8fa7934 100644 --- a/hwe/func_converter.php +++ b/hwe/func_converter.php @@ -791,7 +791,10 @@ function getItemCost($weap) : int { -function ConvertLog(string $str, $type=1) : string { +function ConvertLog(?string $str, $type=1) : string { + if(!$str){ + return ''; + } //TODO: 이 함수는 없애야 한다. CSS로 대신하자 if($type > 0) { $str = str_replace("<1>", "", $str); diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 38632aea..e5da979d 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -943,53 +943,79 @@ function updateNationState() { function checkStatistic() { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); - $connect=$db->get(); $admin = $gameStor->getValues(['year', 'month']); $nationHists = []; $specialHists = []; $personalHists = []; - $specialHists2 = [0]; + $specialHists2 = []; + $crewtypeHists = []; $etc = ''; - $query = "select avg(gold) as avggold, avg(rice) as avgrice, avg(dex0+dex10+dex20+dex30) as avgdex, max(dex0+dex10+dex20+dex30) as maxdex, avg(experience+dedication) as avgexpded, max(experience+dedication) as maxexpded from general"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); - $general['avggold'] = Util::round($general['avggold']); - $general['avgrice'] = Util::round($general['avgrice']); - $general['avgdex'] = Util::round($general['avgdex']); - $general['avgexpded'] = Util::round($general['avgexpded']); - $etc .= "평균 금/쌀 ({$general['avggold']}/{$general['avgrice']}), 평균/최고 숙련({$general['avgdex']}/{$general['maxdex']}), 평균/최고 경험공헌({$general['avgexpded']}/{$general['maxexpded']}), "; + $auxData = [ + 'generals'=>[], + 'nations'=>[], + ]; - $query = "select min(tech) as mintech, max(tech) as maxtech, avg(tech) as avgtech, min(power) as minpower, max(power) as maxpower, avg(power) as avgpower from nation where level>0"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nation = MYDB_fetch_array($result); - $nation['avgtech'] = Util::round($nation['avgtech']); - $nation['avgpower'] = Util::round($nation['avgpower']); - $etc .= "최저/평균/최고 기술({$nation['mintech']}/{$nation['avgtech']}/{$nation['maxtech']}), "; - $etc .= "최저/평균/최고 국력({$nation['minpower']}/{$nation['avgpower']}/{$nation['maxpower']}), "; + $avgGeneral = $db->queryFirstRow( + 'SELECT avg(gold) as avggold, avg(rice) as avgrice, avg(dex0+dex10+dex20+dex30) as avgdex, + max(dex0+dex10+dex20+dex30) as maxdex, avg(experience+dedication) as avgexpded, max(experience+dedication) as maxexpded + FROM general' + ); + $auxData['generals']['avg'] = $avgGeneral; + + $avgGeneral['avggold'] = Util::round($avgGeneral['avggold']); + $avgGeneral['avgrice'] = Util::round($avgGeneral['avgrice']); + $avgGeneral['avgdex'] = Util::round($avgGeneral['avgdex']); + $avgGeneral['avgexpded'] = Util::round($avgGeneral['avgexpded']); + $etc .= "평균 금/쌀 ({$avgGeneral['avggold']}/{$avgGeneral['avgrice']}), 평균/최고 숙련({$avgGeneral['avgdex']}/{$avgGeneral['maxdex']}), 평균/최고 경험공헌({$avgGeneral['avgexpded']}/{$avgGeneral['maxexpded']}), "; + + $avgNation = $db->queryFirstRow( + 'SELECT min(tech) as mintech, max(tech) as maxtech, avg(tech) as avgtech, + min(power) as minpower, max(power) as maxpower, avg(power) as avgpower from nation where level>0'); + $auxData['nations']['avg'] = $avgNation; + + $avgNation['avgtech'] = Util::round($avgNation['avgtech']); + $avgNation['avgpower'] = Util::round($avgNation['avgpower']); + $etc .= "최저/평균/최고 기술({$avgNation['mintech']}/{$avgNation['avgtech']}/{$avgNation['maxtech']}), "; + $etc .= "최저/평균/최고 국력({$avgNation['minpower']}/{$avgNation['avgpower']}/{$avgNation['maxpower']}), "; $nationName = ''; - $power_hist = ''; + $powerHist = ''; - $query = "select nation,name,type,power,gennum,round((gold+rice)/100) as goldrice 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); - for($i=0; $i < $nationCount; $i++) { - $nation = MYDB_fetch_array($result); + $nations = Util::convertArrayToDict( + $db->query( + 'SELECT nation,name,type,power,gennum,gold+rice as goldrice from nation where level>0 order by power desc', 'nation' + ), + 'nation' + ); + $nationCount = count($nations); - $query = "select sum(leader+power+intel) as abil,round(sum(gold+rice)/100) as goldrice,round(sum(dex0+dex10+dex20+dex30)/1000) as dex,round(sum(experience+dedication)/100) as expded from general where nation='{$nation['nation']}'"; - $result2 = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result2); + $nationGeneralInfos = Util::convertArrayToDict( + $db->query( + 'SELECT nation, sum(leader+power+intel) as abil,sum(gold+rice) as goldrice, + sum(dex0+dex10+dex20+dex30) as dex,sum(experience+dedication) as expded + from general GROUP BY nation' + ), + 'nation' + ); - $query = "select count(*) as cnt,round(sum(pop)/100) as pop,round(sum(pop2)/100) as pop2 from city where nation='{$nation['nation']}'"; - $result2 = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result2); + $nationCityInfos = Util::convertArrayToDict( + $db->query('SELECT nation, count(*) as cnt, sum(pop) as pop,sum(pop2) as pop2 from city GROUP BY nation'), + 'nation' + ); + + foreach($nations as $nationNo=>&$nation) { + $general = $nationGeneralInfos[$nationNo]; + $city = $nationCityInfos[$nationNo]; + $nation['generalInfo'] = $general; + $nation['cityInfo'] = $city; + $nationName .= $nation['name'].'('.getNationType($nation['type']).'), '; - $power_hist .= "{$nation['name']}({$nation['power']}/{$nation['gennum']}/{$city['cnt']}/{$city['pop']}/{$city['pop2']}/{$nation['goldrice']}/{$general['goldrice']}/{$general['abil']}/{$general['dex']}/{$general['expded']}), "; + $powerHist .= "{$nation['name']}({$nation['power']}/{$nation['gennum']}/{$city['cnt']}/{$city['pop']}/{$city['pop2']}/{$nation['goldrice']}/{$general['goldrice']}/{$general['abil']}/{$general['dex']}/{$general['expded']}), "; if(!isset($nationHists[$nation['type']])){ $nationHists[$nation['type']] = 0; @@ -997,26 +1023,21 @@ function checkStatistic() { $nationHists[$nation['type']]++; } + $auxData['nations']['all'] = $nations; + $nationHist = ''; for($i=1; $i <= 13; $i++) { if(!Util::array_get($nationHists[$i])) { $nationHists[$i] = '-'; } $nationHist .= getNationType($i)."({$nationHists[$i]}), "; } - $query = "select no from general where npc <= 1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $genCount = MYDB_num_rows($result); + $generals = $db->query('SELECT `no`,npc,personal,special,special2,crewtype FROM general'); - $query = "select no from general where npc > 1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $npcCount = MYDB_num_rows($result); - - $query = "select personal,special,special2 from general"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $generalCount = MYDB_num_rows($result); - for($i=0; $i < $generalCount; $i++) { - $general = MYDB_fetch_array($result); + $genCount = 0; + $npcCount = 0; + $generalCount = count($generals); + foreach($generals as $general) { if(!isset($personalHists[$general['personal']])){ $personalHists[$general['personal']] = 0; } @@ -1029,70 +1050,73 @@ function checkStatistic() { $specialHists2[$general['special2']] = 0; } + if($general['npc'] < 2){ + $genCount+=1; + } + else{ + $npcCount+=1; + } + $personalHists[$general['personal']]++; $specialHists[$general['special']]++; $specialHists2[$general['special2']]++; } + foreach($db->queryAllLists( + 'SELECT crewtype, count(crewtype) AS cnt FROM general WHERE crew>=100 OR deathnum>0 GROUP BY crewtype' + ) as [$crewtype, $cnt] + ){ + $crewtypeHists[$crewtype] = $cnt; + } + + $auxData['generals']['hists'] = [ + 'personal' => $personalHists, + 'special' => $specialHists, + 'special2' => $specialHists2, + 'crewtype' => $crewtypeHists, + 'userCnt' => $genCount, + 'npcCnt' => $npcCount, + ]; + $generalCountStr = "{$generalCount}({$genCount}+{$npcCount})"; - $personalHist = ''; - for($i=0; $i < 11; $i++) { - if(!Util::array_get($personalHists[$i])) { $personalHists[$i] = '-'; } - $personalHist .= getGenChar($i)."({$personalHists[$i]}), "; - } - $specialHist = ''; - for($i=0; $i < 40; $i++) { - $call = getGenSpecial($i); - if($call) { - if(!Util::array_get($specialHists[$i])) { $specialHists[$i] = '-'; } + $personalHistStr = join(', ', array_map(function($histPair){ + [$histKey, $cnt] = $histPair; + return getGenChar($histKey).'('.$cnt.')'; + }, Util::convertDictToArray($personalHists))); - $specialHist .= $call."({$specialHists[$i]}), "; - } - } - $specialHist .= '// '; - $specialHist .= "-({$specialHists2[0]}), "; - for($i=40; $i < 80; $i++) { - $call = getGenSpecial($i); - if($call) { - if(!Util::array_get($specialHists2[$i])) { $specialHists2[$i] = '-'; } + $specialHistsStr = join(', ', array_map(function($histPair){ + [$histKey, $cnt] = $histPair; + return getGenSpecial($histKey).'('.$cnt.')'; + }, Util::convertDictToArray($specialHists))); - $specialHist .= $call."({$specialHists2[$i]}), "; - } - } + $specialHists2Str = join(', ', array_map(function($histPair){ + [$histKey, $cnt] = $histPair; + return getGenSpecial($histKey).'('.$cnt.')'; + }, Util::convertDictToArray($specialHists2))); - $crewtype = ''; - $types = array(0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43); - $count = count($types); - foreach(GameUnitConst::all() as $unit){ - $userCnt = DB::db()->queryFirstField( - "SELECT count(*) as type from general where crewtype=%i and crew>=100", - $unit->id - ); - $crewtype .= "{$unit->name}({$userCnt}), "; - } - for($i=0; $i < $count; $i++) { - - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); + $specialHistsAllStr = "$specialHistsStr // $specialHists2Str"; - - } + $crewtypeHistsStr = join(', ', array_map(function($histPair){ + [$histKey, $cnt] = $histPair; + return getGenSpecial($histKey).'('.$cnt.')'; + }, Util::convertDictToArray($crewtypeHists))); + + $db->insert('statistic', [ + 'year'=>$admin['year'], + 'month'=>$admin['month'], + 'nation_count'=>$nationCount, + 'nation_name'=>$nationName, + 'nation_hist'=>$nationHist, + 'gen_count'=>$generalCountStr, + 'personal_hist'=>$personalHistStr, + 'special_hist'=>$specialHistsAllStr, + 'power_hist'=>$powerHist, + 'crewtype'=>$crewtypeHistsStr, + 'etc'=>$etc, + 'aux'=>Json::encode($auxData) + ]); - - $query = " - insert into statistic ( - year, month, - nation_count, nation_name, nation_hist, - gen_count, personal_hist, special_hist, power_hist, - crewtype, etc - ) values ( - '{$admin['year']}', '{$admin['month']}', - '$nationCount', '$nationName', '$nationHist', - '$generalCountStr', '$personalHist', '$specialHist', '$power_hist', - '$crewtype', '$etc' - )"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } function checkEmperior() { @@ -1106,204 +1130,209 @@ function checkEmperior() { $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $count = MYDB_num_rows($result); - if($count == 1 && $admin['isunited'] == 0) { - $nation = MYDB_fetch_array($result); + if ($count != 1 || $admin['isunited'] != 0) { + return; + } - $query = "select city from city where nation='{$nation['nation']}'"; + checkStatistic(); + + $nation = MYDB_fetch_array($result); + + $query = "select city from city where nation='{$nation['nation']}'"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $count = MYDB_num_rows($result); + + $query = "select city from city"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $allcount = MYDB_num_rows($result); + + if($count == $allcount) { + + $josaYi = JosaUtil::pick($nation['name'], '이'); + + pushNationHistory($nation, "●{$admin['year']}년 {$admin['month']}월:{$nation['name']}{$josaYi} 전토를 통일"); + + $gameStor->isunited = 2; + $gameStor->conlimit = $gameStor->conlimit*100; + + $query = "select no from general where npc<2 and age>=40"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $count = MYDB_num_rows($result); - $query = "select city from city"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $allcount = MYDB_num_rows($result); - - if($count == $allcount) { - - $josaYi = JosaUtil::pick($nation['name'], '이'); - - pushNationHistory($nation, "●{$admin['year']}년 {$admin['month']}월:{$nation['name']}{$josaYi} 전토를 통일"); - - $gameStor->isunited = 2; - $gameStor->conlimit = $gameStor->conlimit*100; - - $query = "select no from general where npc<2 and age>=40"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $count = MYDB_num_rows($result); - - for($i=0; $i < $count; $i++) { - $general = MYDB_fetch_array($result); - CheckHall($general['no']); - } - - $query = "select nation,name,type,color,gold,rice,power,gennum from nation where nation='{$nation['nation']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $nation = MYDB_fetch_array($result); - - $query = "select SUM(pop) as totalpop,SUM(pop2) as maxpop from city where nation='{$nation['nation']}'"; // 도시 이름 목록 - $cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($cityresult); - $pop = "{$city['totalpop']} / {$city['maxpop']}"; - $poprate = round($city['totalpop']/$city['maxpop']*100, 2); - $poprate .= " %"; - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='12'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level12 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='11'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level11 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='10'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level10 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='9'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level9 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='8'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level8 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='7'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level7 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='6'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level6 = MYDB_fetch_array($genresult); - - $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='5'"; - $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $level5 = MYDB_fetch_array($genresult); - - $oldNation = $db->queryFirstRow('SELECT * FROM nation WHERE nation=%i', $nation['nation']); - $oldNationGenerals = $db->query('SELECT * FROM general WHERE nation=%i', $nation['nation']); - $oldNation['generals'] = $oldNationGenerals; - - $query = "select name,picture,killnum from general where nation='{$nation['nation']}' order by killnum desc limit 5"; // 오호장군 - $tigerresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $tigernum = MYDB_num_rows($tigerresult); - $tigerstr = ''; - for($i=0; $i < $tigernum; $i++) { - $tiger = MYDB_fetch_array($tigerresult); - if($tiger['killnum'] > 0) { - $tigerstr .= "{$tiger['name']}【{$tiger['killnum']}】, "; - } - } - - $query = "select name,picture,firenum from general where nation='{$nation['nation']}' order by firenum desc limit 7"; // 건안칠자 - $eagleresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $eaglenum = MYDB_num_rows($eagleresult); - $eaglestr = ''; - for($i=0; $i < $eaglenum; $i++) { - $eagle = MYDB_fetch_array($eagleresult); - if($eagle['firenum'] > 0) { - $eaglestr .= "{$eagle['name']}【{$eagle['firenum']}】, "; - } - } - - $log = ["●{$admin['year']}년 {$admin['month']}월: {$nation['name']}{$josaYi} 전토를 통일하였습니다."]; - - $query = "select no,name from general where nation='{$nation['nation']}' order by dedication desc"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $gencount = MYDB_num_rows($result); - $gen = ''; - for($i=0; $i < $gencount; $i++) { - $general = MYDB_fetch_array($result); - $gen .= "{$general['name']}, "; - - pushGenLog($general, $log); - } - - $nation['type'] = getNationType($nation['type']); - - $query = "select MAX(nation_count) as nc,MAX(gen_count) as gc from statistic"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $stat = MYDB_fetch_array($result); - - $query = "select count(*) as cnt from general"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $gencount = MYDB_fetch_array($result); - - $statNC = "1 / {$stat['nc']}"; - $statGC = "{$gencount['cnt']} / {$stat['gc']}"; - - $query = "select nation_count,nation_name,nation_hist from statistic where nation_count='{$stat['nc']}' limit 0,1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $statNation = MYDB_fetch_array($result); - - $query = "select gen_count,personal_hist,special_hist from statistic order by no desc limit 0,1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $statGeneral = MYDB_fetch_array($result); - - $oldNation = $db->queryFirstRow('SELECT * FROM nation WHERE nation=%i', $nation['nation']); - $oldNation['generals'] = $db->query('SELECT * FROM general WHERE nation=%i', $nation['nation']); - - $db->insert('ng_old_nations', [ - 'server_id'=>UniqueConst::$serverID, - 'nation'=>$nation['nation'], - 'data'=>Json::encode($oldNation) - ]); - - $noNationGeneral = $db->query('SELECT * FROM general WHERE nation=0'); - $db->insert('ng_old_nations', [ - 'server_id'=>UniqueConst::$serverID, - 'nation'=>0, - 'data'=>Json::encode($noNationGeneral) - ]); - - $nationHistory = DB::db()->queryFirstField('SELECT `history` FROM `nation` WHERE `nation` = %i', $nation['nation']); - - $db->insert('emperior', [ - 'phase'=>'-', - 'server_id'=>UniqueConst::$serverID, - 'nation_count'=>$statNC, - 'nation_name'=>$statNation['nation_name'], - 'nation_hist'=>$statNation['nation_hist'], - 'gen_count'=>$statGC, - 'personal_hist'=>$statGeneral['personal_hist'], - 'special_hist'=>$statGeneral['special_hist'], - 'name'=>$nation['name'], - 'type'=>$nation['type'], - 'color'=>$nation['color'], - 'year'=>$admin['year'], - 'month'=>$admin['month'], - 'power'=>$nation['power'], - 'gennum'=>$nation['gennum'], - 'citynum'=>$allcount, - 'pop'=>$pop, - 'poprate'=>$poprate, - 'gold'=>$nation['gold'], - 'rice'=>$nation['rice'], - 'l12name'=>$level12['name'], - 'l12pic'=>$level12['picture'], - 'l11name'=>$level11['name'], - 'l11pic'=>$level11['picture'], - 'l10name'=>$level10['name'], - 'l10pic'=>$level10['picture'], - 'l9name'=>$level9['name'], - 'l9pic'=>$level9['picture'], - 'l8name'=>$level8['name'], - 'l8pic'=>$level8['picture'], - 'l7name'=>$level7['name'], - 'l7pic'=>$level7['picture'], - 'l6name'=>$level6['name'], - 'l6pic'=>$level6['picture'], - 'l5name'=>$level5['name'], - 'l5pic'=>$level5['picture'], - 'tiger'=>$tigerstr, - 'eagle'=>$eaglestr, - 'gen'=>$gen, - 'history'=>$nationHistory - ]); - - $history = ["●{$admin['year']}년 {$admin['month']}월:【통일】{$nation['name']}{$josaYi} 전토를 통일하였습니다."]; - pushWorldHistory($history, $admin['year'], $admin['month']); - - //연감 월결산 - LogHistory(); + for($i=0; $i < $count; $i++) { + $general = MYDB_fetch_array($result); + CheckHall($general['no']); } + + $query = "select nation,name,type,color,gold,rice,power,gennum from nation where nation='{$nation['nation']}'"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $nation = MYDB_fetch_array($result); + + $query = "select SUM(pop) as totalpop,SUM(pop2) as maxpop from city where nation='{$nation['nation']}'"; // 도시 이름 목록 + $cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $city = MYDB_fetch_array($cityresult); + $pop = "{$city['totalpop']} / {$city['maxpop']}"; + $poprate = round($city['totalpop']/$city['maxpop']*100, 2); + $poprate .= " %"; + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='12'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level12 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='11'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level11 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='10'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level10 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='9'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level9 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='8'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level8 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='7'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level7 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='6'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level6 = MYDB_fetch_array($genresult); + + $query = "select name,picture,belong from general where nation='{$nation['nation']}' and level='5'"; + $genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $level5 = MYDB_fetch_array($genresult); + + $oldNation = $db->queryFirstRow('SELECT * FROM nation WHERE nation=%i', $nation['nation']); + $oldNationGenerals = $db->query('SELECT * FROM general WHERE nation=%i', $nation['nation']); + $oldNation['generals'] = $oldNationGenerals; + + $query = "select name,picture,killnum from general where nation='{$nation['nation']}' order by killnum desc limit 5"; // 오호장군 + $tigerresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $tigernum = MYDB_num_rows($tigerresult); + $tigerstr = ''; + for($i=0; $i < $tigernum; $i++) { + $tiger = MYDB_fetch_array($tigerresult); + if($tiger['killnum'] > 0) { + $tigerstr .= "{$tiger['name']}【{$tiger['killnum']}】, "; + } + } + + $query = "select name,picture,firenum from general where nation='{$nation['nation']}' order by firenum desc limit 7"; // 건안칠자 + $eagleresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $eaglenum = MYDB_num_rows($eagleresult); + $eaglestr = ''; + for($i=0; $i < $eaglenum; $i++) { + $eagle = MYDB_fetch_array($eagleresult); + if($eagle['firenum'] > 0) { + $eaglestr .= "{$eagle['name']}【{$eagle['firenum']}】, "; + } + } + + $log = ["●{$admin['year']}년 {$admin['month']}월: {$nation['name']}{$josaYi} 전토를 통일하였습니다."]; + + $query = "select no,name from general where nation='{$nation['nation']}' order by dedication desc"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $gencount = MYDB_num_rows($result); + $gen = ''; + for($i=0; $i < $gencount; $i++) { + $general = MYDB_fetch_array($result); + $gen .= "{$general['name']}, "; + + pushGenLog($general, $log); + } + + $nation['type'] = getNationType($nation['type']); + + $query = "select MAX(nation_count) as nc,MAX(gen_count) as gc from statistic"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $stat = MYDB_fetch_array($result); + + $query = "select count(*) as cnt from general"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $gencount = MYDB_fetch_array($result); + + $statNC = "1 / {$stat['nc']}"; + $statGC = "{$gencount['cnt']} / {$stat['gc']}"; + + $query = "select nation_count,nation_name,nation_hist from statistic where nation_count='{$stat['nc']}' limit 0,1"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $statNation = MYDB_fetch_array($result); + + $query = "select gen_count,personal_hist,special_hist,aux from statistic order by no desc limit 0,1"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $statGeneral = MYDB_fetch_array($result); + + $oldNation = $db->queryFirstRow('SELECT * FROM nation WHERE nation=%i', $nation['nation']); + $oldNation['generals'] = $db->query('SELECT * FROM general WHERE nation=%i', $nation['nation']); + + $db->insert('ng_old_nations', [ + 'server_id'=>UniqueConst::$serverID, + 'nation'=>$nation['nation'], + 'data'=>Json::encode($oldNation) + ]); + + $noNationGeneral = $db->query('SELECT * FROM general WHERE nation=0'); + $db->insert('ng_old_nations', [ + 'server_id'=>UniqueConst::$serverID, + 'nation'=>0, + 'data'=>Json::encode($noNationGeneral) + ]); + + $nationHistory = DB::db()->queryFirstField('SELECT `history` FROM `nation` WHERE `nation` = %i', $nation['nation']); + + $db->insert('emperior', [ + 'phase'=>'-', + 'server_id'=>UniqueConst::$serverID, + 'nation_count'=>$statNC, + 'nation_name'=>$statNation['nation_name'], + 'nation_hist'=>$statNation['nation_hist'], + 'gen_count'=>$statGC, + 'personal_hist'=>$statGeneral['personal_hist'], + 'special_hist'=>$statGeneral['special_hist'], + 'name'=>$nation['name'], + 'type'=>$nation['type'], + 'color'=>$nation['color'], + 'year'=>$admin['year'], + 'month'=>$admin['month'], + 'power'=>$nation['power'], + 'gennum'=>$nation['gennum'], + 'citynum'=>$allcount, + 'pop'=>$pop, + 'poprate'=>$poprate, + 'gold'=>$nation['gold'], + 'rice'=>$nation['rice'], + 'l12name'=>$level12['name'], + 'l12pic'=>$level12['picture'], + 'l11name'=>$level11['name'], + 'l11pic'=>$level11['picture'], + 'l10name'=>$level10['name'], + 'l10pic'=>$level10['picture'], + 'l9name'=>$level9['name'], + 'l9pic'=>$level9['picture'], + 'l8name'=>$level8['name'], + 'l8pic'=>$level8['picture'], + 'l7name'=>$level7['name'], + 'l7pic'=>$level7['picture'], + 'l6name'=>$level6['name'], + 'l6pic'=>$level6['picture'], + 'l5name'=>$level5['name'], + 'l5pic'=>$level5['picture'], + 'tiger'=>$tigerstr, + 'eagle'=>$eaglestr, + 'gen'=>$gen, + 'history'=>$nationHistory, + 'aux'=>$statGeneral['aux'] + ]); + + $history = ["●{$admin['year']}년 {$admin['month']}월:【통일】{$nation['name']}{$josaYi} 전토를 통일하였습니다."]; + pushWorldHistory($history, $admin['year'], $admin['month']); + + //연감 월결산 + LogHistory(); } } diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql index eafa5246..d4cf76eb 100644 --- a/hwe/sql/schema.sql +++ b/hwe/sql/schema.sql @@ -363,7 +363,7 @@ ENGINE=InnoDB; ## 명전 테이블 ########################################################################### -CREATE TABLE if not exists `ng_hall` ( +CREATE TABLE IF NOT EXISTS `ng_hall` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `server_id` CHAR(20) NOT NULL, `scenario` INT(11) NOT NULL, @@ -385,7 +385,7 @@ ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPRESSED; ## 왕조 테이블 ########################################################################### -CREATE TABLE if not exists `ng_games` ( +CREATE TABLE IF NOT EXISTS `ng_games` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `server_id` CHAR(20) NOT NULL, `date` DATETIME NOT NULL, @@ -399,7 +399,7 @@ CREATE TABLE if not exists `ng_games` ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; -CREATE TABLE if not exists `ng_old_nations` ( +CREATE TABLE IF NOT EXISTS `ng_old_nations` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `server_id` CHAR(20) NOT NULL DEFAULT '0', `nation` INT(11) NOT NULL DEFAULT '0', @@ -410,42 +410,51 @@ CREATE TABLE if not exists `ng_old_nations` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPRESSED; -create table if not exists emperior ( - no int(6) not null auto_increment, - phase char(255) default '', - nation_count char(64) default '', - nation_name text default '', - nation_hist text default '', - gen_count char(64) default '', - personal_hist text default '', - special_hist text default '', - name char(64) default '', - type char(64) default '', - color char(7) default '', - year int(4) default 0, - month int(2) default 0, - power int(8) default 0, - gennum int(3) default 0, - citynum int(3) default 0, - pop char(255) default 0, - poprate char(255) default '', - gold int(9) default 0, - rice int(9) default 0, - l12name char(64) default '', l12pic char(32) default '', - l11name char(64) default '', l11pic char(32) default '', - l10name char(64) default '', l10pic char(32) default '', - l9name char(64) default '', l9pic char(32) default '', - l8name char(64) default '', l8pic char(32) default '', - l7name char(64) default '', l7pic char(32) default '', - l6name char(64) default '', l6pic char(32) default '', - l5name char(64) default '', l5pic char(32) default '', - tiger char(64) default '', - eagle char(64) default '', - gen text default '', - history mediumtext default '', - - PRIMARY KEY (no) - ) ENGINE=INNODB ROW_FORMAT=COMPRESSED DEFAULT CHARSET=utf8mb4; +CREATE TABLE IF NOT EXISTS `emperior` ( + `no` INT(6) NOT NULL AUTO_INCREMENT, + `server_id` CHAR(20) NULL DEFAULT '', + `phase` CHAR(255) NULL DEFAULT '', + `nation_count` CHAR(64) NULL DEFAULT '', + `nation_name` TEXT NULL DEFAULT '', + `nation_hist` TEXT NULL DEFAULT '', + `gen_count` CHAR(64) NULL DEFAULT '', + `personal_hist` TEXT NULL DEFAULT '', + `special_hist` TEXT NULL DEFAULT '', + `name` CHAR(64) NULL DEFAULT '', + `type` CHAR(64) NULL DEFAULT '', + `color` CHAR(7) NULL DEFAULT '', + `year` INT(4) NULL DEFAULT '0', + `month` INT(2) NULL DEFAULT '0', + `power` INT(8) NULL DEFAULT '0', + `gennum` INT(3) NULL DEFAULT '0', + `citynum` INT(3) NULL DEFAULT '0', + `pop` CHAR(255) NULL DEFAULT '0', + `poprate` CHAR(255) NULL DEFAULT '', + `gold` INT(9) NULL DEFAULT '0', + `rice` INT(9) NULL DEFAULT '0', + `l12name` CHAR(64) NULL DEFAULT '', + `l12pic` CHAR(32) NULL DEFAULT '', + `l11name` CHAR(64) NULL DEFAULT '', + `l11pic` CHAR(32) NULL DEFAULT '', + `l10name` CHAR(64) NULL DEFAULT '', + `l10pic` CHAR(32) NULL DEFAULT '', + `l9name` CHAR(64) NULL DEFAULT '', + `l9pic` CHAR(32) NULL DEFAULT '', + `l8name` CHAR(64) NULL DEFAULT '', + `l8pic` CHAR(32) NULL DEFAULT '', + `l7name` CHAR(64) NULL DEFAULT '', + `l7pic` CHAR(32) NULL DEFAULT '', + `l6name` CHAR(64) NULL DEFAULT '', + `l6pic` CHAR(32) NULL DEFAULT '', + `l5name` CHAR(64) NULL DEFAULT '', + `l5pic` CHAR(32) NULL DEFAULT '', + `tiger` CHAR(64) NULL DEFAULT '', + `eagle` CHAR(64) NULL DEFAULT '', + `gen` TEXT NULL DEFAULT '', + `history` MEDIUMTEXT NULL DEFAULT '', + `aux` MEDIUMTEXT NULL DEFAULT '' COMMENT 'json', + PRIMARY KEY (`no`) +) ENGINE=INNODB ROW_FORMAT=COMPRESSED DEFAULT CHARSET=utf8mb4; ########################################################################### ## 외교 테이블 @@ -513,27 +522,28 @@ create table auction ( ########################################################################### ## 통계 테이블 ########################################################################### -create table statistic ( - no int(6) not null auto_increment, - year int(4) default 0, - month int(2) default 0, - nation_count int(2) default 0, - nation_name text default '', - nation_hist text default '', - gen_count varchar(32) default '', - personal_hist text default '', - special_hist text default '', - power_hist text default '', - crewtype text default '', - etc text default '', - - PRIMARY KEY (no) - ) ENGINE=INNODB ROW_FORMAT=COMPRESSED DEFAULT CHARSET=utf8mb4; +CREATE TABLE `statistic` ( + `no` INT(6) NOT NULL AUTO_INCREMENT, + `year` INT(4) NULL DEFAULT '0', + `month` INT(2) NULL DEFAULT '0', + `nation_count` INT(2) NULL DEFAULT '0', + `nation_name` TEXT NULL DEFAULT '', + `nation_hist` TEXT NULL DEFAULT '', + `gen_count` VARCHAR(32) NULL DEFAULT '', + `personal_hist` TEXT NULL DEFAULT '', + `special_hist` TEXT NULL DEFAULT '', + `power_hist` TEXT NULL DEFAULT '', + `crewtype` TEXT NULL DEFAULT '', + `etc` TEXT NULL DEFAULT '', + `aux` TEXT NULL DEFAULT '' COMMENT 'json', + PRIMARY KEY (`no`) +) +ENGINE=INNODB ROW_FORMAT=COMPRESSED DEFAULT CHARSET=utf8mb4; ########################################################################### ## 연감 테이블 ########################################################################### -CREATE TABLE if not exists `history` ( +CREATE TABLE IF NOT EXISTS `history` ( `no` INT(6) NOT NULL AUTO_INCREMENT, `server_id` CHAR(20) NOT NULL DEFAULT '', `year` INT(4) NULL DEFAULT '0', @@ -621,7 +631,7 @@ ENGINE=MyISAM; ################### # KV storage ################### -CREATE TABLE if not exists `storage` ( +CREATE TABLE IF NOT EXISTS `storage` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `namespace` VARCHAR(40) NOT NULL, `key` VARCHAR(40) NOT NULL, diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 86c944c2..fdce6f0a 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -187,11 +187,11 @@ class Util extends \utilphp\util return $str; } - public static function mapWithDict($callback, $dict) + public static function mapWithKey($callback, $dict) { $result = []; foreach (array_keys($dict) as $key) { - $result[$key] = ($callback)($dict[$key]); + $result[$key] = ($callback)($key, $dict[$key]); } return $result; } @@ -208,13 +208,19 @@ class Util extends \utilphp\util return $result; } - public static function convertDictToArray($dict, $keys) + public static function convertDictToArray($dict, bool $withKey=true) { $result = []; - foreach ($keys as $key) { - $result[] = Util::array_get($dict[$key], null); + foreach($dict as $key=>$value){ + if($withKey){ + $result[] = [$key, $value]; + } + else{ + $result[] = $value; + } } + return $result; }