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