PocketMine-MP 5.37.4 git-dbb0a3db4df7e1ea8e62dc67aa0a6030f2ac20e4
Loading...
Searching...
No Matches
EffectInstance.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\entity\effect;
25
28
30 private Effect $effectType;
31 private int $duration;
32 private int $amplifier;
33 private bool $visible;
34 private bool $ambient;
35 private Color $color;
36 private bool $infinite;
37
41 public function __construct(Effect $effectType, ?int $duration = null, int $amplifier = 0, bool $visible = true, bool $ambient = false, ?Color $overrideColor = null, bool $infinite = false){
42 $this->effectType = $effectType;
43 $this->setDuration($duration ?? $effectType->getDefaultDuration());
44 $this->setAmplifier($amplifier);
45 $this->visible = $visible;
46 $this->ambient = $ambient;
47 $this->color = $overrideColor ?? $effectType->getColor();
48 $this->infinite = $infinite;
49 }
50
51 public function getType() : Effect{
52 return $this->effectType;
53 }
54
58 public function getDuration() : int{
59 return $this->duration;
60 }
61
69 public function setDuration(int $duration) : EffectInstance{
70 if($duration < 0 || $duration > Limits::INT32_MAX){
71 throw new \InvalidArgumentException("Effect duration must be in range 0 - " . Limits::INT32_MAX . ", got $duration");
72 }
73 $this->duration = $duration;
74
75 return $this;
76 }
77
85 public function decreaseDuration(int $ticks) : EffectInstance{
86 $newDuration = $this->duration - $ticks;
87 if($newDuration <= 0){
88 if($this->infinite){ //wrap around
89 $newDuration += Limits::INT32_MAX;
90 }else{
91 $newDuration = 0;
92 }
93 }
94 $this->duration = $newDuration;
95
96 return $this;
97 }
98
102 public function hasExpired() : bool{
103 return $this->duration <= 0;
104 }
105
106 public function getAmplifier() : int{
107 return $this->amplifier;
108 }
109
113 public function getEffectLevel() : int{
114 return $this->amplifier + 1;
115 }
116
120 public function setAmplifier(int $amplifier) : EffectInstance{
121 if($amplifier < 0 || $amplifier > 255){
122 throw new \InvalidArgumentException("Amplifier must be in range 0 - 255, got $amplifier");
123 }
124 $this->amplifier = $amplifier;
125
126 return $this;
127 }
128
132 public function isVisible() : bool{
133 return $this->visible;
134 }
135
139 public function setVisible(bool $visible = true) : EffectInstance{
140 $this->visible = $visible;
141
142 return $this;
143 }
144
150 public function isAmbient() : bool{
151 return $this->ambient;
152 }
153
157 public function setAmbient(bool $ambient = true) : EffectInstance{
158 $this->ambient = $ambient;
159
160 return $this;
161 }
162
167 public function getColor() : Color{
168 return $this->color;
169 }
170
174 public function setColor(Color $color) : EffectInstance{
175 $this->color = $color;
176
177 return $this;
178 }
179
183 public function resetColor() : EffectInstance{
184 $this->color = $this->effectType->getColor();
185
186 return $this;
187 }
188
192 public function isInfinite() : bool{
193 return $this->infinite;
194 }
195}
__construct(Effect $effectType, ?int $duration=null, int $amplifier=0, bool $visible=true, bool $ambient=false, ?Color $overrideColor=null, bool $infinite=false)