mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
arrows will attack entities
This commit is contained in:
parent
d8e242d0b5
commit
1fa7697503
7 changed files with 61 additions and 20 deletions
|
|
@ -61,13 +61,15 @@ class PlayerAPI{
|
|||
if(is_numeric($data["cause"])){
|
||||
$e = $this->server->api->entity->get($data["cause"]);
|
||||
if($e instanceof Entity){
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
$message = " was killed by " . $e->name;
|
||||
break;
|
||||
default:
|
||||
$message = " was killed by {$e->getName()}";
|
||||
break;
|
||||
if($e instanceof Arrow){
|
||||
if($e->shotByEntity && isset($this->server->api->entity->entities[$e->shooterEID]) && $this->server->api->entity->entities[$e->shooterEID] instanceof Entity){
|
||||
$message = " was shot by {$this->server->api->entity->entities[$e->shooterEID]->name}";
|
||||
}else{
|
||||
$message = " was shot";
|
||||
}
|
||||
|
||||
}else{
|
||||
$message = "was killed by {$e->name}";
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
|
@ -106,7 +108,6 @@ class PlayerAPI{
|
|||
}
|
||||
$this->server->api->chat->broadcast($data["player"]->username . $message);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1729,7 +1729,8 @@ class Player{
|
|||
$e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
||||
$e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
||||
$e->speedY = -sin(($e->pitch / 180) * M_PI);
|
||||
|
||||
$e->shooterEID = $this->entity->eid;
|
||||
$e->shotByEntity = true;
|
||||
/**
|
||||
* Max usage: 72000ticks
|
||||
* initalPower = 72000 - (72000 - usedCtr)
|
||||
|
|
@ -1747,8 +1748,8 @@ class Player{
|
|||
//CANCEL but i am too lazy
|
||||
$power = 0.1;
|
||||
}
|
||||
//console("Arrow sent! power: $power");
|
||||
$e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); //TODO bow power
|
||||
$e->critical = ($power === 1);
|
||||
$e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0);
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -777,6 +777,10 @@ class Entity extends Position
|
|||
}
|
||||
}
|
||||
|
||||
public function canBeShot(){
|
||||
return $this->isPlayer();
|
||||
}
|
||||
|
||||
public function updateFallState($fallTick){
|
||||
if($this->onGround && $this->fallDistance > 0){
|
||||
$this->fall();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
|||
unset($this->pathFollower->entity);
|
||||
unset($this->ai->entity);
|
||||
}
|
||||
|
||||
public function canBeShot(){
|
||||
return true;
|
||||
}
|
||||
public function collideHandler(){
|
||||
$this->level->applyCallbackToNearbyEntities($this, [$this, "applyCollision"], 2); //TODO radiuses
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,20 @@
|
|||
|
||||
class Arrow extends Projectile{
|
||||
const TYPE = OBJECT_ARROW;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
|
||||
public $criticial = false;
|
||||
public $shooterEID = 0;
|
||||
public $shotByEntity;
|
||||
public $airTicks = 0;
|
||||
public $groundTicks = 0;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = [], $shooter = false){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->gravity = 0.05;
|
||||
$this->setSize(0.5, 0.5);
|
||||
$this->setName("Arrow");
|
||||
$this->shooterEID = $shooter;
|
||||
$this->shotByEntity = $shooter instanceof Entity;
|
||||
$this->airTicks = $this->groundTicks = 0;
|
||||
//$this->server->schedule(1210, array($this, "update")); //Despawn
|
||||
}
|
||||
|
||||
|
|
@ -50,13 +61,17 @@ class Arrow extends Projectile{
|
|||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
|
||||
foreach($this->level->players as $p){ //sending packets directly makes movement less laggy
|
||||
$p->directDataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
public function update(){
|
||||
//parent::update();
|
||||
if($this->closed) {
|
||||
$this->close();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->needsUpdate = true;
|
||||
|
||||
if($this->speedX != 0 or $this->speedY != 0 or $this->speedZ != 0){
|
||||
|
|
@ -67,14 +82,30 @@ class Arrow extends Projectile{
|
|||
$this->x += $this->speedX;
|
||||
$this->y += $this->speedY;
|
||||
$this->z += $this->speedZ;
|
||||
/**oh no, entity collision**/
|
||||
++$this->airTicks; //TODO onGround state
|
||||
|
||||
$this->speedX *= 0.99;
|
||||
$this->speedY *= 0.99;
|
||||
$this->speedZ *= 0.99;
|
||||
$this->speedY -= $this->gravity;
|
||||
|
||||
$bbexp = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ)->expand(0, 0.2, 0);
|
||||
$this->sendMotion();
|
||||
$this->updatePosition();
|
||||
|
||||
foreach($this->level->entityList as $e){
|
||||
if($e instanceof Entity && $e->eid !== $this->eid && !$e->closed && $e->canBeShot() && $e->boundingBox->intersectsWith($bbexp)){
|
||||
if($this->shotByEntity && $this->shooterEID === $e->eid && $this->airTicks < 5) continue;
|
||||
$dmg = ceil(sqrt($this->speedX * $this->speedX + $this->speedY * $this->speedY + $this->speedZ * $this->speedZ) * 2);
|
||||
if($this->criticial){
|
||||
$dmg += mt_rand(0, (int)($dmg/2+1));
|
||||
}
|
||||
$e->harm($dmg, $this->eid);
|
||||
$this->closed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Level{
|
|||
*/
|
||||
public $entityList;
|
||||
|
||||
public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner;
|
||||
public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner, $totalMobsAmount = 0;
|
||||
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
|
||||
|
||||
public static $randomUpdateBlocks = [
|
||||
|
|
@ -325,11 +325,17 @@ class Level{
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->totalMobsAmount = 0;
|
||||
foreach($this->entityList as $k => $e){
|
||||
if(!($e instanceof Entity)){
|
||||
unset($this->entityList[$k]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if($e->type === ENTITY_MOB && !$e->isPlayer()){
|
||||
++$this->totalMobsAmount;
|
||||
}
|
||||
|
||||
if($e->needsUpdate){
|
||||
$e->update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,7 @@ class MobSpawner{
|
|||
}
|
||||
|
||||
public function countEntities(){
|
||||
$ents = 0;
|
||||
foreach($this->level->entityList as $e){
|
||||
if(!$e->isPlayer() && $e->class === ENTITY_MOB) ++$ents;
|
||||
}
|
||||
return $ents;
|
||||
return $this->level->totalMobsAmount;
|
||||
}
|
||||
|
||||
public function handle(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue