GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
EntityDamageEvent Class Reference

Public Member Functions

 __construct (Entity $entity, $cause, $damage)
 
 getCause ()
 
 getOriginalDamage ($type=self::MODIFIER_BASE)
 
 getDamage ($type=self::MODIFIER_BASE)
 
 setDamage ($damage, $type=self::MODIFIER_BASE)
 
 getRateDamage ($type=self::MODIFIER_BASE)
 
 setRateDamage ($damage, $type=self::MODIFIER_BASE)
 
 isApplicable ($type)
 
 getFinalDamage ()
 
 getUsedArmors ()
 
 getFireProtectL ()
 
 useArmors ()
 
 createThornsDamage ()
 
 getThornsDamage ()
 
 setThornsArmorUse ()
 
- Public Member Functions inherited from EntityEvent
 getEntity ()
 
- Public Member Functions inherited from Event
 getEventName ()
 
 getHandlers ()
 
- Public Member Functions inherited from Cancellable
 isCancelled ()
 
 setCancelled ($forceCancel=false)
 

Data Fields

const MODIFIER_BASE = 0
 
const MODIFIER_RESISTANCE = 1
 
const MODIFIER_ARMOR = 2
 
const MODIFIER_PROTECTION = 3
 
const MODIFIER_STRENGTH = 4
 
const MODIFIER_WEAKNESS = 5
 
const CAUSE_CONTACT = 0
 
const CAUSE_ENTITY_ATTACK = 1
 
const CAUSE_PROJECTILE = 2
 
const CAUSE_SUFFOCATION = 3
 
const CAUSE_FALL = 4
 
const CAUSE_FIRE = 5
 
const CAUSE_FIRE_TICK = 6
 
const CAUSE_LAVA = 7
 
const CAUSE_DROWNING = 8
 
const CAUSE_BLOCK_EXPLOSION = 9
 
const CAUSE_ENTITY_EXPLOSION = 10
 
const CAUSE_VOID = 11
 
const CAUSE_SUICIDE = 12
 
const CAUSE_MAGIC = 13
 
const CAUSE_CUSTOM = 14
 
const CAUSE_STARVATION = 15
 
const CAUSE_LIGHTNING = 16
 

Static Public Attributes

static $handlerList = null
 

Additional Inherited Members

- Protected Attributes inherited from EntityEvent
 $entity
 
- Protected Attributes inherited from Event
 $eventName = null
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Entity  $entity,
  $cause,
  $damage 
)
Parameters
Entity$entity
int$cause
int|int[]$damage
Exceptions
83  {
84  $this->entity = $entity;
85  $this->cause = $cause;
86  if(is_array($damage)){
87  $this->modifiers = $damage;
88  }else{
89  $this->modifiers = [
90  self::MODIFIER_BASE => $damage
91  ];
92  }
93 
94  $this->originals = $this->modifiers;
95 
96  if(!isset($this->modifiers[self::MODIFIER_BASE])){
97  throw new \InvalidArgumentException("BASE Damage modifier missing");
98  }
99 
100  //For DAMAGE_RESISTANCE
101  if($cause !== self::CAUSE_VOID and $cause !== self::CAUSE_SUICIDE){
102  if($entity->hasEffect(Effect::DAMAGE_RESISTANCE)){
103  $RES_level = 1 - 0.20 * ($entity->getEffect(Effect::DAMAGE_RESISTANCE)->getAmplifier() + 1);
104  if($RES_level < 0){
105  $RES_level = 0;
106  }
107  $this->setRateDamage($RES_level, self::MODIFIER_RESISTANCE);
108  }
109  }
110 
111  //TODO: add zombie
112  if($entity instanceof Player and $entity->getInventory() instanceof PlayerInventory){
113  switch($cause){
114  case self::CAUSE_CONTACT:
115  case self::CAUSE_ENTITY_ATTACK:
116  case self::CAUSE_PROJECTILE:
117  case self::CAUSE_FIRE:
118  case self::CAUSE_LAVA:
119  case self::CAUSE_BLOCK_EXPLOSION:
120  case self::CAUSE_ENTITY_EXPLOSION:
121  case self::CAUSE_LIGHTNING:
122  $points = 0;
123  foreach($entity->getInventory()->getArmorContents() as $index => $i){
124  if($i->isArmor()){
125  $points += $i->getArmorValue();
126  $this->usedArmors[$index] = 1;
127  }
128  }
129  if($points !== 0){
130  $this->setRateDamage(1 - 0.04 * $points, self::MODIFIER_ARMOR);
131  }
132  //For Protection
133  $spe_Prote = null;
134  switch($cause){
135  case self::CAUSE_ENTITY_EXPLOSION:
136  case self::CAUSE_BLOCK_EXPLOSION:
138  break;
139  case self::CAUSE_FIRE:
140  case self::CAUSE_LAVA:
142  break;
143  case self::CAUSE_PROJECTILE:
145  break;
146  default;
147  break;
148  }
149  foreach($this->usedArmors as $index => $cost){
150  $i = $entity->getInventory()->getArmorItem($index);
151  if($i->isArmor()){
152  $this->EPF += $i->getEnchantmentLevel(Enchantment::TYPE_ARMOR_PROTECTION);
153  $this->fireProtectL = max($this->fireProtectL, $i->getEnchantmentLevel(Enchantment::TYPE_ARMOR_FIRE_PROTECTION));
154  if($i->getEnchantmentLevel(Enchantment::TYPE_ARMOR_THORNS) > 0){
155  $this->thornsLevel[$index] = $i->getEnchantmentLevel(Enchantment::TYPE_ARMOR_THORNS);
156  }
157  if($spe_Prote !== null){
158  $this->EPF += 2 * $i->getEnchantmentLevel($spe_Prote);
159  }
160  }
161  }
162  break;
163  case self::CAUSE_FALL:
164  //Feather Falling
165  $i = $entity->getInventory()->getBoots();
166  if($i->isArmor()){
167  $this->EPF += $i->getEnchantmentLevel(Enchantment::TYPE_ARMOR_PROTECTION);
168  $this->EPF += 3 * $i->getEnchantmentLevel(Enchantment::TYPE_ARMOR_FALL_PROTECTION);
169  }
170  break;
171  case self::CAUSE_FIRE_TICK:
172  case self::CAUSE_SUFFOCATION:
173  case self::CAUSE_DROWNING:
174  case self::CAUSE_VOID:
175  case self::CAUSE_SUICIDE:
176  case self::CAUSE_MAGIC:
177  case self::CAUSE_CUSTOM:
178  case self::CAUSE_STARVATION:
179  break;
180  default:
181  break;
182  }
183  if($this->EPF !== 0){
184  $this->EPF = min(20, ceil($this->EPF * mt_rand(50, 100) / 100));
185  $this->setRateDamage(1 - 0.04 * $this->EPF, self::MODIFIER_PROTECTION);
186  }
187  }
188  }

Member Function Documentation

◆ createThornsDamage()

createThornsDamage ( )
316  {
317  if($this->thornsLevel !== []){
318  $this->thornsArmor = array_rand($this->thornsLevel);
319  $thornsL = $this->thornsLevel[$this->thornsArmor];
320  if(mt_rand(1, 100) < $thornsL * 15){
321  //$this->thornsDamage = mt_rand(1, 4);
322  $this->thornsDamage = 0; //Delete When #321 Is Fixed And Add In The Normal Damage
323  }
324  }
325  }

◆ getCause()

getCause ( )
Returns
int
193  {
194  return $this->cause;
195  }

◆ getDamage()

getDamage (   $type = self::MODIFIER_BASE)
Parameters
int$type
Returns
int
214  {
215  if(isset($this->modifiers[$type])){
216  return $this->modifiers[$type];
217  }
218 
219  return 0;
220  }

◆ getFinalDamage()

getFinalDamage ( )
Returns
int
268  {
269  $damage = $this->modifiers[self::MODIFIER_BASE];
270  foreach($this->rateModifiers as $type => $d){
271  $damage *= $d;
272  }
273  foreach($this->modifiers as $type => $d){
274  if($type !== self::MODIFIER_BASE){
275  $damage += $d;
276  }
277  }
278  return $damage;
279  }

◆ getFireProtectL()

getFireProtectL ( )
Returns
Int $fireProtectL
294  {
295  return $this->fireProtectL;
296  }

◆ getOriginalDamage()

getOriginalDamage (   $type = self::MODIFIER_BASE)
Parameters
int$type
Returns
int
202  {
203  if(isset($this->originals[$type])){
204  return $this->originals[$type];
205  }
206  return 0;
207  }

◆ getRateDamage()

getRateDamage (   $type = self::MODIFIER_BASE)
Parameters
int$type
Returns
float 1 - the percentage
237  {
238  if(isset($this->rateModifiers[$type])){
239  return $this->rateModifiers[$type];
240  }
241  return 1;
242  }

◆ getThornsDamage()

getThornsDamage ( )
Returns
int
330  {
331  return $this->thornsDamage;
332  }

◆ getUsedArmors()

getUsedArmors ( )
Returns
Item $usedArmors notice: $usedArmors $index->$cost
index
the

index of ArmorInventory $cost: the num of durability cost

287  {
288  return $this->usedArmors;
289  }

◆ isApplicable()

isApplicable (   $type)
Parameters
int$type
Returns
bool
261  {
262  return isset($this->modifiers[$type]);
263  }

◆ setDamage()

setDamage (   $damage,
  $type = self::MODIFIER_BASE 
)
Parameters
float$damage
int$type
Exceptions
228  {
229  $this->modifiers[$type] = $damage;
230  }

◆ setRateDamage()

setRateDamage (   $damage,
  $type = self::MODIFIER_BASE 
)
Parameters
float$damage
int$typeNotice:If you want to add/reduce the damage without reducing by Armor or effect. set a new Damage using setDamage Notice:If you want to add/reduce the damage within reducing by Armor of effect. Plz change the MODIFIER_BASE Notice:If you want to add/reduce the damage by multiplying. Plz use this function.
252  {
253  $this->rateModifiers[$type] = $damage;
254  }

◆ setThornsArmorUse()

setThornsArmorUse ( )
Returns
bool should be used after getThornsDamage()
337  {
338  if($this->thornsArmor === null){
339  return false;
340  }else{
341  $this->usedArmors[$this->thornsArmor] = 3;
342  return true;
343  }
344  }

◆ useArmors()

useArmors ( )
Returns
bool
301  {
302  if($this->entity instanceof Player){
303  if($this->entity->isSurvival() and $this->entity->isAlive()){
304  foreach($this->usedArmors as $index => $cost){
305  $i = $this->entity->getInventory()->getArmorItem($index);
306  if($i->isArmor()){
307  $this->entity->getInventory()->damageArmor($index, $cost);
308  }
309  }
310  }
311  return true;
312  }
313  return false;
314  }

Field Documentation

◆ $handlerList

$handlerList = null
static

◆ CAUSE_BLOCK_EXPLOSION

const CAUSE_BLOCK_EXPLOSION = 9

◆ CAUSE_CONTACT

const CAUSE_CONTACT = 0

◆ CAUSE_CUSTOM

const CAUSE_CUSTOM = 14

◆ CAUSE_DROWNING

const CAUSE_DROWNING = 8

◆ CAUSE_ENTITY_ATTACK

const CAUSE_ENTITY_ATTACK = 1

◆ CAUSE_ENTITY_EXPLOSION

const CAUSE_ENTITY_EXPLOSION = 10

◆ CAUSE_FALL

const CAUSE_FALL = 4

◆ CAUSE_FIRE

const CAUSE_FIRE = 5

◆ CAUSE_FIRE_TICK

const CAUSE_FIRE_TICK = 6

◆ CAUSE_LAVA

const CAUSE_LAVA = 7

◆ CAUSE_LIGHTNING

const CAUSE_LIGHTNING = 16

◆ CAUSE_MAGIC

const CAUSE_MAGIC = 13

◆ CAUSE_PROJECTILE

const CAUSE_PROJECTILE = 2

◆ CAUSE_STARVATION

const CAUSE_STARVATION = 15

◆ CAUSE_SUFFOCATION

const CAUSE_SUFFOCATION = 3

◆ CAUSE_SUICIDE

const CAUSE_SUICIDE = 12

◆ CAUSE_VOID

const CAUSE_VOID = 11

◆ MODIFIER_ARMOR

const MODIFIER_ARMOR = 2

◆ MODIFIER_BASE

const MODIFIER_BASE = 0

◆ MODIFIER_PROTECTION

const MODIFIER_PROTECTION = 3

◆ MODIFIER_RESISTANCE

const MODIFIER_RESISTANCE = 1

◆ MODIFIER_STRENGTH

const MODIFIER_STRENGTH = 4

◆ MODIFIER_WEAKNESS

const MODIFIER_WEAKNESS = 5

The documentation for this class was generated from the following file: