From 3a44782b056ee929e85b057fcbc7ab3085518e39 Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 20 Apr 2020 00:47:35 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func_history.php | 3 + hwe/func_time_event.php | 13 ++- hwe/func_tournament.php | 38 ++++---- hwe/sammo/ActionLogger.php | 8 +- hwe/sammo/Command/General/che_랜덤임관.php | 14 ++- hwe/sammo/Command/General/che_증여.php | 4 +- hwe/sammo/Command/General/che_출병.php | 7 ++ hwe/sammo/Command/Nation/che_몰수.php | 2 +- hwe/sammo/GeneralAI.php | 100 ++++++++++++++++----- hwe/sammo/TurnExecutionHelper.php | 2 +- 10 files changed, 137 insertions(+), 54 deletions(-) diff --git a/hwe/func_history.php b/hwe/func_history.php index 6c5be9bc..6ab1b556 100644 --- a/hwe/func_history.php +++ b/hwe/func_history.php @@ -268,6 +268,9 @@ function pushNationHistory(int $nationID, ?array $history, ?int $year=null, ?int if(!$history){ return; } + if(!$nationID){ + return; + } $db = DB::db(); if($year === null || $month === null){ diff --git a/hwe/func_time_event.php b/hwe/func_time_event.php index 71bfb36d..2598afd4 100644 --- a/hwe/func_time_event.php +++ b/hwe/func_time_event.php @@ -85,7 +85,8 @@ function processGoldIncome() { ." // 지급률 : ".tab2((string)round($ratio*100,2),5," ") ." % // 결과금 : ".tab2((string)$nation['gold'],6," "); - $incomeLog = "이번 수입은 금 $income입니다."; + $incomeText = number_format($income); + $incomeLog = "이번 수입은 금 $incomeText입니다."; $db->update('nation', [ 'gold'=>$nation['gold'] @@ -101,7 +102,9 @@ function processGoldIncome() { if($generalObj->getVar('officer_level') > 4){ $logger->pushGeneralActionLog($incomeLog, $logger::PLAIN); } - $logger->pushGeneralActionLog("봉급으로 금 $gold을 받았습니다.", $logger::PLAIN); + + $goldText = number_format($gold); + $logger->pushGeneralActionLog("봉급으로 금 $goldText을 받았습니다.", $logger::PLAIN); $generalObj->applyDB($db); } } @@ -357,7 +360,8 @@ function processRiceIncome() { ." // 지급률 : ".tab2((string)round($ratio*100,2),5," ") ." % // 결과곡 : ".tab2((string)$nation['rice'],6," "); - $incomeLog = "이번 수입은 쌀 $income입니다."; + $incomeText = number_format($income); + $incomeLog = "이번 수입은 쌀 $incomeText입니다."; $db->update('nation', [ 'rice'=>$nation['rice'] @@ -373,7 +377,8 @@ function processRiceIncome() { if($generalObj->getVar('officer_level') > 4){ $logger->pushGeneralActionLog($incomeLog, $logger::PLAIN); } - $logger->pushGeneralActionLog("봉급으로 쌀 $rice을 받았습니다.", $logger::PLAIN); + $riceText = number_format($rice); + $logger->pushGeneralActionLog("봉급으로 쌀 $riceText을 받았습니다.", $logger::PLAIN); $generalObj->applyDB($db); } } diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 6d658a96..f03bf6a8 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -660,8 +660,8 @@ function setGift($tnmt_type, $tnmt, $phase) { 'gold'=>$db->sqleval('gold + %i', $cost) ], 'no=%i', $general['no']); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + 1', "{$tp2}g") - ], 'general_id = %i', $general['no']); + 'value' => $db->sqleval('value + 1') + ], 'general_id = %i AND type = %s', $general['no'], "{$tp2}g"); //포상 장수 이름, 금액 $logger = new ActionLogger($generalID, 0, $admin['year'], $admin['month']); @@ -683,8 +683,8 @@ function setGift($tnmt_type, $tnmt, $phase) { 'gold'=>$db->sqleval('gold + %i', $cost) ], 'no=%i', $general['no']); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + 1', "{$tp2}g") - ], 'general_id = %i', $general['no']); + 'value' => $db->sqleval('value + 1') + ], 'general_id = %i AND type = %s', $general['no'], "{$tp2}g"); //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; @@ -699,8 +699,8 @@ function setGift($tnmt_type, $tnmt, $phase) { 'gold'=>$db->sqleval('gold + %i', $cost) ], 'no=%i', $general['no']); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + 2', "{$tp2}g") - ], 'general_id = %i', $general['no']); + 'value' => $db->sqleval('value + 2') + ], 'general_id = %i AND type = %s', $general['no'], "{$tp2}g"); //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; @@ -715,8 +715,8 @@ function setGift($tnmt_type, $tnmt, $phase) { 'gold'=>$db->sqleval('gold + %i', $cost) ], 'no=%i', $general['no']); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + 2', "{$tp2}g") - ], 'general_id = %i', $general['no']); + 'value' => $db->sqleval('value + 2') + ], 'general_id = %i AND type = %s', $general['no'], "{$tp2}g"); //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; @@ -727,15 +727,15 @@ function setGift($tnmt_type, $tnmt, $phase) { } //우승자 명성 돈 $cost = $admin['develcost'] * 8; - foreach($db->query('SELECT no, name FROM tournament WHERE grp>=6 AND no > 0') as $general){ + foreach($db->query('SELECT no, name FROM tournament WHERE grp>=60 AND no > 0') as $general){ $generalID = $general['no']; $db->update('general', [ 'experience'=>$db->sqleval('experience + 200'), 'gold'=>$db->sqleval('gold + %i', $cost) ], 'no=%i', $general['no']); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + 2', "{$tp2}g") - ], 'general_id = %i', $general['no']); + 'value' => $db->sqleval('value + 2') + ], 'general_id = %i AND type = %s', $general['no'], "{$tp2}g"); //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; @@ -1103,18 +1103,18 @@ function fight($tnmt_type, $tnmt, $phs, $group, $g1, $g2, $type) { } $db->update('rank_data', [ - "{$tp2}{$gen1resKey}" => $db->sqleval('%b + 1', "{$tp2}{$gen1resKey}") - ], 'no=%i',$gen1['no']); + 'value' => $db->sqleval('value + 1') + ], 'general_id=%i AND type = %s',$gen1['no'], "{$tp2}{$gen1resKey}"); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + %i', "{$tp2}g", $gl1) - ], 'no=%i',$gen1['no']); + 'value' => $db->sqleval('value + %i', $gl1), + ], 'general_id=%i AND type = %s',$gen1['no'], "{$tp2}g"); $db->update('rank_data', [ - "{$tp2}{$gen2resKey}" => $db->sqleval('%b + 1', "{$tp2}{$gen2resKey}") - ], 'no=%i',$gen2['no']); + 'value' => $db->sqleval('value + 1'), + ], 'general_id=%i AND type = %s',$gen2['no'], "{$tp2}{$gen2resKey}"); $db->update('rank_data', [ - "{$tp2}g" => $db->sqleval('%b + %i', "{$tp2}g", $gl2) - ], 'no=%i',$gen2['no']); + 'value' => $db->sqleval('value + %i', $gl2) + ], 'general_id=%i AND type = %s',$gen2['no'], "{$tp2}g"); diff --git a/hwe/sammo/ActionLogger.php b/hwe/sammo/ActionLogger.php index b0a21649..3ab44a72 100644 --- a/hwe/sammo/ActionLogger.php +++ b/hwe/sammo/ActionLogger.php @@ -74,22 +74,22 @@ class ActionLogger{ } public function flush(){ - if($this->generalHistoryLog){ + if($this->generalHistoryLog && $this->generalID){ pushGeneralHistory($this->generalID, $this->generalHistoryLog, $this->year, $this->month); $this->generalHistoryLog = []; } - if($this->generalActionLog){ + if($this->generalActionLog && $this->generalID){ pushGenLog($this->generalID, $this->generalActionLog, $this->year, $this->month); $this->generalActionLog = []; } - if($this->generalBattleResultLog){ + if($this->generalBattleResultLog && $this->generalID){ pushBatRes($this->generalID, $this->generalBattleResultLog, $this->year, $this->month); $this->generalBattleResultLog = []; } - if($this->generalBattleDetailLog){ + if($this->generalBattleDetailLog && $this->generalID){ pushBatLog($this->generalID, $this->generalBattleDetailLog, $this->year, $this->month); $this->generalBattleDetailLog = []; } diff --git a/hwe/sammo/Command/General/che_랜덤임관.php b/hwe/sammo/Command/General/che_랜덤임관.php index 767b2f77..37680559 100644 --- a/hwe/sammo/Command/General/che_랜덤임관.php +++ b/hwe/sammo/Command/General/che_랜덤임관.php @@ -29,9 +29,14 @@ class che_랜덤임관 extends Command\GeneralCommand{ static public $reqArg = false; protected function argTest():bool{ - if($this->arg === null){ + $this->arg = null; + return true; + + //TODO: 구현 + /*if($this->arg === null){ return true; } + $destNationIDList = $this->arg['destNationIDList']??null; //null은 에러, []는 정상 @@ -53,7 +58,7 @@ class che_랜덤임관 extends Command\GeneralCommand{ 'destNationIDList' => $destNationIDList ]; - return true; + return true;*/ } protected function init(){ @@ -71,9 +76,11 @@ class che_랜덤임관 extends Command\GeneralCommand{ ConstraintHelper::AllowJoinAction(), ]; + /* if($this->arg['destNationIDList']??false){ $this->runnableConstraints[] = ConstraintHelper::ExistsAllowJoinNation($relYear, $this->arg['destNationIDList']); } + */ } public function getCost():array{ @@ -103,7 +110,10 @@ class che_랜덤임관 extends Command\GeneralCommand{ $relYear = $env['year'] - $env['startyear']; + /* $notIn = array_merge($general->getAuxVar('joinedNations')??[], $this->arg['destNationIDList']); + */ + $notIn = null; $destNation = null; diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index 9a4a59c3..0628717d 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -145,8 +145,8 @@ class che_증여 extends Command\GeneralCommand{ $destGeneral->increaseVarWithLimit($resKey, $amount); $general->increaseVarWithLimit($resKey, -$amount, 0); - $destGeneral->getLogger()->pushGeneralActionLog("{$general->getName()}에게서 {$resName} {$amountText}을 증여 받았습니다.", ActionLogger::PLAIN); - $logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} $amountText을 증여했습니다. <1>$date"); + $destGeneral->getLogger()->pushGeneralActionLog("{$general->getName()}에게서 {$resName} {$amountText}을 증여 받았습니다.", ActionLogger::PLAIN); + $logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} $amountText을 증여했습니다. <1>$date"); $exp = 70; $ded = 100; diff --git a/hwe/sammo/Command/General/che_출병.php b/hwe/sammo/Command/General/che_출병.php index 0f1e4b56..a7d66b2b 100644 --- a/hwe/sammo/Command/General/che_출병.php +++ b/hwe/sammo/Command/General/che_출병.php @@ -84,6 +84,13 @@ class che_출병 extends Command\GeneralCommand{ return 0; } + public function getBrief():string{ + $commandName = $this->getName(); + $destCityName = CityConst::byID($this->arg['destCityID'])->name; + $josaRo = JosaUtil::pick($destCityName, '로'); + return "【{$destCityName}】{$josaRo} {$commandName}"; + } + public function getFailString():string{ $commandName = $this->getName(); $failReason = $this->testRunnable(); diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index fad50d06..50fff12f 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -182,7 +182,7 @@ class che_몰수 extends Command\NationCommand{ ], 'nation=%i', $nationID); $destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 몰수 당했습니다.", ActionLogger::PLAIN); - $logger->pushGeneralActionLog("{$destGeneral->getName()}에게서 {$resName} $amountText을 몰수했습니다. <1>$date"); + $logger->pushGeneralActionLog("{$destGeneral->getName()}에게서 {$resName} $amountText을 몰수했습니다. <1>$date"); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->applyDB($db); diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 0b571818..e3537ce7 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -200,9 +200,13 @@ class GeneralAI $warTargetNation[$warNationID] = 1; } } - $warTargetNation[0] = 0; - $this->warTargetNation = $warTargetNation; + if(!$onWar){ + $warTargetNation[0] = 1; + } + + $this->warTargetNation = $warTargetNation; + $minWarTerm = $db->queryFirstField('SELECT min(term) FROM diplomacy WHERE me = %i AND state=1', $nationID); if ($minWarTerm === null) { @@ -1057,6 +1061,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -1148,6 +1153,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -1222,6 +1228,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -1327,6 +1334,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -1449,6 +1457,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -1481,6 +1490,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -1619,7 +1629,6 @@ class GeneralAI $nationStor->setValue("last천도Trial_{$this->nation['nation']}", [$general->getVar('officer_level'), $general->getTurnTime()]); - return $cmd; } @@ -1845,7 +1854,8 @@ class GeneralAI return null; } - return Util::choiceRandomUsingWeightPair($cmdList); + $cmd = Util::choiceRandomUsingWeightPair($cmdList); + return $cmd; } @@ -2149,9 +2159,6 @@ class GeneralAI if (!$this->attackable) { return null; } - if($this->dipState !== self::d전쟁){ - return null; - } $general = $this->getGeneralObj(); $city = $this->city; @@ -2162,13 +2169,24 @@ class GeneralAI $db = DB::db(); - if ($city['front'] <= 1) { + if($general->getVar('train') < $this->nationPolicy->properWarTrainAtmos){ + return null; + } + if($general->getVar('atmos') < $this->nationPolicy->properWarTrainAtmos){ + return null; + } + + if($city['front'] === 0){ + return null; + } + + if ($city['front'] === 1 && $this->dipState === self::d전쟁) { return null; } $attackableNations = []; foreach ($this->warTargetNation as $targetNationID => $state) { - if ($state == 1) { + if ($this->dipState === self::d전쟁 && $state == 1) { continue; } $attackableNations[] = $targetNationID; @@ -2185,7 +2203,12 @@ class GeneralAI throw new \RuntimeException('출병 불가' . $cityID . var_export($attackableNations, true) . var_export($nearCities, true)); } - return buildGeneralCommandClass('che_출병', $general, $this->env, ['destCityID' => Util::choiceRandom($attackableCities)]); + $cmd = buildGeneralCommandClass('che_출병', $general, $this->env, ['destCityID' => Util::choiceRandom($attackableCities)]); + if(!$cmd->isRunnable()){ + return null; + } + + return $cmd; } @@ -2404,6 +2427,11 @@ class GeneralAI $availableTypeCnt += 1; } + if($availableTypeCnt === 0){ + //무능장은 인탐을 하세요. + return null; + } + if(!Util::randBool($warpProp)){ return null; } @@ -2426,7 +2454,10 @@ class GeneralAI } $realDevelRate += $develVal; } + + $realDevelRate /= $availableTypeCnt; + if($realDevelRate >= 0.95){ continue; } @@ -2445,6 +2476,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2461,6 +2493,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2526,6 +2559,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2556,6 +2590,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2565,6 +2600,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2580,6 +2616,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2593,6 +2630,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2616,6 +2654,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } } @@ -2644,6 +2683,7 @@ class GeneralAI if(!$cmd->isRunnable()){ return null; } + return $cmd; } @@ -2695,7 +2735,8 @@ class GeneralAI { $general = $this->general; if($general->getNationID() == 0){ - return buildGeneralCommandClass('che_견문', $this->general, $this->env); + $cmd = buildGeneralCommandClass('che_견문', $this->general, $this->env); + return $cmd; } @@ -2710,7 +2751,8 @@ class GeneralAI $candidate[] = 'che_인재탐색'; - return buildGeneralCommandClass(Util::choiceRandom($candidate), $this->general, $this->env); + $cmd = buildGeneralCommandClass(Util::choiceRandom($candidate), $this->general, $this->env); + return $cmd; } protected function categorizeNationCities():void{ @@ -2966,25 +3008,32 @@ class GeneralAI if($general->getVar('officer_level') === 12 && $this->generalPolicy->can선양){ $result = $this->do선양(); if($result !== null){ + $result->reason='do선양'; return $result; } } if($npcType == 5){ - return $this->do집합(); + $result = $this->do집합(); + $result->reason='do집합'; + return $result; } if(!($reservedCommand instanceof Command\General\휴식)){ + $reservedCommand->reason='do예약턴'; return $reservedCommand; } if ($general->getVar('injury') > 10) { - return buildGeneralCommandClass('che_요양', $general, $this->env); + $result = buildGeneralCommandClass('che_요양', $general, $this->env); + $result->reason='do요양'; + return $result; } if($npcType == 2 && $nationID == 0){ $result = $this->do거병(); if($result !== null){ + $result->reason='do거병'; return $result; } } @@ -2992,24 +3041,30 @@ class GeneralAI if($nationID === 0 && $this->generalPolicy->can국가선택){ $result = $this->do국가선택(); if($result !== null){ + $result->reason='do국가선택'; return $result; } - return $this->do중립(); + $result = $this->do중립(); + $result->reason='do중립'; + return $result; } if($npcType >= 2 && $general->getVar('officer_level') == 12 && !$this->nation['capital']){ //방랑군 건국 $result = $this->do건국(); if($result !== null){ + $result->reason='do건국'; return $result; } $result = $this->do방랑군이동(); if($result !== null){ + $result->reason='do방랑군이동'; return $result; } $result = $this->do해산(); if($result !== null){ + $result->reason='do해산'; return $result; } } @@ -3021,11 +3076,14 @@ class GeneralAI /** @var ?GeneralCommand */ $result = $this->{'do'.$actionName}(); if($result !== null){ + $result->reason='do'.$actionName; return $result; } } - return $this->do중립(); + $result = $this->do중립(); + $result->reason='do중립'; + return $result; } protected function calcNationDevelopedRate() @@ -3139,11 +3197,11 @@ class GeneralAI return [ 'trust' => [$city['trust'] / 100, self::t통솔장], 'pop' => [$city['pop'] / $city['pop_max'], self::t통솔장], - 'agri' => [$city['agri'] / $city['agri_max'], self::t통솔장], - 'comm' => [$city['comm'] / $city['comm_max'], self::t통솔장], - 'secu' => [$city['secu'] / $city['secu_max'], self::t통솔장], - 'def' => [$city['def'] / $city['def_max'], self::t통솔장], - 'wall' => [$city['wall'] / $city['wall_max'], self::t통솔장], + 'agri' => [$city['agri'] / $city['agri_max'], self::t지장], + 'comm' => [$city['comm'] / $city['comm_max'], self::t지장], + 'secu' => [$city['secu'] / $city['secu_max'], self::t무장], + 'def' => [$city['def'] / $city['def_max'], self::t무장], + 'wall' => [$city['wall'] / $city['wall_max'], self::t무장], ]; } diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index c29d6905..d722c466 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -269,7 +269,7 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', } $generalCommandObj = $ai->chooseGeneralTurn($generalCommandObj); // npc AI 처리 - LogText("turn", "General: {$general->getName()}[{$general->getID()},{$general->getStaticNation()['name']}]; run; {$generalCommandObj->getBrief()}"); + LogText("turn", "General, {$general->getName()}, {$general->getID()}, {$general->getStaticNation()['name']}, {$generalCommandObj->getBrief()}, {$generalCommandObj->reason}, "); } if(!$turnObj->processBlocked()){