Giant chestplate regeneration passive
This commit is contained in:
@@ -1336,7 +1336,9 @@ export class GameServer {
|
||||
if (before.cancel || !(final > 0)) {
|
||||
return false;
|
||||
}
|
||||
return player.apply_hurt(final, source);
|
||||
if (!player.apply_hurt(final, source)) return false;
|
||||
this.mods.after.player_damage.emit({ player: before.player, amount: final, cause: source.cause });
|
||||
return true;
|
||||
}
|
||||
|
||||
heal_player(player: ServerPlayer, amount: number) {
|
||||
|
||||
@@ -48,6 +48,7 @@ import { Menu, type MenuSlot } from "./menu.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";
|
||||
import { effect_type, EffectInstance, type EffectType } from "./entity/effects.ts";
|
||||
|
||||
// a list of handlers that can't break each other: one throwing is logged under its mod and the rest still run
|
||||
export class Signal<T> {
|
||||
@@ -126,6 +127,7 @@ export class ModRuntime {
|
||||
chat_send: new Signal(),
|
||||
player_join: new Signal(),
|
||||
player_leave: new Signal(),
|
||||
player_damage: new Signal(),
|
||||
player_death: new Signal(),
|
||||
server_start: new Signal(),
|
||||
tick: new Signal(),
|
||||
@@ -932,7 +934,7 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
game.send_chat(player, String(text));
|
||||
},
|
||||
set_worn(key, items) {
|
||||
if (typeof key !== "string" || key.length === 0) throw new Error("set_worn needs a key, like \"mymod:hats\"");
|
||||
if (typeof key !== "string" || key.length === 0) throw new Error('set_worn needs a key, like "mymod:hats"');
|
||||
if (!Array.isArray(items)) throw new Error("set_worn needs a list of items, [] for none");
|
||||
if (items.length === 0) player.worn.delete(key);
|
||||
else player.worn.set(key, items.map(new_stack));
|
||||
@@ -984,9 +986,31 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
},
|
||||
remove_modifier: (attribute, id) =>
|
||||
player.attributes.get(known_attribute(attribute))?.remove_modifier(id) ?? false,
|
||||
add_effect(id, duration, options = {}) {
|
||||
const type = known_effect(id);
|
||||
if (!Number.isInteger(duration) || (duration < 1 && duration !== -1)) {
|
||||
throw new Error("an effect's duration is a whole number of ticks, or -1 for forever");
|
||||
}
|
||||
const amplifier = options.amplifier ?? 0;
|
||||
if (!Number.isInteger(amplifier) || amplifier < 0) {
|
||||
throw new Error("amplifier must be a whole number of 0 or more");
|
||||
}
|
||||
player.add_effect(new EffectInstance(type, duration, { ...options, amplifier }));
|
||||
},
|
||||
effect(id) {
|
||||
const effect = player.get_effect(known_effect(id));
|
||||
return effect && { amplifier: effect.amplifier, duration: effect.duration };
|
||||
},
|
||||
remove_effect: (id) => player.remove_effect(known_effect(id)),
|
||||
};
|
||||
}
|
||||
|
||||
function known_effect(id: string): EffectType {
|
||||
const type = effect_type(id);
|
||||
if (!type) throw new Error(`unknown effect ${id}`);
|
||||
return type;
|
||||
}
|
||||
|
||||
function known_attribute(id: string): AttributeType {
|
||||
const type = attribute_type(id);
|
||||
if (!type) throw new Error(`unknown attribute ${id}`);
|
||||
|
||||
Reference in New Issue
Block a user