From 8a8842c1ec32703051a6b3ed0ac13109e6e75a13 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 15 Apr 2024 22:32:26 -0700 Subject: [PATCH] Add methods to get requested number of items from BringItemTask --- .../entity/npc/quest/BringItemTask.java | 21 ++++++++++++++++++- .../server/entity/npc/quest/BuiltQuest.java | 9 ++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/games/stendhal/server/entity/npc/quest/BringItemTask.java b/src/games/stendhal/server/entity/npc/quest/BringItemTask.java index 70b63b8561e..7890222a445 100644 --- a/src/games/stendhal/server/entity/npc/quest/BringItemTask.java +++ b/src/games/stendhal/server/entity/npc/quest/BringItemTask.java @@ -1,5 +1,5 @@ /*************************************************************************** - * (C) Copyright 2022 - Faiumoni e.V. * + * (C) Copyright 2022-2024 - Faiumoni e.V. * *************************************************************************** *************************************************************************** * * @@ -59,6 +59,25 @@ public BringItemTask alternativeItem(int quantity, String name) { return this; } + public int getRequestedAmount(final String itemName) { + if (requestItem != null && requestItem.first().equals(itemName)) { + return requestItem.second(); + } + for (final Pair pair: alternativeItems) { + if (pair.first().equals(itemName)) { + return pair.second(); + } + } + return 1; + } + + public int getRequestedAmount() { + if (requestItem != null) { + return requestItem.second(); + } + return 1; + } + @Override void simulate(QuestSimulator simulator) { simulator.info("Player obtained " + requestItem.second() + " " + requestItem.first() + "."); diff --git a/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java b/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java index 221d6770b9b..0297f227929 100644 --- a/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java +++ b/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java @@ -62,8 +62,13 @@ public List getHistory(Player player) { res.addAll(progress); } if ("done".equals(questState) || questBuilder.task().isCompleted(player, questSlot)) { - if (history.getWhenTaskWasCompleted() != null) { - res.add(history.getWhenTaskWasCompleted()); + final String whenTaskWasCompleted = history.getWhenTaskWasCompleted(); + if (whenTaskWasCompleted != null) { + if (questBuilder.task() instanceof BringItemTask) { + res.add(whenTaskWasCompleted.replace("[itthem]", Grammar.itthem(((BringItemTask) questBuilder.task()).getRequestedAmount()))); + } else { + res.add(whenTaskWasCompleted); + } } } if ("done".equals(questState)) {