코드 중간 반영

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