From bbfe5c2ab0c92f9d2667ccbfe742beebbad2c220 Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 29 Apr 2019 00:13:25 +0900 Subject: [PATCH] =?UTF-8?q?processWar=20=EC=9E=85=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EB=B6=80=EA=B7=BC=EC=9D=84=20General=20Object=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 1 + hwe/j_simulate_battle.php | 23 ++++++++--- hwe/process_war.php | 55 ++++++++++++-------------- hwe/sammo/Command/General/che_출병.php | 2 +- hwe/sammo/General.php | 2 + hwe/sammo/WarUnitCity.php | 2 +- hwe/sammo/WarUnitGeneral.php | 2 +- 7 files changed, 48 insertions(+), 39 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 54876998..c6ffd72c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,7 @@ "/twe":true, }, "cSpell.words": [ + "josa", "sammo" ], } \ No newline at end of file diff --git a/hwe/j_simulate_battle.php b/hwe/j_simulate_battle.php index b8076db5..897be47f 100644 --- a/hwe/j_simulate_battle.php +++ b/hwe/j_simulate_battle.php @@ -74,7 +74,7 @@ $rawAttacker['turntime'] = TimeUtil::now(); $rawAttackerCity = $query['attackerCity']; $rawAttackerNation = $query['attackerNation']; -$defenderList = $query['defenderGenerals']; +$rawdefenderList = $query['defenderGenerals']; $rawDefenderCity = $query['defenderCity']; $rawDefenderNation = $query['defenderNation']; @@ -135,7 +135,9 @@ if(!$v->validate()){ ]); } -foreach($defenderList as $idx=>$rawDefenderGeneral){ +$defenderList = []; + +foreach($rawDefenderList as $idx=>$rawDefenderGeneral){ $v = new Validator($rawDefenderGeneral); $v->rules($generalCheck); if(!$v->validate()){ @@ -145,6 +147,7 @@ foreach($defenderList as $idx=>$rawDefenderGeneral){ 'reason'=>"[수비자{$idx}]".$v->errorStr() ]); } + $defenderList[] = new General($rawDefenderGeneral, $rawDefenderCity, $year, $month, true); } @@ -242,7 +245,7 @@ if(!$v->validate()){ } if($action == 'reorder'){ - usort($defenderList, function($lhs, $rhs){ + usort($defenderList, function(General $lhs, General $rhs){ return -(extractBattleOrder($lhs) <=> extractBattleOrder($rhs)); }); @@ -258,7 +261,7 @@ if($action == 'reorder'){ ]); } -usort($defenderList, function($lhs, $rhs){ +usort($defenderList, function(General $lhs, General $rhs){ return -(extractBattleOrder($lhs) <=> extractBattleOrder($rhs)); }); @@ -273,7 +276,11 @@ function simulateBattle( $defenderList, $rawDefenderCity, $rawDefenderNation, $startYear, $year, $month, $cityRate ){ - $attacker = new WarUnitGeneral($rawAttacker, $rawAttackerCity, $rawAttackerNation, true, $year, $month); + $attacker = new WarUnitGeneral( + new General($rawAttacker, $rawAttackerCity, $year, $month), + $rawAttackerNation, + true + ); $city = new WarUnitCity($rawDefenderCity, $rawDefenderNation, $year, $month, $cityRate); $iterDefender = new \ArrayIterator($defenderList); @@ -309,7 +316,11 @@ function simulateBattle( $defenderRice += $rawGeneral['rice']; - $retVal = new WarUnitGeneral($rawGeneral, $rawDefenderCity, $rawDefenderNation, false, $year, $month); + $retVal = new WarUnitGeneral( + new General($rawGeneral, $rawDefenderCity, $year, $month), + $rawDefenderNation, + false + ); $iterDefender->next(); return $retVal; }; diff --git a/hwe/process_war.php b/hwe/process_war.php index 6d2067e4..d7696e39 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -2,7 +2,7 @@ namespace sammo; -function processWar(General $attacker, array $rawNation, array $rawDefenderCity){ +function processWar(General $attackerGeneral, array $rawNation, array $rawDefenderCity){ $db = DB::db(); @@ -28,24 +28,23 @@ function processWar(General $attacker, array $rawNation, array $rawDefenderCity) $gameStor = KVStorage::getStorage($db, 'game_env'); [$startYear, $year, $month, $cityRate, $joinMode] = $gameStor->getValuesAsArray(['startyear', 'year', 'month', 'city_rate', 'join_mode']); - $attacker = new WarUnitGeneral($attacker, $rawNation, true, $year, $month); + $attacker = new WarUnitGeneral($attackerGeneral, $rawNation, true); $city = new WarUnitCity($rawDefenderCity, $rawDefenderNation, $year, $month, $cityRate); - $defenderList = $db->query('SELECT no,name,nation,turntime,personal,special2,crew,crewtype,atmos,train,intel,intel2,book,power,power2,weap,injury,leader,leader2,horse,item,explevel,experience,dedication,level,gold,rice,dex0,dex10,dex20,dex30,dex40,warnum,killnum,deathnum,killcrew,deathcrew,recwar,mode FROM general WHERE nation=%i AND city=%i AND nation!=0 and crew > 0 and rice>(crew/100) and ((train>=60 and atmos>=60 and mode=1) or (train>=80 and atmos>=80 and mode=2))', $city->getVar('nation'), $city->getVar('city')); - - if(!$defenderList){ - $defenderList = []; + $defenderList = []; + foreach ($db->query('SELECT no,name,nation,turntime,personal,special2,crew,crewtype,atmos,train,intel,intel2,book,power,power2,weap,injury,leader,leader2,horse,item,explevel,experience,dedication,level,gold,rice,dex0,dex10,dex20,dex30,dex40,warnum,killnum,deathnum,killcrew,deathcrew,recwar,mode FROM general WHERE nation=%i AND city=%i AND nation!=0 and crew > 0 and rice>(crew/100) and ((train>=60 and atmos>=60 and mode=1) or (train>=80 and atmos>=80 and mode=2))', $city->getVar('nation'), $city->getVar('city')) as $rawGeneral){ + $defenderList[] = new General($rawGeneral, $rawDefenderCity, $year, $month); } - usort($defenderList, function($lhs, $rhs){ + usort($defenderList, function(General $lhs, General $rhs){ return -(extractBattleOrder($lhs) <=> extractBattleOrder($rhs)); }); $iterDefender = new \ArrayIterator($defenderList); $iterDefender->rewind(); - $getNextDefender = function(?WarUnit $prevDefender, bool $reqNext) use ($iterDefender, $rawDefenderCity, $rawDefenderNation, $year, $month, $db) { + $getNextDefender = function(?WarUnit $prevDefender, bool $reqNext) use ($iterDefender, $rawDefenderNation, $db) { if($prevDefender !== null){ $prevDefender->applyDB($db); } @@ -58,12 +57,17 @@ function processWar(General $attacker, array $rawNation, array $rawDefenderCity) return null; } - $rawGeneral = $iterDefender->current(); - if(extractBattleOrder($rawGeneral) <= 0){ + $nextDefender = $iterDefender->current(); + if(extractBattleOrder($nextDefender) <= 0){ return null; } - $retVal = new WarUnitGeneral($rawGeneral, $rawDefenderCity, $rawDefenderNation, false, $year, $month); + + $retVal = new WarUnitGeneral( + $nextDefender, + $rawDefenderNation, + false + ); $iterDefender->next(); return $retVal; }; @@ -172,41 +176,32 @@ function processWar(General $attacker, array $rawNation, array $rawDefenderCity) ], $attacker->getRaw(), $city->getRaw(), $rawAttackerNation, $rawDefenderNation); } -function extractBattleOrder($general){ - if($general['crew'] == 0){ +function extractBattleOrder(General $general){ + if($general->getVar('crew') == 0){ return 0; } - if($general['rice'] <= $general['crew'] / 100){ + if($general->getVar('rice') <= $general->getVar('crew') / 100){ return 0; } - if($general['mode'] == 0){ + if($general->getVar('mode') == 0){ return 0; } - if($general['mode'] == 1 && ($general['train'] < 60 || $general['atmos'] < 60)){ + if($general->getVar('mode') == 1 && ($general->getVar('train') < 60 || $general->getVar('atmos') < 60)){ return 0; } - if($general['mode'] == 2 && ($general['train'] < 80 || $general['atmos'] < 80)){ + if($general->getVar('mode') == 2 && ($general->getVar('train') < 80 || $general->getVar('atmos') < 80)){ return 0; } - $staticNation = getNationStaticInfo($general['nation']); - setLeadershipBonus($general, $staticNation['level']); - - $realStat = - getGeneralLeadership($general, true, true, true, true) + - getGeneralPower($general, true, true, true, true) + - getGeneralIntel($general, true, true, true, true); - $fullStat = - getGeneralLeadership($general, false, true, true, true) + - getGeneralPower($general, false, true, true, true) + - getGeneralIntel($general, false, true, true, true); + $realStat = $general->getLeadership() + $general->getPower() + $general->getIntel(); + $fullStat = $general->getLeadership(false) + $general->getPower(false) + $general->getIntel(false); $totalStat = ($realStat + $fullStat) / 2; - $totalCrew = $general['crew'] / 1000000 * (($general['train'] * $general['atmos']) ** 1.5); + $totalCrew = $general->getVar('crew') / 1000000 * (($general->getVar('train') * $general->getVar('atmos')) ** 1.5); return $totalStat + $totalCrew / 100; } @@ -249,7 +244,7 @@ function processWar_NG( $attacker->addWin(); $defender->addLose(); - $defender->heavyDecreseWealth(); + $defender->heavyDecreaseWealth(); $logger->pushGlobalActionLog("병량 부족으로 {$defender->getName()}의 수비병들이 패퇴합니다."); $josaUl = JosaUtil::pick($defender->getName(), '을'); diff --git a/hwe/sammo/Command/General/che_출병.php b/hwe/sammo/Command/General/che_출병.php index fd939e86..894c3568 100644 --- a/hwe/sammo/Command/General/che_출병.php +++ b/hwe/sammo/Command/General/che_출병.php @@ -128,7 +128,7 @@ class che_출병 extends Command\GeneralCommand{ $general->applyDB($db); //TODO: 장기적으로 통합해야함 - processWar($general->getRaw(), $this->destCity); + processWar($general, $general->getStaticNation(), $this->destCity); tryUniqueItemLottery($general); $general->applyDB($db); diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index a30f12c9..f01ddbf9 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -524,6 +524,8 @@ class General implements iAction{ return $caller; } + //TODO:createGeneralObjListFromDB로, 조건으로 select query나 generalIDList가 들어가는 녀석이 필요할 수 있음 + static public function createGeneralObjFromDB(int $generalID, ?array $column=null, int $constructMode=2):self{ $db = DB::db(); if($constructMode > 0){ diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index 76e4f5af..1daebf89 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -88,7 +88,7 @@ class WarUnitCity extends WarUnit{ return true; } - function heavyDecreseWealth(){ + function heavyDecreaseWealth(){ $this->multiplyVar('agri', 0.5); $this->multiplyVar('comm', 0.5); $this->multiplyVar('secu', 0.5); diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index 5122678f..423d0fb5 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -4,7 +4,7 @@ namespace sammo; class WarUnitGeneral extends WarUnit{ protected $bonusPhase = 0; - function __construct(General $general, array $rawNation, bool $isAttacker, int $year, int $month){ + function __construct(General $general, array $rawNation, bool $isAttacker){ $this->general = $general; $this->raw = $general->getRaw(); $this->rawNation = $rawNation; //read-only