AI 뼈대 다시 잡는중

This commit is contained in:
2020-03-31 02:50:07 +09:00
parent b397c41c9e
commit aa7d01f3d6
4 changed files with 850 additions and 613 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ class AutorunGeneralPolicy{
static $한계징병 = '한계징병';
static $고급병종 = '고급병종';
static $전투준비 = '전투준비';
public $소집해제 = '소집해제';
static $소집해제 = '소집해제';
static $출병 = '출병';
+14
View File
@@ -26,6 +26,8 @@ class AutorunNationPolicy {
static $선포 = '선포';
static $천도 = '천도';
//실제 행동
static public $defaultPriority = [
'선포',
@@ -53,6 +55,18 @@ class AutorunNationPolicy {
'NPC전방발령',
];
//순서는 중요하지 않음
static public $availableInstantTurn = [
'유저장긴급포상'=>true,
'유저장후방발령'=>true,
'유저장전방발령'=>true,
'유저장포상'=>true,
'NPC긴급포상'=>true,
'NPC후방발령'=>true,
'NPC포상'=>true,
'NPC전방발령'=>true,
];
public $priority = [];
public $can부대전방발령 = true;
+342 -118
View File
@@ -1,7 +1,13 @@
<?php
namespace sammo;
class GeneralAI{
use Generator;
use sammo\Command\GeneralCommand;
use sammo\Command\NationCommand;
class GeneralAI
{
/**
* @var General $general
*/
@@ -46,7 +52,8 @@ class GeneralAI{
//수뇌용
public function __construct(General $general){
public function __construct(General $general)
{
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$this->env = $gameStor->getValues(['startyear', 'year', 'month', 'turnterm', 'killturn', 'scenario', 'gold_rate', 'rice_rate', 'develcost']);
@@ -78,14 +85,15 @@ class GeneralAI{
$this->calcGenType();
$this->calcDiplomacyState();
}
public function getGeneralObj():General{
public function getGeneralObj(): General
{
return $this->general;
}
protected function calcGenType(){
protected function calcGenType()
{
$leadership = $this->leadership;
$strength = Util::valueFit($this->strength, 1);
$intel = Util::valueFit($this->intel, 1);
@@ -97,7 +105,6 @@ class GeneralAI{
if (Util::randBool($intel / $strength / 2)) {
$genType |= self::t지장;
}
}
//지장
} else {
@@ -116,7 +123,8 @@ class GeneralAI{
$this->genType = $genType;
}
protected function calcDiplomacyState(){
protected function calcDiplomacyState()
{
$db = DB::db();
$nationID = $this->general->getNationID();
$env = $this->env;
@@ -142,8 +150,7 @@ class GeneralAI{
if ($warState == 0) {
$onWar = true;
$warTargetNation[$warNationID] = 2;
}
else{
} else {
$warTargetNation[$warNationID] = 1;
}
}
@@ -154,14 +161,11 @@ class GeneralAI{
$minWarTerm = $db->queryFirstField('SELECT min(term) FROM diplomacy WHERE me = %i AND state=1', $nationID);
if ($minWarTerm === null) {
$this->dipState = self::d평화;
}
else if($minWarTerm > 8){
} else if ($minWarTerm > 8) {
$this->dipState = self::d선포;
}
else if($minWarTerm > 5){
} else if ($minWarTerm > 5) {
$this->dipState = self::d징병;
}
else{
} else {
$this->dipState = self::d직전;
}
@@ -169,14 +173,252 @@ class GeneralAI{
//전쟁으로 인한 attackable인가?
if ($onWar) {
$this->dipState = self::d전쟁;
}
else{
} else {
$this->dipState = self::d징병;
}
}
}
protected function chooseDevelopTurn(bool &$cityFull):array{
protected function do부대전방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do부대후방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do부대유저장후방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do유저장후방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do유저장전방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function doNPC후방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function doNPC전방발령(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do유저장긴급포상(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do유저장포상(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do유저장몰수(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function doNPC긴급포상(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function doNPC포상(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function doNPC몰수(LastTurn $lastTurn): ?NationCommand
{
return null;
}
// 군주 행동
protected function do선포(LastTurn $lastTurn): ?NationCommand
{
return null;
}
protected function do천도(LastTurn $lastTurn): ?NationCommand
{
return null;
}
//일반장 행동
protected function do일반내정(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do긴급내정(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do전쟁내정(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do금쌀구매(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do징병(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do전투준비(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
public function do소집해제(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do출병(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function doNPC증여(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function doNPC헌납(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do후방워프(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do전방워프(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do내정워프(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do귀환(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do임관(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do집합(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do건국(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do선양(GeneralCommand $reservedCommand): ?GeneralCommand
{
return null;
}
protected function do중립(GeneralCommand $reservedCommand): GeneralCommand
{
return buildGeneralCommandClass(null, $this->general, $this->env);
}
public function chooseNationTurn(NationCommand $reservedCommand): NationCommand{
//TODO: NationTurn과 InstantNationTurn 구분 필요
$lastTurn = $reservedCommand->getLastTurn();
if($reservedCommand->isRunnable()){
return $reservedCommand;
}
foreach($this->nationPolicy->priority as $actionName){
/** @var ?NationCommand */
$result = $this->{'do'.$actionName}($lastTurn);
if($result !== null){
return $result;
}
}
return buildNationCommandClass(null, $this->general, $this->env, $this->general->getLastTurn());
}
public function chooseInstantNationTurn(NationCommand $reservedCommand): ?NationCommand{
if($reservedCommand->isRunnable()){
return $reservedCommand;
}
foreach($this->nationPolicy->priority as $actionName){
/** @var ?NationCommand */
if(!key_exists($actionName, $this->nationPolicy::$availableInstantTurn)){
continue;
}
$result = $this->{'do'.$actionName}($reservedCommand);
if($result !== null){
return $result;
}
}
return buildNationCommandClass(null, $this->general, $this->env, $this->general->getLastTurn());
}
public function chooseGeneralTurn(GeneralCommand $reservedCommand): GeneralCommand{
if($reservedCommand->isRunnable()){
return $reservedCommand;
}
foreach($this->nationPolicy->priority as $actionName){
/** @var ?GeneralCommand */
$result = $this->{'do'.$actionName}($reservedCommand);
if($result !== null){
return $result;
}
}
return $this->do중립($reservedCommand);
}
protected function chooseDevelopTurn(bool &$cityFull): array
{
$general = $this->general;
$city = $this->city;
$nation = $this->nation;
@@ -257,11 +499,9 @@ class GeneralAI{
if (!TechLimit($env['startyear'], $env['year'], $nation['tech'] + 1000)) {
//한등급 이상 뒤쳐져 있다면, 조금 더 열심히 하자.
$commandList['che_기술연구'] = $intel;
}
else{
} else {
$commandList['che_기술연구'] = $intel / 4;
}
}
}
}
@@ -295,13 +535,13 @@ class GeneralAI{
$commandList['che_물자조달'] = (
(GameConst::$minNationalGold + GameConst::$minNationalRice + 24 * 5 * $env['develcost']) /
Util::valueFit($nation['gold'] + $nation['rice'], (GameConst::$defaultGold + GameConst::$defaultRice)/2)
);
Util::valueFit($nation['gold'] + $nation['rice'], (GameConst::$defaultGold + GameConst::$defaultRice) / 2));
return [Util::choiceRandomUsingWeight($commandList), null];
}
public function chooseRecruitCrewType():?array{
public function chooseRecruitCrewType(): ?array
{
$general = $this->getGeneralObj();
$city = $this->city;
$nation = $this->nation;
@@ -380,8 +620,7 @@ class GeneralAI{
if ($typesAll) {
$type = Util::choiceRandomUsingWeightPair($types);
}
else{
} else {
$type = GameUnitConst::DEFAULT_CREWTYPE;
}
@@ -405,7 +644,8 @@ class GeneralAI{
]];
}
public function getPayTurnCandidates(string $resName):array{
public function getPayTurnCandidates(string $resName): array
{
$nation = $this->nation;
$remainResource = ['gold' => $nation['gold'], 'rice' => $nation['rice']];
$candidateCommand = [];
@@ -421,7 +661,6 @@ class GeneralAI{
1
];
}
}
if ($this->npcWarGenerals) {
@@ -469,7 +708,6 @@ class GeneralAI{
2
];
}
}
}
@@ -494,7 +732,8 @@ class GeneralAI{
return $candidateCommand;
}
public function chooseNationTurn($command, $arg):array{
public function old_chooseNationTurn($command, $arg): array
{
$generalObj = $this->getGeneralObj();
//NOTE: 수뇌 턴에서는 general과 city이름의 충돌 가능성이 있음
$env = $this->env;
@@ -554,8 +793,7 @@ class GeneralAI{
if ($nationCity['officer4']) {
$frontImportantCitiesID[] = $cityID;
}
}
else{
} else {
$backupCitiesID[] = $cityID;
}
}
@@ -591,18 +829,15 @@ class GeneralAI{
if (!$nationCities[$cityID]['supply']) {
$lostGenerals[] = $nationGeneral;
}
}
else{
} else {
$lostGenerals[] = $nationGeneral;
}
if ($nationGeneral->npc < 2 && $nationGeneral->killturn >= 5) {
$userGenerals[] = $nationGeneral;
}
else if($nationGeneral->leadership>=40 && $nationGeneral->killturn >= 5){
} else if ($nationGeneral->leadership >= 40 && $nationGeneral->killturn >= 5) {
$npcWarGenerals[] = $nationGeneral;
}
else{
} else {
//삭턴이 몇 안남은 장수는 '내정장 npc'로 처리
$npcCivilGenerals[] = $nationGeneral;
}
@@ -630,8 +865,7 @@ class GeneralAI{
if ($lostGeneral->npc < 2) {
if (in_array($this->dipState, [self::d직전, self::d전쟁]) && $frontCitiesID) {
$selCityID = Util::choiceRandom($frontCitiesID);
}
else{
} else {
$selCityID = Util::choiceRandom($supplyCitiesID);
}
$commandList[] = [['che_발령', ['destGeneralID' => $lostGeneral->no, 'destCityID' => $selCityID]], 200];
@@ -709,8 +943,7 @@ class GeneralAI{
'isGold' => $resName == 'gold',
'amount' => $amount
]], 10]; // 금,쌀 1000단위 포상
}
else{
} else {
$amount = min(GameConst::$maxIncentiveAmount, intdiv(($nation[$resName] - ($resName == 'rice' ? (GameConst::$baserice) : (GameConst::$basegold))), 5000) * 1000 + 1000);
$commandList[] = [['che_포상', [
'destGeneralID' => $userGenerals[0]->no,
@@ -718,7 +951,6 @@ class GeneralAI{
'amount' => $amount
]], 1]; // 금,쌀 1000단위 포상
}
}
break;
}
@@ -744,8 +976,7 @@ class GeneralAI{
if ($targetGeneral) {
if ($targetGeneral === $compNpcCivil) {
$amount = Util::round($targetGeneral->$resName - $minRes * 3, -2);
}
else{
} else {
$amount = min(10000, intdiv($targetGeneral->$resName, 5000) * 1000 + 1000);
}
@@ -756,7 +987,6 @@ class GeneralAI{
'amount' => $amount
]], 3];
}
}
} else { // 포상
$compNpcWar = Util::array_first($npcWarGenerals);
@@ -795,8 +1025,7 @@ class GeneralAI{
}
if (in_array($this->dipState, [self::d직전, self::d전쟁]) && $frontCitiesID) {
$selCityID = Util::choiceRandom($frontCitiesID);
}
else{
} else {
$selCityID = Util::choiceRandom($supplyCitiesID);
}
//고립된 장수가 많을 수록 발령 확률 증가
@@ -820,7 +1049,6 @@ class GeneralAI{
$minCity = $nationCity;
break;
}
}
//reverse_order T_T
@@ -878,16 +1106,13 @@ class GeneralAI{
//세명 이상 차이나야 함
$targetGeneral = Util::choiceRandom($maxCity['generals']);
if ($targetGeneral->npc == 5) {
}
else if($targetGeneral->npc>=2 || $maxCity['dev'] >= 95 && $targetGeneral->troop == 0){
} else if ($targetGeneral->npc >= 2 || $maxCity['dev'] >= 95 && $targetGeneral->troop == 0) {
//유저장은 의도가 있을 것이므로 삽나지 않는 이상 발령 안함!
$commandList[] = [['che_발령', [
'destGeneralID' => $targetGeneral->no,
'destCityID' => $targetCity['city']
]], 5];
}
}
}
@@ -923,8 +1148,7 @@ class GeneralAI{
if (Util::randBool(0.3) && $frontImportantCitiesID) {
$targetCityID = Util::choiceRandom($frontImportantCitiesID);
}
else{
} else {
$targetCityID = Util::choiceRandom($frontCitiesID);
}
@@ -936,8 +1160,7 @@ class GeneralAI{
if ($nationGeneral->npc < 2 && ($workRemain & 2)) {
$workRemain ^= 2;
$commandList[] = [$command, $score];
}
else if($nationGeneral->npc>=2 && ($workRemain&1)){
} else if ($nationGeneral->npc >= 2 && ($workRemain & 1)) {
$workRemain ^= 1;
$commandList[] = [$command, $score];
}
@@ -997,8 +1220,7 @@ class GeneralAI{
if ($nationGeneral->npc < 2 && ($workRemain & 2)) {
$workRemain ^= 2;
$commandList[] = [$command, $score];
}
else if($nationGeneral->npc>=2 && ($workRemain&1)){
} else if ($nationGeneral->npc >= 2 && ($workRemain & 1)) {
$workRemain ^= 1;
$commandList[] = [$command, $score];
}
@@ -1013,7 +1235,8 @@ class GeneralAI{
return Util::choiceRandomUsingWeightPair($commandList);
}
public function chooseNeutralTurn():array{
public function chooseNeutralTurn(): array
{
$general = $this->getGeneralObj();
$city = $this->city;
@@ -1053,8 +1276,7 @@ class GeneralAI{
$notFullNationCnt = $db->queryFirstField('SELECT count(nation) FROM nation WHERE gennum < %i', GameConst::$initialNationGenLimit);
if ($nationCnt == 0 || $notFullNationCnt == 0) {
$available = false;
}
else if(Util::randBool(pow(1 / $nationCnt / pow($notFullNationCnt, 3), 1/4))){
} else if (Util::randBool(pow(1 / $nationCnt / pow($notFullNationCnt, 3), 1 / 4))) {
//국가가 1개일 경우에는 '임관하지 않음'
$available = false;
}
@@ -1062,8 +1284,7 @@ class GeneralAI{
if ($general->getVar('affinity') == 999 || !$available) {
$command = 'che_견문'; //견문
}
else{
} else {
//랜임 커맨드 입력.
$command = 'che_랜덤임관';
$arg = [
@@ -1096,7 +1317,8 @@ class GeneralAI{
return [$command, $arg];
}
protected function chooseEndOfNPCTurn():array{
protected function chooseEndOfNPCTurn(): array
{
$general = $this->getGeneralObj();
$city = $this->city;
$nation = $this->nation;
@@ -1107,7 +1329,8 @@ class GeneralAI{
[$baseArmGold, $baseArmRice] = $this->getBaseArmCost();
if($this->dipState == self::d전쟁 &&
if (
$this->dipState == self::d전쟁 &&
$general->getVar('killturn') > 2 &&
$general->getVar('gold') >= $baseArmGold / 3 &&
$general->getVar('rice') >= $baseArmRice &&
@@ -1127,8 +1350,7 @@ class GeneralAI{
if (180 >= $trainAndAtmos && $trainAndAtmos >= 160) {
if ($general->getVar('train') < 80) {
return ['che_훈련', null];
}
else{
} else {
return ['che_사기진작', null];
}
}
@@ -1136,13 +1358,13 @@ class GeneralAI{
if ($general->getVar('gold') >= $general->getVar('rice')) {
return ['che_헌납', ['isGold' => true, 'amount' => GameConst::$maxResourceActionAmount]];
}
else{
} else {
return ['che_헌납', ['isGold' => false, 'amount' => GameConst::$maxResourceActionAmount]];
}
}
public function chooseGeneralTurn($command, $arg):array{
public function old_chooseGeneralTurn($command, $arg): array
{
$general = $this->getGeneralObj();
$city = $this->city;
$nation = $this->nation;
@@ -1167,14 +1389,12 @@ class GeneralAI{
$command = '휴식'; //휴식
$arg = null;
$general->setVar('killturn', 1);
}
else if($general->getVar('level') == 12){
} else if ($general->getVar('level') == 12) {
$command = 'che_선양';
$arg = [
'destGeneralID' => $db->queryFirstField('SELECT `no` FROM general WHERE nation = %i AND npc != 5 ORDER BY RAND() LIMIT 1', $general->getNationID())
];
}
else{
} else {
$command = 'che_집합'; //집합
$arg = [];
$general->setVar('killturn', rand(70, 75));
@@ -1250,8 +1470,7 @@ class GeneralAI{
if (Util::randBool(0.2)) {
return ['che_견문', null];
}
else{
} else {
return ['che_물자조달', null];
}
}
@@ -1265,8 +1484,7 @@ class GeneralAI{
if ($nation['rice'] < 2000) {
if (($genType & self::t통솔장) && $general->getVar('rice') > $baseArmRice) {
return ['che_헌납', ['isGold' => false, 'amount' => Util::toInt(($general->getVar('rice') - $baseArmRice) / 2)]];
}
else if(!($genType & self::t통솔장)){
} else if (!($genType & self::t통솔장)) {
return ['che_헌납', ['isGold' => false, 'amount' => Util::toInt($general->getVar('rice') / 2)]];
}
}
@@ -1295,8 +1513,7 @@ class GeneralAI{
]
];
}
}
else{
} else {
if ($general->getVar('rice') < $this->baseDevelCost && $general->getVar('gold') >= $this->baseDevelCost * 3) {
return [
'che_군량매매',
@@ -1334,7 +1551,6 @@ class GeneralAI{
$score *= 1.3;
}
$moveCities[$moveCityID] = $score;
}
if ($moveCities) {
return ['che_NPC능동', [
@@ -1342,14 +1558,13 @@ class GeneralAI{
'destCityID' => Util::choiceRandomUsingWeight($moveCities),
]];
}
}
return $developTurn;
}
protected function getBaseArmCost(){
protected function getBaseArmCost()
{
//총 통솔의 절반을 징병하는 것을 기준으로 함
$general = $this->getGeneralObj();
$tech = $this->nation['tech'];
@@ -1367,7 +1582,8 @@ class GeneralAI{
return [$baseArmCost, $baseArmRice];
}
protected function processWar():?array{
protected function processWar(): ?array
{
$db = DB::db();
@@ -1472,8 +1688,7 @@ class GeneralAI{
foreach (array_keys(CityConst::byID($frontCityID)->path) as $nearCity) {
if (!key_exists($nearCity, $nearCities)) {
$nearCities[$nearCity] = [$frontCityID];
}
else{
} else {
$nearCities[$nearCity][] = $frontCityID;
}
}
@@ -1487,7 +1702,6 @@ class GeneralAI{
$targetCityID = $targetCity['city'];
foreach ($nearCities[$targetCityID] as $attackableCity) {
$attackableCities[$attackableCity] += 1;
}
}
@@ -1497,7 +1711,6 @@ class GeneralAI{
'destCityID' => Util::choiceRandomUsingWeight($attackableCities),
]];
}
}
if ($general->getVar('train') < 90) {
@@ -1521,7 +1734,8 @@ class GeneralAI{
return null;
}
protected function processAttack():array{
protected function processAttack(): array
{
$general = $this->getGeneralObj();
$city = $this->city;
$nation = $this->nation;
@@ -1557,7 +1771,8 @@ class GeneralAI{
return ['che_출병', ['destCityID' => Util::choiceRandom($attackableCities)]];
}
protected function proceessNeutralLordTurn():array{
protected function proceessNeutralLordTurn(): array
{
$db = DB::db();
@@ -1582,7 +1797,6 @@ class GeneralAI{
'nationType' => $nationType,
'colorType' => $nationColor
]];
}
//모든 공백지 조사
@@ -1602,11 +1816,9 @@ class GeneralAI{
foreach (array_keys(CityConst::byID($general->getVar('city'))->path) as $nearCityID) {
if (CityConst::byID($nearCityID)->level < 4) {
$targetCity[$nearCityID] = 0.5;
}
else if(!key_exists($nearCityID, $occupiedCities)){
} else if (!key_exists($nearCityID, $occupiedCities)) {
$targetCity[$nearCityID] = 2;
}
else{
} else {
$targetCity[$nearCityID] = 0;
}
@@ -1628,7 +1840,8 @@ class GeneralAI{
return ['che_이동', ['destCityID' => Util::choiceRandomUsingWeight($targetCity)]];
}
protected function processLordTurn():?array{
protected function processLordTurn(): ?array
{
$general = $this->getGeneralObj();
$city = $this->city;
$nation = $this->nation;
@@ -1640,20 +1853,17 @@ class GeneralAI{
if ($general->getVar('npc') == 9 && $this->dipState == self::d평화 && !$this->attackable) {
if ($nation['level'] == 0) {
return ['che_해산', null];
}
else{
} else {
return ['che_방랑', null];
}
}
if (in_array($month, [1, 4, 7, 10])) {
$this->calcPromotion();
}
else if($month == 12){
} else if ($month == 12) {
$this->calcTexRate();
$this->calcGoldBillRate();
}
else if($month == 6){
} else if ($month == 6) {
$this->calcTexRate();
$this->calcRiceBillRate();
}
@@ -1667,7 +1877,8 @@ class GeneralAI{
return null;
}
protected function getNationDevelopedRate(){
protected function getNationDevelopedRate()
{
if ($this->devRate !== null) {
return $this->devRate;
}
@@ -1682,7 +1893,8 @@ class GeneralAI{
return $this->devRate;
}
protected function findWarTarget():?int{
protected function findWarTarget(): ?int
{
$db = DB::db();
@@ -1713,7 +1925,8 @@ class GeneralAI{
return Util::choiceRandomUsingWeight($nations);
}
protected function calcPromotion(){
protected function calcPromotion()
{
$db = DB::db();
$nation = $this->nation;
@@ -1731,7 +1944,8 @@ class GeneralAI{
], 'nation=%i AND npc < 2 AND level > 4', $nationID);
foreach ($db->query(
'SELECT no, npc, level, killturn FROM general WHERE nation = %i AND 12 > level AND level > 4', $nationID
'SELECT no, npc, level, killturn FROM general WHERE nation = %i AND 12 > level AND level > 4',
$nationID
) as $chief) {
if ($chief['npc'] < 2 && $chief['killturn'] < $minKillturn) {
@@ -1780,7 +1994,8 @@ class GeneralAI{
'SELECT no FROM general WHERE nation = %i AND strength >= %i AND level = 1 AND belong >= %i ORDER BY strength DESC LIMIT %i',
$nationID,
GameConst::$chiefStatMin,
$maxBelong, 12 - $minChiefLevel
$maxBelong,
12 - $minChiefLevel
);
//지장 수뇌 후보
$candChiefIntel = $db->queryFirstColumn(
@@ -1816,7 +2031,6 @@ class GeneralAI{
$chiefCandidate[$chiefLevel] = $candidate;
$promoted[$candidate] = $chiefLevel;
}
}
foreach ($chiefCandidate as $chiefLevel => $chiefID) {
@@ -1825,10 +2039,10 @@ class GeneralAI{
], 'no=%i', $chiefID);
}
}
}
protected function calcTexRate():int{
protected function calcTexRate(): int
{
$db = DB::db();
$nation = $this->nation;
$env = $this->env;
@@ -1862,7 +2076,8 @@ class GeneralAI{
}
}
protected function calcGoldBillRate():int{
protected function calcGoldBillRate(): int
{
$db = DB::db();
$nation = $this->nation;
$env = $this->env;
@@ -1885,8 +2100,12 @@ class GeneralAI{
$bill = intval($income / $outcome * 80); // 수입의 80% 만 지급
if($bill < 20) { $bill = 20; }
if($bill > 200) { $bill = 200; }
if ($bill < 20) {
$bill = 20;
}
if ($bill > 200) {
$bill = 200;
}
$db->update('nation', [
'bill' => $bill,
@@ -1895,7 +2114,8 @@ class GeneralAI{
return $bill;
}
protected function calcRiceBillRate():int{
protected function calcRiceBillRate(): int
{
$db = DB::db();
$nation = $this->nation;
$env = $this->env;
@@ -1918,8 +2138,12 @@ class GeneralAI{
$bill = intval($income / $outcome * 80); // 수입의 80% 만 지급
if($bill < 20) { $bill = 20; }
if($bill > 200) { $bill = 200; }
if ($bill < 20) {
$bill = 20;
}
if ($bill > 200) {
$bill = 200;
}
$db->update('nation', [
'bill' => $bill,
+14 -15
View File
@@ -65,14 +65,9 @@ class TurnExecutionHelper
return true;
}
public function processNationCommand(string $commandClassName, ?array $commandArg, LastTurn $commandLast):LastTurn{
public function processNationCommand(Command\NationCommand $commandObj):LastTurn{
$general = $this->getGeneral();
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$commandObj = buildNationCommandClass($commandClassName, $general, $gameStor->getAll(true), $commandLast, $commandArg);
while(true){
$failReason = $commandObj->testRunnable();
if($failReason){
@@ -108,15 +103,13 @@ class TurnExecutionHelper
return $commandObj->getResultTurn();
}
public function processCommand(string $commandClassName, ?array $commandArg){
public function processCommand(Command\GeneralCommand $commandObj){
$general = $this->getGeneral();
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$commandObj = buildGeneralCommandClass($commandClassName, $general, $gameStor->getAll(true), $commandArg);
while(true){
$failReason = $commandObj->testRunnable();
if($failReason){
@@ -230,6 +223,8 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC',
$currentTurn = null;
$gameStor = KVStorage::getStorage($db, 'game_env');
foreach($generalsTodo as $rawGeneral){
$generalCommand = $rawGeneral['action'];
$generalArg = Json::decode($rawGeneral['arg'])??[];
@@ -244,6 +239,9 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC',
$general = General::createGeneralObjFromDB($rawGeneral['no']);
$turnObj = new static($general);
$env = $gameStor->getAll(true);
$generalCommandObj = buildGeneralCommandClass($generalCommand, $general, $env, $generalArg);
$hasNationTurn = false;
if($general->getVar('nation') != 0 && $general->getVar('level') >= 5){
$nationStor = KVStorage::getStorage($db, 'nation_env');
@@ -258,15 +256,18 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC',
$hasNationTurn = true;
$nationCommand = $rawNationTurn['action']??null;
$nationArg = Json::decode($rawNationTurn['arg']??null);
$lastNationTurn = LastTurn::fromJson($lastNationTurn);
$nationCommandObj = buildNationCommandClass($nationCommand, $general, $env, $lastNationTurn, $nationArg);
}
if($general->getVar('npc') >= 2){
$ai = new GeneralAI($turnObj->getGeneral());
if($hasNationTurn){
[$nationCommand, $nationArg] = $ai->chooseNationTurn($nationCommand, $nationArg);
$nationCommandObj = $ai->chooseNationTurn($nationCommandObj);
}
[$generalCommand, $generalArg] = $ai->chooseGeneralTurn($generalCommand, $generalArg); // npc AI 처리
$generalCommandObj = $ai->chooseGeneralTurn($generalCommandObj); // npc AI 처리
}
@@ -274,13 +275,11 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC',
$turnObj->preprocessCommand();
if($hasNationTurn){
$resultNationTurn = $turnObj->processNationCommand(
$nationCommand,
$nationArg,
LastTurn::fromJson($lastNationTurn)
$nationCommandObj
);
$nationStor->setValue($lastNationTurnKey, $resultNationTurn->toJson());
}
$turnObj->processCommand($generalCommand, $generalArg);
$turnObj->processCommand($generalCommandObj);
}
pullNationCommand($general->getVar('nation'), $general->getVar('level'));
pullGeneralCommand($general->getID());