WarUnit의 일부 요소를 General과 ActionSpecialWar 등으로 분리

This commit is contained in:
2019-04-28 05:43:59 +09:00
parent ef40f299ef
commit 477ec440bc
28 changed files with 256 additions and 191 deletions
@@ -0,0 +1,20 @@
<?php
namespace sammo\ActionNationType;
use \sammo\iAction;
use \sammo\General;
class che_회피_둔갑천서 extends \sammo\BaseItem{
protected static $id = 26;
protected static $name = '둔갑천서(회피)';
protected static $info = '[전투] 회피 확률 +20%p';
protected static $cost = 200;
protected static $consumable = false;
public function onCalcStat(General $general, string $statName, $value, $aux=null){
if($statName === 'warAvoidRatio'){
return $value += 0.2;
}
return $value;
}
}
@@ -0,0 +1,20 @@
<?php
namespace sammo\ActionNationType;
use \sammo\iAction;
use \sammo\General;
class che_회피_태평요술 extends \sammo\BaseItem{
protected static $id = 25;
protected static $name = '둔갑천서(회피)';
protected static $info = '[전투] 회피 확률 +20%p';
protected static $cost = 200;
protected static $consumable = false;
public function onCalcStat(General $general, string $statName, $value, $aux=null){
if($statName === 'warAvoidRatio'){
return $value += 0.2;
}
return $value;
}
}
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_격노 implements iAction{ class che_격노 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_견고 implements iAction{ class che_견고 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -4,6 +4,8 @@ use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\GameUnitConst; use \sammo\GameUnitConst;
use \sammo\WarUnit;
use \sammo\WarUnitCity;
class che_공성 implements iAction{ class che_공성 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -27,4 +29,11 @@ class che_공성 implements iAction{
return $value; return $value;
} }
public function getWarPowerMultiplier(WarUnit $unit):array{
if($unit->getOppose() instanceof WarUnitCity){
return [2, 1];
}
return [1, 1];
}
} }
@@ -27,4 +27,11 @@ class che_궁병 implements iAction{
return $value; return $value;
} }
public function onCalcStat(General $general, string $statName, $value, $aux=null){
if($statName === 'warAvoidRatio'){
return $value += 0.2;
}
return $value;
}
} }
@@ -4,6 +4,7 @@ use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\GameUnitConst; use \sammo\GameUnitConst;
use \sammo\WarUnit;
class che_귀병 implements iAction{ class che_귀병 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -4,6 +4,7 @@ use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\GameUnitConst; use \sammo\GameUnitConst;
use \sammo\WarUnit;
class che_기병 implements iAction{ class che_기병 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -26,4 +27,11 @@ class che_기병 implements iAction{
return $value; return $value;
} }
public function getWarPowerMultiplier(WarUnit $unit):array{
if($unit->isAttacker()){
return [1.2, 1];
}
return [1.1, 1];
}
} }
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_돌격 implements iAction{ class che_돌격 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -24,4 +25,11 @@ class che_돌격 implements iAction{
} }
return $value; return $value;
} }
public function getWarPowerMultiplier(WarUnit $unit):array{
if($unit->isAttacker()){
return [1.1, 1];
}
return [1, 1];
}
} }
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_무쌍 implements iAction{ class che_무쌍 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -24,4 +25,8 @@ class che_무쌍 implements iAction{
} }
return $value; return $value;
} }
public function getWarPowerMultiplier(WarUnit $unit):array{
return [1.1, 1];
}
} }
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_반계 implements iAction{ class che_반계 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -4,6 +4,7 @@ use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\GameUnitConst; use \sammo\GameUnitConst;
use \sammo\WarUnit;
class che_보병 implements iAction{ class che_보병 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -26,4 +27,11 @@ class che_보병 implements iAction{
return $value; return $value;
} }
public function getWarPowerMultiplier(WarUnit $unit):array{
if($unit->isAttacker()){
return [0, 0.9];
}
return [0, 0.8];
}
} }
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_신산 implements iAction{ class che_신산 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_신중 implements iAction{ class che_신중 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_위압 implements iAction{ class che_위압 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -6,6 +6,7 @@ use sammo\SpecialityConst;
use \sammo\General; use \sammo\General;
use \sammo\GeneralTrigger; use \sammo\GeneralTrigger;
use \sammo\GeneralTriggerCaller; use \sammo\GeneralTriggerCaller;
use \sammo\WarUnit;
class che_의술 implements iAction{ class che_의술 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_저격 implements iAction{ class che_저격 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_집중 implements iAction{ class che_집중 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_징병 implements iAction{ class che_징병 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_척사 implements iAction{ class che_척사 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -18,4 +19,12 @@ class che_척사 implements iAction{
SpecialityConst::STAT_POWER, SpecialityConst::STAT_POWER,
SpecialityConst::STAT_INTEL SpecialityConst::STAT_INTEL
]; ];
public function getWarPowerMultiplier(WarUnit $unit):array{
$opposeCrewType = $unit->getOppose()->getCrewType();
if($opposeCrewType->reqCities || $opposeCrewType->reqRegions){
return [1.1, 0.9];
}
return [1, 1];
}
} }
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_필살 implements iAction{ class che_필살 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
@@ -3,6 +3,7 @@ namespace sammo\ActionSpecialWar;
use \sammo\iAction; use \sammo\iAction;
use \sammo\General; use \sammo\General;
use \sammo\SpecialityConst; use \sammo\SpecialityConst;
use \sammo\WarUnit;
class che_환술 implements iAction{ class che_환술 implements iAction{
use \sammo\DefaultAction; use \sammo\DefaultAction;
+1 -7
View File
@@ -16,13 +16,7 @@ class DummyGeneral extends General{
$this->resultTurn = new LastTurn(); $this->resultTurn = new LastTurn();
if($initLogger){ if($initLogger){
$this->logger = new ActionLogger( $this->initLogger(1, 1);
$this->getVar('no'),
$this->getVar('nation'),
1,
1,
false
);
} }
} }
+9 -18
View File
@@ -82,26 +82,21 @@ class GameUnitDetail{
return $this->defenceCoef[$armType]??1; return $this->defenceCoef[$armType]??1;
} }
public function getComputedAttack(array $general, int $tech){ public function getComputedAttack(General $general, int $tech){
if($this->armType == GameUnitConst::T_CASTLE){
assert(isset($general['def']) && isset($general['wall']), '도시 정보가 입력되어야 함');
return ($general['def'] + $general['wall']*9) / 500 + 200;
}
if($this->armType == GameUnitConst::T_WIZARD){ if($this->armType == GameUnitConst::T_WIZARD){
$ratio = getGeneralIntel($general, true, true, true)*2 - 40; $ratio = $general->getIntel(true, true, true)*2 - 40;
} }
else if($this->armType == GameUnitConst::T_SIEGE){ else if($this->armType == GameUnitConst::T_SIEGE){
$ratio = getGeneralLeadership($general, true, true, true)*2 - 40; $ratio = $general->getLeadership(true, true, true)*2 - 40;
} }
else if($this->armType == GameUnitConst::T_MISC){ else if($this->armType == GameUnitConst::T_MISC){
$ratio = getGeneralIntel($general, true, true, true) + $ratio = $general->getIntel(true, true, true) +
getGeneralLeadership($general, true, true, true) + $general->getLeadership(true, true, true) +
getGeneralPower($general, true, true, true); $general->getPower(true, true, true);
$ratio = $ratio*2/3 - 40; $ratio = $ratio*2/3 - 40;
} }
else{ else{
$ratio = getGeneralPower($general, true, true, true)*2 - 40; $ratio = $general->getPower(true, true, true)*2 - 40;
} }
if($ratio < 10){ if($ratio < 10){
$ratio = 10; $ratio = 10;
@@ -114,13 +109,9 @@ class GameUnitDetail{
return $att * $ratio / 100; return $att * $ratio / 100;
} }
public function getComputedDefence(array $general, int $tech){ public function getComputedDefence(General $general, int $tech){
if($this->armType == GameUnitConst::T_CASTLE){
assert(isset($general['def']) && isset($general['wall']), '도시 정보가 입력되어야 함');
return ($general['def'] + $general['wall']*9) / 500 + 200;
}
$def = $this->defence + getTechAbil($tech); $def = $this->defence + getTechAbil($tech);
$crew = ($general['crew'] / (7000 / 30)) + 70; $crew = ($general->getVar('crew') / (7000 / 30)) + 70;
return $def * $crew / 100; return $def * $crew / 100;
} }
+11 -7
View File
@@ -52,13 +52,7 @@ class General implements iAction{
$this->resultTurn = new LastTurn(); $this->resultTurn = new LastTurn();
if($year !== null || $month !== null){ if($year !== null || $month !== null){
$this->logger = new ActionLogger( $this->initLogger($year, $month);
$this->getVar('no'),
$this->getVar('nation'),
$year,
$month,
false
);
} }
if(!$fullConstruct){ if(!$fullConstruct){
@@ -90,6 +84,16 @@ class General implements iAction{
//TODO: $specialItemClass 설정 //TODO: $specialItemClass 설정
} }
function initLogger(int $year, int $month){
$this->logger = new ActionLogger(
$this->getVar('no'),
$this->getVar('nation'),
$year,
$month,
false
);
}
function deleteItem(){ function deleteItem(){
$this->setVar('item', 0); $this->setVar('item', 0);
$this->itemObjs['item'] = new ActionItem\che_Dummy(0); $this->itemObjs['item'] = new ActionItem\che_Dummy(0);
+64 -22
View File
@@ -33,6 +33,53 @@ class WarUnit{
private function __construct(General $general){ private function __construct(General $general){
$this->general = $general; $this->general = $general;
} }
/* XXX:Dirty wrapper */
function getRaw():array{
return $this->general->getRaw();
}
function getVar(string $key){
return $this->general->getVar($key);
}
function touchVar(string $key):bool{
return $this->general->touchVar($key);
}
function setVar(string $key, $value){
return $this->general->setVar($key, $value);
}
function updateVar(string $key, $value){
return $this->general->updateVar($key, $value);
}
function updateVarWithLimit(string $key, $value, $min = null, $max = null){
return $this->general->updateVarWithLimit($key, $value, $min, $max);
}
function increaseVar(string $key, $value)
{
return $this->general->increaseVar($key, $value);
}
function increaseVarWithLimit(string $key, $value, $min = null, $max = null){
return $this->general->increaseVarWithLimit($key, $value, $min, $max);
}
function multiplyVar(string $key, $value)
{
return $this->general->multiplyVar($key, $value);
}
function multiplyVarWithLimit(string $key, $value, $min = null, $max = null){
return $this->general->multiplyVarWithLimit($key, $value, $min, $max);
}
function getUpdatedValues():array {
return $this->general->getUpdatedValues();
}
protected function clearActivatedSkill(){ protected function clearActivatedSkill(){
foreach($this->activatedSkill as $skillName=>$state){ foreach($this->activatedSkill as $skillName=>$state){
@@ -91,7 +138,7 @@ class WarUnit{
} }
function getLogger():ActionLogger{ function getLogger():ActionLogger{
return $this->logger; return $this->general->logger;
} }
function getKilled():int{ function getKilled():int{
@@ -114,10 +161,6 @@ class WarUnit{
return $this->general; return $this->general;
} }
function getVar(string $key){
return $this->general->getVar($key);
}
function getMaxPhase():int{ function getMaxPhase():int{
return $this->getCrewType()->speed; return $this->getCrewType()->speed;
} }
@@ -161,11 +204,21 @@ class WarUnit{
$this->warPowerMultiply *= $multiply; $this->warPowerMultiply *= $multiply;
} }
function computeWarPower(){ function getComputedAttack(){
$oppose = $this->oppose; return $this->getCrewType()->getComputedAttack($this->general, $this->getNationVar('tech'));
}
$myAtt = $this->getCrewType()->getComputedAttack($this->getRaw(), $this->getNationVar('tech')); function getComputedDefence(){
$opDef = $oppose->getCrewType()->getComputedDefence($oppose->getRaw(), $oppose->getNationVar('tech')); return $this->getCrewType()->getComputedDefence($this->general, $this->getNationVar('tech'));
}
function computeWarPower(){
$oppose = $this->getOppose();
$general = $this->general;
$opposeGeneral = $oppose->getGeneral();
$myAtt = $this->getComputedAttack();
$opDef = $oppose->getComputedDefence();
// 감소할 병사 수 // 감소할 병사 수
$warPower = GameConst::$armperphase + $myAtt - $opDef; $warPower = GameConst::$armperphase + $myAtt - $opDef;
$opposeWarPowerMultiply = 1.0; $opposeWarPowerMultiply = 1.0;
@@ -177,15 +230,8 @@ class WarUnit{
$warPower = rand($warPower, 100); $warPower = rand($warPower, 100);
} }
$warPower *= CharAtmos( $warPower *= $this->getComputedAtmos();
$this->getComputedAtmos(), $warPower /= $oppose->getComputedTrain();
$this->getCharacter()
);
$warPower /= CharTrain(
$oppose->getComputedTrain(),
$oppose->getCharacter()
);
if($this instanceof WarUnitGeneral){ if($this instanceof WarUnitGeneral){
$genDexAtt = getGenDex($this->getRaw(), $this->getCrewType()->id); $genDexAtt = getGenDex($this->getRaw(), $this->getCrewType()->id);
@@ -254,10 +300,6 @@ class WarUnit{
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function getCharacter():int{
return 0;
}
function useBattleInitItem():bool{ function useBattleInitItem():bool{
return false; return false;
} }
+17 -9
View File
@@ -2,24 +2,24 @@
namespace sammo; namespace sammo;
class WarUnitCity extends WarUnit{ class WarUnitCity extends WarUnit{
use LazyVarUpdater;
protected $hp; protected $hp;
protected $cityRate; protected $cityRate;
function __construct($raw, $rawNation, $year, $month, $cityRate){ function __construct($raw, $rawNation, int $year, int $month, $cityRate){
$general = new DummyGeneral(false);
$general->setVar('city', $raw['city']);
$general->setVar('nation', $raw['nation']);
$general->initLogger($year, $month);
$this->raw = $raw; $this->raw = $raw;
$this->rawNation = $rawNation; $this->rawNation = $rawNation;
$this->isAttacker = false; $this->isAttacker = false;
$this->cityRate = $cityRate; $this->cityRate = $cityRate;
$this->logger = new ActionLogger( $this->logger = $general->getLogger();
0,
$this->getVar('nation'),
$year,
$month,
false
);
$this->crewType = GameUnitConst::byID(GameUnitConst::T_CASTLE); $this->crewType = GameUnitConst::byID(GameUnitConst::T_CASTLE);
$this->hp = $this->getVar('def') * 10; $this->hp = $this->getVar('def') * 10;
@@ -41,6 +41,14 @@ class WarUnitCity extends WarUnit{
return $this->raw[$key]; return $this->raw[$key];
} }
function getComputedAttack(){
return ($this->raw['def'] + $this->raw['wall'] * 9) / 500 + 200;
}
function getComputedDefence(){
return ($this->raw['def'] + $this->raw['wall'] * 9) / 500 + 200;
}
function increaseKilled(int $damage):int{ function increaseKilled(int $damage):int{
$this->killed += $damage; $this->killed += $damage;
$this->killedCurr += $damage; $this->killedCurr += $damage;
@@ -138,13 +146,13 @@ class WarUnitCity extends WarUnit{
function applyDB($db):bool{ function applyDB($db):bool{
$updateVals = $this->getUpdatedValues(); $updateVals = $this->getUpdatedValues();
$this->getLogger()->rollback(); //수비 도시의 로그는 기록하지 않음
if(!$updateVals){ if(!$updateVals){
return false; return false;
} }
$db->update('city', $updateVals, 'city=%i', $this->raw['city']); $db->update('city', $updateVals, 'city=%i', $this->raw['city']);
$this->getLogger()->rollback(); //수비 도시의 로그는 기록하지 않음
return $db->affectedRows() > 0; return $db->affectedRows() > 0;
} }
+47 -128
View File
@@ -95,21 +95,11 @@ class WarUnitGeneral extends WarUnit{
} }
function getComputedAvoidRatio():float{ function getComputedAvoidRatio():float{
$specialWar = $this->getSpecialWar();
$item = $this->getItem();
$avoidRatio = $this->getCrewType()->avoid / 100; $avoidRatio = $this->getCrewType()->avoid / 100;
$avoidRatio *= $this->getComputedTrain() / 100; $avoidRatio *= $this->getComputedTrain() / 100;
//특기보정 : 궁병 $avoidRatio = $general->onCalcStat($general, 'warAvoidRatio', $avoidRatio, ['isAttacker'=>$this->isAttacker]);
if($specialWar == 51){
$avoidRatio += 0.2;
}
//도구 보정 : 둔갑천서, 태평요술
if($item == 26 || $item == 25){
$avoidRatio += 0.2;
}
if($this->getOppose()->getCrewType()->armType == GameUnitConst::T_FOOTMAN){ if($this->getOppose()->getCrewType()->armType == GameUnitConst::T_FOOTMAN){
$avoidRatio *= 0.75; $avoidRatio *= 0.75;
@@ -119,100 +109,51 @@ class WarUnitGeneral extends WarUnit{
} }
function addWin(){ function addWin(){
$this->increaseVar('killnum', 1); $general = $this->general;
$this->multiplyVarWithLimit('atmos', 1.1, null, GameConst::$maxAtmosByWar); $general->increaseVar('killnum', 1);
$general->multiplyVarWithLimit('atmos', 1.1, null, GameConst::$maxAtmosByWar);
$this->addStatExp(1); $this->addStatExp(1);
} }
function addStatExp(int $value = 1){ function addStatExp(int $value = 1){
$general = $this->general;
if($this->crewType->armType == GameUnitConst::T_WIZARD) { // 귀병 if($this->crewType->armType == GameUnitConst::T_WIZARD) { // 귀병
$this->increaseVar('intel2', $value); $general->increaseVar('intel2', $value);
} elseif($this->crewType->armType == GameUnitConst::T_SIEGE) { // 차병 } elseif($this->crewType->armType == GameUnitConst::T_SIEGE) { // 차병
$this->increaseVar('leader2', $value); $general->increaseVar('leader2', $value);
} else { } else {
$this->increaseVar('power2', $value); $general->increaseVar('power2', $value);
} }
} }
function addLevelExp(float $value){ function addLevelExp(float $value){
$general = $this->general;
if(!$this->isAttacker){ if(!$this->isAttacker){
$value *= 0.8; $value *= 0.8;
} }
$value *= getCharExpMultiplier($this->getCharacter()); $value = $general->onCalcStat($general, 'experience', $value);
$this->increaseVar('experience', $value); $general->increaseVar('experience', $value);
} }
function addDedication(float $value){ function addDedication(float $value){
$value *= getCharDedMultiplier($this->getCharacter()); $general = $this->general;
$this->increaseVar('dedication', $value); $value = $general->onCalcStat($general, 'dedication', $value);
$general->increaseVar('dedication', $value);
} }
function addLose(){ function addLose(){
$this->increaseVar('deathnum', 1); $general = $this->general;
$general->increaseVar('deathnum', 1);
$this->addStatExp(1); $this->addStatExp(1);
} }
protected function getWarPowerMultiplyBySpecialWar():array{
//TODO: 장기적으로 if문이 아니라 객체를 이용하여 처리해야함
$myWarPowerMultiply = 1.0;
$opposeWarPowerMultiply = 1.0;
$specialWar = $this->getSpecialWar();
if($specialWar == 53){
if($this->getOppose() instanceof WarUnitCity){
$myWarPowerMultiply *= 2;
}
}
else if($specialWar == 52){
if($this->isAttacker){
$myWarPowerMultiply *= 1.20;
}
else{
$myWarPowerMultiply *= 1.10;
}
}
else if($specialWar == 60){
if($this->isAttacker){
$myWarPowerMultiply *= 1.10;
}
}
else if($specialWar == 61){
$myWarPowerMultiply *= 1.10;
}
else if($specialWar == 62){
$opposeWarPowerMultiply *= 0.95;
}
else if($specialWar == 50){
if($this->isAttacker){
$opposeWarPowerMultiply *= 0.9;
}
else{
$opposeWarPowerMultiply *= 0.8;
}
}
else if($specialWar == 75){
$opposeCrewType = $this->oppose->getCrewType();
if($opposeCrewType->reqCities || $opposeCrewType->reqRegions){
$myWarPowerMultiply *= 1.1;
$opposeWarPowerMultiply *= 0.9;
}
}
return [$myWarPowerMultiply, $opposeWarPowerMultiply];
}
function computeWarPower(){ function computeWarPower(){
[$warPower,$opposeWarPowerMultiply] = parent::computeWarPower(); [$warPower,$opposeWarPowerMultiply] = parent::computeWarPower();
$generalNo = $this->getVar('no'); $general = $this->general;
$genLevel = $this->getVar('level'); $generalNo = $general->getVar('no');
$genLevel = $general->getVar('level');
if($this->isAttacker){ if($this->isAttacker){
if($genLevel == 12){ if($genLevel == 12){
@@ -240,7 +181,7 @@ class WarUnitGeneral extends WarUnit{
} }
} }
$expLevel = $this->getVar('explevel'); $expLevel = $general->getVar('explevel');
if($this->getOppose() instanceof WarUnitCity){ if($this->getOppose() instanceof WarUnitCity){
$warPower *= 1 + $expLevel / 600; $warPower *= 1 + $expLevel / 600;
@@ -251,7 +192,7 @@ class WarUnitGeneral extends WarUnit{
} }
[$specialMyWarPowerMultiply, $specialOpposeWarPowerMultiply] = $this->getWarPowerMultiplyBySpecialWar(); [$specialMyWarPowerMultiply, $specialOpposeWarPowerMultiply] = $this->general->getWarPowerMultiplier($this);
$warPower *= $specialMyWarPowerMultiply; $warPower *= $specialMyWarPowerMultiply;
$opposeWarPowerMultiply *= $specialOpposeWarPowerMultiply; $opposeWarPowerMultiply *= $specialOpposeWarPowerMultiply;
@@ -271,6 +212,7 @@ class WarUnitGeneral extends WarUnit{
$itemActivated = false; $itemActivated = false;
$itemConsumed = false; $itemConsumed = false;
$itemName = getItemName($item); $itemName = getItemName($item);
$general = $this->general;
if($item == 3){ if($item == 3){
//탁주 사용 //탁주 사용
@@ -306,7 +248,7 @@ class WarUnitGeneral extends WarUnit{
} }
if($itemConsumed){ if($itemConsumed){
$this->updateVar('item', 0); $general->updateVar('item', 0);
$josaUl = JosaUtil::pick($itemName, '을'); $josaUl = JosaUtil::pick($itemName, '을');
$this->getLogger()->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용!", ActionLogger::PLAIN); $this->getLogger()->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용!", ActionLogger::PLAIN);
} }
@@ -373,7 +315,7 @@ class WarUnitGeneral extends WarUnit{
if($itemConsumed){ if($itemConsumed){
//NOTE: 소비 아이템은 하나인가?, 1회용인가? //NOTE: 소비 아이템은 하나인가?, 1회용인가?
$this->updateVar('item', 0); $this->general->updateVar('item', 0);
$josaUl = JosaUtil::pick($itemName, '을'); $josaUl = JosaUtil::pick($itemName, '을');
$this->getLogger()->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용!", ActionLogger::PLAIN); $this->getLogger()->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용!", ActionLogger::PLAIN);
} }
@@ -384,6 +326,7 @@ class WarUnitGeneral extends WarUnit{
function applyBattleBeginSkillAndItem():bool{ function applyBattleBeginSkillAndItem():bool{
$result = false; $result = false;
$oppose = $this->getOppose(); $oppose = $this->getOppose();
$general = $this->general;
if($oppose->hasActivatedSkill('저격')){ if($oppose->hasActivatedSkill('저격')){
$result = true; $result = true;
@@ -394,10 +337,10 @@ class WarUnitGeneral extends WarUnit{
$this->getLogger()->pushGeneralBattleDetailLog("상대에게 <R>저격</>당했다!", ActionLogger::PLAIN); $this->getLogger()->pushGeneralBattleDetailLog("상대에게 <R>저격</>당했다!", ActionLogger::PLAIN);
if($oppose->hasActivatedSkill('수극')){ if($oppose->hasActivatedSkill('수극')){
$this->increaseVarWithLimit('injury', Util::randRangeInt(20, 40), null, 80); $general->increaseVarWithLimit('injury', Util::randRangeInt(20, 40), null, 80);
} }
else{ else{
$this->increaseVarWithLimit('injury', Util::randRangeInt(20, 60), null, 80); $general->increaseVarWithLimit('injury', Util::randRangeInt(20, 60), null, 80);
} }
} }
@@ -406,10 +349,11 @@ class WarUnitGeneral extends WarUnit{
} }
function getHP():int{ function getHP():int{
return $this->getVar('crew'); return $this->general->getVar('crew');
} }
function addDex(GameUnitDetail $crewType, float $exp){ function addDex(GameUnitDetail $crewType, float $exp){
$general = $this->general;
$armType = $crewType->armType; $armType = $crewType->armType;
if($armType == GameUnitConst::T_CASTLE){ if($armType == GameUnitConst::T_CASTLE){
@@ -431,15 +375,16 @@ class WarUnitGeneral extends WarUnit{
$ntype = $armType*10; $ntype = $armType*10;
$dexType = "dex{$ntype}"; $dexType = "dex{$ntype}";
$this->increaseVar($dexType, $exp); $general->increaseVar($dexType, $exp);
} }
function decreaseHP(int $damage):int{ function decreaseHP(int $damage):int{
$damage = min($damage, $this->getVar('crew')); $general = $this->general;
$damage = min($damage, $general->getVar('crew'));
$this->dead += $damage; $this->dead += $damage;
$this->deadCurr += $damage; $this->deadCurr += $damage;
$this->increaseVar('crew', -$damage); $general->increaseVar('crew', -$damage);
$addDex = $damage; $addDex = $damage;
if(!$this->isAttacker){ if(!$this->isAttacker){
@@ -447,10 +392,11 @@ class WarUnitGeneral extends WarUnit{
} }
$this->addDex($this->oppose->getCrewType(), $addDex); $this->addDex($this->oppose->getCrewType(), $addDex);
return $this->getVar('crew'); return $general->getVar('crew');
} }
function increaseKilled(int $damage):int{ function increaseKilled(int $damage):int{
$general = $this->general;
$this->addLevelExp($damage / 50); $this->addLevelExp($damage / 50);
$rice = $damage / 100; $rice = $damage / 100;
@@ -461,7 +407,7 @@ class WarUnitGeneral extends WarUnit{
$rice *= $this->crewType->rice; $rice *= $this->crewType->rice;
$rice *= getTechCost($this->getNationVar('tech')); $rice *= getTechCost($this->getNationVar('tech'));
$this->increaseVarWithLimit('rice', -$rice, 0); $general->increaseVarWithLimit('rice', -$rice, 0);
$addDex = $damage; $addDex = $damage;
if(!$this->isAttacker){ if(!$this->isAttacker){
@@ -889,6 +835,7 @@ class WarUnitGeneral extends WarUnit{
} }
function tryWound():bool{ function tryWound():bool{
$general = $this->general;
if($this->hasActivatedSkillOnLog('부상무효')){ if($this->hasActivatedSkillOnLog('부상무효')){
return false; return false;
} }
@@ -896,56 +843,27 @@ class WarUnitGeneral extends WarUnit{
return false; return false;
} }
$this->increaseVarWithLimit('injury', Util::randRangeInt(10, 80), null, 80); $general->increaseVarWithLimit('injury', Util::randRangeInt(10, 80), null, 80);
$this->getLogger()->pushGeneralActionLog("전투중 <R>부상</>당했다!", ActionLogger::PLAIN); $this->getLogger()->pushGeneralActionLog("전투중 <R>부상</>당했다!", ActionLogger::PLAIN);
return true; return true;
} }
function continueWar(&$noRice):bool{ function continueWar(&$noRice):bool{
$general = $this->general;
if($this->getHP() <= 0){ if($this->getHP() <= 0){
$noRice = false; $noRice = false;
return false; return false;
} }
if($this->getVar('rice') <= $this->getHP() / 100){ if($general->getVar('rice') <= $this->getHP() / 100){
$noRice = true; $noRice = true;
return false; return false;
} }
return true; return true;
} }
///checkAbility의 method 버전
function checkStatChange():bool{ function checkStatChange():bool{
//FIXME: 장기적으로는 General 클래스가 별도로 있어야 함 return $this->general->checkStatChange();
$logger = $this->getLogger();
$limit = GameConst::$upgradeLimit;
$table = [
['통솔', 'leader'],
['무력', 'power'],
['지력', 'intel'],
];
$result = false;
foreach($table as [$statNickName, $statName]){
$statExpName = $statName.'2';
if($this->getVar($statExpName) < 0){
$logger->pushGeneralActionLog("<R>{$statNickName}</>이 <C>1</> 떨어졌습니다!", ActionLogger::PLAIN);
$this->increaseVar($statExpName, $limit);
$this->increaseVar($statName, -1);
$result = true;
}
else if($this->getVar($statExpName) >= $limit){
$logger->pushGeneralActionLog("<S>{$statNickName}</>이 <C>1</> 올랐습니다!", ActionLogger::PLAIN);
$this->increaseVar($statExpName, -$limit);
$this->increaseVar($statName, 1);
$result = true;
}
}
return $result;
} }
function finishBattle(){ function finishBattle(){
@@ -954,13 +872,14 @@ class WarUnitGeneral extends WarUnit{
} }
$this->clearActivatedSkill(); $this->clearActivatedSkill();
$this->isFinished = true; $this->isFinished = true;
$general = $this->general;
$this->increaseVar('killcrew', $this->killed); $general->increaseVar('killcrew', $this->killed);
$this->increaseVar('deathcrew', $this->dead); $general->increaseVar('deathcrew', $this->dead);
$this->updateVar('rice', Util::round($this->getVar('rice'))); $general->updateVar('rice', Util::round($general->getVar('rice')));
$this->updateVar('experience', Util::round($this->getVar('experience'))); $general->updateVar('experience', Util::round($general->getVar('experience')));
$this->updateVar('dedication', Util::round($this->getVar('dedication'))); $general->updateVar('dedication', Util::round($general->getVar('dedication')));
$this->checkStatChange(); $this->checkStatChange();
} }