mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
mobs will attack now, fixed division by 0(i hate php)
This commit is contained in:
parent
616c933d3d
commit
b8589c9dd4
13 changed files with 71 additions and 5 deletions
|
|
@ -66,7 +66,7 @@ class PlayerAPI{
|
||||||
$message = " was killed by " . $e->name;
|
$message = " was killed by " . $e->name;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$message = " was killed";
|
$message = " was killed by {$e->getName()}";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1511,6 +1511,7 @@ class Player{
|
||||||
}else{
|
}else{
|
||||||
$this->entity->setPosition($newPos, $packet->yaw, $packet->pitch);
|
$this->entity->setPosition($newPos, $packet->yaw, $packet->pitch);
|
||||||
}
|
}
|
||||||
|
$this->entity->updateAABB();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
|
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ require_once(FILE_PATH . "/src/astarnavigator/TileNavigator.php");
|
||||||
|
|
||||||
|
|
||||||
require_once(FILE_PATH . "/src/entity/ai/tasks/TaskBase.php");
|
require_once(FILE_PATH . "/src/entity/ai/tasks/TaskBase.php");
|
||||||
|
require_once(FILE_PATH. "/src/entity/ai/tasks/TaskTempt.php");
|
||||||
|
|
||||||
require_once(FILE_PATH . "/src/entity/Rideable.php");
|
require_once(FILE_PATH . "/src/entity/Rideable.php");
|
||||||
require_once(FILE_PATH . "/src/entity/Attachable.php");
|
require_once(FILE_PATH . "/src/entity/Attachable.php");
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,7 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
$this->radius = $this->width / 2;
|
||||||
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
||||||
$this->update();
|
$this->update();
|
||||||
$this->updateLast();
|
$this->updateLast();
|
||||||
|
|
@ -1482,6 +1483,10 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAttackDamage(){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function setSpeed($s)
|
public function setSpeed($s)
|
||||||
{
|
{
|
||||||
$this->speed = $s;
|
$this->speed = $s;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
class Monster extends Creature{
|
class Monster extends Creature{
|
||||||
|
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(){
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class EntityAI
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateTasks(){
|
public function updateTasks(){
|
||||||
|
if(!($this->entity instanceof Entity)) return;
|
||||||
foreach($this->tasks as $t){
|
foreach($this->tasks as $t){
|
||||||
if(!$t->isStarted && $t->canBeExecuted($this)){
|
if(!$t->isStarted && $t->canBeExecuted($this)){
|
||||||
$t->isStarted = true;
|
$t->isStarted = true;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class MobController
|
||||||
|
|
||||||
if($pitch){
|
if($pitch){
|
||||||
$diff = sqrt($x * $x + $z * $z);
|
$diff = sqrt($x * $x + $z * $z);
|
||||||
$calcPitch = rad2deg(atan($y / $diff));
|
$calcPitch = $diff == 0 ? ($y < 0 ? -90 : 90) : rad2deg(atan($y / $diff));
|
||||||
$this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch;
|
$this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
39
src/entity/ai/tasks/TaskAttackPlayer.php
Normal file
39
src/entity/ai/tasks/TaskAttackPlayer.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A Tempt but for Monsters
|
||||||
|
*/
|
||||||
|
class TaskAttackPlayer extends TaskTempt
|
||||||
|
{
|
||||||
|
public $attackTime = 0;
|
||||||
|
public function onStart(EntityAI $ai)
|
||||||
|
{
|
||||||
|
$this->selfCounter = 1;
|
||||||
|
}
|
||||||
|
public function onUpdate(EntityAI $ai)
|
||||||
|
{
|
||||||
|
if(($this->target instanceof Entity && !$this->target->isPlayer()) || $this->target->distanceSquared($ai->entity) > 100 || $this->target->level->getName() != $ai->entity->level->getName()){
|
||||||
|
$this->reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z);
|
||||||
|
$ai->mobController->lookOn($this->target);
|
||||||
|
if($ai->entity->boundingBox->intersectsWith($this->target->boundingBox) && $this->attackTime <= 0){
|
||||||
|
$this->attackTime = 20;
|
||||||
|
$this->target->harm($ai->entity->getAttackDamage(), $ai->entity->eid);
|
||||||
|
}
|
||||||
|
--$this->attackTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
public function canBeExecuted(EntityAI $ai)
|
||||||
|
{
|
||||||
|
$target = $this->findTarget($ai->entity, 10);
|
||||||
|
if($target instanceof Entity && $target->class === ENTITY_PLAYER && $target->isPlayer()){
|
||||||
|
$this->target = $target;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -23,7 +23,6 @@ class TaskTempt extends TaskBase
|
||||||
}
|
}
|
||||||
|
|
||||||
$ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z);
|
$ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z);
|
||||||
|
|
||||||
$ai->mobController->lookOn($this->target);
|
$ai->mobController->lookOn($this->target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ class Creeper extends Monster{
|
||||||
$this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0;
|
$this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAttackDamage(){
|
||||||
|
return 0; //TODO special attack
|
||||||
|
}
|
||||||
|
|
||||||
public function setIgnited($v = null){
|
public function setIgnited($v = null){
|
||||||
$this->setState($v === null ? !$this->getState() : $v);
|
$this->setState($v === null ? !$this->getState() : $v);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@ class PigZombie extends Monster{
|
||||||
$this->setSpeed(0.25);
|
$this->setSpeed(0.25);
|
||||||
$this->update();
|
$this->update();
|
||||||
}
|
}
|
||||||
|
public function getAttackDamage(){
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
public function getDrops(){
|
public function getDrops(){
|
||||||
return [
|
return [
|
||||||
[COOKED_PORKCHOP, 0, mt_rand(0,2)],
|
[COOKED_PORKCHOP, 0, mt_rand(0,2)],
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ class Skeleton extends Monster{
|
||||||
$this->update();
|
$this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAttackDamage(){
|
||||||
|
return 0; //TODO special attack
|
||||||
|
}
|
||||||
|
|
||||||
public function updateBurning(){
|
public function updateBurning(){
|
||||||
if($this->fire > 0 or !$this->level->isDay()){
|
if($this->fire > 0 or !$this->level->isDay()){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ class Zombie extends Monster{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAttackDamage(){
|
||||||
|
return 4; //TODO vanillafy(zombies might be able to hold items)
|
||||||
|
}
|
||||||
|
|
||||||
public function update(){
|
public function update(){
|
||||||
$this->updateBurning();
|
$this->updateBurning();
|
||||||
parent::update();
|
parent::update();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue