From dd5b1dbdd8e9ae367f4307508cf765235cf2afda Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 18 Aug 2018 10:53:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=84=ED=88=AC=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/process_war.ng.php | 29 +++++++++++------------------ hwe/process_war.php | 5 ----- hwe/sammo/WarUnit.php | 6 +++++- hwe/sammo/WarUnitCity.php | 14 ++++++++++++++ hwe/sammo/WarUnitGeneral.php | 16 ++++++++++++++++ src/sammo/Util.php | 20 +++++++++++++++++++- 6 files changed, 65 insertions(+), 25 deletions(-) diff --git a/hwe/process_war.ng.php b/hwe/process_war.ng.php index f6cb88bf..bdaafb21 100644 --- a/hwe/process_war.ng.php +++ b/hwe/process_war.ng.php @@ -29,7 +29,7 @@ function processWar_NG( $maxPhase = $attacker->getMaxPhase(); - $defender = ($getNextDefender)(null); + $defender = ($getNextDefender)(null, true); $conquerCity = false; $josaRo = JosaUtil::pick($city->name, '로'); @@ -99,24 +99,24 @@ function processWar_NG( $killedDefender = $attacker->tryAttackInPhase(); $killedAttacker = $defender->tryAttackInPhase(); - //NOTE: 쌀 소모는 tryAttackInPhase 내에서 반영 + //NOTE: 마법, 기술, 쌀 소모는 tryAttackInPhase 내에서 반영 $attackerHP = $attacker->getHP(); $defenderHP = $defender->getHP(); if($killedAttacker > $attackerHP || $killedDefender > $defenderHP){ - $killedAttackerRatio = $attackerHP / $killedAttacker; - $killedDefenderRatio = $defenderHP / $killedDefender; + $killedAttackerRatio = $killedAttacker / $attackerHP; + $killedDefenderRatio = $killedDefender / $defenderHP; - if($killedDefenderRatio < $killedAttackerRatio){ + if($killedDefenderRatio > $killedAttackerRatio){ //수비자가 더 병력 부족 - $killedAttacker *= $killedDefenderRatio; + $killedAttacker /= $killedDefenderRatio; $killedDefender = $defenderHP; break; } else{ //공격자가 더 병력 부족 - $killedDefender *= $killedAttackerRatio; + $killedDefender /= $killedAttackerRatio; $killedAttacker = $attackerHP; break; } @@ -165,7 +165,7 @@ function processWar_NG( $attacker->getLogger()->pushGeneralActionLog("{$defender->getName()}의 {$defender->getCrewType()->name}{$josaYi} 퇴각했습니다.", ActionLogger::PLAIN); $defender->getLogger()->pushGeneralActionLog("퇴각했습니다.", ActionLogger::PLAIN); - $defender = ($getNextDefender)($defender); + $defender = ($getNextDefender)($defender, true); if($defender === null){ continue; } @@ -173,12 +173,11 @@ function processWar_NG( throw new \RuntimeException('다음 수비자를 받아오는데 실패'); } } - - } //TODO: 전투 종료 + ($getNextDefender)($defender, false); if (!$conquerCity) { } @@ -197,14 +196,13 @@ function processWar_NG( if(!$conquerNation){ } - //TODO:국가 정복 처리 + //TODO:국가 정복 처리는 밖에서 하자 } function CriticalScore2($score) { - $score = Util::round($score * (rand()%8 + 13)/10); // 1.3~2.0 - return $score; + return Util::round($score * Util::randRange(1.3, 2.0)); } //0 0 : 100 100 이면 최고 무한대 차이 @@ -226,11 +224,6 @@ function getCrewtypeRice($crewtype, $tech) { // 표준 공 / 수 반환 수치는 약 0이 되게 (100~550) ////////////////////////////////////////////////////////////// -function getRate($admin, $type, $dtype) { - $t = "{$dtype}{$type}"; - return $admin[$t]; -} - function addConflict($city, $nationID, $mykillnum) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/process_war.php b/hwe/process_war.php index a4c3a2fd..c54bc05a 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -1492,11 +1492,6 @@ function getCrewtypeRice($crewtype, $tech) { // 표준 공 / 수 반환 수치는 약 0이 되게 (100~550) ////////////////////////////////////////////////////////////// -function getRate($admin, $type, $dtype) { - $t = "{$dtype}{$type}"; - return $admin[$t]; -} - function addConflict($city, $nationID, $mykillnum) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/WarUnit.php b/hwe/sammo/WarUnit.php index a5b3abb3..de7ecea0 100644 --- a/hwe/sammo/WarUnit.php +++ b/hwe/sammo/WarUnit.php @@ -182,7 +182,7 @@ class WarUnit{ return false; } - function applyBattleBeginSkillAndItem(){ + function applyBattleBeginSkillAndItem():bool{ return false; } @@ -220,6 +220,10 @@ class WarUnit{ return false; } + function applyDB($db):bool{ + return false; + } + diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index 50896c40..e209b22d 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -51,4 +51,18 @@ class WarUnitCity extends WarUnit{ return true; } + function applyDB($db):bool{ + $updateVals = []; + foreach(array_keys($this->updatedVar) as $key){ + $updateVals[$key] = $this->raw[$key]; + } + + if(!$updateVals){ + return false; + } + + $db->update('city', $updateVals, 'city=%i', $this->raw['city']); + return $db->affectedRows() > 0; + } + } \ No newline at end of file diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index 934518aa..225be95f 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -299,5 +299,21 @@ class WarUnitGeneral extends WarUnit{ return true; } + /** + * @param \MeekroDB $db + */ + function applyDB($db):bool{ + $updateVals = []; + foreach(array_keys($this->updatedVar) as $key){ + $updateVals[$key] = $this->raw[$key]; + } + + if(!$updateVals){ + return false; + } + + $db->update('general', $updateVals, 'no=%i', $this->raw['no']); + return $db->affectedRows() > 0; + } } \ No newline at end of file diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 5461d533..a914e38f 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -353,7 +353,7 @@ class Util extends \utilphp\util /** - * 0.0~1.0 사이의 랜덤 float + * [0.0, 1.0] 사이의 선형 랜덤 float * @return float */ public static function randF() @@ -361,6 +361,24 @@ class Util extends \utilphp\util return mt_rand() / mt_getrandmax(); } + /** + * [min, max] 사이의 선형 랜덤 float + * @return float + */ + public static function randRange(float $min, float $max) + { + return static::randF()*($max - $min) + $min; + } + + /** + * [min, max] 사이의 선형 랜덤 int + * 현재는 rand(min, max)와 동일 + * @return int + */ + public static function randRangeInt(int $min, int $max){ + return mt_rand($min, $max); + } + /** * $prob의 확률로 true를 반환 * @return boolean