diff --git a/hwe/j_simulate_battle.php b/hwe/j_simulate_battle.php index e71666a7..38bb2019 100644 --- a/hwe/j_simulate_battle.php +++ b/hwe/j_simulate_battle.php @@ -341,9 +341,13 @@ usort($defenderList, function (WarUnit $lhs, WarUnit $rhs) use ($attacker) { return - (extractBattleOrder($lhs, $attacker) <=> extractBattleOrder($rhs, $attacker)); }); -$rawDefenderList = array_map(function (WarUnit $unit) { - return $unit->getRaw(); -}, $defenderList); +$rawDefenderList = []; +foreach($defenderList as $unit){ + if(extractBattleOrder($unit, $attacker) <= 0){ + continue; + } + $rawDefenderList[] = $unit->getRaw(); +} unset($defenderList); $db = DB::db(); @@ -405,7 +409,9 @@ function simulateBattle( ); } - $defenderList[] = $city; + if(count($defenderList) == 0 && extractBattleOrder($city, $attacker) > 0){ + $defenderList[] = $city; + } $iterDefender = new \ArrayIterator($defenderList); diff --git a/hwe/process_war.php b/hwe/process_war.php index 62de5e10..c53482e9 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -42,10 +42,18 @@ function processWar(string $warSeed, General $attackerGeneral, array $rawAttacke /** @var WarUnit[] */ $defenderList = []; foreach($defenderGeneralList as $defenderGeneral){ - $defenderList[] = new WarUnitGeneral($rng, $defenderGeneral, $rawDefenderNation, false); + + $defenderCandidate = new WarUnitGeneral($rng, $defenderGeneral, $rawDefenderNation, false); + if(extractBattleOrder($defenderCandidate, $attacker) <= 0){ + continue; + } + + $defenderList[] = $defenderCandidate; } - $defenderList[] = $city; + if(count($defenderList) == 0 && extractBattleOrder($city, $attacker) > 0){ + $defenderList[] = $city; + } usort($defenderList, function (WarUnit $lhs, WarUnit $rhs) use ($attacker) { return - (extractBattleOrder($lhs, $attacker) <=> extractBattleOrder($rhs, $attacker)); @@ -183,7 +191,11 @@ function processWar(string $warSeed, General $attackerGeneral, array $rawAttacke function extractBattleOrder(WarUnit $defender, WarUnit $attacker) { if($defender instanceof WarUnitCity){ - return -1; + if(!($attacker instanceof WarUnitGeneral)){ + return 0; + } + $attackerGeneral = $attacker->getGeneral(); + return $attackerGeneral->onCalcOpposeStat($defender->getGeneral(), 'cityBattleOrder', -1); } $general = $defender->getGeneral(); @@ -229,6 +241,7 @@ function processWar_NG( $attackerNationUpdate = []; $defenderNationUpdate = []; + /** @var WarUnit */ $defender = ($getNextDefender)(null, true); $conquerCity = false; @@ -244,6 +257,7 @@ function processWar_NG( $logWritten = false; if ($defender === null) { $defender = $city; + $defender->setSiege(); if ($city->getNationVar('rice') <= 0 && $city->getVar('supply')) { //병량 패퇴 @@ -459,6 +473,11 @@ function processWar_NG( $attacker->finishBattle(); $defender->finishBattle(); + if($city->getDead()){ + $city->setSiege(); + $city->finishBattle(); + } + if ($defender instanceof WarUnitCity) { $newConflict = $defender->addConflict(); if ($newConflict) { diff --git a/hwe/sammo/GameUnitDetail.php b/hwe/sammo/GameUnitDetail.php index d2cf3958..6e524c95 100644 --- a/hwe/sammo/GameUnitDetail.php +++ b/hwe/sammo/GameUnitDetail.php @@ -69,9 +69,14 @@ class GameUnitDetail implements iAction $this->info = $info; $this->initSkillTrigger = $initSkillTrigger; $this->phaseSkillTrigger = $phaseSkillTrigger; - $this->iActionList = array_map(function($rawAction){ - return buildActionCrewTypeClass($rawAction); - }, $iActionList ?? []); + $this->iActionList = []; + foreach($iActionList as $rawAction){ + $action = buildActionCrewTypeClass($rawAction); + if(!$action){ + continue; + } + $this->iActionList[] = $action; + } } public function getInfo(): string @@ -285,7 +290,7 @@ class GameUnitDetail implements iAction public function onCalcStat(General $general, string $statName, $value, $aux = null) { if (!$this->iActionList) { - return; + return $value; } foreach ($this->iActionList as $iAction) { @@ -297,7 +302,7 @@ class GameUnitDetail implements iAction public function onCalcOpposeStat(General $general, string $statName, $value, $aux = null) { if (!$this->iActionList) { - return; + return $value; } foreach ($this->iActionList as $iAction) { @@ -308,7 +313,7 @@ class GameUnitDetail implements iAction public function onCalcStrategic(string $turnType, string $varType, $value) { if (!$this->iActionList) { - return; + return $value; } foreach ($this->iActionList as $iAction) { @@ -319,7 +324,7 @@ class GameUnitDetail implements iAction public function onCalcNationalIncome(string $type, $amount) { if (!$this->iActionList) { - return; + return $amount; } foreach ($this->iActionList as $iAction) { @@ -346,7 +351,7 @@ class GameUnitDetail implements iAction public function onArbitraryAction(General $general, RandUtil $rng, string $actionType, ?string $phase = null, ?array $aux = null): null|array { if (!$this->iActionList) { - return null; + return $aux; } foreach ($this->iActionList as $iAction) { diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index a92f31b1..49369e14 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -7,6 +7,7 @@ class WarUnitCity extends WarUnit{ protected $hp; protected $cityTrainAtmos; + protected $onSiege = false; function __construct(public readonly RandUtil $rng, $raw, $rawNation, int $year, int $month, int $startYear){ $general = new DummyGeneral(false); @@ -77,6 +78,10 @@ class WarUnitCity extends WarUnit{ return $this->hp; } + function setSiege(){ + $this->onSiege = true; + } + function getDex(GameUnitDetail $crewType){ return ($this->cityTrainAtmos - 60) * 7200; } @@ -109,7 +114,7 @@ class WarUnitCity extends WarUnit{ } function finishBattle(){ - if($this->isFinished){ + if($this->isFinished || !$this->onSiege){ return; } $this->clearActivatedSkill();