PocketMine-MP 5.15.1 git-08c6e63aac45a450fe3b437616ee8aa2500e04e2
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
28use function max;
29
31 private Effect $effectType;
32 private int $duration;
33 private int $amplifier;
34 private bool $visible;
35 private bool $ambient;
36 private Color $color;
37
41 public function __construct(Effect $effectType, ?int $duration = null, int $amplifier = 0, bool $visible = true, bool $ambient = false, ?Color $overrideColor = null){
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 }
49
50 public function getType() : Effect{
51 return $this->effectType;
52 }
53
57 public function getDuration() : int{
58 return $this->duration;
59 }
60
68 public function setDuration(int $duration) : EffectInstance{
69 if($duration < 0 || $duration > Limits::INT32_MAX){
70 throw new \InvalidArgumentException("Effect duration must be in range 0 - " . Limits::INT32_MAX . ", got $duration");
71 }
72 $this->duration = $duration;
73
74 return $this;
75 }
76
82 public function decreaseDuration(int $ticks) : EffectInstance{
83 $this->duration = max(0, $this->duration - $ticks);
84
85 return $this;
86 }
87
91 public function hasExpired() : bool{
92 return $this->duration <= 0;
93 }
94
95 public function getAmplifier() : int{
96 return $this->amplifier;
97 }
98
102 public function getEffectLevel() : int{
103 return $this->amplifier + 1;
104 }
105
109 public function setAmplifier(int $amplifier) : EffectInstance{
110 if($amplifier < 0 || $amplifier > 255){
111 throw new \InvalidArgumentException("Amplifier must be in range 0 - 255, got $amplifier");
112 }
113 $this->amplifier = $amplifier;
114
115 return $this;
116 }
117
121 public function isVisible() : bool{
122 return $this->visible;
123 }
124
128 public function setVisible(bool $visible = true) : EffectInstance{
129 $this->visible = $visible;
130
131 return $this;
132 }
133
139 public function isAmbient() : bool{
140 return $this->ambient;
141 }
142
146 public function setAmbient(bool $ambient = true) : EffectInstance{
147 $this->ambient = $ambient;
148
149 return $this;
150 }
151
156 public function getColor() : Color{
157 return $this->color;
158 }
159
163 public function setColor(Color $color) : EffectInstance{
164 $this->color = $color;
165
166 return $this;
167 }
168
172 public function resetColor() : EffectInstance{
173 $this->color = $this->effectType->getColor();
174
175 return $this;
176 }
177}
__construct(Effect $effectType, ?int $duration=null, int $amplifier=0, bool $visible=true, bool $ambient=false, ?Color $overrideColor=null)