Giant chesplate
This commit is contained in:
@@ -104,6 +104,12 @@ export abstract class LivingEntity extends Entity {
|
||||
this.#health = Math.min(this.max_health, Math.max(0, value));
|
||||
}
|
||||
|
||||
// health from a save. it can be over max_health until the next tick, so max_health modifiers given back while
|
||||
// loading, like worn curios', keep it
|
||||
load_health(value: number) {
|
||||
this.#health = Math.max(0, value);
|
||||
}
|
||||
|
||||
get dead() {
|
||||
return this.#health <= 0;
|
||||
}
|
||||
@@ -439,6 +445,8 @@ export abstract class LivingEntity extends Entity {
|
||||
}
|
||||
|
||||
tick_effects() {
|
||||
// like minecraft, losing max health, like a max_health modifier going away, takes the health over it
|
||||
if (this.#health > this.max_health) this.#health = this.max_health;
|
||||
for (const effect of [...this.effects.values()]) {
|
||||
if (this.effects.get(effect.type.id) !== effect) continue;
|
||||
const result = effect.tick(this);
|
||||
|
||||
@@ -1372,6 +1372,7 @@ export class GameServer {
|
||||
}
|
||||
player.vitals.tick(
|
||||
player.health,
|
||||
player.max_health,
|
||||
(amount) => this.heal_player(player, amount),
|
||||
(amount) => this.damage_player(player, amount, "starve"),
|
||||
);
|
||||
@@ -1533,9 +1534,15 @@ export class GameServer {
|
||||
sync("extra", items, () => ({ type: "container", container: "extra", items }));
|
||||
}
|
||||
|
||||
// like minecraft, losing max health, like a curio's modifier going away, takes the health over it
|
||||
if (player.health > player.max_health) player.health = player.max_health;
|
||||
const { food, saturation } = player.vitals;
|
||||
const health = player.health;
|
||||
sync("vitals", [health, food, saturation], () => ({ type: "vitals", health, food, saturation }));
|
||||
const { health, max_health } = player;
|
||||
sync(
|
||||
"vitals",
|
||||
[health, max_health, food, saturation],
|
||||
() => ({ type: "vitals", health, max_health, food, saturation }),
|
||||
);
|
||||
const attack_speed = player.attribute(ATTRIBUTES.attack_speed);
|
||||
sync("attack_speed", attack_speed, () => ({ type: "attack_speed", value: attack_speed }));
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import { AIR_ID } from "$/common/protocol.ts";
|
||||
import type { GameServer } from "./game_server.ts";
|
||||
import type { ServerPlayer } from "./player.ts";
|
||||
import { Menu, type MenuSlot } from "./menu.ts";
|
||||
import { MAX_HEALTH } from "./vitals.ts";
|
||||
import type { Entity } from "./entity/entity.ts";
|
||||
import { create_entity } from "./entity/entity_types.ts";
|
||||
import { attribute_type, type AttributeType, MODIFIER_OPERATIONS } from "./entity/attributes.ts";
|
||||
@@ -938,7 +937,9 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
get health() {
|
||||
return player.health;
|
||||
},
|
||||
max_health: MAX_HEALTH,
|
||||
get max_health() {
|
||||
return player.max_health;
|
||||
},
|
||||
get food() {
|
||||
return player.vitals.food;
|
||||
},
|
||||
|
||||
@@ -213,7 +213,7 @@ export class ServerPlayer extends LivingEntity {
|
||||
this.selected_slot = saved.selected_slot;
|
||||
this.inventory.load(saved.inventory);
|
||||
this.vitals.load(saved.vitals);
|
||||
this.health = saved.vitals?.health ?? this.max_health;
|
||||
this.load_health(saved.vitals?.health ?? this.max_health);
|
||||
this.skin = saved.skin;
|
||||
this.slim = saved.slim ?? false;
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ export class Vitals {
|
||||
return this.food < MAX_FOOD;
|
||||
}
|
||||
|
||||
// one tick, for someone with that much health. heal and hurt go through the game server, which fires events and
|
||||
// handles dying
|
||||
tick(health: number, heal: (amount: number) => void, hurt: (amount: number) => void) {
|
||||
// one tick, for someone with that much health out of max_health. heal and hurt go through the game server, which
|
||||
// fires events and handles dying
|
||||
tick(health: number, max_health: number, heal: (amount: number) => void, hurt: (amount: number) => void) {
|
||||
if (this.exhaustion > EXHAUSTION_PER_POINT) {
|
||||
this.exhaustion -= EXHAUSTION_PER_POINT;
|
||||
if (this.saturation > 0) {
|
||||
@@ -68,7 +68,7 @@ export class Vitals {
|
||||
}
|
||||
}
|
||||
|
||||
const hurt_some = health < MAX_HEALTH;
|
||||
const hurt_some = health < max_health;
|
||||
if (this.saturation > 0 && hurt_some && this.food >= MAX_FOOD) {
|
||||
if (++this.#timer >= FAST_REGEN_TICKS) {
|
||||
const amount = Math.min(this.saturation, 6);
|
||||
|
||||
Reference in New Issue
Block a user