diff --git a/hwe/MYDB.php b/hwe/MYDB.php index 7508470a..6a8478dd 100644 --- a/hwe/MYDB.php +++ b/hwe/MYDB.php @@ -9,6 +9,9 @@ function MYDB_num_rows($result) { return mysqli_num_rows($result); } +/** + * @return mixed[] + */ function MYDB_fetch_array($result) { return mysqli_fetch_array($result); } diff --git a/hwe/func.php b/hwe/func.php index 90dcb561..e3a13f19 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -283,9 +283,9 @@ function myNationInfo() { ".getLevel(12, $nation['level'])." - ";echo $level12==''?"-":"{$level12['name']}"; echo " + ";echo $level12?$level12['name']:"-"; echo " ".getLevel(11, $nation['level'])." - ";echo $level11==''?"-":"{$level11['name']}"; echo " + ";echo $level11?$level11['name']:"-"; echo " 총주민 @@ -2154,6 +2154,8 @@ function uniqueItem($general, $log, $vote=0) { $log = []; $alllog = []; $history = []; + $occupied = []; + $item = []; if($general['npc'] >= 2 || $general['betray'] > 1) { return $log; } if($general['weap'] > 6 || $general['book'] > 6 || $general['horse'] > 6 || $general['item'] > 6) { return $log; } @@ -2204,8 +2206,8 @@ function uniqueItem($general, $log, $vote=0) { $nation = getNationStaticInfo($general['nation']); - if($nation == null) { - $nation['name'] = "재야"; + if($nation === null) { + $nation = ['name' => "재야"]; } switch($sel) { @@ -2422,6 +2424,7 @@ function deleteNation($general) { $db = DB::db(); $connect=$db->get(); + $history = []; $date = substr($general['turntime'],11,5); $query = "select year,month from game limit 1"; @@ -2514,7 +2517,7 @@ function nextRuler($general) { $query = "update city set gen3=0 where gen3='{$nextruler['no']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $history[] = "●{$admin['year']}년 {$admin['month']}월:【유지】{$nextruler['name']}(이)가 {$nation['name']}의 유지를 이어 받았습니다"; + $history = ["●{$admin['year']}년 {$admin['month']}월:【유지】{$nextruler['name']}(이)가 {$nation['name']}의 유지를 이어 받았습니다"]; pushWorldHistory($history, $admin['year'], $admin['month']); pushNationHistory($nation, "●{$admin['year']}년 {$admin['month']}월:【유지】{$nextruler['name']}(이)가 {$nation['name']}의 유지를 이어 받음."); @@ -2574,7 +2577,7 @@ function isClose($nation1, $nation2) { } foreach($db->queryFirstColumn('SELECT city FROM city WHERE nation = %i', $nation2) as $city){ - foreach(array_keys(CityConst::byID($city)->$path) as $adjCity){ + foreach(array_keys(CityConst::byID($city)->path) as $adjCity){ if(key_exists($adjCity, $nation1Cities)){ return true; } @@ -2651,6 +2654,7 @@ function CharCritical($rate, $personal) { function TrickInjury($city, $type=0) { $db = DB::db(); $connect=$db->get(); + $log = []; $query = "select year,month from game limit 1"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); diff --git a/hwe/func_command.php b/hwe/func_command.php index 91e929dc..ce507312 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -254,6 +254,7 @@ function getCoreTurn($nation, $level) { $db = DB::db(); $connect=$db->get(); $str = []; + $turn = []; $turn[0] = $nation["l{$level}turn0"]; $turn[1] = $nation["l{$level}turn1"]; diff --git a/hwe/func_converter.php b/hwe/func_converter.php index 3c88b318..31e55648 100644 --- a/hwe/func_converter.php +++ b/hwe/func_converter.php @@ -395,7 +395,7 @@ function getBill($dedication) { return ($level * 200 + 400); } -function getCost($armtype) { +function getCost(int $armtype) { //FIXME: 정말로 side effect가 없으려면 query는 밖으로 이동해야함. //TODO: 병종 값이 column으로 들어있는건 전혀 옳지 않음. key->value 형태로 바꿔야함 return DB::db()->queryFirstColumn('select %b from game limit 1', sprintf('cst%d', $armtype)); diff --git a/hwe/func_diplomacy.php b/hwe/func_diplomacy.php index 50c454e7..4e5ac8ac 100644 --- a/hwe/func_diplomacy.php +++ b/hwe/func_diplomacy.php @@ -136,7 +136,7 @@ function acceptScout($messageInfo, $general, $msgResponse){ pushGenLog($me, $mylog); pushGenLog($you, $youlog); - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); + pushGeneralPublicRecord($alllog, $year, $month); pushWorldHistory($alllog, $year, $month); return [true, 'success']; @@ -149,6 +149,12 @@ function declineScout($messageInfo, $reason=null){ ]; $you = ['no'=>$messageInfo['src']['id']]; + $nation = getNationStaticInfo($messageInfo['src']['nationID']); + $generalID = $me['no']; + $nationID = $nation['nation']; + $nationName = $nation['name']; + $myName = $me['name']; + $mylog = []; $youlog = []; @@ -167,7 +173,7 @@ function declineScout($messageInfo, $reason=null){ $db = DB::db(); $db->query('UPDATE `message` SET `valid_until`=\'1234-11-22 11:22:33\' WHERE `id` = %i', $messageInfo['id']); - sendRawMessage('private', false, $general['no'], $messageInfo['src'], $messageInfo['dest'], $msg, null, null, ['parent'=>$messageInfo['id']]); + sendRawMessage('private', false, $you['no'], $messageInfo['src'], $messageInfo['dest'], $msg, null, null, ['parent'=>$messageInfo['id']]); pushGenLog($me, $mylog); pushGenLog($you, $youlog); diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 53a9c1ad..f66d0cd3 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -109,7 +109,7 @@ function getSpecial($leader, $power, $intel) { $type = array(1, 2, 3, 31); $special = $type[array_rand($type)]; // 거상, 귀모는 그중에 25% * 10% = 2.5% - if($special == 31 && randBool(0.9)) { + if($special == 31 && Util::randBool(0.9)) { $type = array(1, 2, 3); $special = $type[array_rand($type)]; } @@ -399,8 +399,7 @@ function preUpdateMonthly() { $query = "update general set crew=0,rice=0 where no='{$general['no']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $log[0] = "●군량이 모자라 병사들이 소집해제되었습니다!"; - pushGenLog($general, $log); + pushGenLog($general, ["●군량이 모자라 병사들이 소집해제되었습니다!"]); } //접률감소 @@ -472,11 +471,12 @@ function preUpdateMonthly() { $nationCount = MYDB_num_rows($result); for($i=0; $i < $nationCount; $i++) { $nation = MYDB_fetch_array($result); - $spy = ""; $k = 0; unset($citys); - if($nation['spy'] != "") { $citys = explode("|", $nation['spy']); } + $spy = ""; $k = 0; + $citys = []; + if($nation['spy'] != "") { $citys = explode("|", (string)$nation['spy']); } while(count($citys)) { $citys[$k]--; - if($citys[$k]%10 != 0) { $spy .= "$citys[$k]"; } + if($citys[$k]%10 != 0) { $spy .= (string)$citys[$k]; } $k++; if($k >= count($citys)) { break; } if($citys[$k-1]%10 != 0) { $spy .= "|"; } @@ -676,6 +676,10 @@ function checkMerge() { $db = DB::db(); $connect=$db->get(); + $mylog = []; + $youlog = []; + $history = []; + $query = "select year,month from game limit 1"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $admin = MYDB_fetch_array($result); @@ -781,9 +785,10 @@ function checkMerge() { pushGenLog($me, $mylog); pushGenLog($you, $youlog); pushWorldHistory($history, $admin['year'], $admin['month']); - unset($mylog); - unset($youlog); - unset($history); + + $mylog = []; + $youlog = []; + $history = []; refreshNationStaticInfo(); } @@ -802,6 +807,10 @@ function checkSurrender() { $dipcount = MYDB_num_rows($dipresult); for($i=0; $i < $dipcount; $i++) { + $mylog = []; + $youlog = []; + $history = []; + $dip = MYDB_fetch_array($dipresult); // 아국군주 @@ -904,9 +913,6 @@ function checkSurrender() { pushGenLog($me, $mylog); pushGenLog($you, $youlog); pushWorldHistory($history, $admin['year'], $admin['month']); - unset($mylog); - unset($youlog); - unset($history); refreshNationStaticInfo(); } @@ -1001,6 +1007,9 @@ function checkStatistic() { $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $admin = MYDB_fetch_array($result); + $nationHists = []; + $specialHists = []; + $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"; @@ -1212,6 +1221,7 @@ function checkEmperior() { $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) { @@ -1222,6 +1232,7 @@ function checkEmperior() { $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) { diff --git a/hwe/func_legacy.php b/hwe/func_legacy.php index 2cd36c08..25edfbc7 100644 --- a/hwe/func_legacy.php +++ b/hwe/func_legacy.php @@ -104,7 +104,7 @@ function printCitysName(int $cityNo, int $maxDistance=1) { default: $color = "yellow"; break; } - echo "{$distance}칸 떨어진 도시 : {$cityStr}
"; + echo "{$dist}칸 떨어진 도시 : {$cityStr}
"; } } diff --git a/hwe/func_message.php b/hwe/func_message.php index 9c7bd8e7..a6ee5415 100644 --- a/hwe/func_message.php +++ b/hwe/func_message.php @@ -256,7 +256,7 @@ function getMailboxList(){ $nationID = $nation['nation']; $mailbox = $nationID + 9000; $nation = $nation['name']; - $color = ('#'.$nation['color']).replace('##','#');//xxx: #기호 없는 이전 코드 대비용 + $color = $nation['color']; $generals = Util::array_get($generalNations[$nationID], []); return [ diff --git a/hwe/func_process_chief.php b/hwe/func_process_chief.php index bfdb135f..a11de667 100644 --- a/hwe/func_process_chief.php +++ b/hwe/func_process_chief.php @@ -1857,6 +1857,7 @@ function process_76(&$general) { $log = []; $alllog = []; $history = []; + $tricklog = []; $date = substr($general['turntime'],11,5); diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 6d3eb23a..57e09b72 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -670,15 +670,16 @@ function setGift($tnmt_type, $tnmt, $phase) { $cost = $admin['develcost'] * 20; $cost2 = $admin['develcost'] * 12; - $history[0] = "◆{$admin['year']}년 {$admin['month']}월: {$tp} 대회에서 {$general['name']}(이)가 우승, {$general2['name']}(이)가 준우승을 차지하여 천하에 이름을 떨칩니다!"; - $history[1] = "◆{$admin['year']}년 {$admin['month']}월: {$tp} 대회의 우승자에게는 {$cost}, 준우승자에겐 {$cost2}의 상금과 약간의 명성이 주어집니다!"; + $history = [ + "◆{$admin['year']}년 {$admin['month']}월: {$tp} 대회에서 {$general['name']}(이)가 우승, {$general2['name']}(이)가 준우승을 차지하여 천하에 이름을 떨칩니다!", + "◆{$admin['year']}년 {$admin['month']}월: {$tp} 대회의 우승자에게는 {$cost}, 준우승자에겐 {$cost2}의 상금과 약간의 명성이 주어집니다!" + ]; pushWorldHistory($history, $admin['year'], $admin['month']); for($i=0; $i < count($genNo); $i++) { $general['no'] = $genNo[$i]; $general['name'] = $genName[$i]; - $log[0] = "{$tp} 대회의 {$genCall[$genNo[$i]]}로 {$genGold[$genNo[$i]]}의 상금, 약간의 명성 획득!"; - pushGenLog($general, $log); + pushGenLog($general, ["{$tp} 대회의 {$genCall[$genNo[$i]]}로 {$genGold[$genNo[$i]]}의 상금, 약간의 명성 획득!"]); } //우승자 번호 @@ -766,10 +767,11 @@ function fight($tnmt_type, $tnmt, $phs, $group, $g1, $g2, $type) { if($type == 0) { $turn = 10; } else { $turn = 100; } - if($tnmt_type == 0) { $tp = "tot"; $tp2 = "tt"; } - elseif($tnmt_type == 1) { $tp = "ldr"; $tp2 = "tl"; } + + if($tnmt_type == 1) { $tp = "ldr"; $tp2 = "tl"; } elseif($tnmt_type == 2) { $tp = "pwr"; $tp2 = "tp"; } elseif($tnmt_type == 3) { $tp = "itl"; $tp2 = "ti"; } + else /*$tnmt_type == 0*/{ $tp = "tot"; $tp2 = "tt"; } $e1 = $energy1 = round($gen1[$tp] * getLog($gen1['lvl'], $gen2['lvl']) * 10); $e2 = $energy2 = round($gen2[$tp] * getLog($gen1['lvl'], $gen2['lvl']) * 10); diff --git a/hwe/lib.php b/hwe/lib.php index ab278d1b..50f1c5e4 100644 --- a/hwe/lib.php +++ b/hwe/lib.php @@ -91,7 +91,7 @@ function Error($message, $url="") ob_get_flush(); die($templates->render('error', [ - 'message' => $msg + 'message' => $message ])); } diff --git a/hwe/process_war.php b/hwe/process_war.php index 739756c8..4a08e1f9 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -3,6 +3,8 @@ namespace sammo; function processWar($general, $city) { + '@phan-var array $general'; + $db = DB::db(); $connect=$db->get(); @@ -15,8 +17,24 @@ function processWar($general, $city) { $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $game = MYDB_fetch_array($result); - $deadAmount['att'] = 0; - $deadAmount['def'] = 0; + $year = $game['year']; + $month = $game['month']; + + $log = []; + $batlog = []; + $batres = []; + + $opplog = []; + $oppbatlog = []; + $oppbatres = []; + + $alllog = []; + $history = []; + + $deadAmount = [ + 'att'=>0, + 'def'=>0 + ]; $warphase = GameUnitConst::byID($general['crewtype'])->speed; //병종간 페이즈 수 얻기 @@ -92,8 +110,8 @@ function processWar($general, $city) { if($originCity['level'] == 2) { $genAtmosBonus += 5; } // 출병도시가 진이면 공격자 공격보정 if($city['level'] == 3) { $oppTrainBonus += 5; } // 방어도시가 관이면 방어자 방어보정 - $alllog[] = "●{$game['month']}월:{$nation['name']}{$general['name']}(이)가 {$city['name']}(으)로 진격합니다."; - $log[] = "●{$game['month']}월:{$city['name']}(으)로 진격합니다. <1>$date"; + $alllog[] = "●{$month}월:{$nation['name']}{$general['name']}(이)가 {$city['name']}(으)로 진격합니다."; + $log[] = "●{$month}월:{$city['name']}(으)로 진격합니다. <1>$date"; // 목표 도시내에 목표 국가 소속 장수 중, 병사가 있는 능력치합+병사수 순으로 훈,사 60, 80 이상 $query = "select no,name,turntime,personal,special2,crew,crewtype,atmos,train,intel,intel2,book,power,power2,weap,injury,leader,leader2,horse,item,explevel,level,rice,leader+power+intel+weap+horse+book+crew/100 as sum,dex0,dex10,dex20,dex30,dex40 from general where city='{$city['city']}' and nation='{$city['nation']}' and nation!=0 and crew>'0' and rice>round(crew/100) and ((train>=60 and atmos>=60 and mode=1) or (train>=80 and atmos>=80 and mode=2)) order by sum desc"; @@ -112,10 +130,10 @@ function processWar($general, $city) { $query = "update general set recwar='{$general['turntime']}',train='{$general['train']}',warnum=warnum+1 where no='{$general['no']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $alllog[] = "●{$game['month']}월:병량 부족으로 {$city['name']}의 수비병들이 패퇴합니다."; - $history[] = "●{$game['year']}년 {$game['month']}월:【패퇴】{$destnation['name']}(이)가 병량 부족으로 {$city['name']}(을)를 뺏기고 말았습니다."; + $alllog[] = "●{$month}월:병량 부족으로 {$city['name']}의 수비병들이 패퇴합니다."; + $history[] = "●{$year}년 {$month}월:【패퇴】{$destnation['name']}(이)가 병량 부족으로 {$city['name']}(을)를 뺏기고 말았습니다."; pushGenLog($general, $log); - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); + pushGeneralPublicRecord($alllog, $year, $month); pushWorldHistory($history); unset($log); unset($alllog); @@ -135,7 +153,7 @@ function processWar($general, $city) { break; // 장수가 없어서 도시 공격 } elseif($opposecount == 0) { - $alllog[] = "●{$game['month']}월:{$general['name']}(이)가 ".GameUnitConst::byId($general['crewtype'])->name."(으)로 성벽을 공격합니다."; + $alllog[] = "●{$month}월:{$general['name']}(이)가 ".GameUnitConst::byId($general['crewtype'])->name."(으)로 성벽을 공격합니다."; $log[] = "●".GameUnitConst::byId($general['crewtype'])->name."(으)로 성벽을 공격합니다."; $general['train'] += 1; //훈련 상승 @@ -395,8 +413,8 @@ function processWar($general, $city) { ]; $res = $templates->render('small_war_log',[ - 'year'=>$game['year'], - 'month'=>$game['month'], + 'year'=>$year, + 'month'=>$month, 'war_type'=>'siege', 'war_type_str'=>'성', 'me' => $render_attacker, @@ -417,8 +435,7 @@ function processWar($general, $city) { $query = "update nation set rice='{$destnation['rice']}' where nation='{$destnation['nation']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $adminLog[0] = "성벽 쌀 소모 : $rice"; - pushAdminLog($adminLog); + pushAdminLog(["성벽 쌀 소모 : $rice"]); //원래대로 스케일링 $city['def'] = round($city['def'] / 10); @@ -443,7 +460,7 @@ function processWar($general, $city) { if($nation['type'] == 3 || $nation['type'] == 13) { $num *= 1.1; } if($nation['type'] == 5 || $nation['type'] == 6 || $nation['type'] == 7 || $nation['type'] == 8 || $nation['type'] == 12) { $num *= 0.9; } // 부드러운 기술 제한 - if(TechLimit($game['startyear'], $game['year'], $nation['tech'])) { $num = floor($num/4); } + if(TechLimit($game['startyear'], $year, $nation['tech'])) { $num = floor($num/4); } $query = "update nation set totaltech=totaltech+'$num',tech=totaltech/'$gencount' where nation='{$nation['nation']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); // 죽은수 기술로 누적 @@ -452,7 +469,7 @@ function processWar($general, $city) { if($destnation['type'] == 3 || $destnation['type'] == 13) { $num *= 1.1; } if($destnation['type'] == 5 || $destnation['type'] == 6 || $destnation['type'] == 7 || $destnation['type'] == 8 || $destnation['type'] == 12) { $num *= 0.9; } // 부드러운 기술 제한 - if(TechLimit($game['startyear'], $game['year'], $destnation['tech'])) { $num = floor($num/4); } + if(TechLimit($game['startyear'], $year, $destnation['tech'])) { $num = floor($num/4); } $query = "update nation set totaltech=totaltech+'$num',tech=totaltech/'$destgencount' where nation='{$destnation['nation']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); //양국 평균 기술가격 @@ -484,26 +501,26 @@ function processWar($general, $city) { pushGenLog($general, $log); pushBatLog($general, $batlog); pushBatRes($general, $batres); - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); - pushWorldHistory($history, $admin['year'], $admin['month']); - unset($log); - unset($batlog); - unset($batres); - unset($alllog); - unset($history); + pushGeneralPublicRecord($alllog, $year, $month); + pushWorldHistory($history, $year, $month); + $log = []; + $batlog = []; + $batres = []; + $alllog = []; + $history = []; ConquerCity($game, $general, $city, $nation, $destnation); break; // 공격 장수 병사 소진시 실패 처리 } elseif($general['crew'] <= 0) { - $alllog[] = "●{$game['month']}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; + $alllog[] = "●{$month}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; $log[] = "●퇴각했습니다."; $query = "update general set deathnum=deathnum+1 where no='{$general['no']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); break; } elseif($myRice <= round($general['crew']/100)) { - $alllog[] = "●{$game['month']}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; + $alllog[] = "●{$month}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; $log[] = "●군량 부족으로 퇴각합니다."; $query = "update general set deathnum=deathnum+1 where no='{$general['no']}'"; @@ -513,7 +530,7 @@ function processWar($general, $city) { // 장수 대결 } else { $oppose = MYDB_fetch_array($result); - $alllog[] = "●{$game['month']}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(와)과 {$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 대결합니다."; + $alllog[] = "●{$month}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(와)과 {$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 대결합니다."; $log[] = "●".GameUnitConst::byId($general['crewtype'])->name."(으)로 {$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(을)를 공격합니다."; $opplog[] = "●".GameUnitConst::byId($oppose['crewtype'])->name."(으)로 {$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(을)를 수비합니다."; @@ -1272,8 +1289,8 @@ function processWar($general, $city) { ]; $res = $templates->render('small_war_log',[ - 'year'=>$game['year'], - 'month'=>$game['month'], + 'year'=>$year, + 'month'=>$month, 'war_type'=>'attack', 'war_type_str'=>'공', 'me' => $render_attacker, @@ -1281,8 +1298,8 @@ function processWar($general, $city) { ]); $oppres = $templates->render('small_war_log',[ - 'year'=>$game['year'], - 'month'=>$game['month'], + 'year'=>$year, + 'month'=>$month, 'war_type'=>'defense', 'war_type_str'=>'수', 'me' => $render_defender, @@ -1318,7 +1335,7 @@ function processWar($general, $city) { if($nation['type'] == 3 || $nation['type'] == 13) { $num *= 1.1; } if($nation['type'] == 5 || $nation['type'] == 6 || $nation['type'] == 7 || $nation['type'] == 8 || $nation['type'] == 12) { $num *= 0.9; } // 부드러운 기술 제한 - if(TechLimit($game['startyear'], $game['year'], $nation['tech'])) { $num = floor($num/4); } + if(TechLimit($game['startyear'], $year, $nation['tech'])) { $num = floor($num/4); } $query = "update nation set totaltech=totaltech+'$num',tech=totaltech/'$gencount' where nation='{$nation['nation']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); @@ -1341,7 +1358,7 @@ function processWar($general, $city) { if($destnation['type'] == 3 || $destnation['type'] == 13) { $num *= 1.1; } if($destnation['type'] == 5 || $destnation['type'] == 6 || $destnation['type'] == 7 || $destnation['type'] == 8 || $destnation['type'] == 12) { $num *= 0.9; } // 부드러운 기술 제한 - if(TechLimit($game['startyear'], $game['year'], $destnation['tech'])) { $num = floor($num/4); } + if(TechLimit($game['startyear'], $year, $destnation['tech'])) { $num = floor($num/4); } $query = "update nation set totaltech=totaltech+'$num',tech=totaltech/'$destgencount' where nation='{$destnation['nation']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); //양국 평균 기술가격 @@ -1365,11 +1382,11 @@ function processWar($general, $city) { // 상대 병사 소진이나 쌀 소진시 다음 장수 if($oppose['crew'] <= 0 || ($opRice <= round($oppose['crew']/100) && $general['crew'] > 0)) { if($opRice <= round($oppose['crew']/100)) { - $alllog[] = "●{$game['month']}월:{$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 패퇴했습니다."; + $alllog[] = "●{$month}월:{$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 패퇴했습니다."; $log[] = "{$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 패퇴했습니다."; $opplog[] = "●군량 부족으로 패퇴합니다."; } else { - $alllog[] = "●{$game['month']}월:{$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 전멸했습니다."; + $alllog[] = "●{$month}월:{$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 전멸했습니다."; $log[] = "{$oppose['name']}의 ".GameUnitConst::byId($oppose['crewtype'])->name."(이)가 전멸했습니다."; $opplog[] = "●전멸했습니다."; } @@ -1403,11 +1420,11 @@ function processWar($general, $city) { // 공격 장수 병사 소진이나 쌀 소진시 실패 처리 } elseif($general['crew'] <= 0 || $myRice <= round($general['crew']/100)) { if($myRice <= round($general['crew']/100)) { - $alllog[] = "●{$game['month']}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; + $alllog[] = "●{$month}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; $log[] = "●군량 부족으로 퇴각합니다."; $opplog[] = "{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; } else { - $alllog[] = "●{$game['month']}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; + $alllog[] = "●{$month}월:{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; $log[] = "●퇴각했습니다."; $opplog[] = "{$general['name']}의 ".GameUnitConst::byId($general['crewtype'])->name."(이)가 퇴각했습니다."; } @@ -1445,7 +1462,7 @@ function processWar($general, $city) { unset($opplog); unset($oppbatlog); unset($oppbatres); -// $alllog[] = "●{$game['month']}월:{$general['name']}(이)가 }{$city['name']} 공략에 실패했습니다. <1>$date"; +// $alllog[] = "●{$month}월:{$general['name']}(이)가 }{$city['name']} 공략에 실패했습니다. <1>$date"; // $log[] = "{$city['name']} 공략에 실패했습니다. <1>$date"; break; } else { @@ -1497,7 +1514,7 @@ function processWar($general, $city) { pushGenLog($general, $log); pushBatLog($general, $batlog); pushBatRes($general, $batres); - pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']); + pushGeneralPublicRecord($alllog, $year, $month); pushWorldHistory($history); return $deadAmount; @@ -1593,16 +1610,16 @@ function addConflict($city, $nationnum, $mykillnum) { $db = DB::db(); $connect=$db->get(); + $nationlist = []; + $killnum = []; + $query = "select year,month from game limit 1"; $result = MYDB_query($query, $connect) or Error("addConflict ".MYDB_error($connect),""); $game = MYDB_fetch_array($result); - if($city['conflict'] == "") { - unset($nationlist); - unset($killnum); - } else { - $nationlist = explode("|", $city['conflict']); - $killnum = explode("|", $city['conflict2']); + if($city['conflict']){ + $nationlist = array_map('intval', explode("|", $city['conflict'])); + $killnum = array_map('intval', explode("|", $city['conflict2'])); } for($i=0; $i < count($nationlist); $i++) { @@ -1611,8 +1628,7 @@ function addConflict($city, $nationnum, $mykillnum) { if($i != 0 && $i == count($nationlist)) { // 두번째 나라부터 분쟁 가담 메시지 출력 $nation = getNationStaticInfo($nationnum); - $history[] = "●{$game['year']}년 {$game['month']}월:【분쟁】{$nation['name']}(이)가 {$city['name']} 공략에 가담하여 분쟁이 발생하고 있습니다."; - pushWorldHistory($history); + pushWorldHistory(["●{$game['year']}년 {$game['month']}월:【분쟁】{$nation['name']}(이)가 {$city['name']} 공략에 가담하여 분쟁이 발생하고 있습니다."]); } $nationlist[$i] = $nationnum; @@ -1663,12 +1679,12 @@ function DeleteConflict($nation) { } } -function getConquerNation($city) { +function getConquerNation($city) : int { $db = DB::db(); $connect=$db->get(); - $nationlist = explode("|", (string)$city['conflict']); - $killnum = explode("|", (string)$city['conflict2']); + $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++) { @@ -1681,23 +1697,31 @@ function getConquerNation($city) { } function ConquerCity($game, $general, $city, $nation, $destnation) { + '@phan-var array $city'; $db = DB::db(); $connect=$db->get(); global $_maximumatmos; + $alllog = []; + $log = []; + $history = []; + if($destnation['nation'] > 0) { $destnationName = "{$destnation['name']}의"; } else { $destnationName = "공백지인"; } - $alllog[] = "●{$game['month']}월:{$general['name']}(이)가 {$city['name']} 공략에 성공했습니다."; + $year = $game['year']; + $month = $game['month']; + + $alllog[] = "●{$month}월:{$general['name']}(이)가 {$city['name']} 공략에 성공했습니다."; $log[] = "{$city['name']} 공략에 성공했습니다."; - $history[] = "●{$game['year']}년 {$game['month']}월:【지배】{$nation['name']}(이)가 {$city['name']}(을)를 지배했습니다."; - pushGeneralHistory($general, "●{$game['year']}년 {$game['month']}월:{$city['name']}(을)를 함락시킴"); - pushNationHistory($nation, "●{$game['year']}년 {$game['month']}월:{$general['name']}(이)가 {$destnationName} {$city['name']}(을)를 점령"); - pushNationHistory($destnation, "●{$game['year']}년 {$game['month']}월:{$nation['name']}{$general['name']}에 의해 {$city['name']}(이)가 함락"); + $history[] = "●{$year}년 {$month}월:【지배】{$nation['name']}(이)가 {$city['name']}(을)를 지배했습니다."; + pushGeneralHistory($general, "●{$year}년 {$month}월:{$city['name']}(을)를 함락시킴"); + pushNationHistory($nation, "●{$year}년 {$month}월:{$general['name']}(이)가 {$destnationName} {$city['name']}(을)를 점령"); + pushNationHistory($destnation, "●{$year}년 {$month}월:{$nation['name']}{$general['name']}에 의해 {$city['name']}(이)가 함락"); $query = "select city from city where nation='{$city['nation']}'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); @@ -1710,8 +1734,8 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $losenation = MYDB_fetch_array($result); - $history[] = "●{$game['year']}년 {$game['month']}월:【멸망】{$losenation['name']}(이)가 멸망하였습니다."; - pushNationHistory($nation, "●{$game['year']}년 {$game['month']}월:{$losenation['name']}(을)를 정복"); + $history[] = "●{$year}년 {$month}월:【멸망】{$losenation['name']}(이)가 멸망하였습니다."; + pushNationHistory($nation, "●{$year}년 {$month}월:{$losenation['name']}(을)를 정복"); $query = "select no from general where nation='{$general['nation']}' and level='12'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); @@ -1728,7 +1752,7 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { $query = "select no,name,nation,npc,gold,rice from general where nation='{$city['nation']}'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $gencount = MYDB_num_rows($result); - $genlog[0] = "{$losenation['name']}(이)가 멸망했습니다."; + $genlog = ["{$losenation['name']}(이)가 멸망했습니다."]; for($i=0; $i < $gencount; $i++) { $gen = MYDB_fetch_array($result); @@ -1741,7 +1765,7 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { pushGenLog($gen, $genlog); - pushGeneralHistory($gen, "●{$game['year']}년 {$game['month']}월:{$losenation['name']}(이)가 멸망"); + pushGeneralHistory($gen, "●{$year}년 {$month}월:{$losenation['name']}(이)가 멸망"); $loseGeneralGold += $loseGold; $loseGeneralRice += $loseRice; @@ -1751,7 +1775,7 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { || $nation['name'] == "남만족" || $nation['name'] == "산월족" || $nation['name'] == "오환족" || $nation['name'] == "왜족") { //등용장 미발부 - } elseif(randBool(0.5)) { + } elseif(Util::randBool(0.5)) { sendScoutMsg([ 'id' => $ruler['no'], 'nation_id' => $ruler['nation'] @@ -1857,6 +1881,7 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { foreach($distList[$dist] as $cityID){ $city = $cities[$cityID]; + '@phan-var array $city'; if($city['nation'] != $destnation['nation']){ continue; } @@ -1877,13 +1902,13 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { $minCityName = CityConst::byID($minCity)->name; - $history[] = "●{$game['year']}년 {$game['month']}월:【긴급천도】{$destnation['name']}(이)가 수도가 함락되어 $minCityName으로 긴급천도하였습니다."; + $history[] = "●{$year}년 {$month}월:【긴급천도】{$destnation['name']}(이)가 수도가 함락되어 $minCityName으로 긴급천도하였습니다."; //아국 수뇌부에게 로그 전달 $query = "select no,name,nation from general where nation='{$destnation['nation']}' and level>='5'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $gencount = MYDB_num_rows($result); - $genlog[0] = "●수도가 함락되어 $minCityName으로 긴급천도합니다."; + $genlog = ["●수도가 함락되어 $minCityName으로 긴급천도합니다."]; for($i=0; $i < $gencount; $i++) { $gen = MYDB_fetch_array($result); pushGenLog($gen, $genlog); @@ -1930,29 +1955,44 @@ function ConquerCity($game, $general, $city, $nation, $destnation) { $query = "select name,nation from nation where nation='$conquerNation'"; $conquerResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $conquerNationArray = MYDB_fetch_array($conquerResult); + - $history[] = "●{$game['year']}년 {$game['month']}월:【분쟁협상】{$conquerNationArray['name']}(이)가 영토분쟁에서 우위를 점하여 {$city['name']}(을)를 양도받았습니다."; - pushNationHistory($nation, "●{$game['year']}년 {$game['month']}월:{$city['name']}(을)를 {$conquerNationArray['name']}양도"); - pushNationHistory($conquerNationArray, "●{$game['year']}년 {$game['month']}월:{$nation['name']}에서 {$city['name']}(을)를 양도 받음"); + + $history[] = "●{$year}년 {$month}월:【분쟁협상】{$conquerNationArray['name']}(이)가 영토분쟁에서 우위를 점하여 {$city['name']}(을)를 양도받았습니다."; + pushNationHistory($nation, "●{$year}년 {$month}월:{$city['name']}(을)를 {$conquerNationArray['name']}양도"); + pushNationHistory($conquerNationArray, "●{$year}년 {$month}월:{$nation['name']}에서 {$city['name']}(을)를 양도 받음"); // 이동X 및 사기 변경 $query = "update general set atmos='{$general['atmos']}',killnum=killnum+1 where no='{$general['no']}'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + + $query = [ + 'supply'=>1, + 'term'=>0, + 'conflict2'=>'', + 'agri'=>$db->sqleval('agri*0.7'), + 'comm'=>$db->sqleval('comm*0.7'), + 'secu'=>$db->sqleval('secu*0.7'), + 'nation'=>$conquerNation, + 'gen1'=>0, + 'gen2'=>0, + 'gen3'=>0 + ]; 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='$conquerNation',gen1=0,gen2=0,gen3=0 where city='{$city['city']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $query['def'] = 1000; + $query['wall'] = 1000; } 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='$conquerNation',gen1=0,gen2=0,gen3=0 where city='{$city['city']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $query['def'] = $db->sqleval('def2/2'); + $query['wall'] = $db->sqleval('wall2/2'); } + $db->update('city', $query, 'city=%i', (int)$city['city']); //전방설정 SetNationFront($destnation['nation']); SetNationFront($conquerNation); } pushGenLog($general, $log); - pushGeneralPublicRecord($alllog, $game['year'], $game['month']); + pushGeneralPublicRecord($alllog, $year, $month); pushWorldHistory($history); } diff --git a/hwe/sammo/CityHelper.php b/hwe/sammo/CityHelper.php index c234f9f6..1bad62bb 100644 --- a/hwe/sammo/CityHelper.php +++ b/hwe/sammo/CityHelper.php @@ -21,6 +21,10 @@ class CityHelper{ $list = []; $listInv = []; $listByNation = []; + + '@phan-var array|null $list'; + '@phan-var array|null $listInv'; + '@phan-var array|null $listByNation'; foreach (DB::db()->query('SELECT `city` as `id`, `name`, `level`, `nation` from city') as $city) { $id = $city['id']; diff --git a/hwe/sammo/Event/Action/ChangeCity.php b/hwe/sammo/Event/Action/ChangeCity.php index 849f5c57..cc9c0370 100644 --- a/hwe/sammo/Event/Action/ChangeCity.php +++ b/hwe/sammo/Event/Action/ChangeCity.php @@ -20,7 +20,7 @@ class ChangeCity extends \sammo\Event\Action{ private $queries; private $targetType = 'all'; private $targetArgs = []; - public function __construct($target = null, array $actions){ + public function __construct($target, array $actions){ //values 포맷은 key, value로 @@ -74,7 +74,7 @@ class ChangeCity extends \sammo\Event\Action{ $matches = null; if(preg_match(self::REGEXP_PERCENT, $value, $matches)){ - $value = round($matches[1], 0); + $value = (int)round((float)$matches[1], 0); return DB::db()->sqleval('%i', Util::valueFit($value, 0, 100)); } @@ -106,7 +106,7 @@ class ChangeCity extends \sammo\Event\Action{ $matches = null; if(preg_match(self::REGEXP_PERCENT, $value, $matches)){ - $value = round($matches[1], 0); + $value = (int)round((float)$matches[1], 0); return DB::db()->sqleval('ROUND(%b * %d, 0)', $keyMax, $value/100); }