mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
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:
parent
2cd42fb605
commit
81aa575749
7 changed files with 84 additions and 30 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue