diff --git a/src/js/stendhal/event/generic/KikaPunishmentEvent.ts b/src/js/stendhal/event/generic/KikaPunishmentEvent.ts index 18ba0cf2b11..9655b2014c3 100644 --- a/src/js/stendhal/event/generic/KikaPunishmentEvent.ts +++ b/src/js/stendhal/event/generic/KikaPunishmentEvent.ts @@ -10,7 +10,7 @@ * * ***************************************************************************/ -import { RPEvent } from "../RPEvent"; +import { SubEvent } from "./SubEvent"; import { Paths } from "../../data/Paths"; import { store } from "../../data/SpriteStore"; @@ -31,23 +31,30 @@ import { Color } from "../../util/Color"; * TODO: * - maybe make thunderclap louder * - add some type of beforehand notice, maybe in travel log, about potential punishment + * - move to more generic name such as "LightningStrikeEvent" for use by other events */ -export class KikaPunishmentEvent extends RPEvent { +export class KikaPunishmentEvent extends SubEvent { private startTime = 0; private image = store.get(Paths.maps + "/effect/lightning.png"); + private flash = true; + private lightning = true; - override execute(entity: any) { + override execute(entity: any, flags: string[]) { this.startTime = Date.now(); + this.flash = flags.indexOf("no-flash") < 0; + this.lightning = flags.indexOf("no-lightning") < 0; // thunder sound SoundManager.get().playGlobalizedEffect(SoundID["thunderclap"]!, SoundLayer.SFX.value); - // lightning visual effect - const viewport = ViewPort.get(); - viewport.onDrawComplete = (ctx: CanvasRenderingContext2D, offsetX: number, offsetY: number) => { - this.drawLightning(ctx, offsetX, offsetY); + if (this.flash || this.lightning) { + // lightning visual effect + const viewport = ViewPort.get(); + viewport.onDrawComplete = (ctx: CanvasRenderingContext2D, offsetX: number, offsetY: number) => { + this.drawLightning(ctx, offsetX, offsetY); + } + window.setTimeout(function() { viewport.onDrawComplete = undefined; }, 300); } - window.setTimeout(function() { viewport.onDrawComplete = undefined; }, 300); } /** @@ -62,17 +69,20 @@ export class KikaPunishmentEvent extends RPEvent { */ private drawLightning(ctx: CanvasRenderingContext2D, offsetX: number, offsetY: number) { const timeDiff = Date.now() - this.startTime; - ctx.save(); - if (timeDiff <= 100 || timeDiff > 200) { - ctx.globalAlpha = 0.5; - } else { - ctx.globalAlpha = 0.75; + if (this.flash) { + ctx.save(); + if (timeDiff <= 100 || timeDiff > 200) { + ctx.globalAlpha = 0.5; + } else { + ctx.globalAlpha = 0.75; + } + ctx.fillStyle = Color.WHITE; + ctx.fillRect(offsetX, offsetY, 640, 480); + ctx.restore(); } - ctx.fillStyle = Color.WHITE; - ctx.fillRect(offsetX, offsetY, 640, 480); - ctx.restore(); - if (this.image.height) { + if (this.lightning && this.image.height) { ctx.drawImage(this.image, offsetX, offsetY); } + ctx.restore(); } }