mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Implemented attack cooldown
This commit is contained in:
parent
ad7acb93b6
commit
84e62598ce
@ -38,6 +38,8 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
protected $gravity = 0.08;
|
protected $gravity = 0.08;
|
||||||
protected $drag = 0.02;
|
protected $drag = 0.02;
|
||||||
|
|
||||||
|
protected $attackTime = 0;
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
if(isset($this->namedtag->HealF)){
|
if(isset($this->namedtag->HealF)){
|
||||||
$this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]);
|
$this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]);
|
||||||
@ -64,7 +66,13 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||||
//TODO: attack tick limit
|
if($this->attackTime > 0){
|
||||||
|
$lastCause = $this->getLastDamageCause();
|
||||||
|
if($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$pk = new EntityEventPacket();
|
$pk = new EntityEventPacket();
|
||||||
$pk->eid = $this->getID();
|
$pk->eid = $this->getID();
|
||||||
$pk->event = 2; //Ouch!
|
$pk->event = 2; //Ouch!
|
||||||
@ -82,6 +90,7 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
$this->setMotion($motion);
|
$this->setMotion($motion);
|
||||||
$this->setHealth($this->getHealth() - $damage);
|
$this->setHealth($this->getHealth() - $damage);
|
||||||
|
|
||||||
|
$this->attackTime = 10; //0.5 seconds cooldown
|
||||||
}
|
}
|
||||||
|
|
||||||
public function heal($amount){
|
public function heal($amount){
|
||||||
@ -106,6 +115,11 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
public function entityBaseTick(){
|
public function entityBaseTick(){
|
||||||
Timings::$timerEntityBaseTick->startTiming();
|
Timings::$timerEntityBaseTick->startTiming();
|
||||||
parent::entityBaseTick();
|
parent::entityBaseTick();
|
||||||
|
|
||||||
|
if($this->attackTime > 0){
|
||||||
|
--$this->attackTime;
|
||||||
|
}
|
||||||
|
|
||||||
Timings::$timerEntityBaseTick->stopTiming();
|
Timings::$timerEntityBaseTick->stopTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user