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