Effect command

This commit is contained in:
2026-10-02 13:19:12 -03:00
parent f749f6be79
commit cd07d441b2
5 changed files with 38 additions and 0 deletions
+4
View File
@@ -32,6 +32,10 @@ export function effect_type(id: string): EffectType | undefined {
return registry.get(id);
}
export function effect_type_ids(): string[] {
return [...registry.keys()];
}
// what level.json keeps of an effect, the doc's active_effects entries
export interface SavedEffect {
id: string;
+23
View File
@@ -65,6 +65,7 @@ import { EntityManager } from "./entity/entity_manager.ts";
import { NaturalSpawner } from "./natural_spawner.ts";
import { create_entity, entity_type_ids } from "./entity/entity_types.ts";
import { damage_source, type DamageSource, type SavedEntity } from "./entity/entity.ts";
import { effect_type, effect_type_ids, EffectInstance } from "./entity/effects.ts";
import { ATTRIBUTES } from "./entity/attributes.ts";
// how far from a player's eyes a block can be changed, a bit more than the client's reach
@@ -1186,6 +1187,28 @@ export class GameServer {
),
);
// TODO: only let operators do this
const add_effect = (context: CommandContext<ServerCommandSource>, seconds: number) => {
const id = context.get<string>("effect");
const type = effect_type(id);
if (!type) throw new CommandError(`There's no effect ${id}`);
context.source.server_player.add_effect(new EffectInstance(type, seconds * TICKS_PER_SECOND));
context.source.send_message(`Gave ${display_name(id)} for ${seconds} seconds`);
};
register(
literal<ServerCommandSource>("effect").describe("Gives you a status effect").then(
argument<string, ServerCommandSource>("effect", word())
.suggests((partial) =>
effect_type_ids().filter((id) => id.startsWith(partial)).map((text) => ({ text }))
)
.executes((context) => add_effect(context, 30))
.then(
argument<number, ServerCommandSource>("seconds", integer(1, 1_000_000))
.executes((context) => add_effect(context, context.get<number>("seconds"))),
),
),
);
register(
literal<ServerCommandSource>("tps").describe("Shows how the game loop keeps up").executes((context) => {
if (!this.loop) {