From bf09f481965b0c22703a0c15ec638331bbe95d81 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 18 Aug 2018 22:21:25 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=84=ED=88=AC=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/process_war.ng.php | 72 ++++++++++-------------------------- hwe/sammo/WarUnit.php | 49 +++++++++++++++++++++--- hwe/sammo/WarUnitCity.php | 43 ++++++++++++++++++++- hwe/sammo/WarUnitGeneral.php | 58 ++++++++++++++++++++++++++--- 4 files changed, 156 insertions(+), 66 deletions(-) diff --git a/hwe/process_war.ng.php b/hwe/process_war.ng.php index 1c17488d..eb504e44 100644 --- a/hwe/process_war.ng.php +++ b/hwe/process_war.ng.php @@ -35,7 +35,8 @@ function processWar_NG( $defender = $city; if($city->getRawNation()['rice'] <= 0 && $city->getRaw()['supply'] == 1){ - $attacker->setOppose(null); + $attacker->setOppose($defender); + $defender->setOppose($attacker); $attacker->addTrain(1); $attacker->addWin(); $conquerCity = true; @@ -80,21 +81,25 @@ function processWar_NG( $defender->applyBattleBeginSkillAndItem(); } - $attacker->computeWarPower(); - $defender->computeWarPower(); + $attacker->beginPhase(); + $defender->beginPhase(); + + $attacker->checkPreActiveSkill(); + $defender->checkPreActiveSkill(); $attacker->checkActiveSkill(); $defender->checkActiveSkill(); + //NOTE: 마법은 checkActiveSkill, checkPostActiveSkill 내에서 반영 $attacker->checkPostActiveSkill(); $defender->checkPostActiveSkill(); + //NOTE: 반계류 등의 스킬을 post에서 반영 $attacker->applyActiveSkill(); $defender->applyActiveSkill(); - $deadDefender = $attacker->tryAttackInPhase(); - $deadAttacker = $defender->tryAttackInPhase(); - //NOTE: 마법은 tryAttackInPhase 내에서 반영 + $deadDefender = $attacker->calcDamage(); + $deadAttacker = $defender->calcDamage(); $attackerHP = $attacker->getHP(); $defenderHP = $defender->getHP(); @@ -189,10 +194,18 @@ function processWar_NG( } - //TODO: 전투 종료 $attacker->finishBattle(); $defender->finishBattle(); + if($defender instanceof WarUnitCity){ + $newConflict = $defender->addConflict(); + if($newConflict){ + $nationName = $attacker->getRawNation()['name']; + $josaYi = JosaUtil::pick($nationName, '이'); + $logger->pushGlobalHistoryLog("【분쟁】{$nationName}{$josaYi} {$defender->getName()} 공략에 가담하여 분쟁이 발생하고 있습니다."); + } + } + ($getNextDefender)($defender, false); //NOTE: 공격자의 applyDB는 함수 호출자가 실행 @@ -204,51 +217,6 @@ function processWar_NG( } -////////////////////////////////////////////////////////////// -// 표준 공 / 수 반환 수치는 약 0이 되게 (100~550) -////////////////////////////////////////////////////////////// - -function addConflict($city, $nationID, $mykillnum) { - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - - $nationlist = []; - $killnum = [0]; - - list($year, $month) = $gameStor->getValuesAsArray(['year', 'month']); - - $conflict = Json::decode($city['conflict']); - - if(!$conflict || $city['def'] == 0){ // 선타, 막타 보너스 - $mykillnum *= 1.05; - } - - if (!$conflict) { - $conflict[$nationID] = $mykillnum; - } - else if(key_exists($nationID, $conflict)){ - $conflict[$nationID] += $mykillnum; - arsort($conflict); - } - else{ - $conflict[$nationID] = $mykillnum; - arsort($conflict); - - $nation = getNationStaticInfo($nationID); - $josaYi = JosaUtil::pick($nation['name'], '이'); - pushWorldHistory(["●{$year}년 {$month}월:【분쟁】{$nation['name']}{$josaYi} {$city['name']} 공략에 가담하여 분쟁이 발생하고 있습니다."]); - } - - $rawConflict = Json::encode($conflict); - $city['conflict'] = $rawConflict; - - $db->update('city', [ - 'conflict'=>$rawConflict - ], 'city=%i',$city['city']); - - return $city; -} - function DeleteConflict($nation) { $db = DB::db(); diff --git a/hwe/sammo/WarUnit.php b/hwe/sammo/WarUnit.php index b581587f..ee473506 100644 --- a/hwe/sammo/WarUnit.php +++ b/hwe/sammo/WarUnit.php @@ -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(); } diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index 3be1f524..5a12bf2e 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -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{ diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index 8daa7810..451ad8ad 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -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("{$statNickName}이 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("{$statNickName}이 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(); } /**