fix: 랜덤임관시 u국 임관하는 문제 수정

This commit is contained in:
2021-08-11 16:15:46 +09:00
parent 836278cfdf
commit be423d8a08
+84 -79
View File
@@ -1,21 +1,22 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil, TimeUtil, Json,
General,
ActionLogger,
GameConst, GameUnitConst,
LastTurn,
Command
};
use \sammo\DB;
use \sammo\Util;
use \sammo\JosaUtil;
use \sammo\TimeUtil;
use \sammo\Json;
use \sammo\General;
use \sammo\ActionLogger;
use \sammo\GameConst;
use \sammo\GameUnitConst;
use \sammo\LastTurn;
use \sammo\Command;
use function \sammo\{
tryUniqueItemLottery,
getInvitationList,
getNationStaticInfo
};
use function \sammo\tryUniqueItemLottery;
use function \sammo\getInvitationList;
use function \sammo\getNationStaticInfo;
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
@@ -24,10 +25,12 @@ use sammo\MustNotBeReachedException;
class che_랜덤임관 extends Command\GeneralCommand{
class che_랜덤임관 extends Command\GeneralCommand
{
static protected $actionName = '랜덤임관';
protected function argTest():bool{
protected function argTest(): bool
{
$this->arg = null;
return true;
@@ -71,7 +74,7 @@ class che_랜덤임관 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->fullConditionConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::BeNeutral(),
ConstraintHelper::AllowJoinAction(),
];
@@ -83,28 +86,34 @@ class che_랜덤임관 extends Command\GeneralCommand{
*/
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
return '무작위 국가로 임관';
}
public function getBrief():string{
public function getBrief(): string
{
return '무작위 국가로 임관';
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function run():bool{
if(!$this->hasFullConditionMet()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -126,108 +135,107 @@ class che_랜덤임관 extends Command\GeneralCommand{
$destNation = null;
if ($general->getNPCType() >= 2 && !$env['fiction'] && 1000 <= $env['scenario'] && $env['scenario'] < 2000) {
if($notIn){
if ($notIn) {
$nations = $db->query(
'SELECT nation.`name` as `name`,nation.nation as nation,scout,gennum,`affinity` FROM nation join general on general.nation = nation.nation and general.officer_level = 12 WHERE scout=0 and gennum<%i and nation.nation not in %li',
$relYear<3?GameConst::$initialNationGenLimit:GameConst::$defaultMaxGeneral,
$relYear < 3 ? GameConst::$initialNationGenLimit : GameConst::$defaultMaxGeneral,
$notIn
);
}
else{
} else {
$nations = $db->query(
'SELECT nation.`name` as `name`,nation.nation as nation,scout,gennum,`affinity` FROM nation join general on general.nation = nation.nation and general.officer_level = 12 WHERE scout=0 and gennum<%i',
$relYear<3?GameConst::$initialNationGenLimit:GameConst::$defaultMaxGeneral
$relYear < 3 ? GameConst::$initialNationGenLimit : GameConst::$defaultMaxGeneral
);
}
shuffle($nations);
$allGen = Util::arraySum($nations, 'gennum');
$maxScore = 1<<30;
$maxScore = 1 << 30;
$affinity = $general->getVar('affinity');
foreach($nations as $testNation){
foreach ($nations as $testNation) {
$affinity = abs($affinity - $testNation['affinity']);
$affinity = min($affinity, abs($affinity - 150));
$score = log($affinity + 1, 2);//0~
$score = log($affinity + 1, 2); //0~
//쉐킷쉐킷
$score += Util::randF();
$score += sqrt($testNation['gennum']/$allGen);
if($score < $maxScore){
$score += sqrt($testNation['gennum'] / $allGen);
if ($score < $maxScore) {
$maxScore = $score;
$destNation = $testNation;
}
}
}
else{
} else {
$onlyRandom = $env['join_mode'] == 'onlyRandom';
$genLimit = GameConst::$defaultMaxGeneral;
if($onlyRandom && TimeUtil::IsRangeMonth($env['init_year'], $env['init_month'], 1, $env['year'], $env['month'])){
if ($onlyRandom && TimeUtil::IsRangeMonth($env['init_year'], $env['init_month'], 1, $env['year'], $env['month'])) {
$genLimit = GameConst::$initialNationGenLimitForRandInit;
}
else if($relYear < 3){
} else if ($relYear < 3) {
$genLimit = GameConst::$initialNationGenLimit;
}
$generalsCnt = [];
if($notIn){
if ($notIn) {
$rawGeneralsCnt = $db->query(
'SELECT general.nation as nation, nation.gennum, nation.name, npc, count(*) as cnt FROM general JOIN nation ON general.nation = nation.nation WHERE npc != 9 AND nation.gennum < %i AND nation.scout=0 AND nation.nation NOT IN %li GROUP BY general.nation, general.npc',
$genLimit,
$notIn
);
}
else{
} else {
$rawGeneralsCnt = $db->query(
'SELECT general.nation as nation, nation.gennum, nation.name, npc, count(*) as cnt FROM general JOIN nation ON general.nation = nation.nation WHERE npc != 9 AND nation.gennum < %i AND nation.scout=0 GROUP BY general.nation, general.npc',
$genLimit
);
}
foreach($rawGeneralsCnt as $nation){
foreach ($rawGeneralsCnt as $nation) {
$nationID = $nation['nation'];
if(!\key_exists($nationID, $generalsCnt)){
if (!\key_exists($nationID, $generalsCnt)) {
$generalsCnt[$nationID] = [
'nation'=>$nationID,
'gennum'=>$nation['gennum'],
'name'=>$nation['name'],
'cnt'=>0,
'nation' => $nationID,
'gennum' => $nation['gennum'],
'name' => $nation['name'],
'cnt' => 0,
];
$generalsCnt[$nationID]['cnt'] = 0;
}
if($nation['npc'] <= 2){
if ($nation['npc'] <= 2) {
$calcCnt = $nation['cnt'];
}
else{
} else {
$calcCnt = $nation['cnt'] / 2;
}
if ($general->getNPCType() < 2 && Util::starts_with($nation['name'], 'ⓤ')) {
$calcCnt *= 0.01;
}
$generalsCnt[$nationID]['cnt'] += $calcCnt;
}
$randVals = [];
foreach($generalsCnt as $testNation){
$randVals[] = [$testNation, 1/$testNation['cnt']];
foreach ($generalsCnt as $testNation) {
$randVals[] = [$testNation, 1 / $testNation['cnt']];
}
if($randVals){
if ($randVals) {
$destNation = Util::choiceRandomUsingWeightPair($randVals);
}
}
$logger = $general->getLogger();
if(!$destNation){
if (!$destNation) {
//임관 가능한 국가가 없다!
$logger->pushGeneralActionLog("임관 가능한 국가가 없습니다. <1>$date</>");
$logger->pushGeneralActionLog("임관 가능한 국가가 없습니다. <1>$date</>");
$this->alternative = new che_요양($general, $this->env, null);
return false;
}
@@ -236,7 +244,7 @@ class che_랜덤임관 extends Command\GeneralCommand{
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$talkList = [
'어쩌다 보니',
@@ -257,10 +265,9 @@ class che_랜덤임관 extends Command\GeneralCommand{
$logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>에 랜덤 임관");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} {$randomTalk} <D><b>{$destNationName}</b></>에 <S>임관</>했습니다.");
if($gennum < GameConst::$initialNationGenLimit) {
if ($gennum < GameConst::$initialNationGenLimit) {
$exp = 700;
}
else {
} else {
$exp = 100;
}
@@ -268,22 +275,21 @@ class che_랜덤임관 extends Command\GeneralCommand{
$general->setVar('officer_level', 1);
$general->setVar('officer_city', 0);
$general->setVar('belong', 1);
if($this->destGeneralObj !== null){
if ($this->destGeneralObj !== null) {
$general->setVar('city', $this->destGeneralObj->getCityID());
}
else{
} else {
$targetCityID = $db->queryFirstField('SELECT city FROM general WHERE nation = %i AND officer_level=12', $destNationID);
$general->setVar('city', $targetCityID);
}
$db->update('nation', [
'gennum'=>$db->sqleval('gennum + 1')
'gennum' => $db->sqleval('gennum + 1')
], 'nation=%i', $destNationID);
$relYear = $env['year'] - $env['startyear'];
if($general->getNPCType() == 1 || $relYear >= 3){
$joinedNations = $general->getAuxVar('joinedNations')??[];
if ($general->getNPCType() == 1 || $relYear >= 3) {
$joinedNations = $general->getAuxVar('joinedNations') ?? [];
$joinedNations[] = $destNationID;
$general->setAuxVar('joinedNations', $joinedNations);
}
@@ -296,5 +302,4 @@ class che_랜덤임관 extends Command\GeneralCommand{
return true;
}
}
}