Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 14, 2024
1 parent fb08acc commit 1e3f51e
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/js/stendhal/event/generic/KikaPunishmentEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* *
***************************************************************************/

import { RPEvent } from "../RPEvent";
import { SubEvent } from "./SubEvent";

import { Paths } from "../../data/Paths";
import { store } from "../../data/SpriteStore";
Expand All @@ -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);
}

/**
Expand All @@ -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();
}
}

0 comments on commit 1e3f51e

Please sign in to comment.