armor rewrite

This commit is contained in:
GameHerobrine 2023-01-23 17:39:57 +03:00
parent 45b36cb034
commit bae0d4618e
34 changed files with 143 additions and 67 deletions

View file

@ -1,9 +1,9 @@
<?php <?php
class TileNavigator implements ITileNavigator class TileNavigator implements ITileNavigator
{ {
private $blockedProvider, $neighborProvider, $distanceAlgorithm; private $blockedProvider, $neighborProvider, $distanceAlgorithm;
public static $pathfinderAccessed = 0; public static $pathfinderAccessed = 0;
public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm){ public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm){
$this->blockedProvider = $blockedProvider; $this->blockedProvider = $blockedProvider;

View file

@ -7,7 +7,7 @@ class Pythagoras3D implements IDistanceAlgorithm
public function calculate(PathTile $from, PathTile $to) public function calculate(PathTile $from, PathTile $to)
{ {
if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){ if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
return Utils::distance_noroot($from->asArray(), $to->asArray()); return Utils::distance_noroot($from->asArray(), $to->asArray());
} }
return INF; return INF;
} }

View file

@ -13,12 +13,12 @@ class MCDiagonalProvider implements INeighborProvider
foreach(MCDiagonalProvider::$neighbors as $offset){ foreach(MCDiagonalProvider::$neighbors as $offset){
$pnt = $tile->addOffset($offset); $pnt = $tile->addOffset($offset);
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y, $pnt->z, false)->isSolid){ if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y, $pnt->z, false)->isSolid){
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y - 1, $pnt->z, false)->isSolid){ if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y - 1, $pnt->z, false)->isSolid){
--$pnt->y; --$pnt->y;
} }
$pnts[] = $pnt; $pnts[] = $pnt;
}else{ }else{
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y + 1, $pnt->z, false)->isSolid){ if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y + 1, $pnt->z, false)->isSolid){
++$pnt->y; ++$pnt->y;
$pnts[] = $pnt; $pnts[] = $pnt;
} }

View file

@ -28,7 +28,9 @@ abstract class Creature extends Living{
public function getSpeedModifer(){ public function getSpeedModifer(){
return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7); return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7);
} }
public function getArmorValue(){
return 2;
}
public function spawn($player){ public function spawn($player){
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$player = $this->server->api->player->get($player); $player = $this->server->api->player->get($player);

View file

@ -73,7 +73,7 @@ class Entity extends Position
public $hasKnockback; public $hasKnockback;
public $hasJumped; public $hasJumped;
public $onGround, $inWater; public $onGround, $inWater;
public $carryoverDamage;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()) function __construct(Level $level, $eid, $class, $type = 0, $data = array())
{ {
$this->random = new Random(); $this->random = new Random();
@ -754,7 +754,7 @@ class Entity extends Position
} }
} }
if($this->knockbackTime > 0){ if($this->knockbackTime > 0){
--$this->knockbackTime; --$this->knockbackTime;
} }
if($this->moveTime > 0){ if($this->moveTime > 0){
@ -1272,6 +1272,7 @@ class Entity extends Position
if (! $this->canBeAttacked) { if (! $this->canBeAttacked) {
return false; return false;
} }
$dmg = $this->applyArmor($dmg, $cause); //TODO HURTCAM
$ret = $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force); $ret = $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force);
if ($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false) { if ($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false) {
@ -1350,7 +1351,7 @@ class Entity extends Position
public function moveEntityWithOffset($oX, $oY, $oZ) public function moveEntityWithOffset($oX, $oY, $oZ)
{ {
$oX = $oX === 0 ? $this->speedX : ($this->getSpeedModifer() * $oX * $this->getSpeed()); $oX = $oX === 0 ? $this->speedX : ($this->getSpeedModifer() * $oX * $this->getSpeed());
$oY = $oY <= 0 ? $this->speedY : (0.5); $oY = $oY <= 0 ? $this->speedY : (0.5);
$oZ = $oZ === 0 ? $this->speedZ : ($this->getSpeedModifer() * $oZ * $this->getSpeed()); $oZ = $oZ === 0 ? $this->speedZ : ($this->getSpeedModifer() * $oZ * $this->getSpeed());
$this->setVelocity($oX, $oY, $oZ); $this->setVelocity($oX, $oY, $oZ);
@ -1360,6 +1361,28 @@ class Entity extends Position
{ {
return $this->speedModifer; return $this->speedModifer;
} }
public function getArmorValue(){
$pnts = 0;
if($this->isPlayer()){
foreach($this->player->armor as $slot => $part){
if($part instanceof ArmorItem){
$pnts += $part->getDamageReduceAmount();
$this->player->damageArmorPart($slot, $part);
}
}
$this->player->sendArmor($this->player);
}
return $pnts;
}
public function applyArmor($damage, $cause){
if(is_numeric($cause)){
$var3 = 25 - $this->getArmorValue();
$var4 = $damage * $var3 + $this->carryoverDamage;
$damage = $var4 / 25;
$this->carryoverDamage = $var4 % 25;
}
return $damage;
}
public function setHealth($health, $cause = "generic", $force = false) public function setHealth($health, $cause = "generic", $force = false)
{ {
@ -1368,42 +1391,6 @@ class Entity extends Position
if($health < $this->health){ if($health < $this->health){
$harm = true; $harm = true;
$dmg = $this->health - $health; $dmg = $this->health - $health;
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player)){
$points = 0;
$values = array(
LEATHER_CAP => 1,
LEATHER_TUNIC => 3,
LEATHER_PANTS => 2,
LEATHER_BOOTS => 1,
CHAIN_HELMET => 1,
CHAIN_CHESTPLATE => 5,
CHAIN_LEGGINGS => 4,
CHAIN_BOOTS => 1,
GOLDEN_HELMET => 1,
GOLDEN_CHESTPLATE => 5,
GOLDEN_LEGGINGS => 3,
GOLDEN_BOOTS => 1,
IRON_HELMET => 2,
IRON_CHESTPLATE => 6,
IRON_LEGGINGS => 5,
IRON_BOOTS => 2,
DIAMOND_HELMET => 3,
DIAMOND_CHESTPLATE => 8,
DIAMOND_LEGGINGS => 6,
DIAMOND_BOOTS => 3
);
foreach($this->player->armor as $slot => $part){
if($part instanceof Item and isset($values[$part->getID()])){
if(is_numeric($cause)){ // check was entity damage by another entity
$points += $values[$part->getID()];
$this->player->damageArmorPart($slot, $part);
}
}
}
$this->player->sendArmor($this->player);
$dmg = (int) ($dmg - ($dmg * $points * 0.04));
$health = $this->health - $dmg;
}
if(($this->class !== ENTITY_PLAYER or (($this->player instanceof Player) and (($this->player->gamemode & 0x01) === 0x00 or $force === true))) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and ! $this->dead){ if(($this->class !== ENTITY_PLAYER or (($this->player instanceof Player) and (($this->player->gamemode & 0x01) === 0x00 or $force === true))) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and ! $this->dead){
$this->dmgcounter[0] = microtime(true) + 0.5; $this->dmgcounter[0] = microtime(true) + 0.5;
$this->dmgcounter[1] = $dmg; $this->dmgcounter[1] = $dmg;
@ -1492,7 +1479,7 @@ class Entity extends Position
} }
public function getAttackDamage(){ public function getAttackDamage(){
return 0; return 0;
} }
public function setSpeed($s) public function setSpeed($s)

View file

@ -34,7 +34,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
$this->ai->updateTasks(); $this->ai->updateTasks();
} }
if($this->onGround){ if($this->onGround){
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ //if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10); // $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
//} //}
$this->pathFollower->followPath(); $this->pathFollower->followPath();

View file

@ -47,7 +47,7 @@ class EntityAI
} }
public function updateTasks(){ public function updateTasks(){
if(!($this->entity instanceof Entity)) return; 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;

View file

@ -15,7 +15,7 @@ class Creeper extends Monster{
} }
public function getAttackDamage(){ public function getAttackDamage(){
return 0; //TODO special attack return 0; //TODO special attack
} }
public function setIgnited($v = null){ public function setIgnited($v = null){

View file

@ -10,7 +10,7 @@ class PigZombie extends Monster{
$this->update(); $this->update();
} }
public function getAttackDamage(){ public function getAttackDamage(){
return 5; return 5;
} }
public function getDrops(){ public function getDrops(){
return [ return [

View file

@ -11,7 +11,7 @@ class Skeleton extends Monster{
} }
public function getAttackDamage(){ public function getAttackDamage(){
return 0; //TODO special attack return 0; //TODO special attack
} }
public function updateBurning(){ public function updateBurning(){

View file

@ -10,6 +10,10 @@ class Zombie extends Monster{
$this->update(); $this->update();
} }
public function getArmorValue(){
return 2;
}
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;
@ -31,7 +35,7 @@ class Zombie extends Monster{
} }
public function getAttackDamage(){ public function getAttackDamage(){
return 4; //TODO vanillafy(zombies might be able to hold items) return 4; //TODO vanillafy(zombies might be able to hold items)
} }
public function update(){ public function update(){

View file

@ -10,6 +10,8 @@ abstract class ArmorItem extends Item{ //abstract to avoid making instances of i
public abstract function getBaseDurability(); public abstract function getBaseDurability();
public abstract function getDamageReduceAmount();
public function getMaxDurability(){ public function getMaxDurability(){
return $this->getMaterialDurability() * $this->getBaseDurability(); return $this->getMaterialDurability() * $this->getBaseDurability();
} }

View file

@ -13,5 +13,10 @@ class ChainBootsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 13; return 13;
} }
public function getDamageReduceAmount()
{
return 1;
}
} }

View file

@ -13,4 +13,8 @@ class ChainChestplateItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 16; return 16;
} }
public function getDamageReduceAmount()
{
return 5;
}
} }

View file

@ -13,4 +13,8 @@ class ChainHelmetItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 11; return 11;
} }
public function getDamageReduceAmount()
{
return 1;
}
} }

View file

@ -13,4 +13,8 @@ class ChainLeggingsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 15; return 15;
} }
public function getDamageReduceAmount()
{
return 4;
}
} }

View file

@ -13,4 +13,8 @@ class DiamondBootsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 13; return 13;
} }
public function getDamageReduceAmount()
{
return 3;
}
} }

View file

@ -13,4 +13,8 @@ class DiamondChestplateItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 16; return 16;
} }
public function getDamageReduceAmount()
{
return 8;
}
} }

View file

@ -13,4 +13,8 @@ class DiamondHelmetItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 11; return 11;
} }
public function getDamageReduceAmount()
{
return 3;
}
} }

View file

@ -13,4 +13,8 @@ class DiamondLeggingsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 15; return 15;
} }
public function getDamageReduceAmount()
{
return 6;
}
} }

View file

@ -13,4 +13,8 @@ class GoldenBootsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 13; return 13;
} }
public function getDamageReduceAmount()
{
return 1;
}
} }

View file

@ -13,4 +13,8 @@ class GoldenChestplateItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 16; return 16;
} }
public function getDamageReduceAmount()
{
return 5;
}
} }

View file

@ -13,4 +13,8 @@ class GoldenHelmetItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 11; return 11;
} }
public function getDamageReduceAmount()
{
return 1;
}
} }

View file

@ -13,4 +13,8 @@ class GoldenLeggingsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 15; return 15;
} }
public function getDamageReduceAmount()
{
return 3;
}
} }

View file

@ -13,4 +13,8 @@ class IronBootsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 13; return 13;
} }
public function getDamageReduceAmount()
{
return 2;
}
} }

View file

@ -13,4 +13,8 @@ class IronChestplateItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 16; return 16;
} }
public function getDamageReduceAmount()
{
return 6;
}
} }

View file

@ -13,4 +13,8 @@ class IronHelmetItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 11; return 11;
} }
public function getDamageReduceAmount()
{
return 2;
}
} }

View file

@ -13,4 +13,8 @@ class IronLeggingsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 15; return 15;
} }
public function getDamageReduceAmount()
{
return 5;
}
} }

View file

@ -13,4 +13,8 @@ class LeatherBootsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 13; return 13;
} }
public function getDamageReduceAmount()
{
return 1;
}
} }

View file

@ -13,4 +13,8 @@ class LeatherCapItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 11; return 11;
} }
public function getDamageReduceAmount()
{
return 1;
}
} }

View file

@ -13,4 +13,8 @@ class LeatherPantsItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 15; return 15;
} }
public function getDamageReduceAmount()
{
return 2;
}
} }

View file

@ -13,4 +13,8 @@ class LeatherTunicItem extends ArmorItem{
public function getBaseDurability(){ public function getBaseDurability(){
return 16; return 16;
} }
public function getDamageReduceAmount()
{
return 3;
}
} }

View file

@ -575,16 +575,16 @@ class Utils{
* Euclidian distance, but without square roots * Euclidian distance, but without square roots
*/ */
public static function distance_noroot($pos1, $pos2){ public static function distance_noroot($pos1, $pos2){
if($pos1 instanceof Vector3){ if($pos1 instanceof Vector3){
$pos1 = $pos1->toArray(); $pos1 = $pos1->toArray();
} }
if($pos2 instanceof Vector3){ if($pos2 instanceof Vector3){
$pos2 = $pos2->toArray(); $pos2 = $pos2->toArray();
} }
$pX = ($pos1["x"] - $pos2["x"]); $pX = ($pos1["x"] - $pos2["x"]);
$pY = ($pos1["y"] - $pos2["y"]); $pY = ($pos1["y"] - $pos2["y"]);
$pZ = ($pos1["z"] - $pos2["z"]); $pZ = ($pos1["z"] - $pos2["z"]);
return ($pX*$pX) + ($pY*$pY) + ($pZ*$pZ); return ($pX*$pX) + ($pY*$pY) + ($pZ*$pZ);
} }
/** /**

View file

@ -32,10 +32,10 @@ class Explosion{
$server = ServerAPI::request(); $server = ServerAPI::request();
if(!Explosion::$enableExplosions){ /*Disable Explosions*/ if(!Explosion::$enableExplosions){ /*Disable Explosions*/
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){ foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //pla> $impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //pla>
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
$entity->harm($damage, "explosion"); $entity->harm($damage, "explosion");
} }
return; return;
} }
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [ if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [