feat: '선제 페이즈' 도입

- 일종의 '음수' 페이즈
   - 先 표기
   - 수비자 기준
- 내부의 currPhase가 변할 수 있도록 로직 변경
This commit is contained in:
2022-04-12 21:40:49 +09:00
parent 657a47c9ad
commit aa2e50366b
2 changed files with 171 additions and 95 deletions
+14 -7
View File
@@ -231,7 +231,7 @@ function processWar_NG(
$logger->pushGlobalActionLog("<D><b>{$attacker->getNationVar('name')}</b></>의 <Y>{$attacker->getName()}</>{$josaYi} <G><b>{$city->getName()}</b></>{$josaRo} 진격합니다."); $logger->pushGlobalActionLog("<D><b>{$attacker->getNationVar('name')}</b></>의 <Y>{$attacker->getName()}</>{$josaYi} <G><b>{$city->getName()}</b></>{$josaRo} 진격합니다.");
$logger->pushGeneralActionLog("<G><b>{$city->getName()}</b></>{$josaRo} <M>진격</>합니다. <1>$date</>"); $logger->pushGeneralActionLog("<G><b>{$city->getName()}</b></>{$josaRo} <M>진격</>합니다. <1>$date</>");
for ($currPhase = 0; $currPhase < $attacker->getMaxPhase(); $currPhase += 1) { while($attacker->getPhase() < $attacker->getMaxPhase()){
if ($defender === null) { if ($defender === null) {
$defender = $city; $defender = $city;
@@ -257,7 +257,7 @@ function processWar_NG(
} }
if ($defender->getPhase() == 0) { if ($defender->getPhase() == 0) {
$defender->setPrePhase($currPhase); $defender->setPrePhase($attacker->getPhase());
$attacker->addTrain(1); $attacker->addTrain(1);
$defender->addTrain(1); $defender->addTrain(1);
@@ -347,15 +347,22 @@ function processWar_NG(
$attacker->increaseKilled($deadDefender); $attacker->increaseKilled($deadDefender);
$defender->increaseKilled($deadAttacker); $defender->increaseKilled($deadAttacker);
$phaseNickname = $currPhase + 1; if($defender->getPhase() < 0){
$phaseNickname = '先';
}
else{
$currPhase = $attacker->getPhase() + 1;
$phaseNickname = "{$currPhase} ";
}
if ($deadAttacker > 0 || $deadDefender > 0) { if ($deadAttacker > 0 || $deadDefender > 0) {
$attacker->getLogger()->pushGeneralBattleDetailLog( $attacker->getLogger()->pushGeneralBattleDetailLog(
"$phaseNickname : <Y1>【{$attacker->getName()}】</> <C>{$attacker->getHP()} (-$deadAttacker)</> VS <C>{$defender->getHP()} (-$deadDefender)</> <Y1>【{$defender->getName()}】</>" "$phaseNickname: <Y1>【{$attacker->getName()}】</> <C>{$attacker->getHP()} (-$deadAttacker)</> VS <C>{$defender->getHP()} (-$deadDefender)</> <Y1>【{$defender->getName()}】</>"
); );
$defender->getLogger()->pushGeneralBattleDetailLog( $defender->getLogger()->pushGeneralBattleDetailLog(
"$phaseNickname : <Y1>【{$defender->getName()}】</> <C>{$defender->getHP()} (-$deadDefender)</> VS <C>{$attacker->getHP()} (-$deadAttacker)</> <Y1>【{$attacker->getName()}】</>" "$phaseNickname: <Y1>【{$defender->getName()}】</> <C>{$defender->getHP()} (-$deadDefender)</> VS <C>{$attacker->getHP()} (-$deadAttacker)</> <Y1>【{$attacker->getName()}】</>"
); );
} }
@@ -414,7 +421,7 @@ function processWar_NG(
$defender->getLogger()->pushGeneralActionLog("전멸했습니다.", ActionLogger::PLAIN); $defender->getLogger()->pushGeneralActionLog("전멸했습니다.", ActionLogger::PLAIN);
} }
if ($currPhase + 1 == $attacker->getMaxPhase()) { if ($attacker->getPhase() == $attacker->getMaxPhase()) {
break; break;
} }
@@ -427,7 +434,7 @@ function processWar_NG(
} }
} }
if ($currPhase == $attacker->getMaxPhase()) { if ($attacker->getPhase() == $attacker->getMaxPhase()) {
//마지막 페이즈의 전투 마무리 //마지막 페이즈의 전투 마무리
$attacker->logBattleResult(); $attacker->logBattleResult();
$defender->logBattleResult(); $defender->logBattleResult();
+150 -81
View File
@@ -1,7 +1,9 @@
<?php <?php
namespace sammo; namespace sammo;
class WarUnit{ class WarUnit
{
protected $general; protected $general;
protected $rawNation; protected $rawNation;
@@ -31,32 +33,39 @@ class WarUnit{
protected $logActivatedSkill = []; protected $logActivatedSkill = [];
protected $isFinished = false; protected $isFinished = false;
private function __construct(General $general){ private function __construct(General $general)
{
$this->general = $general; $this->general = $general;
} }
/* XXX:Dirty wrapper */ /* XXX:Dirty wrapper */
function getRaw():array{ function getRaw(): array
{
return $this->general->getRaw(); return $this->general->getRaw();
} }
function getVar(string $key){ function getVar(string $key)
{
return $this->general->getVar($key); return $this->general->getVar($key);
} }
function touchVar(string $key):bool{ function touchVar(string $key): bool
{
return $this->general->touchVar($key); return $this->general->touchVar($key);
} }
function setVar(string $key, $value){ function setVar(string $key, $value)
{
return $this->general->setVar($key, $value); return $this->general->setVar($key, $value);
} }
function updateVar(string $key, $value){ function updateVar(string $key, $value)
{
return $this->general->updateVar($key, $value); return $this->general->updateVar($key, $value);
} }
function updateVarWithLimit(string $key, $value, $min = null, $max = null){ function updateVarWithLimit(string $key, $value, $min = null, $max = null)
{
return $this->general->updateVarWithLimit($key, $value, $min, $max); return $this->general->updateVarWithLimit($key, $value, $min, $max);
} }
@@ -65,7 +74,8 @@ class WarUnit{
return $this->general->increaseVar($key, $value); return $this->general->increaseVar($key, $value);
} }
function increaseVarWithLimit(string $key, $value, $min = null, $max = null){ function increaseVarWithLimit(string $key, $value, $min = null, $max = null)
{
return $this->general->increaseVarWithLimit($key, $value, $min, $max); return $this->general->increaseVarWithLimit($key, $value, $min, $max);
} }
@@ -74,159 +84,192 @@ class WarUnit{
return $this->general->multiplyVar($key, $value); return $this->general->multiplyVar($key, $value);
} }
function multiplyVarWithLimit(string $key, $value, $min = null, $max = null){ function multiplyVarWithLimit(string $key, $value, $min = null, $max = null)
{
return $this->general->multiplyVarWithLimit($key, $value, $min, $max); return $this->general->multiplyVarWithLimit($key, $value, $min, $max);
} }
function getUpdatedValues():array { function getUpdatedValues(): array
{
return $this->general->getUpdatedValues(); return $this->general->getUpdatedValues();
} }
function flushUpdateValues():void { function flushUpdateValues(): void
{
$this->general->flushUpdateValues(); $this->general->flushUpdateValues();
} }
protected function clearActivatedSkill(){ protected function clearActivatedSkill()
foreach($this->activatedSkill as $skillName=>$state){ {
if(!$state){ foreach ($this->activatedSkill as $skillName => $state) {
if (!$state) {
continue; continue;
} }
if(!key_exists($skillName, $this->logActivatedSkill)){ if (!key_exists($skillName, $this->logActivatedSkill)) {
$this->logActivatedSkill[$skillName] = 1; $this->logActivatedSkill[$skillName] = 1;
} } else {
else{
$this->logActivatedSkill[$skillName] += 1; $this->logActivatedSkill[$skillName] += 1;
} }
} }
$this->activatedSkill = []; $this->activatedSkill = [];
} }
function getActivatedSkillLog():array{ function getActivatedSkillLog(): array
{
return $this->logActivatedSkill; return $this->logActivatedSkill;
} }
function getRawNation():array{ function getRawNation(): array
{
return $this->rawNation; return $this->rawNation;
} }
function getNationVar(string $key){ function getNationVar(string $key)
{
return $this->rawNation[$key]; return $this->rawNation[$key];
} }
function getPhase():int{ function getPhase(): int
{
return $this->currPhase; return $this->currPhase;
} }
function getRealPhase():int{ function getRealPhase(): int
{
return $this->prePhase + $this->currPhase; return $this->prePhase + $this->currPhase;
} }
function getName():string{ function getName(): string
{
return 'EMPTY'; return 'EMPTY';
} }
function isAttacker():bool{ function isAttacker(): bool
{
return $this->isAttacker; return $this->isAttacker;
} }
function getCrewType():GameUnitDetail{ function getCrewType(): GameUnitDetail
{
return $this->crewType; return $this->crewType;
} }
function getCrewTypeName():string{ function getCrewTypeName(): string
{
return $this->getCrewType()->name; return $this->getCrewType()->name;
} }
function getCrewTypeShortName():string{ function getCrewTypeShortName(): string
{
return $this->getCrewType()->getShortName(); return $this->getCrewType()->getShortName();
} }
function getLogger():ActionLogger{ function getLogger(): ActionLogger
{
$logger = $this->getGeneral()->getLogger(); $logger = $this->getGeneral()->getLogger();
if($logger === null){ if ($logger === null) {
throw new \RuntimeException(); throw new \RuntimeException();
} }
return $logger; return $logger;
} }
function getKilled():int{ function getKilled(): int
{
return $this->killed; return $this->killed;
} }
function getDead():int{ function getDead(): int
{
return $this->dead; return $this->dead;
} }
function getKilledCurrentBattle():int{ function getKilledCurrentBattle(): int
{
return $this->killedCurr; return $this->killedCurr;
} }
function getDeadCurrentBattle():int{ function getDeadCurrentBattle(): int
{
return $this->deadCurr; return $this->deadCurr;
} }
function getGeneral():General{ function getGeneral(): General
{
return $this->general; return $this->general;
} }
function getMaxPhase():int{ function getMaxPhase(): int
{
$phase = $this->getCrewType()->speed; $phase = $this->getCrewType()->speed;
return $phase + $this->bonusPhase; return $phase + $this->bonusPhase;
} }
function setPrePhase(int $phase){ function setPrePhase(int $phase)
{
$this->prePhase = $phase; $this->prePhase = $phase;
} }
function addPhase(){ function addPhase(int $phase = 1)
$this->currPhase += 1; {
$this->currPhase += $phase;
} }
function addBonusPhase(int $cnt){ function addBonusPhase(int $cnt)
{
$this->bonusPhase += $cnt; $this->bonusPhase += $cnt;
} }
function setOppose(?WarUnit $oppose){ function setOppose(?WarUnit $oppose)
{
$this->oppose = $oppose; $this->oppose = $oppose;
$this->killedCurr = 0; $this->killedCurr = 0;
$this->deadCurr = 0; $this->deadCurr = 0;
$this->clearActivatedSkill(); $this->clearActivatedSkill();
} }
function getOppose():?WarUnit{ function getOppose(): ?WarUnit
{
return $this->oppose; return $this->oppose;
} }
function getWarPower(){ function getWarPower()
{
return $this->warPower * $this->warPowerMultiply; return $this->warPower * $this->warPowerMultiply;
} }
function getRawWarPower(){ function getRawWarPower()
{
return $this->warPower; return $this->warPower;
} }
function getWarPowerMultiply(){ function getWarPowerMultiply()
{
return $this->warPowerMultiply; return $this->warPowerMultiply;
} }
function setWarPowerMultiply($multiply = 1.0){ function setWarPowerMultiply($multiply = 1.0)
{
$this->warPowerMultiply = $multiply; $this->warPowerMultiply = $multiply;
} }
function multiplyWarPowerMultiply($multiply){ function multiplyWarPowerMultiply($multiply)
{
$this->warPowerMultiply *= $multiply; $this->warPowerMultiply *= $multiply;
} }
function getComputedAttack(){ function getComputedAttack()
{
return $this->getCrewType()->getComputedAttack($this->general, $this->getNationVar('tech')); return $this->getCrewType()->getComputedAttack($this->general, $this->getNationVar('tech'));
} }
function getComputedDefence(){ function getComputedDefence()
{
return $this->getCrewType()->getComputedDefence($this->general, $this->getNationVar('tech')); return $this->getCrewType()->getComputedDefence($this->general, $this->getNationVar('tech'));
} }
function computeWarPower(){ function computeWarPower()
{
$oppose = $this->getOppose(); $oppose = $this->getOppose();
$general = $this->general; $general = $this->general;
$opposeGeneral = $oppose->getGeneral(); $opposeGeneral = $oppose->getGeneral();
@@ -237,7 +280,7 @@ class WarUnit{
$warPower = GameConst::$armperphase + $myAtt - $opDef; $warPower = GameConst::$armperphase + $myAtt - $opDef;
$opposeWarPowerMultiply = 1.0; $opposeWarPowerMultiply = 1.0;
if($warPower < 100){ if ($warPower < 100) {
//최소 전투력 50 보장 //최소 전투력 50 보장
$warPower = max(0, $warPower); $warPower = max(0, $warPower);
$warPower = ($warPower + 100) / 2; $warPower = ($warPower + 100) / 2;
@@ -262,117 +305,143 @@ class WarUnit{
return [$warPower, $opposeWarPowerMultiply]; return [$warPower, $opposeWarPowerMultiply];
} }
function addTrain(int $train){ function addTrain(int $train)
{
return; return;
} }
function addAtmos(int $atmos){ function addAtmos(int $atmos)
{
return; return;
} }
function addTrainBonus(int $trainBonus){ function addTrainBonus(int $trainBonus)
{
$this->trainBonus += $trainBonus; $this->trainBonus += $trainBonus;
} }
function addAtmosBonus(int $atmosBonus){ function addAtmosBonus(int $atmosBonus)
{
$this->atmosBonus += $atmosBonus; $this->atmosBonus += $atmosBonus;
} }
function getComputedTrain(){ function getComputedTrain()
{
return GameConst::$maxTrainByCommand; return GameConst::$maxTrainByCommand;
} }
function getComputedAtmos(){ function getComputedAtmos()
{
return GameConst::$maxAtmosByCommand; return GameConst::$maxAtmosByCommand;
} }
function getComputedCriticalRatio():float{ function getComputedCriticalRatio(): float
{
return $this->getCrewType()->getCriticalRatio($this->general); return $this->getCrewType()->getCriticalRatio($this->general);
} }
function getComputedAvoidRatio():float{ function getComputedAvoidRatio(): float
{
return $this->getCrewType()->avoid / 100; return $this->getCrewType()->avoid / 100;
} }
function addWin(){ function addWin()
{
} }
function addLose(){ function addLose()
{
} }
function getDex(GameUnitDetail $crewType){ function getDex(GameUnitDetail $crewType)
{
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function finishBattle(){ function finishBattle()
{
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function beginPhase():void{ function beginPhase(): void
{
$this->clearActivatedSkill(); $this->clearActivatedSkill();
$this->computeWarPower(); $this->computeWarPower();
} }
function hasActivatedSkill(string $skillName):bool{ function hasActivatedSkill(string $skillName): bool
return $this->activatedSkill[$skillName]??false; {
return $this->activatedSkill[$skillName] ?? false;
} }
function hasActivatedSkillOnLog(string $skillName):int{ function hasActivatedSkillOnLog(string $skillName): int
return ($this->logActivatedSkill[$skillName]??0)+($this->hasActivatedSkill($skillName)?1:0); {
return ($this->logActivatedSkill[$skillName] ?? 0) + ($this->hasActivatedSkill($skillName) ? 1 : 0);
} }
function activateSkill(... $skillNames){ function activateSkill(...$skillNames)
foreach($skillNames as $skillName){ {
foreach ($skillNames as $skillName) {
$this->activatedSkill[$skillName] = true; $this->activatedSkill[$skillName] = true;
} }
} }
function deactivateSkill(... $skillNames){ function deactivateSkill(...$skillNames)
foreach($skillNames as $skillName){ {
foreach ($skillNames as $skillName) {
$this->activatedSkill[$skillName] = false; $this->activatedSkill[$skillName] = false;
} }
} }
function getHP():int{ function getHP(): int
{
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function decreaseHP(int $damage):int{ function decreaseHP(int $damage): int
{
$this->dead += $damage; $this->dead += $damage;
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function increaseKilled(int $damage):int{ function increaseKilled(int $damage): int
{
$this->killed += $damage; $this->killed += $damage;
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function calcDamage():int{ function calcDamage(): int
{
$warPower = $this->getWarPower(); $warPower = $this->getWarPower();
$warPower *= Util::randRange(0.9, 1.1); $warPower *= Util::randRange(0.9, 1.1);
return Util::round($warPower); return Util::round($warPower);
} }
function tryWound():bool{ function tryWound(): bool
{
return false; return false;
} }
function continueWar(&$noRice):bool{ function continueWar(&$noRice): bool
{
//전투가 가능하면 true //전투가 가능하면 true
$noRice = false; $noRice = false;
return false; return false;
} }
function logBattleResult(){ function logBattleResult()
{
$this->getLogger()->pushBattleResultTemplate($this, $this->getOppose()); $this->getLogger()->pushBattleResultTemplate($this, $this->getOppose());
} }
function criticalDamage():float{ function criticalDamage(): float
{
//전특, 병종에 따라 필살 데미지가 달라질지도 모르므로 static 함수는 아닌 것으로 //전특, 병종에 따라 필살 데미지가 달라질지도 모르므로 static 함수는 아닌 것으로
return Util::randRange(1.3, 2.0); return Util::randRange(1.3, 2.0);
} }
function applyDB(\MeekroDB $db):bool{ function applyDB(\MeekroDB $db): bool
{
throw new MustNotBeReachedException('Must be WarUnitCity or WarUnitGeneral'); throw new MustNotBeReachedException('Must be WarUnitCity or WarUnitGeneral');
} }
} }