fix: ReqCities, ReqRegion 버그

This commit is contained in:
2025-01-21 17:13:37 +00:00
parent 9f81c760d0
commit 84fee0f1f2
7 changed files with 52 additions and 42 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ class GetConst extends \sammo\BaseAPI
$crewtypeMap[$crewtypeObj->id] = [ $crewtypeMap[$crewtypeObj->id] = [
'value'=>(string)$crewtypeObj->id, 'value'=>(string)$crewtypeObj->id,
'name'=>$crewtypeObj->name, 'name'=>$crewtypeObj->name,
'info'=>$crewtypeObj->getInfo(), 'info'=>$crewtypeObj->getInfoArr(),
]; ];
} }
$iActionInfo['crewtype'] = $crewtypeMap; $iActionInfo['crewtype'] = $crewtypeMap;
+2 -2
View File
@@ -297,7 +297,7 @@ class che_징병 extends Command\GeneralCommand
} }
*/ */
$crewObj->notAvailable = !$unit->isValid($ownCities, $ownRegions, $relativeYear, $tech); $crewObj->notAvailable = !$unit->isValid($general, $ownCities, $ownRegions, $relativeYear, $tech);
$crewObj->baseRice = $general->onCalcDomestic($this->getName(), 'rice', $unit->riceWithTech($tech), ['armType' => $unit->armType]); $crewObj->baseRice = $general->onCalcDomestic($this->getName(), 'rice', $unit->riceWithTech($tech), ['armType' => $unit->armType]);
$crewObj->baseCost = $general->onCalcDomestic($this->getName(), 'cost', $unit->costWithTech($tech), ['armType' => $unit->armType]); $crewObj->baseCost = $general->onCalcDomestic($this->getName(), 'cost', $unit->costWithTech($tech), ['armType' => $unit->armType]);
@@ -313,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->getInfo(); $crewObj->info = $unit->getInfoArr();
$armCrewType['values'][] = $crewObj; $armCrewType['values'][] = $crewObj;
} }
+2 -7
View File
@@ -254,7 +254,7 @@ class GameUnitConstBase{
[ [
1402, self::T_WIZARD, '백귀병', 1402, self::T_WIZARD, '백귀병',
80, 130, 7, 5, 0.6, 9, 11, 80, 130, 7, 5, 0.6, 9, 11,
[new ReqTech(2000), new ReqRegions('오환')], [new ReqTech(2000), new ReqCities('오환')],
[self::T_SIEGE=>1.2], [self::T_SIEGE=>1.2],
[self::T_SIEGE=>0.8], [self::T_SIEGE=>0.8],
['저렴하고 튼튼합니다.'], ['저렴하고 튼튼합니다.'],
@@ -263,7 +263,7 @@ class GameUnitConstBase{
[ [
1403, self::T_WIZARD, '흑귀병', 1403, self::T_WIZARD, '흑귀병',
130, 80, 7, 5, 0.6, 11, 9, 130, 80, 7, 5, 0.6, 11, 9,
[new ReqTech(2000), new ReqRegions('왜')], [new ReqTech(2000), new ReqCities('왜')],
[self::T_SIEGE=>1.2], [self::T_SIEGE=>1.2],
[self::T_SIEGE=>0.8], [self::T_SIEGE=>0.8],
['저렴하고 강력합니다.'], ['저렴하고 강력합니다.'],
@@ -442,11 +442,6 @@ class GameUnitConstBase{
$iActionList, $iActionList,
] = $rawUnit; ] = $rawUnit;
foreach($reqConstraints as $value){
/** @var GameUnitConstraint\BaseGameUnitConstraint $value */
$info[] = $value->getInfo();
}
$unit = new GameUnitDetail( $unit = new GameUnitDetail(
$id, $id,
$armType, $armType,
+15 -10
View File
@@ -5,18 +5,28 @@ namespace sammo\GameUnitConstraint;
use sammo\CityConst; use sammo\CityConst;
use sammo\General; use sammo\General;
class ReqCities extends BaseGameUnitConstraint { class ReqCities extends BaseGameUnitConstraint
{
public readonly array $reqCities; public readonly array $reqCities;
public function __construct(...$reqCities) public function __construct(...$reqCities)
{ {
$this->reqCities = $reqCities; $dstReqCities = [];
if (count($reqCities) == 0) {
$this->reqCities = [];
return;
}
foreach ($reqCities as $city) {
$dstReqCities[CityConst::byName($city)->id] = $city;
}
$this->reqCities = $dstReqCities;
} }
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
{ {
foreach ($this->reqCities as $city) { foreach ($this->reqCities as $cityID => $cityName) {
if (key_exists($city, $ownCities)) { if (key_exists($cityID, $ownCities)) {
return true; return true;
} }
} }
@@ -26,12 +36,7 @@ class ReqCities extends BaseGameUnitConstraint {
public function getInfo(): string public function getInfo(): string
{ {
$cityNames = []; $cityNameText = implode(', ', $this->reqCities);
foreach ($this->reqCities as $city) {
$cityNames[] = CityConst::byID($city)->name;
}
$cityNameText = implode(', ', $cityNames);
return "{$cityNameText} 소유시 가능"; return "{$cityNameText} 소유시 가능";
} }
} }
+16 -11
View File
@@ -5,20 +5,30 @@ namespace sammo\GameUnitConstraint;
use sammo\CityConst; use sammo\CityConst;
use sammo\General; use sammo\General;
class ReqRegions extends BaseGameUnitConstraint { class ReqRegions extends BaseGameUnitConstraint
{
public readonly array $reqRegions; public readonly array $reqRegions;
public function __construct(...$reqRegions) public function __construct(...$reqRegions)
{ {
$this->reqRegions = $reqRegions; $dstReqRegions = [];
if (count($reqRegions) == 0) {
$this->reqRegions = [];
return;
}
foreach ($reqRegions as $region) {
$dstReqRegions[CityConst::$regionMap[$region]] = $region;
}
$this->reqRegions = $dstReqRegions;
} }
public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool public function test(General $general, array $ownCities, array $ownRegions, int $relativeYear, int $tech, array $nationAux): bool
{ {
foreach ($this->reqRegions as $region) { foreach ($this->reqRegions as $regionID => $regionText) {
if (key_exists($region, $ownRegions)) { if (key_exists($regionID, $ownRegions)) {
return true; return true;
break;
} }
} }
@@ -27,12 +37,7 @@ class ReqRegions extends BaseGameUnitConstraint {
public function getInfo(): string public function getInfo(): string
{ {
$regionNames = []; $regionNameText = implode(', ', $this->reqRegions);
foreach ($this->reqRegions as $region) {
$regionNames[] = CityConst::$regionMap[$region];
}
$regionNameText = implode(', ', $regionNames);
return "{$regionNameText} 지역 소유시 가능"; return "{$regionNameText} 지역 소유시 가능";
} }
} }
+12 -7
View File
@@ -26,7 +26,7 @@ class GameUnitDetail implements iAction
public $iActionList; public $iActionList;
public array $reqConstraints; public array $reqConstraints;
protected ?string $info; protected ?array $info = null;
public function __construct( public function __construct(
int $id, int $id,
@@ -42,6 +42,7 @@ class GameUnitDetail implements iAction
array $reqConstraints, array $reqConstraints,
array $attackCoef, array $attackCoef,
array $defenceCoef, array $defenceCoef,
public readonly array $baseInfo,
?array $initSkillTrigger, ?array $initSkillTrigger,
?array $phaseSkillTrigger, ?array $phaseSkillTrigger,
?array $iActionList, ?array $iActionList,
@@ -75,20 +76,24 @@ class GameUnitDetail implements iAction
} }
} }
public function getInfo(): string public function getInfoArr(): array {
{
if($this->info !== null){ if($this->info !== null){
return $this->info; return $this->info;
} }
$info = []; $info = $this->baseInfo;
foreach ($this->reqConstraints as $constraint) { foreach ($this->reqConstraints as $constraint) {
$info[] = $constraint->getInfo(); $info[] = $constraint->getInfo();
} }
$this->info = join("\n<br>", $info); $this->info = $info;
return $this->info; return $this->info;
} }
public function getInfo(): string
{
return join("\n<br>", $this->getInfoArr());
}
public function getShortName(): string public function getShortName(): string
{ {
return StringUtil::subStringForWidth($this->name, 0, 4); return StringUtil::subStringForWidth($this->name, 0, 4);
@@ -198,13 +203,13 @@ class GameUnitDetail implements iAction
return $defaultWar; return $defaultWar;
} }
public function isValid($ownCities, $ownRegions, $relativeYear, $tech) public function isValid(General $general, $ownCities, $ownRegions, $relativeYear, $tech, $nationAux = [])
{ {
//음수 없음 //음수 없음
$relativeYear = max(0, $relativeYear); $relativeYear = max(0, $relativeYear);
foreach($this->reqConstraints as $constraint){ foreach($this->reqConstraints as $constraint){
if(!$constraint->test($ownCities, $ownRegions, $relativeYear, $tech)){ if(!$constraint->test($general, $ownCities, $ownRegions, $relativeYear, $tech, $nationAux)){
return false; return false;
} }
} }
+2 -2
View File
@@ -2570,7 +2570,7 @@ class GeneralAI
$types = []; $types = [];
foreach (GameUnitConst::byType($armType) as $crewtype) { foreach (GameUnitConst::byType($armType) as $crewtype) {
if ($crewtype->isValid($cities, $regions, $relYear, $tech)) { if ($crewtype->isValid($general, $cities, $regions, $relYear, $tech)) {
$score = $crewtype->pickScore($tech); $score = $crewtype->pickScore($tech);
$types[$crewtype->id] = $score; $types[$crewtype->id] = $score;
} }
@@ -2584,7 +2584,7 @@ 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($general, $cities, $regions, $relYear, $tech)) {
$reqTechObj = $currCrewType->reqConstraints['reqTech'] ?? null; $reqTechObj = $currCrewType->reqConstraints['reqTech'] ?? null;
if($reqTechObj){ if($reqTechObj){
$reqTech = $reqTechObj->getValue($tech); $reqTech = $reqTechObj->getValue($tech);