import { Entity, Player, RawMessage } from "@minecraft/server"; /** * Define a boss skill. * @beta */ export class BossSkill { constructor( /** * Id of the boss skill. */ public id: string, /** * Cooldown of the boss skill. */ public cooldownTime: number, /** * The radius within which entity can be effected by the skill. */ public radius: number, /** * The effect of the skill. */ public effect: SkillEffect, /** * Message when the skill unleash. */ public message?: string | RawMessage ) {} /** * Unleash the skill to an entity. * @param entity * @param boss */ unleash(entity: Entity, boss?: Entity) { const EFFECT = this.effect; if (entity instanceof Player) { if (this.message) entity.sendMessage(this.message); if (EFFECT.exp) entity.addExperience(EFFECT.exp); if (EFFECT.level) entity.addLevels(EFFECT.level); } if (EFFECT.damage) entity.applyDamage(EFFECT.damage); if (EFFECT.event) { EFFECT.event(entity, boss); } } /** * Unleash the skill to entities. * @param entity */ /** * Unleash the skill to entities. * @param entity */ unleashArray(entiies: Entity[], boss?: Entity) { for (const [index, entity] of entiies.entries()) { if (index === 0) { this.unleash(entity, boss); } else { this.unleash(entity); } } } } /** * Unleash effect of boss skill. */ export interface SkillEffect { /** * The trigger effect when skill unleash. */ event?: (entity: Entity, boss?: Entity) => void; /** * Add exp when skill unleash. */ exp?: number; /** * Add level when skill unleash. */ level?: number; /** * Apply damage when skill unleash. */ damage?: number; }