Player::teleport will set motion to 0, fixed possible divby0 when skeletonm shooting the player, fixed entities not untargetting dead players, fixed wrong distance calculations

This commit is contained in:
GameHerobrine 2024-07-12 17:50:06 +03:00
parent 2cd42fb605
commit 81aa575749
7 changed files with 84 additions and 30 deletions

View file

@ -1,8 +1,10 @@
<?php
class Monster extends Creature{
public $closestPlayerToAttackEID = false;
public $closestPlayerToAttackDist = INF;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
//$this->ai->addTask(new TaskAttackPlayer());
}
public function getAttackDamage(){
@ -20,4 +22,34 @@ class Monster extends Creature{
return false;
}
}
public function isPlayerValid(Player $player){
return $player->spawned && !$player->entity->dead;
}
public function handlePrePlayerSearcher(){
parent::handlePrePlayerSearcher();
if($this->closestPlayerToAttackEID !== false){
$player = $this->level->entityList[$this->closestPlayerToAttackEID] ?? false;
if($player === false || !$this->isPlayerValid($player->player)){
$this->closestPlayerToAttackEID = false;
$this->closestPlayerToAttackDist = INF;
}else{
$dist = ($this->x - $player->x)*($this->x - $player->x) + ($this->y - $player->y)*($this->y - $player->y) + ($this->z - $player->z)*($this->z - $player->z);
$this->closestPlayerToAttackDist = $dist;
}
}
}
public function handlePlayerSearcher(Player $player, $dist){
parent::handlePlayerSearcher($player, $dist);
if($this->closestPlayerToAttackDist >= $dist){
if($this->isPlayerValid($player)){
$this->closestPlayerToAttackDist = $dist;
$this->closestPlayerToAttackEID = $player->entity->eid;
}
}
}
}