From 4d8c3c75d6c3e79315824e46be293bdaf6bb80c3 Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 25 Jun 2020 23:43:35 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=88=20=EA=B8=88=EC=8C=80=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/GeneralAI.php | 167 +++++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 72 deletions(-) diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 9495428a..05500803 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -2145,97 +2145,120 @@ class GeneralAI protected function do금쌀구매(): ?GeneralCommand { $general = $this->general; - $avgAmount = ($general->getVar('gold') + $general->getVar('rice'))/2; if($this->city['trade'] === null && !$this->generalPolicy->can상인무시){ return null; } - if($avgAmount < $this->baseDevelCost){ + $kill = $general->getRankVar('killcrew') + 50000; + $death = $general->getRankVar('deathcrew') + 50000; + $deathRate = $death/$kill; + + $absGold = $general->getVar('gold'); + $absRice = $general->getVar('rice'); + + $relGold = $absGold; + $relRice = $absRice * $deathRate; + + if($absGold + $absRice < $this->baseDevelCost * 2){ return null; } - if($this->dipState !== self::d평화 && ($this->genType & self::t통솔장)){ - $crewType = $general->getCrewTypeObj(); - if($this->generalPolicy->can모병){ - $costCmd = buildGeneralCommandClass('che_모병', $general, $this->env, [ - 'crewType'=>$crewType->id, - 'amount'=>$this->fullLeadership*100 - ]); - } - else{ - $costCmd = buildGeneralCommandClass('che_징병', $general, $this->env, [ - 'crewType'=>$crewType->id, - 'amount'=>$this->fullLeadership*100 - ]); - } + $crewType = $general->getCrewTypeObj(); + if($this->generalPolicy->can모병){ + $costCmd = buildGeneralCommandClass('che_모병', $general, $this->env, [ + 'crewType'=>$crewType->id, + 'amount'=>$this->fullLeadership*100 + ]); + } + else{ + $costCmd = buildGeneralCommandClass('che_징병', $general, $this->env, [ + 'crewType'=>$crewType->id, + 'amount'=>$this->fullLeadership*100 + ]); + } - $goldCost = $costCmd->getCost()[0]; - $riceCost = $crewType->riceWithTech( - $this->nation['tech'], - $this->fullLeadership*100 * - $general->getRankVar('killcrew')/max($general->getRankVar('deathcrew'),1) - ); + $goldCost = $costCmd->getCost()[0]; + $riceCost = $crewType->riceWithTech( + $this->nation['tech'], + $this->fullLeadership*100 + ); - if($avgAmount * 2 > $goldCost + $riceCost){ - if ($general->getVar('rice') < $riceCost * 2 && $general->getVar('gold') >= $goldCost * 4) { - //1:1 - $amount = Util::valueFit(Util::toInt($general->getVar('gold') - $avgAmount), 100, GameConst::$maxResourceActionAmount); - if($amount >= $this->nationPolicy->minimumResourceActionAmount){ - $cmd = buildGeneralCommandClass('che_군량매매', $general, $this->env, - [ - 'buyRice' => true, - 'amount' => $amount - ] - ); - if($cmd->hasFullConditionMet()){ - return $cmd; - } - } - - } - if ($general->getVar('gold') < $goldCost && $general->getVar('rice') >= $riceCost * 2) { - $avgAmount = ($general->getVar('gold') + $general->getVar('rice'))/2; - $amount = Util::valueFit(Util::toInt($general->getVar('rice') - $avgAmount), 100, GameConst::$maxResourceActionAmount); - if($amount >= $this->nationPolicy->minimumResourceActionAmount){ - $cmd = buildGeneralCommandClass('che_군량매매', $general, $this->env, - [ - 'buyRice' => false, - 'amount' => $amount - ] - ); - if($cmd->hasFullConditionMet()){ - return $cmd; - } - } + if(($relGold + $relRice) * 1.5 <= $goldCost + $riceCost){ + return null; + } + + $tryBuying = false; + if ($this->generalPolicy->can상인무시){ + if($relRice * 1.5 < $relGold && $relRice < $riceCost * 2) + { + $tryBuying = true; + } + else if($relRice * 2 < $relGold) + { + $tryBuying = true; + } + + } + else{ + if($relRice * 2 < $relGold && $relRice < $riceCost * 3) + { + $tryBuying = true; + } + } + + if ($tryBuying) { + //1:1 + $amount = Util::valueFit(Util::toInt(($relGold - $relRice) / (1 + $deathRate)), 100, GameConst::$maxResourceActionAmount); + if($amount >= $this->nationPolicy->minimumResourceActionAmount){ + $cmd = buildGeneralCommandClass('che_군량매매', $general, $this->env, + [ + 'buyRice' => true, + 'amount' => $amount + ] + ); + if($cmd->hasFullConditionMet()){ + return $cmd; } } } - if ($general->getVar('rice') < $this->baseDevelCost && $general->getVar('gold') >= $this->baseDevelCost * 3) { - $cmd = buildGeneralCommandClass('che_군량매매', $general, $this->env, - [ - 'buyRice' => true, - 'amount' => Util::valueFit(Util::toInt($general->getVar('gold') - $avgAmount), 100, GameConst::$maxResourceActionAmount) - ] - ); - if($cmd->hasFullConditionMet()){ - return $cmd; + $trySelling = false; + if ($this->generalPolicy->can상인무시){ + if($relGold * 1.5 < $relRice && $relGold < $goldCost * 2) + { + $trySelling = true; + } + else if($relGold * 2 < $relRice) + { + $trySelling = true; + } + + } + else{ + if($relGold * 2 < $relRice && $relGold < $goldCost * 3) + { + $trySelling = true; } } - if ($general->getVar('gold') < $this->baseDevelCost && $general->getVar('rice') >= $this->baseDevelCost * 3) { - $avgAmount = ($general->getVar('gold') + $general->getVar('rice'))/2; - $cmd = buildGeneralCommandClass('che_군량매매', $general, $this->env, - [ - 'buyRice' => false, - 'amount' => Util::valueFit(Util::toInt($general->getVar('rice') - $avgAmount), 100, GameConst::$maxResourceActionAmount) - ] - ); - if($cmd->hasFullConditionMet()){ - return $cmd; + + if ($trySelling) { + $amount = Util::valueFit(Util::toInt(($relRice - $relGold) / (1 + $deathRate)), 100, GameConst::$maxResourceActionAmount); + if($amount >= $this->nationPolicy->minimumResourceActionAmount){ + $cmd = buildGeneralCommandClass('che_군량매매', $general, $this->env, + [ + 'buyRice' => false, + 'amount' => $amount + ] + ); + if($cmd->hasFullConditionMet()){ + return $cmd; + } } } + + return null; }