mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +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(){
|
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);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
@ -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) {
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,10 @@ class ChainBootsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 13;
|
return 13;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class ChainChestplateItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class ChainHelmetItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class ChainLeggingsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class DiamondBootsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 13;
|
return 13;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class DiamondChestplateItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class DiamondHelmetItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class DiamondLeggingsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class GoldenBootsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 13;
|
return 13;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class GoldenChestplateItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class GoldenHelmetItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class GoldenLeggingsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class IronBootsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 13;
|
return 13;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class IronChestplateItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class IronHelmetItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class IronLeggingsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class LeatherBootsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 13;
|
return 13;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class LeatherCapItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class LeatherPantsItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,4 +13,8 @@ class LeatherTunicItem extends ArmorItem{
|
||||||
public function getBaseDurability(){
|
public function getBaseDurability(){
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
public function getDamageReduceAmount()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue