forked from devsam/core
병종이 행동에 전투에 event로 개입 가능하도록 수정 중
This commit is contained in:
+26
-17
@@ -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("<Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaWa} <Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaYi} 대결합니다.");
|
||||
$josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로');
|
||||
$josaUl = JosaUtil::pick($defender->getCrewTypeName(), '을');
|
||||
$attacker->getLogger()->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} <Y>{$defender->getName()}</>의 {$defender->getCrewTypeName()}{$josaUl} <M>공격</>합니다.");
|
||||
$josaRo = JosaUtil::pick($defender->getCrewTypeName(), '로');
|
||||
$josaUl = JosaUtil::pick($attacker->getCrewTypeName(), '을');
|
||||
$defender->getLogger()->pushGeneralActionLog("{$defender->getCrewTypeName()}{$josaRo} <Y>{$attacker->getName()}</>의 {$attacker->getCrewTypeName()}{$josaUl} <M>수비</>합니다.");
|
||||
$defenderName = $defender->getName();
|
||||
$defenderCrewTypeName = $defender->getCrewTypeName();
|
||||
|
||||
$josaWa = JosaUtil::pick($attackerCrewTypeName, '와');
|
||||
$josaYi = JosaUtil::pick($defenderCrewTypeName, '이');
|
||||
$logger->pushGlobalActionLog("<Y>{$attackerName}</>의 {$attackerCrewTypeName}{$josaWa} <Y>{$defenderName}</>의 {$defenderCrewTypeName}{$josaYi} 대결합니다.");
|
||||
|
||||
$josaRo = JosaUtil::pick($attackerCrewTypeName, '로');
|
||||
$josaUl = JosaUtil::pick($defenderCrewTypeName, '을');
|
||||
$attacker->getLogger()->pushGeneralActionLog("{$attackerCrewTypeName}{$josaRo} <Y>{$defenderName}</>의 {$defenderCrewTypeName}{$josaUl} <M>공격</>합니다.");
|
||||
|
||||
$josaRo = JosaUtil::pick($defenderCrewTypeName, '로');
|
||||
$josaUl = JosaUtil::pick($attackerCrewTypeName, '을');
|
||||
$defender->getLogger()->pushGeneralActionLog("{$defenderCrewTypeName}{$josaRo} <Y>{$attackerName}</>의 {$attackerCrewTypeName}{$josaUl} <M>수비</>합니다.");
|
||||
}
|
||||
else{
|
||||
$josaYi = JosaUtil::pick($attacker->getName(), '이');
|
||||
$josaRo = JosaUtil::pick($attacker->getCrewTypeName(), '로');
|
||||
$logger->pushGlobalActionLog("<Y>{$attacker->getName()}</>{$josaYi} {$attacker->getCrewTypeName()}{$josaRo} 성벽을 공격합니다.");
|
||||
$logger->pushGeneralActionLog("{$attacker->getCrewTypeName()}{$josaRo} 성벽을 <M>공격</>합니다.", ActionLogger::PLAIN);
|
||||
$josaYi = JosaUtil::pick($attackerName, '이');
|
||||
$josaRo = JosaUtil::pick($attackerCrewTypeName, '로');
|
||||
$logger->pushGlobalActionLog("<Y>{$attackerName}</>{$josaYi} {$attackerCrewTypeName}{$josaRo} 성벽을 공격합니다.");
|
||||
$logger->pushGeneralActionLog("{$attackerCrewTypeName}{$josaRo} 성벽을 <M>공격</>합니다.", ActionLogger::PLAIN);
|
||||
}
|
||||
|
||||
$defender->useBattleInitItem();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class GameUnitActionBase implements iAction{
|
||||
use DefaultAction;
|
||||
|
||||
|
||||
public function getWarPowerMultiplier(WarUnit $unit):array{
|
||||
return [1, 1];
|
||||
}
|
||||
|
||||
public function getBattleInitSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{
|
||||
return new WarUnitTriggerCaller([new GameUnitInitTriggerBase($unit)]);
|
||||
}
|
||||
public function getBattlePhaseSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{
|
||||
return new WarUnitTriggerCaller([new GameUnitPhaseTriggerBase($unit)]);
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,11 @@ class GameUnitConstBase{
|
||||
|
||||
|
||||
|
||||
protected static $constID = null;
|
||||
protected static $constName = null;
|
||||
protected static $constCity = null;
|
||||
protected static $constRegion = null;
|
||||
protected static $constType = null;
|
||||
protected static $constID = [];
|
||||
protected static $constName = [];
|
||||
protected static $constCity = [];
|
||||
protected static $constRegion = [];
|
||||
protected static $constType = [];
|
||||
|
||||
protected static $typeData = [
|
||||
self::T_FOOTMAN => '보병',
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class GameUnitDetail{
|
||||
class GameUnitDetail extends GameUnitActionBase{
|
||||
|
||||
public $id;
|
||||
public $armType;
|
||||
public $name;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class GameUnitInitTriggerBase extends ObjectTrigger{
|
||||
static protected $priority = 10000;
|
||||
|
||||
public function __construct(WarUnit $unit){
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class GameUnitPhaseTriggerBase extends ObjectTrigger{
|
||||
static protected $priority = 10000;
|
||||
|
||||
public function __construct(WarUnit $unit){
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -95,6 +95,7 @@ class WarUnitGeneral extends WarUnit{
|
||||
}
|
||||
|
||||
function getComputedAvoidRatio():float{
|
||||
$general = $this->general;
|
||||
|
||||
$avoidRatio = $this->getCrewType()->avoid / 100;
|
||||
$avoidRatio *= $this->getComputedTrain() / 100;
|
||||
|
||||
Reference in New Issue
Block a user