trigger 구성을 올바르게 수정
This commit is contained in:
@@ -19,7 +19,7 @@ class che_의술 implements iAction{
|
|||||||
SpecialityConst::STAT_INTEL
|
SpecialityConst::STAT_INTEL
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getPreTurnExecuteTriggerList(General $general):array{
|
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
trait DefaultAction{
|
trait DefaultAction{
|
||||||
public function getPreTurnExecuteTriggerList(General $general):array{
|
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
public function onCalcDomestic(string $turnType, string $varType, float $value):float{
|
public function onCalcDomestic(string $turnType, string $varType, float $value):float{
|
||||||
return $value;
|
return $value;
|
||||||
@@ -24,10 +24,10 @@ trait DefaultAction{
|
|||||||
public function getWarPowerMultiplier(WarUnit $unit):array{
|
public function getWarPowerMultiplier(WarUnit $unit):array{
|
||||||
return [1, 1];
|
return [1, 1];
|
||||||
}
|
}
|
||||||
public function getBattleInitSkillTriggerList(WarUnit $unit):array{
|
public function getBattleInitSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
public function getBattlePhaseSkillTriggerList(WarUnit $unit):array{
|
public function getBattlePhaseSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller{
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+30
-10
@@ -276,8 +276,8 @@ class General implements iAction{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPreTurnExecuteTriggerList(General $general):array{
|
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||||
$chain = [];
|
$caller = new GeneralTriggerCaller();
|
||||||
foreach(array_merge([
|
foreach(array_merge([
|
||||||
$this->nationType,
|
$this->nationType,
|
||||||
$this->levelObj,
|
$this->levelObj,
|
||||||
@@ -288,9 +288,14 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$chain[] = $iObj->getPreTurnExecuteTriggerList($general);
|
/** @var iAction $iObj */
|
||||||
|
$caller->merge($iObj->getPreTurnExecuteTriggerList($general));
|
||||||
}
|
}
|
||||||
return array_merge([], ...$chain);
|
|
||||||
|
if($caller->isEmpty()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $caller;
|
||||||
}
|
}
|
||||||
public function onCalcDomestic(string $turnType, string $varType, float $value):float{
|
public function onCalcDomestic(string $turnType, string $varType, float $value):float{
|
||||||
foreach(array_merge([
|
foreach(array_merge([
|
||||||
@@ -303,6 +308,7 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/** @var iAction $iObj */
|
||||||
$value = $iObj->onCalcDomestic($turnType, $varType, $value);
|
$value = $iObj->onCalcDomestic($turnType, $varType, $value);
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
@@ -320,6 +326,7 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/** @var iAction $iObj */
|
||||||
$value = $iObj->onPreGeneralStatUpdate($this, $statName, $value);
|
$value = $iObj->onPreGeneralStatUpdate($this, $statName, $value);
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
@@ -336,6 +343,7 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/** @var iAction $iObj */
|
||||||
$value = $iObj->onCalcStrategic($turnType, $varType, $value);
|
$value = $iObj->onCalcStrategic($turnType, $varType, $value);
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
@@ -352,6 +360,7 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/** @var iAction $iObj */
|
||||||
$amount = $iObj->onCalcNationalIncome($type, $amount);
|
$amount = $iObj->onCalcNationalIncome($type, $amount);
|
||||||
}
|
}
|
||||||
return $amount;
|
return $amount;
|
||||||
@@ -371,6 +380,7 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/** @var iAction $iObj */
|
||||||
[$attV, $defV] = $iObj->getWarPowerMultiplier($unit);
|
[$attV, $defV] = $iObj->getWarPowerMultiplier($unit);
|
||||||
$att *= $attV;
|
$att *= $attV;
|
||||||
$def *= $defV;
|
$def *= $defV;
|
||||||
@@ -378,7 +388,7 @@ class General implements iAction{
|
|||||||
return [$att, $def];
|
return [$att, $def];
|
||||||
}
|
}
|
||||||
public function getBattleInitSkillTriggerList(WarUnit $unit):array{
|
public function getBattleInitSkillTriggerList(WarUnit $unit):array{
|
||||||
$chain = [];
|
$caller = new WarUnitTriggerCaller();
|
||||||
foreach(array_merge([
|
foreach(array_merge([
|
||||||
$this->nationType,
|
$this->nationType,
|
||||||
$this->levelObj,
|
$this->levelObj,
|
||||||
@@ -389,12 +399,17 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$chain[] = $iObj->getBattleInitSkillTriggerList($unit);
|
/** @var iAction $iObj */
|
||||||
|
$caller->merge($iObj->getBattleInitSkillTriggerList($unit));
|
||||||
}
|
}
|
||||||
return array_merge([], ...$chain);
|
|
||||||
|
if($caller->isEmpty()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $caller;
|
||||||
}
|
}
|
||||||
public function getBattlePhaseSkillTriggerList(WarUnit $unit):array{
|
public function getBattlePhaseSkillTriggerList(WarUnit $unit):array{
|
||||||
$chain = [];
|
$caller = new WarUnitTriggerCaller();
|
||||||
foreach(array_merge([
|
foreach(array_merge([
|
||||||
$this->nationType,
|
$this->nationType,
|
||||||
$this->levelObj,
|
$this->levelObj,
|
||||||
@@ -405,8 +420,13 @@ class General implements iAction{
|
|||||||
if(!$iObj){
|
if(!$iObj){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$chain[] = $iObj->getBattlePhaseSkillTriggerList($unit);
|
/** @var iAction $iObj */
|
||||||
|
$caller->merge($iObj->getBattlePhaseSkillTriggerList($unit));
|
||||||
}
|
}
|
||||||
return array_merge([], ...$chain);
|
|
||||||
|
if($caller->isEmpty()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $caller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+88
-10
@@ -7,15 +7,19 @@ abstract class TriggerCaller{
|
|||||||
|
|
||||||
abstract function checkValidTrigger(iObjectTrigger $trigger):bool;
|
abstract function checkValidTrigger(iObjectTrigger $trigger):bool;
|
||||||
|
|
||||||
|
function isEmpty():bool{
|
||||||
|
return !$this->triggerListByPriority;
|
||||||
|
}
|
||||||
|
|
||||||
function __construct(?array $triggerList=null)
|
function __construct(?array $triggerList=null)
|
||||||
{
|
{
|
||||||
if(!$triggerList){
|
if(!$triggerList){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->merge($triggerList);
|
|
||||||
}
|
|
||||||
|
|
||||||
function merge(array $triggerList){
|
$sorted = true;
|
||||||
|
$minPriority = iObjectTrigger::PRIORITY_MAX;
|
||||||
|
|
||||||
foreach($triggerList as $trigger){
|
foreach($triggerList as $trigger){
|
||||||
if(!checkValidTrigger($trigger)){
|
if(!checkValidTrigger($trigger)){
|
||||||
throw new \InvalidArgumentException('Invalid Trigger Type');
|
throw new \InvalidArgumentException('Invalid Trigger Type');
|
||||||
@@ -23,18 +27,92 @@ abstract class TriggerCaller{
|
|||||||
/** @var iObjectTrigger $trigger */
|
/** @var iObjectTrigger $trigger */
|
||||||
$priority = $trigger->getPriority();
|
$priority = $trigger->getPriority();
|
||||||
$uniqueID = $trigger->getUniqueID();
|
$uniqueID = $trigger->getUniqueID();
|
||||||
if(!key_exists($priority, $this->triggerListByPriority)){
|
|
||||||
$this->triggerListByPriority[$priority] = [];
|
if($sorted){
|
||||||
|
if($minPriority > $priority){
|
||||||
|
$minPriority = $priority;
|
||||||
|
}
|
||||||
|
else if($minPriority < $priority){
|
||||||
|
$sorted = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$subTriggerList = &$this->triggerListByPriority[$priority];
|
if(!key_exists($priority, $this->triggerListByPriority)){
|
||||||
|
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||||
if(key_exists($uniqueID, $subTriggerList)){
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$subTriggerList[$uniqueID] = $trigger;
|
|
||||||
|
$this->triggerListByPriority[$priority][$uniqueID] = $trigger;
|
||||||
}
|
}
|
||||||
$this->sorted = false;
|
|
||||||
|
if(!$sorted){
|
||||||
|
krsort($this->triggerListByPriority);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function append(iObjectTrigger $trigger){
|
||||||
|
if(!checkValidTrigger($trigger)){
|
||||||
|
throw new \InvalidArgumentException('Invalid Trigger Type');
|
||||||
|
}
|
||||||
|
$priority = $trigger->getPriority();
|
||||||
|
$uniqueID = $trigger->getUniqueID();
|
||||||
|
|
||||||
|
if(!$this->triggerListByPriority){
|
||||||
|
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lastKey = Util::array_last_key($this->triggerListByPriority);
|
||||||
|
if($lastKey > $priority){
|
||||||
|
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key_exists($priority, $this->triggerListByPriority)){
|
||||||
|
$this->triggerListByPriority[$priority][$uniqueID] = $trigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||||
|
krsort($this->triggerListByPriority);
|
||||||
|
}
|
||||||
|
|
||||||
|
function merge(?TriggerCaller $other){
|
||||||
|
if($other === null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newTriggerList = [];
|
||||||
|
$iterLhs = new \ArrayIterator($this->triggerListByPriority);
|
||||||
|
$iterRhs = new \ArrayIterator($other->triggerListByPriority);
|
||||||
|
|
||||||
|
while($iterLhs->valid() && $iterRhs->valid()){
|
||||||
|
if($iterLhs->key() > $iterRhs->key()){
|
||||||
|
$newTriggerList[$iterLhs->key()] = $iterLhs->current();
|
||||||
|
$iterLhs->next();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($iterRhs->key() > $iterLhs->key()){
|
||||||
|
$newTriggerList[$iterRhs->key()] = $iterRhs->current();
|
||||||
|
$iterRhs->next();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$newTriggerList[$iterLhs->key()] = $iterLhs->current() + $iterRhs->current();
|
||||||
|
$iterLhs->next();
|
||||||
|
$iterRhs->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
while($iterLhs->valid()){
|
||||||
|
$newTriggerList[$iterLhs->key()] = $iterLhs->current();
|
||||||
|
$iterLhs->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
while($iterRhs->valid()){
|
||||||
|
$newTriggerList[$iterRhs->key()] = $iterRhs->current();
|
||||||
|
$iterRhs->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->triggerListByPriority = $newTriggerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fire(?array $env = null, $arg = null):?array{
|
function fire(?array $env = null, $arg = null):?array{
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ class TurnExecutionHelper
|
|||||||
|
|
||||||
public function preprocessCommand(){
|
public function preprocessCommand(){
|
||||||
$general = $this->getGeneral();
|
$general = $this->getGeneral();
|
||||||
$general->getPreTurnExecuteTriggerList($general);
|
$caller = $general->getPreTurnExecuteTriggerList($general);
|
||||||
|
|
||||||
|
$caller->fire();
|
||||||
|
|
||||||
if($general->getVar('injury') && !$general->hasActivatedSkill('pre.부상경감')){
|
if($general->getVar('injury') && !$general->hasActivatedSkill('pre.부상경감')){
|
||||||
$general->increaseVarWithLimit('injury', -10, 0);
|
$general->increaseVarWithLimit('injury', -10, 0);
|
||||||
|
|||||||
+4
-23
@@ -2,18 +2,8 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
interface iAction{
|
interface iAction{
|
||||||
|
|
||||||
const PRIORITY_BEGIN = 50000;
|
|
||||||
const PRIORITY_PRE = 40000;
|
|
||||||
const PRIORITY_BODY = 30000;
|
|
||||||
const PRIORITY_POST = 20000;
|
|
||||||
const PRIORITY_FINAL = 10000;
|
|
||||||
|
|
||||||
//TODO: 능력치는?
|
//TODO: 능력치는?
|
||||||
/**
|
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller;
|
||||||
* @return iGeneralTrigger[]
|
|
||||||
*/
|
|
||||||
public function getPreTurnExecuteTriggerList(General $general):array;
|
|
||||||
public function onCalcDomestic(string $turnType, string $varType, float $value):float;
|
public function onCalcDomestic(string $turnType, string $varType, float $value):float;
|
||||||
|
|
||||||
public function onPreGeneralStatUpdate(General $general, string $statName, $value);
|
public function onPreGeneralStatUpdate(General $general, string $statName, $value);
|
||||||
@@ -21,16 +11,7 @@ interface iAction{
|
|||||||
public function onCalcStrategic(string $turnType, string $varType, $value);
|
public function onCalcStrategic(string $turnType, string $varType, $value);
|
||||||
public function onCalcNationalIncome(string $type, int $amount):int;
|
public function onCalcNationalIncome(string $type, int $amount):int;
|
||||||
|
|
||||||
/**
|
public function getWarPowerMultiplier(WarUnit $unit):?WarUnitTriggerCaller;
|
||||||
* @return iWarUnitTrigger[]
|
public function getBattleInitSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller;
|
||||||
*/
|
public function getBattlePhaseSkillTriggerList(WarUnit $unit):?WarUnitTriggerCaller;
|
||||||
public function getWarPowerMultiplier(WarUnit $unit):array;
|
|
||||||
/**
|
|
||||||
* @return iWarUnitTrigger[]
|
|
||||||
*/
|
|
||||||
public function getBattleInitSkillTriggerList(WarUnit $unit):array;
|
|
||||||
/**
|
|
||||||
* @return iWarUnitTrigger[]
|
|
||||||
*/
|
|
||||||
public function getBattlePhaseSkillTriggerList(WarUnit $unit):array;
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,13 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
interface iObjectTrigger{
|
interface iObjectTrigger{
|
||||||
|
const PRIORITY_MAX = 99999;
|
||||||
|
const PRIORITY_BEGIN = 50000;
|
||||||
|
const PRIORITY_PRE = 40000;
|
||||||
|
const PRIORITY_BODY = 30000;
|
||||||
|
const PRIORITY_POST = 20000;
|
||||||
|
const PRIORITY_FINAL = 10000;
|
||||||
|
|
||||||
public function getPriority():int;
|
public function getPriority():int;
|
||||||
public function action(?array $env=null, $arg=null):?array;
|
public function action(?array $env=null, $arg=null):?array;
|
||||||
public function getUniqueID():string;
|
public function getUniqueID():string;
|
||||||
|
|||||||
Reference in New Issue
Block a user