전투 구현 반영

This commit is contained in:
2018-08-18 22:21:25 +09:00
parent 2a5af15aef
commit bf09f48196
4 changed files with 156 additions and 66 deletions
+43 -6
View File
@@ -24,6 +24,8 @@ class WarUnit{
protected $warPower;
protected $warPowerMultiply = 1.0;
protected $activatedSkill = [];
private function __construct(){
}
@@ -99,6 +101,10 @@ class WarUnit{
$this->oppose = $oppose;
}
function getOppose():?WarUnit{
return $this->oppose;
}
function getWarPower(){
return $this->warPower * $this->warPowerMultiply;
}
@@ -124,9 +130,11 @@ class WarUnit{
$warPower = GameConst::$armperphase + $myAtt - $opDef;
$opposeWarPowerMultiply = 1.0;
if($warPower <= 0){
//FIXME: 0으로 잡을때 90~100이면, 1은 너무 억울하지 않나?
$warPower = rand(90, 100);
if($warPower < 100){
//최소 전투력 50 보장
$warPower = max(0, $warPower);
$warPower = ($warPower + 100) / 2;
$warPower = rand($warPower, 100);
}
$warPower *= CharAtmos(
@@ -139,8 +147,20 @@ class WarUnit{
$oppose->getCharacter()
);
$genDexAtt = getGenDex($this->getRaw(), $this->getCrewType()->id);
$oppDexDef = getGenDex($oppose->getRaw(), $this->getCrewType()->id);
if($this instanceof WarUnitGeneral){
$genDexAtt = getGenDex($this->getRaw(), $this->getCrewType()->id);
}
else{
$genDexAtt = ($this->cityRate - 60) * 7200;
}
if($this instanceof WarUnitGeneral){
$oppDexDef = getGenDex($oppose->getRaw(), $this->getCrewType()->id);
}
else{
$oppDexDef = ($this->cityRate - 60) * 7200;
}
$warPower *= getDexLog($genDexAtt, $oppDexDef);
$warPower *= $this->getCrewType()->getAttackCoef($oppose->getCrewType());
@@ -189,6 +209,11 @@ class WarUnit{
return false;
}
function beginPhase():void{
$this->activatedSkill = [];
$this->computeWarPower();
}
function checkBattleBeginSkill():bool{
return false;
}
@@ -201,6 +226,18 @@ class WarUnit{
return false;
}
function hasActivatedSkill(string $skillName):bool{
return $this->activatedSkill[$skillName] ?? false;
}
function deactivateSkill(string $skillName):bool{
$this->activatedSkill[$skillName] = false;
}
function checkPreActiveSkill():bool{
return false;
}
function checkActiveSkill():bool{
return false;
}
@@ -227,7 +264,7 @@ class WarUnit{
throw new NotInheritedMethodException();
}
function tryAttackInPhase():int{
function calcDamage():int{
return $this->getWarPower();
}
+41 -2
View File
@@ -11,14 +11,22 @@ class WarUnitCity extends WarUnit{
protected $trainAtmos;
protected $rice = 0;
public $cityRate;
protected $updatedVar = [];
function __construct($raw, $rawNation, $year, $month){
protected $year;
protected $month;
function __construct($raw, $rawNation, $year, $month, $cityRate){
$this->raw = $raw;
$this->rawNation = $rawNation;
$this->year = $year;
$this->month = $month;
$this->isAttacker = false;
$this->cityRate = $cityRate;
$this->logger = new ActionLogger(0, $raw['nation'], $year, $month);
$this->crewType = GameUnitConst::byID($raw['crewtype']);
@@ -39,7 +47,7 @@ class WarUnitCity extends WarUnit{
return $this->raw['name'];
}
function tryAttackInPhase():int{
function calcDamage():int{
$warPower = $this->getWarPower();
$warPower *= Util::randRange(0.9, 1.1);
}
@@ -89,6 +97,37 @@ class WarUnitCity extends WarUnit{
$this->updatedVar['secu'] = true;
}
function addConflict():bool{
$conflict = Json::decode($this->raw['conflict']);
$opposeNation = $this->getOppose()->getRawNation();
$nationID = $opposeNation['nation'];
$newConflict = false;
$dead = $this->dead;
if(!$conflict || $this->getHP() == 0){ // 선타, 막타 보너스
$dead *= 1.05;
}
if(!$conflict){
$conflict = [$nationID => $dead];
}
else if(key_exists($nationID, $conflict)){
$conflict[$nationID] += $dead;
arsort($conflict);
}
else{
$conflict[$nationID] = $dead;
arsort($conflict);
$newConflict = true;
}
$this->raw['conflict'] = Json::encode($conflict);
$this->updatedVar['conflict'] = true;
return $newConflict;
}
function applyDB($db):bool{
+52 -6
View File
@@ -355,7 +355,11 @@ class WarUnitGeneral extends WarUnit{
$this->dead += $damage;
$this->raw['crew'] -= $damage;
$addDex = $damage;
if(!$this->isAttacker){
$addDex *= 0.9;
}
$this->addDex($this->oppose->getCrewType(), $addDex);
return $this->raw['crew'];
}
@@ -375,14 +379,18 @@ class WarUnitGeneral extends WarUnit{
$rice = min($this->raw['rice'], $rice);
$this->raw['rice'] -= $rice;
$this->updatedVar['rice'] = true;
//TODO: 죽인 만큼 숙련도 변경
//TODO: 죽인 만큼 쌀 소모
$addDex = $damage;
if(!$this->isAttacker){
$addDex *= 0.9;
}
$this->addDex($this->oppose->getCrewType(), $addDex);
$this->killed += $damage;
return $this->killed;
}
function tryAttackInPhase():int{
function calcDamage():int{
//TODO
return 0;
}
@@ -416,9 +424,45 @@ class WarUnitGeneral extends WarUnit{
return true;
}
function finishBattle(){
//TODO: 전투 종료 처리. 경험치 등
///checkAbility의 method 버전
function checkStatChange():bool{
//FIXME: 장기적으로는 General 클래스가 별도로 있어야 함
$logger = $this->getLogger();
$limit = GameConst::$upgradeLimit;
$table = [
['통솔', 'leader'],
['무력', 'power'],
['지력', 'intel'],
];
$result = false;
foreach($table as [$statNickName, $statName]){
$statExpName = $statName.'2';
if($this->raw[$statExpName] < 0){
$logger->pushGeneralActionLog("<R>{$statNickName}</>이 <C>1</> 떨어졌습니다!", ActionLogger::PLAIN);
$this->raw[$statExpName] += $limit;
$this->updatedVar[$statExpName] = true;
$this->raw[$statName] -= 1;
$this->updatedVar[$statName] = true;
$result = true;
}
else if($this->raw[$statExpName] >= $limit){
$logger->pushGeneralActionLog("<R>{$statNickName}</>이 <C>1</> 올랐습니다!", ActionLogger::PLAIN);
$this->raw[$statExpName] -= $limit;
$this->updatedVar[$statExpName] = true;
$this->raw[$statName] += 1;
$this->updatedVar[$statName] = true;
$result = true;
}
}
return $result;
}
function finishBattle(){
if($this->isAttacker){
$this->raw['recwar'] = $this->raw['turntime'];
}
@@ -436,6 +480,8 @@ class WarUnitGeneral extends WarUnit{
Util::setRound($this->raw['rice']);
Util::setRound($this->raw['experience']);
Util::setRound($this->raw['dedication']);
$this->checkStatChange();
}
/**