From e77b9036480e815c7018b0c59cb41c4d353cb8e9 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Fri, 24 May 2024 20:55:52 -0700 Subject: [PATCH] Class for adding a customized result to BuiltQuest history --- .../server/entity/npc/quest/BuiltQuest.java | 1 + .../entity/npc/quest/QuestHistoryBuilder.java | 35 ++++++++++++++++++- .../entity/npc/quest/QuestHistoryResult.java | 33 +++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/games/stendhal/server/entity/npc/quest/QuestHistoryResult.java diff --git a/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java b/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java index 2eef1a713c6..4b6c2aa4a22 100644 --- a/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java +++ b/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java @@ -86,6 +86,7 @@ public List getHistory(Player player) { res.add(completionsShown); } } + history.applyOtherResults(player, res); return res; } diff --git a/src/games/stendhal/server/entity/npc/quest/QuestHistoryBuilder.java b/src/games/stendhal/server/entity/npc/quest/QuestHistoryBuilder.java index 58e8eda3b8e..03b8df07a61 100644 --- a/src/games/stendhal/server/entity/npc/quest/QuestHistoryBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/QuestHistoryBuilder.java @@ -1,5 +1,5 @@ /*************************************************************************** - * (C) Copyright 2022 - Faiumoni e.V. * + * (C) Copyright 2022-2024 - Faiumoni e.V. * *************************************************************************** *************************************************************************** * * @@ -11,6 +11,12 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; +import java.util.LinkedList; +import java.util.List; + +import games.stendhal.server.entity.player.Player; + + /** * defines the "history" of player progress as shown in the travel log * @@ -25,9 +31,13 @@ public class QuestHistoryBuilder { private String whenQuestCanBeRepeated; private String whenCompletionsShown; + private List otherResults; + + // hide constructor QuestHistoryBuilder() { super(); + otherResults = new LinkedList<>(); } public QuestHistoryBuilder whenNpcWasMet(String whenNpcWasMet) { @@ -72,6 +82,16 @@ public QuestHistoryBuilder whenCompletionsShown(String whenCompletionsShown) { return this; } + /** + * Adds a custom conditional result to history. + * + * @param result + * History result object to be called when history is requested. + */ + public void addResult(final QuestHistoryResult result) { + otherResults.add(result); + } + String getWhenNpcWasMet() { return whenNpcWasMet; } @@ -100,4 +120,17 @@ String getWhenCompletionsShown() { return this.whenCompletionsShown; } + /** + * Calls results objects to update history items list. + * + * @param player + * Player for which history is requested. + * @param res + * History items. + */ + void applyOtherResults(final Player player, List res) { + for (final QuestHistoryResult result: otherResults) { + result.apply(player, res); + } + } } diff --git a/src/games/stendhal/server/entity/npc/quest/QuestHistoryResult.java b/src/games/stendhal/server/entity/npc/quest/QuestHistoryResult.java new file mode 100644 index 00000000000..e3ca29df147 --- /dev/null +++ b/src/games/stendhal/server/entity/npc/quest/QuestHistoryResult.java @@ -0,0 +1,33 @@ +/*************************************************************************** + * 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.server.entity.npc.quest; + +import java.util.List; + +import games.stendhal.server.entity.player.Player; + + +/** + * Class for adding a customized result to BuiltQuest history. + */ +public interface QuestHistoryResult { + + /** + * Called when history is requested. + * + * @param player + * Player for which history is requested. + * @param res + * History items. + */ + abstract void apply(Player player, List res); +}