diff --git a/hwe/sammo/Scenario/GeneralBuilder.php b/hwe/sammo/Scenario/GeneralBuilder.php index 31ddb4a1..2ed6e8f7 100644 --- a/hwe/sammo/Scenario/GeneralBuilder.php +++ b/hwe/sammo/Scenario/GeneralBuilder.php @@ -136,13 +136,13 @@ class GeneralBuilder{ $this->specialWar = GameConst::$defaultSpecialWar; } try{ - $this->specialDomestic = SpecialityHelper::getDomesticClassByName($special); - $this->specialWar = GameConst::$defaultSpecialWar; - } - catch (\Exception $e){ $this->specialDomestic = GameConst::$defaultSpecialDomestic; $this->specialWar = SpecialityHelper::getWarClassByName($special); } + catch (\Exception $e){ + $this->specialDomestic = SpecialityHelper::getDomesticClassByName($special); + $this->specialWar = GameConst::$defaultSpecialWar; + } return $this; } @@ -735,4 +735,4 @@ class GeneralBuilder{ return true; //생성되었다. } -} \ No newline at end of file +} diff --git a/tests/ScenarioGeneralBuilderSpecialTest.php b/tests/ScenarioGeneralBuilderSpecialTest.php new file mode 100644 index 00000000..fe37ca8e --- /dev/null +++ b/tests/ScenarioGeneralBuilderSpecialTest.php @@ -0,0 +1,80 @@ +addPsr4('sammo\\', __DIR__ . '/../hwe/sammo', true); + +require_once __DIR__ . '/../hwe/func_converter.php'; +require_once __DIR__ . '/../hwe/sammo/ActionLogger.php'; +require_once __DIR__ . '/../hwe/sammo/GameConstBase.php'; +require_once __DIR__ . '/../hwe/d_setting/GameConst.php'; +require_once __DIR__ . '/../hwe/sammo/Scenario/GeneralBuilder.php'; + +final class ScenarioGeneralBuilderSpecialTest extends TestCase +{ + public function testAsiaPossessionScenarioWarSpecialsUseWarSlot(): void + { + $scenario = json_decode( + file_get_contents(__DIR__ . '/../hwe/scenario/scenario_2702.json'), + true, + 512, + JSON_THROW_ON_ERROR + ); + $specials = array_values(array_unique(array_filter(array_column($scenario['general'], 12)))); + + self::assertNotEmpty($specials); + foreach ($specials as $special) { + $builder = $this->newBuilder()->setSpecialSingle($special); + + self::assertSame( + GameConst::$defaultSpecialDomestic, + $this->readProperty($builder, 'specialDomestic'), + "{$special} must not occupy the domestic-special slot" + ); + self::assertSame( + "che_{$special}", + $this->readProperty($builder, 'specialWar'), + "{$special} must occupy the war-special slot" + ); + } + } + + public function testScenarioDomesticSpecialStillUsesDomesticSlot(): void + { + $builder = $this->newBuilder()->setSpecialSingle('경작'); + + self::assertSame('che_경작', $this->readProperty($builder, 'specialDomestic')); + self::assertSame(GameConst::$defaultSpecialWar, $this->readProperty($builder, 'specialWar')); + } + + public function testCentennialEventWarSpecialCanStillBeAssignedToDomesticSlotExplicitly(): void + { + $builder = $this->newBuilder()->setSpecial('che_event_위압', GameConst::$defaultSpecialWar); + + self::assertSame('che_event_위압', $this->readProperty($builder, 'specialDomestic')); + self::assertSame(GameConst::$defaultSpecialWar, $this->readProperty($builder, 'specialWar')); + } + + private function newBuilder(): GeneralBuilder + { + return new GeneralBuilder( + new RandUtil(new LiteHashDRBG(Util::simpleSerialize(self::class))), + '특기 슬롯 검사', + false, + null, + 0 + ); + } + + private function readProperty(GeneralBuilder $builder, string $property): mixed + { + $reflection = new ReflectionProperty($builder, $property); + return $reflection->getValue($builder); + } +}