Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kika Clouds Gatekeeper #707

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4b3ce3
Generic event
AntumDeluge May 18, 2024
1d2ea89
Add support for generic events in web client
AntumDeluge May 18, 2024
62684eb
Add support for generic events in Java client
AntumDeluge May 18, 2024
c18d98e
Punishment for visiting Kika clouds too frequently
AntumDeluge Apr 20, 2024
8733167
Add sound effect to balloon when popped
AntumDeluge May 3, 2024
77f25db
Louder thunderclap for kika punishment
AntumDeluge May 10, 2024
e51b84c
Web client effect for Kika punishment
AntumDeluge May 11, 2024
f180638
Requests made to enter clouds within cooldown period do not count as...
AntumDeluge May 18, 2024
7040554
Remove the more punishing aspects of the Kika gatekeeper
AntumDeluge May 18, 2024
fbf7cbb
Change slot from "heaven_gatekeeper" to "kika_gatekeeper"
AntumDeluge May 18, 2024
7b2e257
Increase time between first & second notification
AntumDeluge May 18, 2024
83a4096
Fix import
AntumDeluge May 18, 2024
d685807
Rename KikaPunishmentEvent to ThunderclapEvent
AntumDeluge May 18, 2024
a78bfe3
Remove redundant text in message
AntumDeluge May 18, 2024
acab6bf
Change notification type
AntumDeluge May 18, 2024
66fe39b
Use thunderclap event
AntumDeluge May 18, 2024
d52c695
Don't play global sound for thunderclap event
AntumDeluge May 18, 2024
ee929af
Rename ViewPort.onDrawComplete to ViewPort.onSceneComplete
AntumDeluge May 18, 2024
c573e35
Set SubEvent flags in constructor
AntumDeluge May 18, 2024
9174ecc
Update thunderclap event for changes to SubEvent class
AntumDeluge May 18, 2024
ffe1124
Add wrapper methods to play sounds in Java client
AntumDeluge May 18, 2024
c95774d
Add optional callable to execute instructions after scene...
AntumDeluge May 18, 2024
a3034ad
Add support for thunderclap event to Java client
AntumDeluge May 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildtools/ant_modules/dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<exclude name="logic/layer/"/>
</fileset>
</copy>
<copy todir="${build_client_data}/${maps}/effect">
<fileset dir="${maps}/effect"/>
</copy>
<mkdir dir="${maps}/parallax"/> <!-- in case no parallax images available -->
<copy todir="${build_client_data}/data/maps/parallax">
<fileset dir="${maps}/parallax" includes="**/*.png"/>
Expand Down
Binary file added data/maps/effect/lightning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/sounds/balloon/pop.ogg
Binary file not shown.
Binary file added data/sounds/event/thunderclap.ogg
Binary file not shown.
Binary file added data/sounds/lossless_sources/balloon/pop.flac
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions doc/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Changelog
- new achievements:
- 30 Minutes or Less: Deliver 25 hot pizzas
- Balduin allows requesting different item for Ultimate Collector quest
- Kikareukin's Gatekeeper manages requests to enter the clouds

*web client*
- fixed text extending past edge of notification bubbles
Expand Down
3 changes: 3 additions & 0 deletions doc/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,9 @@ The following people released their work to the public with a suitable license f
* [Bart Kelsey](https://opengameart.org/users/bart)
* [David Kvistorf (fluffclipse)](https://soundcloud.com/david-kvistorf)
* [Aidan Walker](https://opengameart.org/users/aidanwalker)
* [Gniffelbaf](https://freesound.org/people/Gniffelbaf/)
* [Kevin Luce (kevp888)](https://freesound.org/people/kevp888/)
* [Gordon Dylan Johnson (GDJ)](https://openclipart.org/artist/GDJ)
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
14 changes: 14 additions & 0 deletions doc/contributors/contributors.json
Original file line number Diff line number Diff line change
Expand Up @@ -4777,6 +4777,20 @@
{
"name": "Aidan Walker",
"link": "https://opengameart.org/users/aidanwalker"
},
{
"name": "Gniffelbaf",
"link": "https://freesound.org/people/Gniffelbaf/"
},
{
"name": "kevp888",
"fullname": "Kevin Luce",
"link": "https://freesound.org/people/kevp888/"
},
{
"name": "GDJ",
"fullname": "Gordon Dylan Johnson",
"link": "https://openclipart.org/artist/GDJ"
}
]
}
2 changes: 2 additions & 0 deletions doc/sources/audio-sfx.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

data/sounds/

balloon/pop Gniffelbaf; CC0; https://opengameart.org/node/132360, https://freesound.org/s/82119/
event/thunderclap Kevin Luce (kevp888); CC BY 4.0; https://freesound.org/s/639273/
alligator-1.ogg U.S. Fish and Wildlife Service; public domain; https://fws.gov/video/sound.htm
arrow-hit-1.ogg Storyteller; GPL
attack-fire-1.* Nic3_one; CC0; https://freesound.org/people/Nic3_one/sounds/166555/
Expand Down
4 changes: 4 additions & 0 deletions doc/sources/graphics-misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ rotate* rg1024; CC0; https://openclipart.org/detail/20247
settings* ben; CC0; https://openclipart.org/detail/192629
sound* mightyman; CC0; https://openclipart.org/detail/165992

data/maps/effect/

lightning Gordon Dylan Johnson (GDJ); CC0; https://openclipart.org/detail/268835

data/maps/parallax/

stars Jordan Irwin (AntumDeluge); CC0; Stendhal
Expand Down
17 changes: 17 additions & 0 deletions src/games/stendhal/client/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public final class GameScreen extends JComponent implements IGameScreen, DropTar

private AchievementBoxFactory achievementBoxFactory;

/**
* Callback for instructions to execute when scene drawing is complete for a cycle.
*/
public SceneCompleteRunnable onSceneComplete;

/** the singleton instance. */
private static GameScreen screen;

Expand Down Expand Up @@ -591,6 +596,10 @@ public void paintComponent(final Graphics g) {
drawText(g2d);
drawEmojis(g2d);

if (onSceneComplete != null) {
onSceneComplete.run(g2d, 0, 0);
}

paintOffLineIfNeeded(g2d);

// Ask window manager to not skip frame drawing
Expand Down Expand Up @@ -1049,4 +1058,12 @@ private RPObject findSpell(KeyEvent e) {
public boolean canAccept(IEntity entity) {
return (entity instanceof Item) || (entity instanceof Corpse);
}


/**
* Class for executing instructions after scene is complete in a draw cycle.
*/
public static abstract class SceneCompleteRunnable {
public abstract void run(Graphics2D ctx, int offsetX, int offsetY);
}
}
4 changes: 3 additions & 1 deletion src/games/stendhal/client/events/EventFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand Down Expand Up @@ -123,6 +123,8 @@ private static Event<Entity> createEventsForEntity(Entity entity, RPEvent rpeven
event = new EntityMessageEvent();
} else if (name.equals(Events.GLOBAL_VISUAL)) {
event = new GlobalVisualEffectEvent();
} else if (name.equals(Events.GENERIC)) {
event = new GenericEvent();
}

if (event != null) {
Expand Down
57 changes: 57 additions & 0 deletions src/games/stendhal/client/events/GenericEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/***************************************************************************
* Copyright © 2024 - Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package games.stendhal.client.events;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import games.stendhal.client.entity.Entity;
import games.stendhal.client.events.generic.SubEvent;
import games.stendhal.client.events.generic.ThunderclapEvent;


/**
* A generic event that will execute a registered sub-event.
*
* TODO: allow execution without an associated entity
*/
public class GenericEvent extends Event<Entity> {

/** Registered sub-events. */
private static Map<String, Class<? extends SubEvent>> registry = new HashMap<String,
Class<? extends SubEvent>>() {{
put("thunderclap", ThunderclapEvent.class);
}};


@Override
public void execute() {
final String subevent = event.get("subevent");
if (subevent == null || !registry.containsKey(subevent)) {
Logger.getLogger(GenericEvent.class).warn("Unknown generic event: " + subevent);
return;
}
final String[] flags = event.has("flags") ? event.get("flags").split(",") : new String[] {};
try {
final Constructor<? extends SubEvent> constructor = registry.get(subevent)
.getConstructor(String[].class);
constructor.newInstance((Object) flags).execute(entity);
} catch (NoSuchMethodException|SecurityException|InstantiationException|IllegalAccessException
|IllegalArgumentException|InvocationTargetException e) {
Logger.getLogger(GenericEvent.class).error("Failed to create sub-event instance", e);
}
}
}
64 changes: 64 additions & 0 deletions src/games/stendhal/client/events/generic/SubEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/***************************************************************************
* Copyright © 2024 - Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package games.stendhal.client.events.generic;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import games.stendhal.client.entity.Entity;


/**
* Sub-event for generic events.
*/
public abstract class SubEvent {

/** List of enabled flags. */
private final List<String> flags;


/**
* Creates a new event.
*
* @param flags
* List of enabled flags.
*/
public SubEvent(final String[] flags) {
this.flags = Collections.unmodifiableList(Arrays.asList(flags));
}

/**
* Called when the event occurs.
*
* @param entity
* Entity associated with event.
*/
public abstract void execute(Entity entity);

/**
* Checks if a flag has been specified.
*
* @param flag
* Name of flag checking for.
* @return
* {@code true} if {@code flag} found in list of enabled flags.
*/
protected boolean flagEnabled(final String flag) {
for (final String f: flags) {
if (f.equals(flag)) {
return true;
}
}
return false;
}
}
121 changes: 121 additions & 0 deletions src/games/stendhal/client/events/generic/ThunderclapEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/***************************************************************************
* Copyright © 2024 - Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package games.stendhal.client.events.generic;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.util.Timer;
import java.util.TimerTask;

import games.stendhal.client.ClientSingletonRepository;
import games.stendhal.client.GameScreen;
import games.stendhal.client.GameScreen.SceneCompleteRunnable;
import games.stendhal.client.entity.Entity;
import games.stendhal.client.sound.ConfiguredSounds;
import games.stendhal.client.sprite.Sprite;
import games.stendhal.client.sprite.SpriteStore;
import games.stendhal.common.constants.SoundID;
import games.stendhal.common.constants.SoundLayer;


/**
* Creates a thunder and lightning effect.
*/
public class ThunderclapEvent extends SubEvent {

/** Thunder image. */
private static final Sprite image = SpriteStore.get().getSprite("data/maps/effect/lightning.png");

/** Determines if screen should flash white. */
private final boolean flash;
/** Determines if lightning bolt should be drawn. */
private final boolean lightning;
/** Time that event execution began. */
private long startTime;

/** Width of viewport for drawing flash. */
private int width;
/** Height of viewport for drawing flash. */
private int height;


/**
* Creates a new thunderclap event.
*
* @param flags
* List of enabled flags.
*/
public ThunderclapEvent(final String[] flags) {
super(flags);
flash = !flagEnabled("no-flash");
lightning = !flagEnabled("no-lightning");
startTime = 0;

final GameScreen screen = GameScreen.get();
width = screen.getWidth();
height = screen.getHeight();
}

@Override
public void execute(final Entity entity) {
startTime = System.currentTimeMillis();
// thunder sound
ClientSingletonRepository.getSound().playLocalizedEffect(ConfiguredSounds.get(
SoundID.THUNDERCLAP), (int) entity.getX(), (int) entity.getY(), SoundLayer.FIGHTING_NOISE);
if (flash || lightning) {
final GameScreen viewport = GameScreen.get();
viewport.onSceneComplete = new SceneCompleteRunnable() {
@Override
public void run(final Graphics2D ctx, final int offsetX, final int offsetY) {
drawLightning(ctx, offsetX, offsetY);
}
};
new Timer().schedule(new TimerTask() {
@Override
public void run() {
viewport.onSceneComplete = null;
}
}, 300L);
}
}

/**
* Draws a lightning effect on the viewport.
*
* @param ctx
* Viewport drawing canvas.
* @param offsetX
* Canvas horizontal offset.
* @param offsetY
* Canvas vertical offset.
*/
private void drawLightning(final Graphics2D ctx, final int offsetX, final int offsetY) {
final int timeDiff = (int) (System.currentTimeMillis() - startTime);
if (flash) {
final Composite savedComposite = ctx.getComposite();
if (timeDiff <= 100 || timeDiff > 200) {
ctx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
} else {
ctx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f));
}
ctx.setColor(Color.WHITE);
ctx.fillRect(offsetX, offsetY, width, height);
// restore composite info to make lightning opaque
ctx.setComposite(savedComposite);
}
if (lightning) {
image.draw(ctx, offsetX, offsetY);
}
}
}
12 changes: 12 additions & 0 deletions src/games/stendhal/client/events/generic/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/***************************************************************************
* Copyright © 2024 - Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package games.stendhal.client.events.generic;
3 changes: 2 additions & 1 deletion src/games/stendhal/client/sound/ConfiguredSounds.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright © 2020 - Arianne *
* Copyright © 2020-2024 - Arianne *
***************************************************************************
***************************************************************************
* *
Expand All @@ -26,6 +26,7 @@ public class ConfiguredSounds {
put(SoundID.COMMERCE, "coins-01");
put(SoundID.COMMERCE2, "cha-ching");
put(SoundID.HEAL, "heal-01");
put(SoundID.THUNDERCLAP, "event/thunderclap");
}};


Expand Down
Loading
Loading