Skip to content

Commit

Permalink
Class for adding a customized result to BuiltQuest history
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 25, 2024
1 parent c4fe94d commit e77b903
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/games/stendhal/server/entity/npc/quest/BuiltQuest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public List<String> getHistory(Player player) {
res.add(completionsShown);
}
}
history.applyOtherResults(player, res);
return res;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* (C) Copyright 2022 - Faiumoni e.V. *
* (C) Copyright 2022-2024 - Faiumoni e.V. *
***************************************************************************
***************************************************************************
* *
Expand All @@ -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
*
Expand All @@ -25,9 +31,13 @@ public class QuestHistoryBuilder {
private String whenQuestCanBeRepeated;
private String whenCompletionsShown;

private List<QuestHistoryResult> otherResults;


// hide constructor
QuestHistoryBuilder() {
super();
otherResults = new LinkedList<>();
}

public QuestHistoryBuilder whenNpcWasMet(String whenNpcWasMet) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<String> res) {
for (final QuestHistoryResult result: otherResults) {
result.apply(player, res);
}
}
}
33 changes: 33 additions & 0 deletions src/games/stendhal/server/entity/npc/quest/QuestHistoryResult.java
Original file line number Diff line number Diff line change
@@ -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<String> res);
}

0 comments on commit e77b903

Please sign in to comment.