코드 중간 반영

This commit is contained in:
2018-08-18 20:45:59 +09:00
parent 4bc78dba1e
commit d76d1f913a
5 changed files with 123 additions and 36 deletions
+23 -16
View File
@@ -35,6 +35,9 @@ function processWar_NG(
$defender = $city; $defender = $city;
if($city->getRawNation()['rice'] <= 0 && $city->getRaw()['supply'] == 1){ if($city->getRawNation()['rice'] <= 0 && $city->getRaw()['supply'] == 1){
$attacker->setOppose(null);
$attacker->addTrain(1);
$attacker->addWin();
$conquerCity = true; $conquerCity = true;
break; break;
} }
@@ -47,18 +50,18 @@ function processWar_NG(
$defender->addTrain(1); $defender->addTrain(1);
if($defender instanceof WarUnitGeneral){ if($defender instanceof WarUnitGeneral){
$josaWa = JosaUtil::pick($attacker->getCrewType()->name, '와'); $josaWa = JosaUtil::pick($attacker->getCrewTypeName(), '와');
$josaYi = JosaUtil::pick($defender->getCrewType()->name, '이'); $josaYi = JosaUtil::pick($defender->getCrewTypeName(), '이');
$logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewType()->name}{$josaWa} <Y>{$defender->getName()}</>의 {$defender->getCrewType()->name}{$josaYi} 대결합니다."); $logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaWa} <Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaYi} 대결합니다.");
$josaUl = JosaUtil::pick($defender->getCrewType()->name, '을'); $josaUl = JosaUtil::pick($defender->getCrewTypeName(), '을');
$josaRo = JosaUtil::pick($attacker->getCrewType()->name, '로'); $josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로');
$attacker->getLogger()->pushGeneralActionLog("{$attacker->getCrewType()->name}{$josaRo} <Y>{$defender->name}</>의 {$defender->getCrewType()->name}{$josaUl} <M>공격</>합니다."); $attacker->getLogger()->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} <Y>{$defender->name}</>의 {$defender->getCrewTypeName()}{$josaUl} <M>공격</>합니다.");
$defender->getLogger()->pushGeneralActionLog("{$defender->getCrewType()->name}{$josaRo} <Y>{$attacker->name}</>의 {$attacker->getCrewType()->name}{$josaUl} <M>수비</>합니다."); $defender->getLogger()->pushGeneralActionLog("{$defender->getCrewTypeName()}{$josaRo} <Y>{$attacker->name}</>의 {$attacker->getCrewTypeName()}{$josaUl} <M>수비</>합니다.");
} }
else{ else{
$josaYi = JosaUtil::pick($attacker->getName(), '이'); $josaYi = JosaUtil::pick($attacker->getName(), '이');
$josaRo = JosaUtil::pick($attacker->getCrewType()->name, '로'); $josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로');
$logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>{$josaYi} {$attacker->getCrewType()->name}{$josaRo} 성벽을 공격합니다."); $logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>{$josaYi} {$attacker->getCrewTypeName()}{$josaRo} 성벽을 공격합니다.");
$logger->pushGeneralActionLog("<C>●</>{$generalCrewType->name}{$josaRo} 성벽을 <M>공격</>합니다.", ActionLogger::PLAIN); $logger->pushGeneralActionLog("<C>●</>{$generalCrewType->name}{$josaRo} 성벽을 <M>공격</>합니다.", ActionLogger::PLAIN);
} }
@@ -83,6 +86,9 @@ function processWar_NG(
$attacker->checkActiveSkill(); $attacker->checkActiveSkill();
$defender->checkActiveSkill(); $defender->checkActiveSkill();
$attacker->checkPostActiveSkill();
$defender->checkPostActiveSkill();
$attacker->applyActiveSkill(); $attacker->applyActiveSkill();
$defender->applyActiveSkill(); $defender->applyActiveSkill();
@@ -119,7 +125,8 @@ function processWar_NG(
$attacker->increaseKilled($deadDefender); $attacker->increaseKilled($deadDefender);
$defender->increaseKilled($deadAttacker); $defender->increaseKilled($deadAttacker);
//TODO: 기술, 쌀 소모 반영등은 이전 코드와 달리 동적으로 매 페이즈마다 추가 계산 //TODO: 쌀 소모 반영등은 이전 코드와 달리 동적으로 매 페이즈마다 추가 계산
//NOTE: 기술, 도시 사망자 수는 '전투 종료 후' 외부에서 반영.
//TODO: 로그 출력 //TODO: 로그 출력
@@ -136,10 +143,10 @@ function processWar_NG(
$attacker->tryWound(); $attacker->tryWound();
$defender->tryWound(); $defender->tryWound();
$josaYi = JosaUtil::pick($attacker->getCrewType()->name, '이'); $josaYi = JosaUtil::pick($attacker->getCrewTypeName(), '이');
$logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewType()->name}{$josaYi} 퇴각했습니다."); $logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaYi} 퇴각했습니다.");
$attacker->getLogger()->pushGeneralActionLog("퇴각했습니다.", ActionLogger::PLAIN); $attacker->getLogger()->pushGeneralActionLog("퇴각했습니다.", ActionLogger::PLAIN);
$defender->getLogger()->pushGeneralActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewType()->name}{$josaYi} 퇴각했습니다.", ActionLogger::PLAIN); $defender->getLogger()->pushGeneralActionLog("<Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaYi} 퇴각했습니다.", ActionLogger::PLAIN);
break; break;
} }
@@ -157,9 +164,9 @@ function processWar_NG(
break; break;
} }
$josaYi = JosaUtil::pick($defender->getCrewType()->name, '이'); $josaYi = JosaUtil::pick($defender->getCrewTypeName(), '이');
$logger->pushGlobalActionLog("<Y>{$defender->getName()}</>의 {$defender->getCrewType()->name}{$josaYi} 퇴각했습니다."); $logger->pushGlobalActionLog("<Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaYi} 퇴각했습니다.");
$attacker->getLogger()->pushGeneralActionLog("<Y>{$defender->getName()}</>의 {$defender->getCrewType()->name}{$josaYi} 퇴각했습니다.", ActionLogger::PLAIN); $attacker->getLogger()->pushGeneralActionLog("<Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaYi} 퇴각했습니다.", ActionLogger::PLAIN);
$defender->getLogger()->pushGeneralActionLog("퇴각했습니다.", ActionLogger::PLAIN); $defender->getLogger()->pushGeneralActionLog("퇴각했습니다.", ActionLogger::PLAIN);
$defender->finishBattle(); $defender->finishBattle();
+4
View File
@@ -58,6 +58,10 @@ class GameUnitDetail{
$this->info = $info; $this->info = $info;
} }
public function getShortName():string{
return StringUtil::subStringForWidth($this->name, 0, 4);
}
public function costWithTech(int $tech, int $crew=100):float{ public function costWithTech(int $tech, int $crew=100):float{
return $this->cost * getTechCost($tech) * $crew / 100; return $this->cost * getTechCost($tech) * $crew / 100;
} }
+15 -2
View File
@@ -51,6 +51,14 @@ class WarUnit{
return $this->crewType; return $this->crewType;
} }
function getCrewTypeName():string{
return $this->getCrewType()->name;
}
function getCrewTypeShortName():string{
return $this->getCrewType()->getShortName();
}
function getLogger():ActionLogger{ function getLogger():ActionLogger{
return $this->logger; return $this->logger;
} }
@@ -87,9 +95,8 @@ class WarUnit{
$this->currPhase += 1; $this->currPhase += 1;
} }
function setOppose(WarUnit $oppose){ function setOppose(?WarUnit $oppose){
$this->oppose = $oppose; $this->oppose = $oppose;
} }
function getWarPower(){ function getWarPower(){
@@ -198,6 +205,10 @@ class WarUnit{
return false; return false;
} }
function checkPostActiveSkill():bool{
return false;
}
function applyActiveSkill():bool{ function applyActiveSkill():bool{
return false; return false;
} }
@@ -207,10 +218,12 @@ class WarUnit{
} }
function decreaseHP(int $damage):int{ function decreaseHP(int $damage):int{
$this->dead += $damage;
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
function increaseKilled(int $damage):int{ function increaseKilled(int $damage):int{
$this->killed += $damage;
throw new NotInheritedMethodException(); throw new NotInheritedMethodException();
} }
+44 -7
View File
@@ -7,14 +7,13 @@ class WarUnitCity extends WarUnit{
protected $logger; protected $logger;
protected $crewType; protected $crewType;
protected $hp;
protected $trainAtmos;
protected $rice = 0; protected $rice = 0;
protected $updatedVar = []; protected $updatedVar = [];
protected $def;
protected $wall;
function __construct($raw, $rawNation, $year, $month){ function __construct($raw, $rawNation, $year, $month){
$this->raw = $raw; $this->raw = $raw;
$this->rawNation = $rawNation; $this->rawNation = $rawNation;
@@ -24,11 +23,12 @@ class WarUnitCity extends WarUnit{
$this->logger = new ActionLogger(0, $raw['nation'], $year, $month); $this->logger = new ActionLogger(0, $raw['nation'], $year, $month);
$this->crewType = GameUnitConst::byID($raw['crewtype']); $this->crewType = GameUnitConst::byID($raw['crewtype']);
$this->def = $raw['def'] * 10;
$this->wall = $raw['wall'] * 10;
$this->rice = $this->rawNation['rice']; $this->rice = $this->rawNation['rice'];
$this->crewType = GameUnitConst::byID(GameUnitConst::T_CASTLE); $this->crewType = GameUnitConst::byID(GameUnitConst::T_CASTLE);
$this->hp = $this->raw['def'] * 10;;
$this->trainAtmos = $this->raw['wall'] * 10;
} }
function getRaw():array{ function getRaw():array{
@@ -44,10 +44,27 @@ class WarUnitCity extends WarUnit{
$warPower *= Util::randRange(0.9, 1.1); $warPower *= Util::randRange(0.9, 1.1);
} }
function increaseKilled(int $damage):int{
$this->killed += $damage;
return $this->killed;
}
function getHP():int{
return $this->hp;
}
function decreaseHP(int $damage):int{
$damage = min($damage, $this->hp);
$this->dead += $damage;
$this->hp -= $damage;
}
function continueWar(&$noRice):bool{ function continueWar(&$noRice):bool{
//전투가 가능하면 true //전투가 가능하면 true
$noRice = false; $noRice = false;
if($this->def <= 0){ if($this->getHP() <= 0){
return false; return false;
} }
@@ -55,6 +72,26 @@ class WarUnitCity extends WarUnit{
return true; return true;
} }
function finishBattle(){
$this->raw['def'] = Util::round($this->hp / 10);
$this->updatedVar['def'] = true;
$this->raw['wall'] = Util::round($this->trainAtmos / 10);
$this->updatedVar['wall'] = true;
$this->raw['dead'] += $this->dead;
$this->updatedVar['dead'] = true;
$decWealth = $this->dead / 10;
$this->raw['agri'] = max(0, Util::round($this->raw['agri'] - $decWealth));
$this->updatedVar['agri'] = true;
$this->raw['comm'] = max(0, Util::round($this->raw['comm'] - $decWealth));
$this->updatedVar['comm'] = true;
$this->raw['secu'] = max(0, Util::round($this->raw['secu'] - $decWealth));
$this->updatedVar['secu'] = true;
}
function applyDB($db):bool{ function applyDB($db):bool{
$updateVals = []; $updateVals = [];
foreach(array_keys($this->updatedVar) as $key){ foreach(array_keys($this->updatedVar) as $key){
+37 -11
View File
@@ -25,8 +25,8 @@ class WarUnitGeneral extends WarUnit{
setLeadershipBonus($raw, $rawNation['level']); setLeadershipBonus($raw, $rawNation['level']);
$this->raw = $raw; $this->raw = $raw;
$this->rawCity = $rawCity; $this->rawCity = $rawCity; //read-only
$this->rawNation = $rawNation; $this->rawNation = $rawNation; //read-only
$this->isAttacker = $isAttacker; $this->isAttacker = $isAttacker;
$this->logger = new ActionLogger($this->raw['no'], $this->raw['nation'], $year, $month); $this->logger = new ActionLogger($this->raw['no'], $this->raw['nation'], $year, $month);
@@ -64,6 +64,12 @@ class WarUnitGeneral extends WarUnit{
return $this->raw['special']; return $this->raw['special'];
} }
function setOppose(?WarUnit $oppose){
$this->oppose = $oppose;
$this->raw['warnum'] += 1;
$this->updatedVar['warnum'] = true;
}
function getSpecialWar():int{ function getSpecialWar():int{
return $this->raw['special2']; return $this->raw['special2'];
} }
@@ -92,6 +98,8 @@ class WarUnitGeneral extends WarUnit{
function addWin(){ function addWin(){
$this->win += 1; $this->win += 1;
$this->raw['killnum'] += 1;
$this->updatedVar['killnum'] = true;
$this->raw['atmos'] = min($this->raw['atmos'] * 1.1, GameConst::$maxAtmosByWar); $this->raw['atmos'] = min($this->raw['atmos'] * 1.1, GameConst::$maxAtmosByWar);
$this->updatedVar['atmos'] = true; $this->updatedVar['atmos'] = true;
@@ -125,19 +133,14 @@ class WarUnitGeneral extends WarUnit{
} }
function addLose(){ function addLose(){
$this->raw['deathnum'] += 1;
$this->updatedVar['deathnum'] = true;
$this->addStatExp(1); $this->addStatExp(1);
//TODO: 1패 로그 추가 //TODO: 1패 로그 추가
} }
function finishBattle(){
//TODO: 전투 종료 처리. 경험치 등
Util::setRound($this->raw['rice']);
Util::setRound($this->raw['experience']);
Util::setRound($this->raw['dedication']);
}
protected function getWarPowerMultiplyBySpecialWar():array{ protected function getWarPowerMultiplyBySpecialWar():array{
//TODO: 장기적으로 if문이 아니라 객체를 이용하여 처리해야함 //TODO: 장기적으로 if문이 아니라 객체를 이용하여 처리해야함
@@ -323,6 +326,8 @@ class WarUnitGeneral extends WarUnit{
function decreaseHP(int $damage):int{ function decreaseHP(int $damage):int{
$damage = min($damage, $this->raw['crew']); $damage = min($damage, $this->raw['crew']);
$this->dead += $damage;
$this->raw['crew'] -= $damage; $this->raw['crew'] -= $damage;
//TODO: 죽은 만큼 숙련도 변경 //TODO: 죽은 만큼 숙련도 변경
@@ -331,7 +336,6 @@ class WarUnitGeneral extends WarUnit{
} }
function increaseKilled(int $damage):int{ function increaseKilled(int $damage):int{
$this->addLevelExp($damage / 50); $this->addLevelExp($damage / 50);
$rice = $damage / 100; $rice = $damage / 100;
@@ -387,6 +391,28 @@ class WarUnitGeneral extends WarUnit{
return true; return true;
} }
function finishBattle(){
//TODO: 전투 종료 처리. 경험치 등
if($this->isAttacker){
$this->raw['recwar'] = $this->raw['turntime'];
}
else{
$this->raw['recwar'] = $this->oppose->getRaw()['turntime'];
}
$this->updatedVar['recwar'] = true;
$this->raw['killcrew'] += $this->killed;
$this->updatedVar['killcrew'] = true;
$this->raw['deathcrew'] += $this->dead;
$this->updatedVar['deathcrew'] = true;
Util::setRound($this->raw['rice']);
Util::setRound($this->raw['experience']);
Util::setRound($this->raw['dedication']);
}
/** /**
* @param \MeekroDB $db * @param \MeekroDB $db
*/ */