코드 중간 반영

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
+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
*/