Physical and arcane damage
This commit is contained in:
@@ -33,7 +33,6 @@ const SLOW_FALL_GRAVITY = 0.01;
|
||||
|
||||
export interface SavedLivingEntity extends SavedEntity {
|
||||
health?: number;
|
||||
absorption_amount?: number;
|
||||
active_effects?: SavedEffect[];
|
||||
attributes?: unknown;
|
||||
death_time?: number;
|
||||
@@ -51,7 +50,6 @@ export abstract class LivingEntity extends Entity {
|
||||
|
||||
attributes = new AttributeMap(this.default_attributes());
|
||||
#health = this.max_health;
|
||||
#absorption = 0;
|
||||
effects = new Map<string, EffectInstance>();
|
||||
equipment = new Map<EquipmentSlot, ItemStack>();
|
||||
|
||||
@@ -80,9 +78,6 @@ export abstract class LivingEntity extends Entity {
|
||||
default_attributes(): [AttributeType, number?][] {
|
||||
return [
|
||||
[ATTRIBUTES.max_health],
|
||||
[ATTRIBUTES.max_absorption],
|
||||
[ATTRIBUTES.armor],
|
||||
[ATTRIBUTES.armor_toughness],
|
||||
[ATTRIBUTES.knockback_resistance],
|
||||
[ATTRIBUTES.movement_speed],
|
||||
[ATTRIBUTES.jump_strength],
|
||||
@@ -109,15 +104,6 @@ export abstract class LivingEntity extends Entity {
|
||||
this.#health = Math.min(this.max_health, Math.max(0, value));
|
||||
}
|
||||
|
||||
// extra health from the absorption effect, used up before health
|
||||
get absorption() {
|
||||
return this.#absorption;
|
||||
}
|
||||
|
||||
set absorption(value: number) {
|
||||
this.#absorption = Math.min(this.attribute(ATTRIBUTES.max_absorption), Math.max(0, value));
|
||||
}
|
||||
|
||||
get dead() {
|
||||
return this.#health <= 0;
|
||||
}
|
||||
@@ -326,22 +312,23 @@ export abstract class LivingEntity extends Entity {
|
||||
return true;
|
||||
}
|
||||
|
||||
// after armor, resistance and absorption
|
||||
// after resistance
|
||||
actually_hurt(amount: number, source: DamageSource) {
|
||||
if (!source.bypasses_armor) {
|
||||
amount = damage_after_armor(
|
||||
amount,
|
||||
this.attribute(ATTRIBUTES.armor),
|
||||
this.attribute(ATTRIBUTES.armor_toughness),
|
||||
);
|
||||
// absolute damage, take it and theres no counterplay
|
||||
if (source.type === "absolute") {
|
||||
this.health -= amount;
|
||||
return;
|
||||
}
|
||||
|
||||
const resistance = this.get_effect(EFFECTS.resistance);
|
||||
if (resistance && !source.bypasses_invulnerability) {
|
||||
amount = Math.max(0, amount * (25 - (resistance.amplifier + 1) * 5) / 25);
|
||||
}
|
||||
const absorbed = Math.min(amount, this.absorption);
|
||||
this.absorption -= absorbed;
|
||||
this.health -= amount - absorbed;
|
||||
const shielding = this.attribute(
|
||||
source.type === "physical" ? ATTRIBUTES.physical_shielding : ATTRIBUTES.arcane_shielding,
|
||||
);
|
||||
const post_mitigation = amount * (100 / (100 + shielding));
|
||||
this.health -= post_mitigation;
|
||||
}
|
||||
|
||||
// it was just hurt, for kinds that react
|
||||
@@ -464,7 +451,6 @@ export abstract class LivingEntity extends Entity {
|
||||
effect.type.on_removed?.(this, effect.amplifier);
|
||||
// back inside what the attributes allow now
|
||||
this.health = this.#health;
|
||||
this.absorption = this.#absorption;
|
||||
}
|
||||
|
||||
// equipment
|
||||
@@ -503,7 +489,6 @@ export abstract class LivingEntity extends Entity {
|
||||
override save_additional(saved: SavedLivingEntity) {
|
||||
super.save_additional(saved);
|
||||
saved.health = this.#health;
|
||||
if (this.#absorption) saved.absorption_amount = this.#absorption;
|
||||
if (this.effects.size) saved.active_effects = [...this.effects.values()].map((effect) => effect.save());
|
||||
const attributes = this.attributes.save(new AttributeMap(this.default_attributes()));
|
||||
if (attributes.length) saved.attributes = attributes;
|
||||
@@ -534,7 +519,6 @@ export abstract class LivingEntity extends Entity {
|
||||
this.#apply_modifiers(effect);
|
||||
}
|
||||
this.health = finite(saved.health, this.max_health);
|
||||
this.absorption = finite(saved.absorption_amount, 0);
|
||||
this.death_time = finite(saved.death_time, 0);
|
||||
this.hurt_time = finite(saved.hurt_time, 0);
|
||||
this.last_hurt_by_mob = typeof saved.last_hurt_by_mob === "string" ? saved.last_hurt_by_mob : undefined;
|
||||
@@ -550,9 +534,3 @@ export abstract class LivingEntity extends Entity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// minecraft's CombatRules.getDamageAfterAbsorb
|
||||
export function damage_after_armor(damage: number, armor: number, toughness: number) {
|
||||
const reduction = Math.min(20, Math.max(armor * 0.2, armor - damage / (2 + toughness / 4)));
|
||||
return damage * (1 - reduction / 25);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user