=2";
-} else {
- $sel = "npc<2";
-}
-$nationName = ['재야'];
-$nationColor = ['#000000'];
+
+$nationName = [0=>'재야'];
+$nationColor = [0=>'#000000'];
foreach (getAllNationStaticInfo() as $nation) {
$nationName[$nation['nation']] = $nation['name'];
$nationColor[$nation['nation']] = $nation['color'];
}
-$type = array(
- "명 성",
- "계 급",
- "계 략 성 공",
- "전 투 횟 수",
- "승 리",
- "승 률",
- "사 살",
- "살 상 률",
- "보 병 숙 련 도",
- "궁 병 숙 련 도",
- "기 병 숙 련 도",
- "귀 병 숙 련 도",
- "차 병 숙 련 도",
- "전 력 전 승 률",
- "통 솔 전 승 률",
- "일 기 토 승 률",
- "설 전 승 률",
- "베 팅 투 자 액",
- "베 팅 당 첨",
- "베 팅 수 익 금",
- "베 팅 수 익 률"
-);
+$types = [
+ ["명 성", "int", function($v){$v['value'] = $v['experience']; return $v; }],
+ ["계 급", "int", function($v){$v['value'] = $v['dedication']; return $v; }],
+ ["계 략 성 공", "int", function($v){
+ $v['value'] = $v['firenum'];
+ $v['nationName'] = '???';
+ $v['pictureFullPath'] = GetImageURL(0)."/default.jpg";
+ $v['name'] = '???';
+ $v['owner_name'] = null;
+ $v['bgColor'] = GameConst::$basecolor4;
+ $v['fgColor'] = newColor($v['bgColor']);
+ return $v;
+ }],
+ ["전 투 횟 수", "int", function($v){$v['value'] = $v['warnum']; return $v; }],
+ ["승 리", "int", function($v){$v['value'] = $v['killnum']; return $v; }],
+ ["승 률", "percent", function($v){$v['value'] = $v['killnum'] / max(1, $v['warnum']); return $v; }],
+ ["사 살", "int", function($v){$v['value'] = $v['killcrew']; return $v; }],
+ ["살 상 률", "percent", function($v){$v['value'] = $v['killcrew'] / max(1, $v['deathcrew']); return $v; }],
+ ["보 병 숙 련 도", "int", function($v){$v['value'] = $v['dex0']; return $v; }],
+ ["궁 병 숙 련 도", "int", function($v){$v['value'] = $v['dex10']; return $v; }],
+ ["기 병 숙 련 도", "int", function($v){$v['value'] = $v['dex20']; return $v; }],
+ ["귀 병 숙 련 도", "int", function($v){$v['value'] = $v['dex30']; return $v; }],
+ ["차 병 숙 련 도", "int", function($v){$v['value'] = $v['dex40']; return $v; }],
+ ["전 력 전 승 률", "percent", function($v){$v['value'] = $v['ttw']/max(1, $v['ttw']+$v['ttd']+$v['ttl']); return $v; }],
+ ["통 솔 전 승 률", "percent", function($v){$v['value'] = $v['tlw']/max(1, $v['tlw']+$v['tld']+$v['tll']); return $v; }],
+ ["일 기 토 승 률", "percent", function($v){$v['value'] = $v['tpw']/max(1, $v['tpw']+$v['tpd']+$v['tpl']); return $v; }],
+ ["설 전 승 률", "percent", function($v){$v['value'] = $v['ttw']/max(1, $v['tiw']+$v['tid']+$v['til']); return $v; }],
+ ["베 팅 투 자 액", "int", function($v){$v['value'] = $v['betgold']; return $v; }],
+ ["베 팅 당 첨", "int", function($v){$v['value'] = $v['betwin']; return $v; }],
+ ["베 팅 수 익 금", "int", function($v){$v['value'] = $v['betwingold']; return $v; }],
+ ["베 팅 수 익 률", "percent", function($v){$v['value'] = $v['betwingold']/max(1, $v['betgold']); return $v; }],
+];
-
-for ($i=0; $i < 21; $i++) {
- $name = [];
- $data = [];
- $color = [];
- $pic = [];
-
- //FIXME: 쿼리에 index를 사용할 수 없는 녀석들이 있다. 그냥 모두 받아서 일괄 처리하는게 더 나을 수도 있음.
- switch ($i) {
- case 0: $query = "select nation,no,name,picture,imgsvr,experience as data from general where $sel order by data desc limit 0,10"; break;
- case 1: $query = "select nation,no,name,picture,imgsvr,dedication as data from general where $sel order by data desc limit 0,10"; break;
- case 2: $query = "select nation,no,name,picture,imgsvr,firenum as data from general where $sel order by data desc limit 0,10"; break;
- case 3: $query = "select nation,no,name,picture,imgsvr,warnum as data from general where $sel order by data desc limit 0,10"; break;
- case 4: $query = "select nation,no,name,picture,imgsvr,killnum as data from general where $sel order by data desc limit 0,10"; break;
- case 5: $query = "select nation,no,name,picture,imgsvr,killnum/warnum*10000 as data from general where warnum>=10 and $sel order by data desc limit 0,10"; break;
- case 6: $query = "select nation,no,name,picture,imgsvr,killcrew as data from general where $sel order by data desc limit 0,10"; break;
- case 7: $query = "select nation,no,name,picture,imgsvr,killcrew/deathcrew*10000 as data from general where warnum>=10 and $sel order by data desc limit 0,10"; break;
- case 8: $query = "select nation,no,name,picture,imgsvr,dex0 as data from general where $sel order by data desc limit 0,10"; break;
- case 9: $query = "select nation,no,name,picture,imgsvr,dex10 as data from general where $sel order by data desc limit 0,10"; break;
- case 10: $query = "select nation,no,name,picture,imgsvr,dex20 as data from general where $sel order by data desc limit 0,10"; break;
- case 11: $query = "select nation,no,name,picture,imgsvr,dex30 as data from general where $sel order by data desc limit 0,10"; break;
- case 12: $query = "select nation,no,name,picture,imgsvr,dex40 as data from general where $sel order by data desc limit 0,10"; break;
- case 13: $query = "select nation,no,name,picture,imgsvr,ttw/(ttw+ttd+ttl)*10000 as data from general where $sel and (ttw+ttd+ttl)>=50 order by data desc limit 0,10"; break;
- case 14: $query = "select nation,no,name,picture,imgsvr,tlw/(tlw+tld+tll)*10000 as data from general where $sel and (tlw+tld+tll)>=50 order by data desc limit 0,10"; break;
- case 15: $query = "select nation,no,name,picture,imgsvr,tpw/(tpw+tpd+tpl)*10000 as data from general where $sel and (tpw+tpd+tpl)>=50 order by data desc limit 0,10"; break;
- case 16: $query = "select nation,no,name,picture,imgsvr,tiw/(tiw+tid+til)*10000 as data from general where $sel and (tiw+tid+til)>=50 order by data desc limit 0,10"; break;
- case 17: $query = "select nation,no,name,picture,imgsvr,betgold as data from general where $sel order by data desc limit 0,10"; break;
- case 18: $query = "select nation,no,name,picture,imgsvr,betwin as data from general where $sel order by data desc limit 0,10"; break;
- case 19: $query = "select nation,no,name,picture,imgsvr,betwingold as data from general where $sel order by data desc limit 0,10"; break;
- case 20: $query = "select nation,no,name,picture,imgsvr,betwingold/betgold*10000 as data from general where $sel and betgold >= 1000 order by data desc limit 0,10"; break;
+$generals = array_map(function($general) use($nationColor, $nationName) {
+ $general['bgColor'] = $nationColor[$general['nation']]??GameConst::$basecolor4;
+ $general['fgColor'] = newColor($general['bgColor']);
+ $general['nationName'] = $nationName[$general['nation']];
+
+ if(key_exists('picture', $general)){
+ $imageTemp = GetImageURL($general['imgsvr']);
+ $general['pictureFullPath'] = "$imageTemp/{$general['picture']}";
}
- $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), "");
-
- echo "
-
| $type[$i] |
-
| 1위 | 2위 | 3위 | 4위 | 5위 | 6위 | 7위 | 8위 | 9위 | 10위 |
-
";
-
- for ($k=0; $k < 10; $k++) {
- $gen = MYDB_fetch_array($result);
-
- if ($i != 2) {
- if (isset($gen)) {
- $name[$k] = $gen['name'];
- $nation[$k] = $nationName[$gen['nation']];
- $data[$k] = $gen['data'];
- $color[$k] = $nationColor[$gen['nation']];
- $pic[$k] = $gen['picture'];
- } else {
- $name[$k] = "-";
- $nation[$k] = "-";
- $data[$k] = "-";
- $color[$k] = GameConst::$basecolor4;
- $pic[$k] = "";
- }
- } else {
- $name[$k] = "???";
- $nation[$k] = "???";
- $data[$k] = $gen['data'];
- $color[$k] = GameConst::$basecolor4;
- $gen['imgsvr'] = 0;
- $pic[$k] = "9999.jpg";
- }
- if ($color[$k] == "") {
- $color[$k] = GameConst::$basecolor4;
- }
- if ($nation[$k] == "") {
- $nation[$k] = " ";
- }
- if ($pic[$k] == "") {
- echo "| | ";
- } else {
- $imageTemp = GetImageURL($gen['imgsvr']);
- echo " | ";
- }
+ else{
+ $general['pictureFullPath'] = GetImageURL(0)."/default.jpg";
}
- echo "
";
+ return $general;
+}, $db->query(
+ "SELECT nation,no,name,name2 as owner_name, picture, imgsvr,
+ experience, dedication, firenum, warnum, killnum, killcrew, deathcrew,
+ dex0, dex10, dex20, dex30, dex40,
+ ttw, ttd, ttl, tlw, tld, tll, tpw, tpd, tpl, tiw, tid, til,
+ betgold, betwin, betwingold,
+ horse, weap, book, item
+ FROM general WHERE %l", $btn == "NPC 보기"?"npc>=2":"npc<2"));
- for ($k=0; $k < 10; $k++) {
- echo "| {$nation[$k]} | ";
- }
- echo "
";
+$templates = new \League\Plates\Engine('templates');
- for ($k=0; $k < 10; $k++) {
- echo "| {$name[$k]} | ";
- }
+foreach($types as $idx=>[$typeName, $typeValue, $typeFunc]){
+ $typeGenerals = array_map(function($general) use($typeValue, $typeFunc){
+ $general = ($typeFunc)($general);
+ $value = $general['value'];
- echo "
";
-
- for ($k=0; $k < 10; $k++) {
- if($data[$k] === '-'){
- //do Nothing
+ if($typeValue == 'percent'){
+ $general['printValue'] = number_format($value*100, 2).'%';
}
- else if ($i == 5 || $i == 7 || $i == 20) {
- $data[$k] = intdiv($data[$k], 100).".".($data[$k]%100)." %";
+ else {
+ $general['printValue'] = number_format($value);
}
- else if ($i >= 13 && $i <= 16) {
- $data[$k] = intdiv($data[$k], 100).".".($data[$k]%100)." %";
- }
- echo "| {$data[$k]} | ";
- }
- echo "
|
";
+ return $general;
+ }, $generals);
+
+ usort($typeGenerals, function($lhs, $rhs){
+ //내림차순
+ return -($lhs['value'] - $rhs['value']);
+ });
+
+ echo $templates->render('hallOfFrame', [
+ 'typeName'=>$typeName,
+ 'generals'=>array_slice($typeGenerals, 0, 10, true)
+ ]);
}
-
-echo "
-