arg = null; return true; } protected function init(){ $general = $this->generalObj; $this->setCity(); $this->setNation(); [$reqGold, $reqRice] = $this->getCost(); $this->fullConditionConstraints=[ ConstraintHelper::NotBeNeutral(), ConstraintHelper::NotWanderingNation(), ConstraintHelper::OccupiedCity(), ConstraintHelper::SuppliedCity(), ConstraintHelper::ReqGeneralGold($reqGold), ConstraintHelper::ReqGeneralRice($reqRice), ConstraintHelper::RemainCityTrust(static::$actionName) ]; $this->reqRice = $reqRice; } public function getCommandDetailTitle():string{ $name = $this->getName(); $statTypeBase = [ 'leadership'=>'통솔경험', 'strength'=>'무력경험', 'intel'=>'지력경험', ]; $statType = $statTypeBase[static::$statKey]; [$reqGold, $reqRice] = $this->getCost(); $title = "{$name}({$statType}"; if($reqGold > 0){ $title .= ", 자금{$reqGold}"; } if($reqRice > 0){ $title .= ", 군량{$reqRice}"; } $title .= ')'; return $title; } public function getCost():array{ $develCost = $this->env['develcost'] * 2; $reqGold = 0; $reqRice = $this->generalObj->onCalcDomestic(static::$actionKey, 'cost', $develCost); return [$reqGold, Util::round($reqRice)]; } public function getCompensationStyle():?int{ return $this->generalObj->onCalcDomestic(static::$actionKey, 'score', 100)<=>100; } public function getPreReqTurn():int{ return 0; } public function getPostReqTurn():int{ return 0; } protected function calcBaseScore(RandUtil $rng):float{ $general = $this->generalObj; if(static::$statKey == 'leadership'){ $score = $general->getLeadership(true, true, true, false); } else{ throw new \sammo\MustNotBeReachedException(); } $adjustedStat = $score; $expLevel = $general->getVar('explevel'); $expBonus = getDomesticExpLevelBonus($expLevel); $score *= $expBonus; $randomMultiplier = $rng->nextRange(0.8, 1.2); $score *= $randomMultiplier; $score = $general->onCalcDomestic(static::$actionKey, 'score', $score); $score = Util::valueFit($score, 1); $this->baseTrace = [ 'adjustedStat' => $adjustedStat, 'expLevel' => $expLevel, 'expBonus' => $expBonus, 'randomMultiplier' => $randomMultiplier, 'domesticScore' => $score, ]; return $score; } public function run(\Sammo\RandUtil $rng):bool{ if(!$this->hasFullConditionMet()){ throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } $db = DB::db(); $general = $this->generalObj; $calculatedBaseScore = $this->calcBaseScore($rng); $score = Util::valueFit($calculatedBaseScore, 1); ['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general, static::$statKey); $successRatio = $general->onCalcDomestic(static::$actionKey, 'success', $successRatio); $failRatio = $general->onCalcDomestic(static::$actionKey, 'fail', $failRatio); $successRatio = Util::valueFit($successRatio, 0, 1); $failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio); $normalRatio = 1 - $failRatio - $successRatio; $pick = $rng->choiceUsingWeight([ 'fail'=>$failRatio, 'success'=>$successRatio, 'normal'=>$normalRatio ]); $logger = $general->getLogger(); $date = $general->getTurnTime($general::TURNTIME_HM); $criticalMultiplier = CriticalScoreEx($rng, $pick); $score *= $criticalMultiplier; $exp = $score * 0.7; $ded = $score * 1.0; if (in_array((string)$general->getID(), array_filter(explode(',', (string)getenv('REF_AI_TRACE_GENERAL_IDS')), 'strlen'), true)) { fwrite(STDOUT, 'DOMESTIC_CALC_TRACE ' . json_encode([ 'engine' => 'ref', 'generalId' => $general->getID(), 'action' => static::class, 'calculatedBaseScore' => $calculatedBaseScore, 'baseTrace' => $this->baseTrace, 'successRatio' => $successRatio, 'failRatio' => $failRatio, 'normalRatio' => $normalRatio, 'pick' => $pick, 'criticalMultiplier' => $criticalMultiplier, 'rewardScore' => $score, 'appliedScore' => $score / 10, 'exp' => $exp, 'dedication' => $ded, ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n"); } if($pick == 'success'){ updateMaxDomesticCritical($general, $score); } else{ $general->setAuxVar('max_domestic_critical', 0); } $score /= 10; $scoreText = number_format($score, 1); $josaUl = JosaUtil::pick(static::$actionName, '을'); if($pick == 'fail'){ $logger->pushGeneralActionLog(static::$actionName."{$josaUl} 실패하여 $scoreText 상승했습니다. <1>$date"); } else if($pick == 'success'){ $logger->pushGeneralActionLog(static::$actionName."{$josaUl} 성공하여 $scoreText 상승했습니다. <1>$date"); } else{ $logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 $scoreText 상승했습니다. <1>$date"); } //NOTE: 내정량 상승시 초과 가능? $cityUpdated = [ static::$cityKey => Util::valueFit( $this->city[static::$cityKey] + $score, 0, 100 ) ]; $db->update('city', $cityUpdated, 'city=%i', $general->getVar('city')); $general->increaseVarWithLimit('rice', -$this->reqRice, 0); $general->addExperience($exp); $general->addDedication($ded); $general->increaseVar(static::$statKey.'_exp', 1); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); StaticEventHandler::handleEvent($this->generalObj, $this->destGeneralObj, $this::class, $this->env, $this->arg ?? []); tryUniqueItemLottery(\sammo\genGenericUniqueRNGFromGeneral($general, static::$actionName), $general); $general->applyDB($db); return true; } }