feat, refac(wip): 징병 기준을 GameUnitConstraint 기반으로 변경

This commit is contained in:
2025-01-21 15:41:41 +00:00
parent 77ec4c6572
commit 01094d376f
7 changed files with 36 additions and 47 deletions
+13 -5
View File
@@ -256,8 +256,11 @@ class che_징병 extends Command\GeneralCommand
$ownCities = []; $ownCities = [];
$ownRegions = []; $ownRegions = [];
foreach (DB::db()->query('SELECT city, region from city where nation = %i', $general->getNationID()) as $city) { foreach (DB::db()->query('SELECT city, region, secu, level from city where nation = %i', $general->getNationID()) as $city) {
$ownCities[$city['city']] = 1; $ownCities[$city['city']] = [
'secu' => $city['secu'],
'level' => $city['level'],
];
$ownRegions[$city['region']] = 1; $ownRegions[$city['region']] = 1;
} }
@@ -278,8 +281,13 @@ class che_징병 extends Command\GeneralCommand
$crewObj = new \stdClass; $crewObj = new \stdClass;
$crewObj->id = $unit->id; $crewObj->id = $unit->id;
$crewObj->reqTech = $unit->reqTech; /** @var ?\sammo\GameUnitConstraints\ReqTech */
$crewObj->reqYear = $unit->reqYear; $reqTechObj = $unit->reqConstraints['reqTech'] ?? null;
$crewObj->reqTech = $reqTechObj ? $reqTechObj->reqTech : 0;
/** @var ?\sammo\GameUnitConstraint\ReqMinRelYear */
$reqMinRelYearObj = $unit->reqConstraints['reqMinRelYear'] ?? null;
$crewObj->reqYear = $reqMinRelYearObj ? $reqMinRelYearObj->reqMinRelYear : 0;
/* /*
if ($unit->reqTech == 0) { if ($unit->reqTech == 0) {
@@ -305,7 +313,7 @@ class che_징병 extends Command\GeneralCommand
$crewObj->img = ServConfig::$gameImagePath . "/crewtype" . $unit->id . ".png"; $crewObj->img = ServConfig::$gameImagePath . "/crewtype" . $unit->id . ".png";
} }
$crewObj->info = $unit->info; $crewObj->info = $unit->getInfo();
$armCrewType['values'][] = $crewObj; $armCrewType['values'][] = $crewObj;
} }
+1 -1
View File
@@ -7,7 +7,7 @@ use sammo\General;
class ReqCities extends BaseGameUnitConstraint { class ReqCities extends BaseGameUnitConstraint {
public function __construct(protected array $reqCities) public function __construct(public readonly array $reqCities)
{ {
} }
@@ -6,7 +6,7 @@ use sammo\General;
class ReqMinRelYear extends BaseGameUnitConstraint { class ReqMinRelYear extends BaseGameUnitConstraint {
public function __construct(protected int $reqMinRelYear) public function __construct(public readonly int $reqMinRelYear)
{ {
} }
+1 -1
View File
@@ -7,7 +7,7 @@ use sammo\General;
class ReqRegions extends BaseGameUnitConstraint { class ReqRegions extends BaseGameUnitConstraint {
public function __construct(protected array $reqRegions) public function __construct(public readonly array $reqRegions)
{ {
} }
+1 -1
View File
@@ -7,7 +7,7 @@ use sammo\KVStorage;
class ReqTech extends BaseGameUnitConstraint { class ReqTech extends BaseGameUnitConstraint {
public function __construct(protected int $reqTech) public function __construct(public readonly int $reqTech)
{ {
} }
+5 -31
View File
@@ -56,7 +56,11 @@ class GameUnitDetail implements iAction
$this->magicCoef = $magicCoef; $this->magicCoef = $magicCoef;
$this->cost = $cost; $this->cost = $cost;
$this->rice = $rice; $this->rice = $rice;
$this->reqConstraints = $reqConstraints; $this->reqConstraints = [];
foreach($reqConstraints as $constraint){
$className = Util::getClassNameFromObj($constraint);
$this->reqConstraints[$className] = $constraint;
}
$this->attackCoef = $attackCoef; $this->attackCoef = $attackCoef;
$this->defenceCoef = $defenceCoef; $this->defenceCoef = $defenceCoef;
$this->initSkillTrigger = $initSkillTrigger; $this->initSkillTrigger = $initSkillTrigger;
@@ -205,36 +209,6 @@ class GameUnitDetail implements iAction
} }
} }
if ($tech < $this->reqTech) {
return false;
}
if ($this->reqCities !== null) {
$valid = false;
foreach ($this->reqCities as $reqCity) {
if (\key_exists($reqCity, $ownCities)) {
$valid = true;
break;
}
}
if (!$valid) {
return false;
}
}
if ($this->reqRegions !== null) {
$valid = false;
foreach ($this->reqRegions as $reqRegion) {
if (\key_exists($reqRegion, $ownRegions)) {
$valid = true;
break;
}
}
if (!$valid) {
return false;
}
}
return true; return true;
} }
+14 -7
View File
@@ -2558,8 +2558,11 @@ class GeneralAI
$cities = []; $cities = [];
$regions = []; $regions = [];
foreach ($db->queryAllLists('SELECT city, region FROM city WHERE nation = %i', $nationID) as [$cityID, $regionID]) { foreach ($db->queryAllLists('SELECT city, region, secu, level FROM city WHERE nation = %i', $nationID) as [$cityID, $regionID, $secu, $level]) {
$cities[$cityID] = true; $cities[$cityID] = [
'secu' => $secu,
'level' => $level,
];
$regions[$regionID] = true; $regions[$regionID] = true;
} }
$relYear = Util::valueFit($env['year'] - $env['startyear'], 0); $relYear = Util::valueFit($env['year'] - $env['startyear'], 0);
@@ -2582,11 +2585,15 @@ class GeneralAI
if ($this->generalPolicy->can고급병종) { if ($this->generalPolicy->can고급병종) {
$currCrewType = $general->getCrewTypeObj(); $currCrewType = $general->getCrewTypeObj();
if ($currCrewType->isValid($cities, $regions, $relYear, $tech)) { if ($currCrewType->isValid($cities, $regions, $relYear, $tech)) {
if ($currCrewType->reqTech >= 2000) { $reqTechObj = $currCrewType->reqConstraints['reqTech'] ?? null;
$type = $currCrewType->id; if($reqTechObj){
} else if ($currCrewType->armType != $armType && $currCrewType->reqTech >= 1000) { $reqTech = $reqTechObj->getValue($tech);
//굳이 뽑은 이유가 있겠지 if ($reqTech >= 2000) {
$type = $currCrewType->id; $type = $currCrewType->id;
} else if ($currCrewType->armType != $armType && $reqTech >= 1000) {
//굳이 뽑은 이유가 있겠지
$type = $currCrewType->id;
}
} }
} }
} }