Skip to content

Commit

Permalink
Add methods to get requested number of items from BringItemTask
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 29, 2024
1 parent 51bdae4 commit 8a8842c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/games/stendhal/server/entity/npc/quest/BringItemTask.java
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 Down Expand Up @@ -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<String, Integer> 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() + ".");
Expand Down
9 changes: 7 additions & 2 deletions src/games/stendhal/server/entity/npc/quest/BuiltQuest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public List<String> 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)) {
Expand Down

0 comments on commit 8a8842c

Please sign in to comment.