PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
EntityDamageByEntityEvent.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
25
29
34 private int $damagerEntityId;
35
39 public function __construct(
40 Entity $damager,
42 int $cause,
43 float $damage,
44 array $modifiers = [],
45 private float $knockBack = Living::DEFAULT_KNOCKBACK_FORCE,
46 private float $verticalKnockBackLimit = Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT
47 ){
48 $this->damagerEntityId = $damager->getId();
49 parent::__construct($entity, $cause, $damage, $modifiers);
50 $this->addAttackerModifiers($damager);
51 }
52
53 protected function addAttackerModifiers(Entity $damager) : void{
54 if($damager instanceof Living){ //TODO: move this to entity classes
55 $effects = $damager->getEffects();
56 if(($strength = $effects->get(VanillaEffects::STRENGTH())) !== null){
57 $this->setModifier($this->getBaseDamage() * 0.3 * $strength->getEffectLevel(), self::MODIFIER_STRENGTH);
58 }
59
60 if(($weakness = $effects->get(VanillaEffects::WEAKNESS())) !== null && $this->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK){
61 $this->setModifier(-($this->getBaseDamage() * 0.2 * $weakness->getEffectLevel()), self::MODIFIER_WEAKNESS);
62 }
63 }
64 }
65
69 public function getDamager() : ?Entity{
70 return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->damagerEntityId);
71 }
72
78 public function getKnockBack() : float{
79 return $this->knockBack;
80 }
81
87 public function setKnockBack(float $knockBack) : void{
88 $this->knockBack = $knockBack;
89 }
90
97 public function getVerticalKnockBackLimit() : float{
98 return $this->verticalKnockBackLimit;
99 }
100
105 public function setVerticalKnockBackLimit(float $verticalKnockBackLimit) : void{
106 $this->verticalKnockBackLimit = $verticalKnockBackLimit;
107 }
108}
__construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers=[], private float $knockBack=Living::DEFAULT_KNOCKBACK_FORCE, private float $verticalKnockBackLimit=Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT)