From 17a59cbdd5dc799b45c90b8cc0e59df928ab2c7b Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 29 Apr 2019 01:01:47 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=91=EC=A2=85=EC=9D=B4=20=ED=96=89?= =?UTF-8?q?=EB=8F=99=EC=97=90=20=EC=A0=84=ED=88=AC=EC=97=90=20event?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=9C=EC=9E=85=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/process_war.php | 43 ++++++++++++++---------- hwe/sammo/GameUnitActionBase.php | 18 +++++++++++ hwe/sammo/GameUnitConstBase.php | 45 ++++++++++++++++++++++---- hwe/sammo/GameUnitDetail.php | 3 +- hwe/sammo/GameUnitInitTriggerBase.php | 24 ++++++++++++++ hwe/sammo/GameUnitPhaseTriggerBase.php | 23 +++++++++++++ hwe/sammo/General.php | 8 +++++ hwe/sammo/WarUnitGeneral.php | 1 + 8 files changed, 141 insertions(+), 24 deletions(-) create mode 100644 hwe/sammo/GameUnitActionBase.php create mode 100644 hwe/sammo/GameUnitInitTriggerBase.php create mode 100644 hwe/sammo/GameUnitPhaseTriggerBase.php diff --git a/hwe/process_war.php b/hwe/process_war.php index d7696e39..1203061a 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -2,10 +2,11 @@ namespace sammo; -function processWar(General $attackerGeneral, array $rawNation, array $rawDefenderCity){ +function processWar(General $attackerGeneral, array $rawAttackerNation, array $rawDefenderCity){ $db = DB::db(); + $attackerNationID = $attackerGeneral->getNationID(); $defenderNationID = $rawDefenderCity['nation']; if($defenderNationID == 0){ @@ -28,7 +29,7 @@ function processWar(General $attackerGeneral, array $rawNation, array $rawDefend $gameStor = KVStorage::getStorage($db, 'game_env'); [$startYear, $year, $month, $cityRate, $joinMode] = $gameStor->getValuesAsArray(['startyear', 'year', 'month', 'city_rate', 'join_mode']); - $attacker = new WarUnitGeneral($attackerGeneral, $rawNation, true); + $attacker = new WarUnitGeneral($attackerGeneral, $rawAttackerNation, true); $city = new WarUnitCity($rawDefenderCity, $rawDefenderNation, $year, $month, $cityRate); @@ -101,7 +102,7 @@ function processWar(General $attackerGeneral, array $rawNation, array $rawDefend $db->update('city', [ 'dead' => $db->sqleval('dead + %i', $totalDead * 0.4) - ], 'city=%i', $rawAttackerCity['city']); + ], 'city=%i', $attackerGeneral->getCityID()); $db->update('city', [ 'dead' => $db->sqleval('dead + %i', $totalDead * 0.6) @@ -160,7 +161,7 @@ function processWar(General $attackerGeneral, array $rawNation, array $rawDefend } //XXX: 새 도시점령 코드 작성하기 전까지 유지 - $rawAttackerCity = $db->queryFirstRow('SELECT * FROM city WHERE city = %i', $rawAttacker['city']); + $rawAttackerCity = $db->queryFirstRow('SELECT * FROM city WHERE city = %i', $attackerGeneral->getCityID()); $rawAttackerNation = $db->queryFirstRow('SELECT nation,`level`,`name`,capital,gennum,tech,`type`,gold,rice FROM nation WHERE nation = %i', $attackerNationID); if($defenderNationID !== 0){ @@ -262,22 +263,30 @@ function processWar_NG( $attacker->addTrain(1); $defender->addTrain(1); + $attackerName = $attacker->getName(); + $attackerCrewTypeName = $attacker->getCrewTypeName(); + if($defender instanceof WarUnitGeneral){ - $josaWa = JosaUtil::pick($attacker->getCrewTypeName(), '와'); - $josaYi = JosaUtil::pick($defender->getCrewTypeName(), '이'); - $logger->pushGlobalActionLog("{$attacker->getName()}의 {$attacker->getCrewTypeName()}{$josaWa} {$defender->getName()}의 {$defender->getCrewTypeName()}{$josaYi} 대결합니다."); - $josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로'); - $josaUl = JosaUtil::pick($defender->getCrewTypeName(), '을'); - $attacker->getLogger()->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} {$defender->getName()}의 {$defender->getCrewTypeName()}{$josaUl} 공격합니다."); - $josaRo = JosaUtil::pick($defender->getCrewTypeName(), '로'); - $josaUl = JosaUtil::pick($attacker->getCrewTypeName(), '을'); - $defender->getLogger()->pushGeneralActionLog("{$defender->getCrewTypeName()}{$josaRo} {$attacker->getName()}의 {$attacker->getCrewTypeName()}{$josaUl} 수비합니다."); + $defenderName = $defender->getName(); + $defenderCrewTypeName = $defender->getCrewTypeName(); + + $josaWa = JosaUtil::pick($attackerCrewTypeName, '와'); + $josaYi = JosaUtil::pick($defenderCrewTypeName, '이'); + $logger->pushGlobalActionLog("{$attackerName}의 {$attackerCrewTypeName}{$josaWa} {$defenderName}의 {$defenderCrewTypeName}{$josaYi} 대결합니다."); + + $josaRo = JosaUtil::pick($attackerCrewTypeName, '로'); + $josaUl = JosaUtil::pick($defenderCrewTypeName, '을'); + $attacker->getLogger()->pushGeneralActionLog("{$attackerCrewTypeName}{$josaRo} {$defenderName}의 {$defenderCrewTypeName}{$josaUl} 공격합니다."); + + $josaRo = JosaUtil::pick($defenderCrewTypeName, '로'); + $josaUl = JosaUtil::pick($attackerCrewTypeName, '을'); + $defender->getLogger()->pushGeneralActionLog("{$defenderCrewTypeName}{$josaRo} {$attackerName}의 {$attackerCrewTypeName}{$josaUl} 수비합니다."); } else{ - $josaYi = JosaUtil::pick($attacker->getName(), '이'); - $josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로'); - $logger->pushGlobalActionLog("{$attacker->getName()}{$josaYi} {$attacker->getCrewTypeName()}{$josaRo} 성벽을 공격합니다."); - $logger->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} 성벽을 공격합니다.", ActionLogger::PLAIN); + $josaYi = JosaUtil::pick($attackerName, '이'); + $josaRo = JosaUtil::pick($attackerCrewTypeName, '로'); + $logger->pushGlobalActionLog("{$attackerName}{$josaYi} {$attackerCrewTypeName}{$josaRo} 성벽을 공격합니다."); + $logger->pushGeneralActionLog("{$attackerCrewTypeName}{$josaRo} 성벽을 공격합니다.", ActionLogger::PLAIN); } $defender->useBattleInitItem(); diff --git a/hwe/sammo/GameUnitActionBase.php b/hwe/sammo/GameUnitActionBase.php new file mode 100644 index 00000000..8e58eb3d --- /dev/null +++ b/hwe/sammo/GameUnitActionBase.php @@ -0,0 +1,18 @@ + '보병', @@ -303,6 +303,34 @@ class GameUnitConstBase{ ] ]; + public static function addGameUnit(GameUnitDetail $unitType){ + static::_generate(); + + static::$constID[$unitType->id] = $unitType; + static::$constName[$unitType->name] = $unitType; + + if(!key_exists($unitType->armType, static::$constType)){ + static::$constType[$unitType->armType] = []; + } + static::$constType[$unitType->armType][] = $unitType; + + foreach($unitType->reqCities as $reqCity){ + if(!key_exists($reqCity, static::$constCity)){ + static::$constCity[$reqCity] = []; + } + static::$constCity[$reqCity][] = $unitType; + } + + if($unitType->reqRegions){ + foreach($unitType->reqRegions as $reqRegion){ + if(!key_exists($reqRegion, static::$constRegion)){ + static::$constRegion[$reqRegion] = []; + } + static::$constRegion[$reqRegion][] = $unitType; + } + } + } + /** * @return \sammo\GameUnitDetail[] */ @@ -354,6 +382,10 @@ class GameUnitConstBase{ return static::$constType[$type]; } + protected static function _generateOptional(){ + //for inheritance + } + protected static function _generate(){ if(static::$constID || static::$constName || static::$constCity || static::$constRegion || static::$constType){ @@ -462,6 +494,7 @@ class GameUnitConstBase{ static::$constCity = $constCity; static::$constRegion = $constRegion; static::$constType = $constType; - + + static::_generateOptional(); } } \ No newline at end of file diff --git a/hwe/sammo/GameUnitDetail.php b/hwe/sammo/GameUnitDetail.php index 3ad1d56e..229972c2 100644 --- a/hwe/sammo/GameUnitDetail.php +++ b/hwe/sammo/GameUnitDetail.php @@ -1,7 +1,8 @@ object = $unit; + $this->unitType = $unit->getCrewType(); + } + + public function action(?array $env=null, $arg=null):?array{ + /** @var WarUnitGeneral $attacker */ + /** @var WarUnit $defender */ + [$attacker, $defender] = $arg; + + $attackerCrewType = $attacker->getCrewType(); + $defenderCrewType = $defender->getCrewType(); + + //TODO: 충차는 성벽 상대로 부상입지 않음 + + return $env; + } +} \ No newline at end of file diff --git a/hwe/sammo/GameUnitPhaseTriggerBase.php b/hwe/sammo/GameUnitPhaseTriggerBase.php new file mode 100644 index 00000000..2cc8acd4 --- /dev/null +++ b/hwe/sammo/GameUnitPhaseTriggerBase.php @@ -0,0 +1,23 @@ +object = $unit; + $this->unitType = $unit->getCrewType(); + } + + public function action(?array $env=null, $arg=null):?array{ + /** @var WarUnitGeneral $attacker */ + /** @var WarUnit $defender */ + [$attacker, $defender] = $arg; + + $attackerCrewType = $attacker->getCrewType(); + $defenderCrewType = $defender->getCrewType(); + + //TODO: 목우 + return $env; + } +} \ No newline at end of file diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index f01ddbf9..96bdf4f1 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -377,6 +377,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ @@ -398,6 +399,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; @@ -416,6 +418,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; @@ -433,6 +436,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; @@ -450,6 +454,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; @@ -470,6 +475,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; @@ -489,6 +495,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; @@ -510,6 +517,7 @@ class General implements iAction{ $this->specialDomesticObj, $this->specialWarObj, $this->personalityObj, + $this->getCrewTypeObj(), ], $this->itemObjs) as $iObj){ if(!$iObj){ continue; diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index 423d0fb5..011a9ea7 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -95,6 +95,7 @@ class WarUnitGeneral extends WarUnit{ } function getComputedAvoidRatio():float{ + $general = $this->general; $avoidRatio = $this->getCrewType()->avoid / 100; $avoidRatio *= $this->getComputedTrain() / 100;