34 public function __construct(
37 parent::__construct();
43 public function remove(
Effect $effectType) : void{
44 $index = spl_object_id($effectType);
45 if(isset($this->effects[$index])){
46 $effect = $this->effects[$index];
49 if($ev->isCancelled()){
50 foreach($this->effectAddHooks as $hook){
51 $hook($ev->getEffect(),
true);
56 $effect->getType()->remove($this->entity, $effect);
57 parent::remove($effectType);
62 $index = spl_object_id($effect->getType());
63 $oldEffect = $this->effects[$index] ??
null;
66 if(!$this->canAdd($effect)){
71 if($ev->isCancelled()){
75 if($oldEffect !==
null){
76 $oldEffect->getType()->remove($this->entity, $oldEffect);
79 $effect->getType()->add($this->entity, $effect);
81 return parent::add($effect);
84 public function tick(
int $tickDiff = 1) : bool{
85 foreach($this->effects as $instance){
86 $type = $instance->getType();
87 if($type->canTick($instance)){
88 $type->applyEffect($this->entity, $instance);
90 $instance->decreaseDuration($tickDiff);
91 if($instance->hasExpired()){
92 $this->remove($instance->getType());
96 return count($this->effects) > 0;