From 8d41dead5d7bc0d46cc9b387e5a25df657f85b2f Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 19 Apr 2020 18:48:56 +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_tournament.php | 9 +- hwe/sammo/Command/General/che_군량매매.php | 5 +- hwe/sammo/Command/General/che_증여.php | 5 +- hwe/sammo/Command/General/che_헌납.php | 5 +- hwe/sammo/Command/Nation/che_몰수.php | 5 +- hwe/sammo/Command/Nation/che_증축.php | 12 +-- hwe/sammo/Command/Nation/che_포상.php | 5 +- hwe/sammo/GameUnitConstBase.php | 1 + hwe/sammo/GeneralAI.php | 99 +++++++++++++--------- hwe/sammo/WarUnitCity.php | 2 +- hwe/sammo/WarUnitGeneral.php | 2 +- 11 files changed, 90 insertions(+), 60 deletions(-) diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 38ff5bbf..6d658a96 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -1051,13 +1051,8 @@ function fight($tnmt_type, $tnmt, $phs, $group, $g1, $g2, $type) { if($energy2 <= 0) { $sel = 0; break; } } - $query = "select {$tp2}g as gl from general where no='{$gen1['no']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general1 = MYDB_fetch_array($result); - - $query = "select {$tp2}g as gl from general where no='{$gen2['no']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general2 = MYDB_fetch_array($result); + $general1 = $db->queryFirstRow('SELECT value as gl FROM rank_data WHERE general_id = %i AND type = %s', $gen1['no'], $tp2.'g'); + $general2 = $db->queryFirstRow('SELECT value as gl FROM rank_data WHERE general_id = %i AND type = %s', $gen2['no'], $tp2.'g'); switch($sel) { case 0: diff --git a/hwe/sammo/Command/General/che_군량매매.php b/hwe/sammo/Command/General/che_군량매매.php index 50852b8f..2618bf94 100644 --- a/hwe/sammo/Command/General/che_군량매매.php +++ b/hwe/sammo/Command/General/che_군량매매.php @@ -35,7 +35,10 @@ class che_군량매매 extends Command\GeneralCommand{ } $buyRice = boolval($buyRice); $amount = $this->arg['amount']??null; - if(!is_int($amount)){ + if(is_float($amount)){ + $amount = Util::toInt($amount); + } + else if(!is_int($amount)){ return false; } $amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount); diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index cde45b17..9a4a59c3 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -43,7 +43,10 @@ class che_증여 extends Command\GeneralCommand{ $isGold = $this->arg['isGold']; $amount = $this->arg['amount']; $destGeneralID = $this->arg['destGeneralID']; - if(!is_int($amount)){ + if(is_float($amount)){ + $amount = Util::toInt($amount); + } + else if(!is_int($amount)){ return false; } $amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount); diff --git a/hwe/sammo/Command/General/che_헌납.php b/hwe/sammo/Command/General/che_헌납.php index 424da5a3..916f16d9 100644 --- a/hwe/sammo/Command/General/che_헌납.php +++ b/hwe/sammo/Command/General/che_헌납.php @@ -38,7 +38,10 @@ class che_헌납 extends Command\GeneralCommand{ } $isGold = $this->arg['isGold']; $amount = $this->arg['amount']; - if(!is_int($amount)){ + if(is_float($amount)){ + $amount = Util::toInt($amount); + } + else if(!is_int($amount)){ return false; } $amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount); diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index 33d15f1b..fad50d06 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -44,7 +44,10 @@ class che_몰수 extends Command\NationCommand{ $isGold = $this->arg['isGold']; $amount = $this->arg['amount']; $destGeneralID = $this->arg['destGeneralID']; - if(!is_int($amount)){ + if(is_float($amount)){ + $amount = Util::toInt($amount); + } + else if(!is_int($amount)){ return false; } $amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount); diff --git a/hwe/sammo/Command/Nation/che_증축.php b/hwe/sammo/Command/Nation/che_증축.php index 27995f1a..9f6812d7 100644 --- a/hwe/sammo/Command/Nation/che_증축.php +++ b/hwe/sammo/Command/Nation/che_증축.php @@ -170,12 +170,12 @@ class che_증축 extends Command\NationCommand{ $db->update('city', [ 'level'=>$db->sqleval('level+1'), - 'pop2'=>$db->sqleval('pop_max + %i', GameConst::$expandCityPopIncreaseAmount), - 'agri2'=>$db->sqleval('agri_max + %i', GameConst::$expandCityDevelIncreaseAmount), - 'comm2'=>$db->sqleval('comm_max + %i', GameConst::$expandCityDevelIncreaseAmount), - 'secu2'=>$db->sqleval('secu_max + %i', GameConst::$expandCityDevelIncreaseAmount), - 'def2'=>$db->sqleval('def_max + %i', GameConst::$expandCityWallIncreaseAmount), - 'wall2'=>$db->sqleval('wall_max + %i', GameConst::$expandCityWallIncreaseAmount), + 'pop_max'=>$db->sqleval('pop_max + %i', GameConst::$expandCityPopIncreaseAmount), + 'agri_max'=>$db->sqleval('agri_max + %i', GameConst::$expandCityDevelIncreaseAmount), + 'comm_max'=>$db->sqleval('comm_max + %i', GameConst::$expandCityDevelIncreaseAmount), + 'secu_max'=>$db->sqleval('secu_max + %i', GameConst::$expandCityDevelIncreaseAmount), + 'def_max'=>$db->sqleval('def_max + %i', GameConst::$expandCityWallIncreaseAmount), + 'wall_max'=>$db->sqleval('wall_max + %i', GameConst::$expandCityWallIncreaseAmount), ], 'city=%i', $destCityID); [$reqGold, $reqRice] = $this->getCost(); diff --git a/hwe/sammo/Command/Nation/che_포상.php b/hwe/sammo/Command/Nation/che_포상.php index cd9f80da..6b53aedf 100644 --- a/hwe/sammo/Command/Nation/che_포상.php +++ b/hwe/sammo/Command/Nation/che_포상.php @@ -41,7 +41,10 @@ class che_포상 extends Command\NationCommand{ $isGold = $this->arg['isGold']; $amount = $this->arg['amount']; $destGeneralID = $this->arg['destGeneralID']; - if(!is_int($amount)){ + if(is_float($amount)){ + $amount = Util::toInt($amount); + } + else if(!is_int($amount)){ return false; } $amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount); diff --git a/hwe/sammo/GameUnitConstBase.php b/hwe/sammo/GameUnitConstBase.php index 4b482069..21c7ccfc 100644 --- a/hwe/sammo/GameUnitConstBase.php +++ b/hwe/sammo/GameUnitConstBase.php @@ -13,6 +13,7 @@ class GameUnitConstBase{ const T_WIZARD = 4; const T_SIEGE = 5; const T_MISC = 6; + const CREWTYPE_CASTLE = 1000; const DEFAULT_CREWTYPE = 1100; diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 09d2dc15..0b571818 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -360,7 +360,7 @@ class GeneralAI //충분히 징병 가능한 도시의 부대는 제자리 유지 $city = $this->supplyCities[$currentCityID]; - if($city['pop'] / $city['pop2'] >= $this->nationPolicy->safeRecruitCityPopulationRatio){ + if($city['pop'] / $city['pop_max'] >= $this->nationPolicy->safeRecruitCityPopulationRatio){ continue; } @@ -744,7 +744,7 @@ class GeneralAI $dev = min($city['dev'], 0.999); $score = 1 - $dev; $score **= 2; - $score /= sqrt(count($city['generals']) + 1); + $score /= sqrt(count($city['generals']??[]) + 1); $cityCandidiates[$city['city']] = $score; } @@ -961,7 +961,7 @@ class GeneralAI $dev = min($city['dev'], 0.999); $score = 1 - $dev; $score **= 2; - $score /= sqrt(count($city['generals']) + 1); + $score /= sqrt(count($city['generals']??[]) + 1); $cityCandidiates[$city['city']] = $score; } @@ -1045,6 +1045,10 @@ class GeneralAI ]; } } + + if(!$candidateArgs){ + return null; + } $cmd = buildNationCommandClass( 'che_포상', $this->general, $this->env, $lastTurn, @@ -1133,6 +1137,9 @@ class GeneralAI } } + if(!$candidateArgs){ + return null; + } $cmd = buildNationCommandClass( 'che_포상', $this->general, $this->env, $lastTurn, @@ -1203,6 +1210,10 @@ class GeneralAI ]; } } + + if(!$candidateArgs){ + return null; + } $cmd = buildNationCommandClass( 'che_포상', $this->general, $this->env, $lastTurn, @@ -1304,6 +1315,10 @@ class GeneralAI } } + + if(!$candidateArgs){ + return null; + } $cmd = buildNationCommandClass( 'che_포상', $this->general, $this->env, $lastTurn, @@ -1422,6 +1437,10 @@ class GeneralAI } } + + if(!$candidateArgs){ + return null; + } $cmd = buildNationCommandClass( 'che_몰수', $this->general, $this->env, $lastTurn, @@ -1605,7 +1624,7 @@ class GeneralAI } //일반장 행동 - protected function do일반내정(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do일반내정(): ?GeneralCommand { $leadership = $this->leadership; $strength = $this->strength; @@ -1691,7 +1710,7 @@ class GeneralAI return Util::choiceRandomUsingWeightPair($cmdList); } - protected function do긴급내정(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do긴급내정(): ?GeneralCommand { if($this->dipState === self::d평화){ return null; @@ -1724,7 +1743,7 @@ class GeneralAI return null; } - protected function do전쟁내정(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do전쟁내정(): ?GeneralCommand { if($this->dipState === self::d평화){ @@ -1830,7 +1849,7 @@ class GeneralAI } - protected function do금쌀구매(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do금쌀구매(): ?GeneralCommand { $general = $this->general; $avgAmount = ($general->getVar('gold') + $general->getVar('rice'))/2; @@ -1920,7 +1939,7 @@ class GeneralAI return null; } - protected function do징병(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do징병(): ?GeneralCommand { if (in_array($this->dipState, [self::d평화, self::d선포])) { return null; @@ -2072,7 +2091,7 @@ class GeneralAI return $cmd; } - protected function do전투준비(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do전투준비(): ?GeneralCommand { if (in_array($this->dipState, [self::d평화, self::d선포])) { return null; @@ -2103,7 +2122,7 @@ class GeneralAI return Util::choiceRandomUsingWeightPair($cmdList); } - public function do소집해제(GeneralCommand $reservedCommand): ?GeneralCommand + public function do소집해제(): ?GeneralCommand { if ($this->attackable){ return null; @@ -2125,7 +2144,7 @@ class GeneralAI } - protected function do출병(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do출병(): ?GeneralCommand { if (!$this->attackable) { return null; @@ -2171,13 +2190,13 @@ class GeneralAI /* - protected function doNPC증여(GeneralCommand $reservedCommand): ?GeneralCommand + protected function doNPC증여(): ?GeneralCommand { return null; } */ - protected function doNPC헌납(GeneralCommand $reservedCommand): ?GeneralCommand + protected function doNPC헌납(): ?GeneralCommand { $policy = $this->nationPolicy; $general = $this->general; @@ -2241,7 +2260,7 @@ class GeneralAI } - protected function do후방워프(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do후방워프(): ?GeneralCommand { if (in_array($this->dipState, [self::d평화, self::d선포])) { return null; @@ -2318,7 +2337,7 @@ class GeneralAI return $cmd; } - protected function do전방워프(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do전방워프(): ?GeneralCommand { if(!$this->attackable){ return null; @@ -2365,7 +2384,7 @@ class GeneralAI return $cmd; } - protected function do내정워프(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do내정워프(): ?GeneralCommand { $city = $this->city; @@ -2399,6 +2418,7 @@ class GeneralAI if($city['city'] === $candidate['city']){ continue; } + $realDevelRate = 0; foreach($this->calcCityDevelRate($city) as $develKey => [$develVal, $develType]){ if(!($this->genType & $develType)){ @@ -2411,7 +2431,7 @@ class GeneralAI continue; } - $candidateCities[$city['city']] = $realDevelRate / \sqrt(count($city['generals']) + 1); + $candidateCities[$city['city']] = $realDevelRate / \sqrt(count($city['generals']??[]) + 1); } if(!$candidateCities){ @@ -2429,7 +2449,7 @@ class GeneralAI } - protected function do귀환(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do귀환(): ?GeneralCommand { $general = $this->general; $city = $this->city; @@ -2444,9 +2464,8 @@ class GeneralAI return $cmd; } - protected function do집합(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do집합(): ?GeneralCommand { - $cmd = $reservedCommand; $general = $this->general; $cmd = buildGeneralCommandClass('che_집합', $general, $this->env); @@ -2455,7 +2474,7 @@ class GeneralAI return $cmd; } - protected function do방랑군이동(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do방랑군이동(): ?GeneralCommand { $db = DB::db(); @@ -2510,7 +2529,7 @@ class GeneralAI return $cmd; } - protected function do거병(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do거병(): ?GeneralCommand { $general = $this->general; // 초반이면서 능력이 좋은놈 위주로 1.4%확률로 거병 @@ -2540,7 +2559,7 @@ class GeneralAI return $cmd; } - protected function do해산(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do해산(): ?GeneralCommand { $cmd = buildGeneralCommandClass('che_해산', $this->general, $this->env, null); if(!$cmd->isRunnable()){ @@ -2549,7 +2568,7 @@ class GeneralAI return $cmd; } - protected function do건국(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do건국(): ?GeneralCommand { $nationType = Util::choiceRandom(GameConst::$availableNationType); $nationColor = Util::choiceRandom(array_keys(GetNationColors())); @@ -2564,7 +2583,7 @@ class GeneralAI return $cmd; } - protected function do선양(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do선양(): ?GeneralCommand { $db = DB::db(); $cmd = buildGeneralCommandClass('che_선양', $this->general, $this->env, [ @@ -2577,7 +2596,7 @@ class GeneralAI return $cmd; } - protected function do국가선택(GeneralCommand $reservedCommand): ?GeneralCommand + protected function do국가선택(): ?GeneralCommand { $general = $this->getGeneralObj(); $city = $this->city; @@ -2621,7 +2640,7 @@ class GeneralAI } //랜임 커맨드 입력. - $cmd = buildGeneralCommandClass('che_랜덤임관', $general, $env, ['destNationID' => $rulerNation]); + $cmd = buildGeneralCommandClass('che_랜덤임관', $general, $env); if(!$cmd->isRunnable()){ return null; } @@ -2672,7 +2691,7 @@ class GeneralAI return null; } - protected function do중립(GeneralCommand $reservedCommand): GeneralCommand + protected function do중립(): GeneralCommand { $general = $this->general; if($general->getNationID() == 0){ @@ -2870,7 +2889,7 @@ class GeneralAI $this->chooseNonLordPromotion(); } - if(!($reservedCommand instanceof Command\NationCommand\휴식) && $reservedCommand->isRunnable()){ + if(!($reservedCommand instanceof Command\Nation\휴식) && $reservedCommand->isRunnable()){ return $reservedCommand; } @@ -2945,17 +2964,17 @@ class GeneralAI } if($general->getVar('officer_level') === 12 && $this->generalPolicy->can선양){ - $result = $this->do선양($reservedCommand); + $result = $this->do선양(); if($result !== null){ return $result; } } if($npcType == 5){ - return $this->do집합($reservedCommand); + return $this->do집합(); } - if(!($reservedCommand instanceof Command\General\휴식) && $reservedCommand->isRunnable()){ + if(!($reservedCommand instanceof Command\General\휴식)){ return $reservedCommand; } @@ -2964,32 +2983,32 @@ class GeneralAI } if($npcType == 2 && $nationID == 0){ - $result = $this->do거병($reservedCommand); + $result = $this->do거병(); if($result !== null){ return $result; } } if($nationID === 0 && $this->generalPolicy->can국가선택){ - $result = $this->do국가선택($reservedCommand); + $result = $this->do국가선택(); if($result !== null){ return $result; } - return $this->do중립($reservedCommand); + return $this->do중립(); } if($npcType >= 2 && $general->getVar('officer_level') == 12 && !$this->nation['capital']){ //방랑군 건국 - $result = $this->do건국($reservedCommand); + $result = $this->do건국(); if($result !== null){ return $result; } - $result = $this->do방랑군이동($reservedCommand); + $result = $this->do방랑군이동(); if($result !== null){ return $result; } - $result = $this->do해산($reservedCommand); + $result = $this->do해산(); if($result !== null){ return $result; } @@ -3000,13 +3019,13 @@ class GeneralAI continue; } /** @var ?GeneralCommand */ - $result = $this->{'do'.$actionName}($reservedCommand); + $result = $this->{'do'.$actionName}(); if($result !== null){ return $result; } } - return $this->do중립($reservedCommand); + return $this->do중립(); } protected function calcNationDevelopedRate() diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index 4dc8790e..2b5416e6 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -21,7 +21,7 @@ class WarUnitCity extends WarUnit{ $this->cityRate = $cityRate; $this->logger = $general->getLogger(); - $this->crewType = GameUnitConst::byID(GameUnitConst::T_CASTLE); + $this->crewType = GameUnitConst::byID(GameUnitConst::CREWTYPE_CASTLE); $this->hp = $this->getVar('def') * 10; diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index 4617167b..46c65d0e 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -46,7 +46,7 @@ class WarUnitGeneral extends WarUnit{ function setOppose(?WarUnit $oppose){ parent::setOppose($oppose); $general = $this->general; - $this->general->increaseVar('warnum', 1); + $this->general->increaseRankVar('warnum', 1); if($this->isAttacker){ $general->updateVar('recent_war', $general->getTurnTime());