mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
armor rewrite
This commit is contained in:
parent
45b36cb034
commit
bae0d4618e
34 changed files with 143 additions and 67 deletions
|
|
@ -28,7 +28,9 @@ abstract class Creature extends Living{
|
|||
public function getSpeedModifer(){
|
||||
return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7);
|
||||
}
|
||||
|
||||
public function getArmorValue(){
|
||||
return 2;
|
||||
}
|
||||
public function spawn($player){
|
||||
if(!($player instanceof Player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class Entity extends Position
|
|||
public $hasKnockback;
|
||||
public $hasJumped;
|
||||
public $onGround, $inWater;
|
||||
|
||||
public $carryoverDamage;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
||||
{
|
||||
$this->random = new Random();
|
||||
|
|
@ -754,7 +754,7 @@ class Entity extends Position
|
|||
}
|
||||
}
|
||||
if($this->knockbackTime > 0){
|
||||
--$this->knockbackTime;
|
||||
--$this->knockbackTime;
|
||||
}
|
||||
|
||||
if($this->moveTime > 0){
|
||||
|
|
@ -1272,6 +1272,7 @@ class Entity extends Position
|
|||
if (! $this->canBeAttacked) {
|
||||
return false;
|
||||
}
|
||||
$dmg = $this->applyArmor($dmg, $cause); //TODO HURTCAM
|
||||
$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) {
|
||||
|
|
@ -1350,7 +1351,7 @@ class Entity extends Position
|
|||
|
||||
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);
|
||||
$oZ = $oZ === 0 ? $this->speedZ : ($this->getSpeedModifer() * $oZ * $this->getSpeed());
|
||||
$this->setVelocity($oX, $oY, $oZ);
|
||||
|
|
@ -1360,7 +1361,29 @@ class Entity extends Position
|
|||
{
|
||||
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)
|
||||
{
|
||||
$health = (int) $health;
|
||||
|
|
@ -1368,42 +1391,6 @@ class Entity extends Position
|
|||
if($health < $this->health){
|
||||
$harm = true;
|
||||
$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){
|
||||
$this->dmgcounter[0] = microtime(true) + 0.5;
|
||||
$this->dmgcounter[1] = $dmg;
|
||||
|
|
@ -1492,7 +1479,7 @@ class Entity extends Position
|
|||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function setSpeed($s)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
|||
$this->ai->updateTasks();
|
||||
}
|
||||
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->pathFollower->followPath();
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class EntityAI
|
|||
}
|
||||
|
||||
public function updateTasks(){
|
||||
if(!($this->entity instanceof Entity)) return;
|
||||
if(!($this->entity instanceof Entity)) return;
|
||||
foreach($this->tasks as $t){
|
||||
if(!$t->isStarted && $t->canBeExecuted($this)){
|
||||
$t->isStarted = true;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class Creeper extends Monster{
|
|||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
return 0; //TODO special attack
|
||||
return 0; //TODO special attack
|
||||
}
|
||||
|
||||
public function setIgnited($v = null){
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class PigZombie extends Monster{
|
|||
$this->update();
|
||||
}
|
||||
public function getAttackDamage(){
|
||||
return 5;
|
||||
return 5;
|
||||
}
|
||||
public function getDrops(){
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Skeleton extends Monster{
|
|||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
return 0; //TODO special attack
|
||||
return 0; //TODO special attack
|
||||
}
|
||||
|
||||
public function updateBurning(){
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ class Zombie extends Monster{
|
|||
$this->update();
|
||||
}
|
||||
|
||||
public function getArmorValue(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or !$this->level->isDay()){
|
||||
return false;
|
||||
|
|
@ -31,7 +35,7 @@ class Zombie extends Monster{
|
|||
}
|
||||
|
||||
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(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue