인재탐색 추가. gencount, npc_id 관련 수정
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
namespace sammo\GeneralCommand;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst, GameUnitConst,
|
||||
LastTurn,
|
||||
Command
|
||||
};
|
||||
|
||||
|
||||
use function \sammo\{
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use sammo\CityConst;
|
||||
use sammo\MustNotBeReachedException;
|
||||
|
||||
|
||||
|
||||
class che_랜덤임관 extends Command\GeneralCommand{
|
||||
static protected $actionName = '랜덤임관';
|
||||
|
||||
protected function argTest():bool{
|
||||
|
||||
$destNationIDList = $this->arg['destNationIDList']??null;
|
||||
//null은 에러, []는 정상
|
||||
|
||||
if($destNationIDList === null || is_array($destNationIDList)){
|
||||
return false;
|
||||
}
|
||||
if(Util::isDict($destNationIDList)){
|
||||
return false;
|
||||
}
|
||||
foreach($destNationIDList as $nationID){
|
||||
if(!is_int($nationID)){
|
||||
return false;
|
||||
}
|
||||
if($nationID < 1){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->arg = [
|
||||
'destNationIDList' => $destNationIDList
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
$env = $this->env;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['BeNeutral'],
|
||||
['ExistsDestNation'],
|
||||
['AllowJoinAction'],
|
||||
['ExistsAllowJoinNation', $relYear, [$this->arg['destNationIDList']]],
|
||||
];
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$env = $this->env;
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = substr($general->getVar('turntime'),11,5);
|
||||
$generalName = $general->getName();
|
||||
$josaYi = JosaUtil::pick($generalName, '이');
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$notIn = array_merge(Json::decode($general->getVar(['nations'])), $this->arg['destNationIDList']);
|
||||
|
||||
$destNation = null;
|
||||
|
||||
if ($general->getVar('npc') >= 2 && !$env['fiction'] && 1000 <= $admin['scenario'] && $admin['scenario'] < 2000) {
|
||||
$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.level = 12 WHERE scout=0 and gennum<%i and nation.nation not in %li',
|
||||
$notIn,
|
||||
$relYear<3?GameConst::$initialNationGenLimit:GameConst::$defaultMaxGeneral
|
||||
);
|
||||
shuffle($nations);
|
||||
|
||||
$allGen = Util::arraySum($nations, 'gennum');
|
||||
|
||||
$maxScore = 1<<30;
|
||||
|
||||
$affinity = $general->getVar('affinity');
|
||||
|
||||
foreach($nations as $testNation){
|
||||
$affinity = abs($affinity - $testNation['affinity']);
|
||||
$affinity = min($affinity, abs($affinity - 150));
|
||||
|
||||
$score = log($affinity + 1, 2);//0~
|
||||
|
||||
//쉐킷쉐킷
|
||||
$score += Util::randF();
|
||||
|
||||
$score += sqrt($testNation['gennum']/$allGen);
|
||||
|
||||
if($score < $maxScore){
|
||||
$maxScore = $score;
|
||||
$destNation = $testNation;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$nations = $db->queryFirstColumn(
|
||||
'SELECT nation, name, gennum, scout FROM nation WHERE scout=0 AND gennum < %i AND no NOT IN %li',
|
||||
$relYear<3?GameConst::$initialNationGenLimit:GameConst::$defaultMaxGeneral,
|
||||
$notIn
|
||||
);
|
||||
|
||||
$allGen = Util::arraySum($nations, 'gennum');
|
||||
|
||||
$randVals = [];
|
||||
foreach($nations as $testNation){
|
||||
$nationID = $nations['nation'];
|
||||
$randVals[] = [$testNation, sqrt($allGen/$testNation['gennum'])];
|
||||
}
|
||||
|
||||
$destNation = Util::choiceRandomUsingWeightPair($randVals);
|
||||
}
|
||||
|
||||
if(!$destNation){
|
||||
throw new MustNotBeReachedException();
|
||||
}
|
||||
|
||||
$destNation = $this->destNation;
|
||||
$gennum = $destNation['gennum'];
|
||||
$destNationID = $destNation['nation'];
|
||||
$destNationName = $destNation['name'];
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$talkList = [
|
||||
'어쩌다 보니',
|
||||
'인연이 닿아',
|
||||
'발길이 닿는 대로',
|
||||
'소문을 듣고',
|
||||
'점괘에 따라',
|
||||
];
|
||||
$randomTalk = Util::choiceRandom($talkList);
|
||||
|
||||
$logger->pushGeneralActionLog("<D>{$destNationName}</>에 랜덤 임관했습니다. <1>$date</>");
|
||||
$logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>에 랜덤 임관");
|
||||
$logger->pushGlobalActionLog("{$generalName}</>{$josaYi} {$randomTalk} <D><b>{$destNationName}</b></>에 <S>임관</>했습니다.");
|
||||
|
||||
if($gennum < GameConst::$initialNationGenLimit) {
|
||||
$exp = 700;
|
||||
}
|
||||
else {
|
||||
$exp = 100;
|
||||
}
|
||||
|
||||
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
||||
$general->setVar('nation', $destNationID);
|
||||
$general->setVar('level', 1);
|
||||
$general->setVar('belong', 1);
|
||||
|
||||
if($this->destGeneralObj !== null){
|
||||
$general->setVar('city', $this->destGeneralObj->getCityID());
|
||||
}
|
||||
else{
|
||||
$targetCityID = $db->queryFirstField('SELECT city FROM nation WHERE nation = %i AND level=12', $destNationID);
|
||||
$general->setVar('city', $targetCityID);
|
||||
}
|
||||
|
||||
$db->update('nation', [
|
||||
'gennum'=>$db->sqleval('gennum + 1')
|
||||
], 'nation=%i', $destNationID);
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
if($general->getVar('npc') == 1 || $relYear >= 3){
|
||||
$joinedNations = Join::decode($general->getVar('nations'));
|
||||
$joinedNations[] = $destNationID;
|
||||
$general->setVar('nations', Join::encode($joinedNations));
|
||||
}
|
||||
|
||||
$general->increaseVar('experience', $exp);
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general, '랜덤 임관');
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
namespace sammo\GeneralCommand;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function \sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
|
||||
|
||||
class che_인재탐색 extends Command\GeneralCommand{
|
||||
static protected $actionName = '인재탐색';
|
||||
|
||||
protected function argTest():bool{
|
||||
$this->arg = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setNation(['gennum']);
|
||||
$env = $this->env;
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['NotBeNeutral'],
|
||||
['NotWanderingNation'],
|
||||
['ReqGeneralGold', $reqGold],
|
||||
['ReqGeneralRice', $reqRice],
|
||||
];
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
if($relYear < 3 && $this->nation['gennum'] >= GameConst::$initialNationGenLimit){
|
||||
$nationName = $this->nation['name'];
|
||||
$josaUn = JosaUtil::pick($nationName, '은');
|
||||
$this->runnableConstraints[] = ['AlwaysFail', "현재 <D>{$nationName}</>{$josaUn} 탐색이 제한되고 있습니다."];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
return [$this->env['develcost'], 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$env = $this->env;
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = substr($general->getVar('turntime'),11,5);
|
||||
|
||||
$nationID = $general->getNationID();
|
||||
|
||||
$genCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation=%i AND npc < 2', $nationID);
|
||||
$npcCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation=%i AND npc == 3', $nationID);
|
||||
$npcOtherCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation!=%i AND npc == 32', $nationID);
|
||||
|
||||
|
||||
$genCount = Util::valueFit($genCount, 1);
|
||||
$npcCount = Util::valueFit($npcCount, 1);
|
||||
$npcOtherCountScore = Util::round(sqrt($npcOtherCount + 1)) - 1;
|
||||
|
||||
//TODO: 수식 재 설계
|
||||
$randPick = 1 / (sqrt($genCount * $npcCount * $npcCount) + $npcOtherCount);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
if(!Util::randBool($randPick)){
|
||||
$logger->pushGeneralActionLog("인재를 찾을 수 없었습니다. <1>$date</>");
|
||||
|
||||
$incStat = Util::choiceRandomUsingWeight([
|
||||
'leader2'=>$general->getLeadership(false, false, false, false),
|
||||
'power2'=>$general->getPower(false, false, false, false),
|
||||
'intel2'=>$general->getIntel(false, false, false, false)
|
||||
]);
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$exp = 100;
|
||||
$ded = 70;
|
||||
|
||||
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
||||
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
|
||||
|
||||
$general->increaseVarWithLimit('gold', -$reqGold, 0);
|
||||
$general->increaseVarWithLimit('rice', -$reqRice, 0);
|
||||
$general->increaseVar('experience', $exp);
|
||||
$general->increaseVar('dedication', $ded);
|
||||
$general->increaseVar($incStat, 1);
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
return true;
|
||||
}
|
||||
//인간적으로 너무 길어서 끊었다!
|
||||
|
||||
$exp = 200;
|
||||
$ded = 300;
|
||||
|
||||
if($env['scenario'] < 100){
|
||||
$pickTypeList = ['무'=>4, '지'=>6];
|
||||
}
|
||||
else{
|
||||
$pickTypeList = ['무'=>4, '지'=>4, '무지'=>2];
|
||||
}
|
||||
|
||||
$pickType = Util::choiceRandomUsingWeightPair($pickTypeList);
|
||||
|
||||
$mainStat = GameConst::$defaultStatMax - Util::randRangeInt(0, 10);
|
||||
$otherStat = GameConst::$defaultStatMin + Util::randRangeInt(0, 5);
|
||||
$subStat = GameConst::$defaultStatTotal - $mainStat - $otherStat;
|
||||
if($subStat < GameConst::$defaultStatMin){
|
||||
$subStat = $otherStat;
|
||||
$otherStat = GameConst::$defaultStatMin;
|
||||
$mainStat = GameConst::$defaultStatTotal - $subStat - $otherStat;
|
||||
if($mainStat){
|
||||
throw new \LogicException('기본 스탯 설정값이 잘못되어 있음');
|
||||
}
|
||||
}
|
||||
|
||||
$avgGen = $db->queryFirstRow(
|
||||
'SELECT max(leader+power+intel) as lpi, avg(dedication) as ded,avg(experience) as exp,
|
||||
avg(dex0) as dex0, avg(dex10) as dex10, avg(dex20) as dex20, avg(dex30) as dex30, avg(dex40) as dex40
|
||||
from general where nation=%i',
|
||||
$nationID
|
||||
);
|
||||
|
||||
if($pickType == '무'){
|
||||
$leader = $subStat;
|
||||
$power = $mainStat;
|
||||
$intel = $otherStat;
|
||||
}
|
||||
else if($pickType == '지'){
|
||||
$leader = $subStat;
|
||||
$power = $otherStat;
|
||||
$intel = $mainStat;
|
||||
}
|
||||
else{
|
||||
$leader = $otherStat;
|
||||
$power = $subStat;
|
||||
$intel = $mainStat;
|
||||
}
|
||||
|
||||
// 국내 최고능치 기준으로 랜덤성 스케일링
|
||||
$maxLPI = $avgGen['lpi'];
|
||||
if($maxLPI > 210) {
|
||||
$leader *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.6, 0.9);
|
||||
$power *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.6, 0.9);
|
||||
$intel *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.6, 0.9);
|
||||
} elseif($maxLPI > 180) {
|
||||
$leader *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.75, 0.95);
|
||||
$power *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.75, 0.95);
|
||||
$intel *= $avgGen['lpi'] / GameConst::$defaultStatTotal * Util::randRange(0.75, 0.95);
|
||||
} else {
|
||||
$leader *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.9, 1);
|
||||
$power *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.9, 1);
|
||||
$intel *= $maxLPI / GameConst::$defaultStatTotal * Util::randRange(0.9, 1);
|
||||
}
|
||||
$leader = Util::round($leader);
|
||||
$power = Util::round($power);
|
||||
$intel = Util::round($intel);
|
||||
|
||||
$isOurNation = $this->nation['scout'] == 0;
|
||||
|
||||
$newNPC = new \sammo\Scenario\NPC(
|
||||
Util::randRangeInt(1, 150),
|
||||
\sammo\getRandGenName(),
|
||||
null,
|
||||
$isOurNation?$nationID:0,
|
||||
$general->getCityID(),
|
||||
$leader,
|
||||
$power,
|
||||
$intel,
|
||||
$isOurNation?1:0,
|
||||
$env['year'] - 20,
|
||||
$env['year'] + Util::randRangeInt(10, 50),
|
||||
null,
|
||||
null
|
||||
);
|
||||
$newNPC->npc = 3;
|
||||
$newNPC->setMoney(100, 100);
|
||||
$newNPC->setExpDed($avgGen['exp'], $avgGen['ded']);
|
||||
$newNPC->setSpecYear(
|
||||
Util::round((80 - $age)/12) + $age,
|
||||
Util::round((80 - $age)/3) + $age
|
||||
);
|
||||
$newNPC->setDex(
|
||||
$avgGen['dex0'],
|
||||
$avgGen['dex10'],
|
||||
$avgGen['dex20'],
|
||||
$avgGen['dex30'],
|
||||
$avgGen['dex40']
|
||||
);
|
||||
|
||||
$newNPC->build($this->env);
|
||||
$npcName = $newNPC->realName;
|
||||
$josaRa = JosaUtil::pick($npcName, '라');
|
||||
|
||||
if($isOurNation){
|
||||
$scoutType = '영입';
|
||||
$db->update('nation', [
|
||||
'gennum'=>$db->sqleval('gennum + 1')
|
||||
], 'nation=%i', $nationID);
|
||||
}
|
||||
else{
|
||||
$scoutType = '발견';
|
||||
}
|
||||
|
||||
$generalName = $general->getName();
|
||||
$josaYi = JosaUtil::pick($generalName, '이');
|
||||
|
||||
$logger->pushGeneralActionLog("<Y>$npcName</>{$josaRa}는 <C>인재</>를 {$scoutType}하였습니다! <1>$date</>");
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <Y>$npcName</>{$josaRa}는 <C>인재</>를 {$scoutType}하였습니다!");
|
||||
$logger->pushGeneralHistoryLog("<Y>$npcName</>{$josaRa}는 <C>인재</>를 {$scoutType}");
|
||||
|
||||
$incStat = Util::choiceRandomUsingWeight([
|
||||
'leader2'=>$general->getLeadership(false, false, false, false),
|
||||
'power2'=>$general->getPower(false, false, false, false),
|
||||
'intel2'=>$general->getIntel(false, false, false, false)
|
||||
]);
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$exp = 200;
|
||||
$ded = 300;
|
||||
|
||||
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
||||
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
|
||||
|
||||
$general->increaseVarWithLimit('gold', -$reqGold, 0);
|
||||
$general->increaseVarWithLimit('rice', -$reqRice, 0);
|
||||
$general->increaseVar('experience', $exp);
|
||||
$general->increaseVar('dedication', $ded);
|
||||
$general->increaseVar($incStat, 3);
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general);
|
||||
$general->applyDB($db);
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -66,6 +66,7 @@ class che_임관 extends Command\GeneralCommand{
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
$env = $this->env;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
@@ -80,7 +81,7 @@ class che_임관 extends Command\GeneralCommand{
|
||||
$this->setDestNation($destNationID, ['gennum', 'scout']);
|
||||
}
|
||||
|
||||
$relYear = $env['year'] = $env['startyear'];
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['BeNeutral'],
|
||||
@@ -150,7 +151,7 @@ class che_임관 extends Command\GeneralCommand{
|
||||
'gennum'=>$db->sqleval('gennum + 1')
|
||||
], 'nation=%i', $destNationID);
|
||||
|
||||
$relYear = $env['year'] = $env['startyear'];
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
if($general->getVar('npc') == 1 || $relYear >= 3){
|
||||
$joinedNations = Join::decode($general->getVar('nations'));
|
||||
$joinedNations[] = $destNationID;
|
||||
|
||||
@@ -75,10 +75,10 @@ class che_장비매매 extends Command\GeneralCommand{
|
||||
$this->runnableConstraints[] = ['ReqGeneralValue', $itemType, $itemTypeName, 1];
|
||||
}
|
||||
else if($itemCode == $general->getVar($itemType)){
|
||||
$this->runnableConstraints = [['AlwaysFail', '이미 가지고 있습니다.']];
|
||||
$this->runnableConstraints[] = ['AlwaysFail', '이미 가지고 있습니다.'];
|
||||
}
|
||||
else if($itemType != 'item' && $general->getVar($itemType) > 6){
|
||||
$this->runnableConstraints[] = [['AlwaysFail', '이미 진귀한 것을 가지고 있습니다.']];
|
||||
$this->runnableConstraints[] = ['AlwaysFail', '이미 진귀한 것을 가지고 있습니다.'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user