Trigger 추가 수정
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
namespace sammo\ActionSpecialWar;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\SpecialityConst;
|
||||
use \sammo;
|
||||
|
||||
class che_의술 implements iAction{
|
||||
use \sammo\DefaultAction;
|
||||
@@ -22,4 +20,6 @@ class che_의술 implements iAction{
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class che_전역치료 extends
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
abstract class GeneralTrigger extends ObjectTrigger{
|
||||
abstract public function __construct(General $general);
|
||||
}
|
||||
?>
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
class GeneralTriggerCaller extends TriggerCaller{
|
||||
function checkValidTrigger(iObjectTrigger $trigger):bool{
|
||||
if($trigger instanceof iGeneralTrigger){
|
||||
function checkValidTrigger(ObjectTrigger $trigger):bool{
|
||||
if($trigger instanceof GeneralTrigger){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
abstract class ObjectTrigger{
|
||||
const PRIORITY_MAX = 99999;
|
||||
const PRIORITY_BEGIN = 50000;
|
||||
const PRIORITY_PRE = 40000;
|
||||
const PRIORITY_BODY = 30000;
|
||||
const PRIORITY_POST = 20000;
|
||||
const PRIORITY_FINAL = 10000;
|
||||
|
||||
static protected $priority;
|
||||
protected $object = null;
|
||||
|
||||
static public function getPriority():int{
|
||||
return static::$priority;
|
||||
}
|
||||
abstract public function action(?array $env=null, $arg=null):?array;
|
||||
public function getUniqueID():string{
|
||||
$priority = static::$priority;
|
||||
$hash = spl_object_hash($this->object);
|
||||
$fqn = static::class;
|
||||
return "{$priority}_{$fqn}_{$hash}";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -5,7 +5,7 @@ abstract class TriggerCaller{
|
||||
protected $triggerListByPriority = [];
|
||||
protected $sorted = false;
|
||||
|
||||
abstract function checkValidTrigger(iObjectTrigger $trigger):bool;
|
||||
abstract function checkValidTrigger(ObjectTrigger $trigger):bool;
|
||||
|
||||
function isEmpty():bool{
|
||||
return !$this->triggerListByPriority;
|
||||
@@ -18,13 +18,13 @@ abstract class TriggerCaller{
|
||||
}
|
||||
|
||||
$sorted = true;
|
||||
$minPriority = iObjectTrigger::PRIORITY_MAX;
|
||||
$minPriority = ObjectTrigger::PRIORITY_MAX;
|
||||
|
||||
foreach($triggerList as $trigger){
|
||||
if(!checkValidTrigger($trigger)){
|
||||
throw new \InvalidArgumentException('Invalid Trigger Type');
|
||||
}
|
||||
/** @var iObjectTrigger $trigger */
|
||||
/** @var ObjectTrigger $trigger */
|
||||
$priority = $trigger->getPriority();
|
||||
$uniqueID = $trigger->getUniqueID();
|
||||
|
||||
@@ -51,7 +51,7 @@ abstract class TriggerCaller{
|
||||
|
||||
}
|
||||
|
||||
function append(iObjectTrigger $trigger){
|
||||
function append(ObjectTrigger $trigger){
|
||||
if(!checkValidTrigger($trigger)){
|
||||
throw new \InvalidArgumentException('Invalid Trigger Type');
|
||||
}
|
||||
@@ -122,7 +122,7 @@ abstract class TriggerCaller{
|
||||
}
|
||||
|
||||
foreach($this->triggerListByPriority as $subTriggerList){
|
||||
/** @var iObjectTrigger[] $subTriggerList */
|
||||
/** @var ObjectTrigger[] $subTriggerList */
|
||||
foreach($subTriggerList as $trigger){
|
||||
$env = $trigger->action($env, $arg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
abstract class WarUnitTrigger extends ObjectTrigger{
|
||||
abstract public function __construct(WarUnit $unit);
|
||||
}
|
||||
?>
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
class WarUnitTriggerCaller extends TriggerCaller{
|
||||
function checkValidTrigger(iObjectTrigger $trigger):bool{
|
||||
if($trigger instanceof iWarUnitTrigger){
|
||||
function checkValidTrigger(ObjectTrigger $trigger):bool{
|
||||
if($trigger instanceof WarUnitTrigger){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
interface iGeneralTrigger extends iObjectTrigger{
|
||||
public function __construct(General $general);
|
||||
}
|
||||
?>
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
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 action(?array $env=null, $arg=null):?array;
|
||||
public function getUniqueID():string;
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
interface iWarUnitTrigger extends iObjectTrigger{
|
||||
public function __construct(WarUnit $general);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user