From 711208051676c75a50ec22651c4b2fa3b1dcfa16 Mon Sep 17 00:00:00 2001 From: Hendrik Brummermann Date: Wed, 13 Sep 2023 23:27:02 +0200 Subject: [PATCH] implemented DeliverItemQuestHistoryBuilder an infrastructure --- .../core/scripting/lua/LuaQuestHelper.java | 4 +- .../npc/quest/BringItemQuestBuilder.java | 3 +- .../server/entity/npc/quest/BuiltQuest.java | 12 +- .../npc/quest/DeliverItemQuestBuilder.java | 3 +- .../quest/DeliverItemQuestHistoryBuilder.java | 107 ++++++++++++++++++ .../entity/npc/quest/DeliverItemTask.java | 52 +++++---- .../npc/quest/KillCreaturesQuestBuilder.java | 3 +- .../server/entity/npc/quest/QuestBuilder.java | 7 +- .../entity/npc/quest/QuestManuscript.java | 2 +- .../entity/npc/quest/QuestTaskBuilder.java | 4 +- .../server/maps/quests/PizzaDelivery.java | 9 +- 11 files changed, 165 insertions(+), 41 deletions(-) create mode 100644 src/games/stendhal/server/entity/npc/quest/DeliverItemQuestHistoryBuilder.java diff --git a/src/games/stendhal/server/core/scripting/lua/LuaQuestHelper.java b/src/games/stendhal/server/core/scripting/lua/LuaQuestHelper.java index cf129b5eb93..40aed9b5439 100644 --- a/src/games/stendhal/server/core/scripting/lua/LuaQuestHelper.java +++ b/src/games/stendhal/server/core/scripting/lua/LuaQuestHelper.java @@ -124,7 +124,7 @@ public LuaQuest create(final String slotName, final String name, final String de * @return * New quest. */ - public IQuest createManuscript(final QuestBuilder builder) { + public IQuest createManuscript(final QuestBuilder builder) { return new BuiltQuest(builder); } @@ -136,7 +136,7 @@ public IQuest createManuscript(final QuestBuilder builder) { * @return * New QuestBuilder. */ - public QuestBuilder createBuilder(final String task) { + public QuestBuilder createBuilder(final String task) { if ("BringItemTask".equals(task)) { return new BringItemQuestBuilder(); } else if ("KillCreaturesTask".equals(task)) { diff --git a/src/games/stendhal/server/entity/npc/quest/BringItemQuestBuilder.java b/src/games/stendhal/server/entity/npc/quest/BringItemQuestBuilder.java index 28c5e1637b0..2c2dcc97b2b 100644 --- a/src/games/stendhal/server/entity/npc/quest/BringItemQuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/BringItemQuestBuilder.java @@ -11,11 +11,12 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; -public class BringItemQuestBuilder extends QuestBuilder { +public class BringItemQuestBuilder extends QuestBuilder { public BringItemQuestBuilder() { super(new BringItemTask()); complete = new SimpleQuestCompleteBuilder(); + history = new QuestHistoryBuilder(); } } diff --git a/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java b/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java index 3bf20766fd2..b010a0df354 100644 --- a/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java +++ b/src/games/stendhal/server/entity/npc/quest/BuiltQuest.java @@ -29,7 +29,7 @@ * @author hendrik */ public class BuiltQuest extends AbstractQuest { - private QuestBuilder questBuilder; + private QuestBuilder questBuilder; private String questSlot = null; /** @@ -37,7 +37,7 @@ public class BuiltQuest extends AbstractQuest { * * @param questBuilder quest builder */ - public BuiltQuest(QuestBuilder questBuilder) { + public BuiltQuest(QuestBuilder questBuilder) { this.questBuilder = questBuilder; this.questSlot = questBuilder.info().getInternalName().toLowerCase(); } @@ -57,12 +57,14 @@ public List getHistory(Player player) { return res; } res.add(history.getWhenQuestWasAccepted()); - List progress = questBuilder.task().calculateHistoryProgress(player); + List progress = questBuilder.task().calculateHistoryProgress(history, player); if (progress != null) { res.addAll(progress); } if ("done".equals(questState) || ("start".equals(questState) && questBuilder.task().isCompleted(player, questSlot))) { - res.add(history.getWhenTaskWasCompleted()); + if (history.getWhenTaskWasCompleted() != null) { + res.add(history.getWhenTaskWasCompleted()); + } } if ("done".equals(questState)) { res.add(history.getWhenQuestWasCompleted()); @@ -139,7 +141,7 @@ public String getSlotName() { @Override public boolean isRepeatable(final Player player) { return isCompleted(player) - && questBuilder.info().getRepeatableAfterMinutes() > 0 + && questBuilder.info().getRepeatableAfterMinutes() > -1 && new TimePassedCondition(questSlot, 1, questBuilder.info().getRepeatableAfterMinutes()).fire(player,null, null); } } diff --git a/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java index f5abafde689..e80e398252b 100644 --- a/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java @@ -11,11 +11,12 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; -public class DeliverItemQuestBuilder extends QuestBuilder { +public class DeliverItemQuestBuilder extends QuestBuilder { public DeliverItemQuestBuilder() { super(new DeliverItemTask()); complete = new DeliverItemQuestCompleteBuilder(task()); + history = new DeliverItemQuestHistoryBuilder(); } } diff --git a/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestHistoryBuilder.java b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestHistoryBuilder.java new file mode 100644 index 00000000000..a54308f254e --- /dev/null +++ b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestHistoryBuilder.java @@ -0,0 +1,107 @@ +/*************************************************************************** + * (C) Copyright 2022-2023 - 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; + +/** + * defines the "history" of player progress as shown in the travel log + * + * @author hendrik + */ +public class DeliverItemQuestHistoryBuilder extends QuestHistoryBuilder { + + private String whenItemWasGiven; + private String whenToldAboutCustomer; + private String whenInTime; + private String whenOutOfTime; + + + @Override + public DeliverItemQuestHistoryBuilder whenNpcWasMet(String whenNpcWasMet) { + super.whenNpcWasMet(whenNpcWasMet); + return this; + } + + @Override + public DeliverItemQuestHistoryBuilder whenQuestWasRejected(String whenQuestWasRejected) { + super.whenQuestWasRejected(whenQuestWasRejected); + return this; + } + + @Override + public DeliverItemQuestHistoryBuilder whenQuestWasAccepted(String whenQuestWasAccepted) { + super.whenQuestWasAccepted(whenQuestWasAccepted); + return this; + } + + @Override + public DeliverItemQuestHistoryBuilder whenTaskWasCompleted(String whenTaskWasCompleted) { + super.whenTaskWasCompleted(whenTaskWasCompleted); + return this; + } + + @Override + public DeliverItemQuestHistoryBuilder whenQuestWasCompleted(String whenQuestWasCompleted) { + super.whenQuestWasCompleted(whenQuestWasCompleted); + return this; + } + + @Override + public DeliverItemQuestHistoryBuilder whenQuestCanBeRepeated(String whenQuestCanBeRepeated) { + super.whenQuestCanBeRepeated(whenQuestCanBeRepeated); + return this; + } + + @Override + public DeliverItemQuestHistoryBuilder whenCompletionsShown(String whenCompletionsShown) { + super.whenCompletionsShown(whenCompletionsShown); + return this; + } + + + public DeliverItemQuestHistoryBuilder whenItemWasGiven(String whenItemWasGiven) { + this.whenItemWasGiven = whenItemWasGiven; + return this; + } + + public DeliverItemQuestHistoryBuilder whenToldAboutCustomer(String whenToldAboutCustomer) { + this.whenToldAboutCustomer = whenToldAboutCustomer; + return this; + } + + public DeliverItemQuestHistoryBuilder whenInTime(String whenInTime) { + this.whenInTime = whenInTime; + return this; + } + + public DeliverItemQuestHistoryBuilder whenOutOfTime(String whenOutOfTime) { + this.whenOutOfTime = whenOutOfTime; + return this; + } + + + public String getWhenItemWasGiven() { + return whenItemWasGiven; + } + + public String getWhenToldAboutCustomer() { + return whenToldAboutCustomer; + } + + public String getWhenInTime() { + return whenInTime; + } + + public String getWhenOutOfTime() { + return whenOutOfTime; + } + +} diff --git a/src/games/stendhal/server/entity/npc/quest/DeliverItemTask.java b/src/games/stendhal/server/entity/npc/quest/DeliverItemTask.java index ad92177427e..79752dab242 100644 --- a/src/games/stendhal/server/entity/npc/quest/DeliverItemTask.java +++ b/src/games/stendhal/server/entity/npc/quest/DeliverItemTask.java @@ -29,9 +29,10 @@ import games.stendhal.server.entity.npc.NPCList; import games.stendhal.server.entity.npc.SpeakerNPC; import games.stendhal.server.entity.npc.action.SetQuestToTimeStampAction; +import games.stendhal.server.entity.npc.condition.AlwaysFalseCondition; import games.stendhal.server.entity.npc.condition.OutfitCompatibleWithClothesCondition; -import games.stendhal.server.entity.npc.condition.QuestCompletedCondition; import games.stendhal.server.entity.player.Player; +import games.stendhal.server.util.StringUtils; public class DeliverItemTask extends QuestTaskBuilder { @@ -41,27 +42,6 @@ public class DeliverItemTask extends QuestTaskBuilder { private Map orders = new HashMap<>(); - /* - @Override - public List getHistory(final Player player) { - final String questState = player.getQuest(QUEST_SLOT); - res.add("I met Leander and agreed to help with pizza delivery."); - if (!"done".equals(questState)) { - final String[] questData = questState.split(";"); - final String customerName = questData[0]; - final CustomerData customerData = customerDB.get(customerName); - res.add("Leander gave me a " + customerData.flavor + " for " + customerName + "."); - res.add("Leander told me: \"" + customerData.npcDescription + "\""); - if (!isDeliveryTooLate(player)) { - res.add("If I hurry I might still get there with the pizza hot."); - } else { - res.add("The pizza has already gone cold."); - } - } - return res; - } -*/ - /** * Get a list of customers appropriate for a player @@ -214,12 +194,11 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser @Override ChatCondition buildQuestCompletedCondition(String questSlot) { - return new QuestCompletedCondition(questSlot); + return new AlwaysFalseCondition(); } @Override ChatAction buildQuestCompleteAction(String questSlot) { - // TODO Auto-generated method stub return null; } @@ -234,4 +213,29 @@ Map getOrders() { String getItemName() { return "pizza"; } + + @Override + public List calculateHistoryProgress(QuestHistoryBuilder historyBuilder, Player player) { + DeliverItemQuestHistoryBuilder history = (DeliverItemQuestHistoryBuilder) historyBuilder; + List res = new LinkedList<>(); + final String questState = player.getQuest(QUEST_SLOT, 0); + if (!"done".equals(questState)) { + final String[] questData = questState.split(";"); + final String customerName = questData[0]; + final DeliverItemOrder customerData = orders.get(customerName); + Map params = new HashMap<>(); + params.put("flavor", customerData.getFlavor()); + params.put("customerName", customerName); + params.put("customerDescription", customerData.getNpcDescription()); + res.add(StringUtils.substitute(history.getWhenItemWasGiven(), params)); + res.add(StringUtils.substitute(history.getWhenToldAboutCustomer(), params)); + if (!isDeliveryTooLate(player)) { + res.add(StringUtils.substitute(history.getWhenInTime(), params)); + } else { + res.add(StringUtils.substitute(history.getWhenOutOfTime(), params)); + } + } + return res; + } + } diff --git a/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java b/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java index 4d13ca1c359..5f1fa21114d 100644 --- a/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java @@ -11,11 +11,12 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; -public class KillCreaturesQuestBuilder extends QuestBuilder { +public class KillCreaturesQuestBuilder extends QuestBuilder { public KillCreaturesQuestBuilder() { super(new KillCreaturesTask()); complete = new SimpleQuestCompleteBuilder(); + history = new QuestHistoryBuilder(); } } diff --git a/src/games/stendhal/server/entity/npc/quest/QuestBuilder.java b/src/games/stendhal/server/entity/npc/quest/QuestBuilder.java index 2a9503ac897..5cee8e86cc6 100644 --- a/src/games/stendhal/server/entity/npc/quest/QuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/QuestBuilder.java @@ -17,13 +17,14 @@ * @author hendrik * @param QuestTaskBuilder */ -public class QuestBuilder { +public class QuestBuilder { private QuestInfoBuilder info = new QuestInfoBuilder(); - private QuestHistoryBuilder history = new QuestHistoryBuilder(); + @SuppressWarnings("unchecked") private QuestOfferBuilder offer = new QuestOfferBuilder(); private T task = null; protected C complete; + protected H history = null; /** * creates a QuestBuilder @@ -48,7 +49,7 @@ public QuestInfoBuilder info() { * * @return QuestHistoryBuilder */ - public QuestHistoryBuilder history() { + public H history() { return history; } diff --git a/src/games/stendhal/server/entity/npc/quest/QuestManuscript.java b/src/games/stendhal/server/entity/npc/quest/QuestManuscript.java index 4ef85dbe117..7f3e531eff2 100644 --- a/src/games/stendhal/server/entity/npc/quest/QuestManuscript.java +++ b/src/games/stendhal/server/entity/npc/quest/QuestManuscript.java @@ -23,5 +23,5 @@ public interface QuestManuscript { * * @return QuestBuilder */ - public QuestBuilder story(); + public QuestBuilder story(); } diff --git a/src/games/stendhal/server/entity/npc/quest/QuestTaskBuilder.java b/src/games/stendhal/server/entity/npc/quest/QuestTaskBuilder.java index 0659c019243..cab264df765 100644 --- a/src/games/stendhal/server/entity/npc/quest/QuestTaskBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/QuestTaskBuilder.java @@ -45,7 +45,9 @@ boolean isCompleted(Player player, String questSlot) { return buildQuestCompletedCondition(questSlot).fire(player, null, null); } - public List calculateHistoryProgress(@SuppressWarnings("unused") Player player) { + public List calculateHistoryProgress( + @SuppressWarnings("unused") QuestHistoryBuilder history, + @SuppressWarnings("unused") Player player) { return null; } diff --git a/src/games/stendhal/server/maps/quests/PizzaDelivery.java b/src/games/stendhal/server/maps/quests/PizzaDelivery.java index df1b565ecb2..33d77852a46 100644 --- a/src/games/stendhal/server/maps/quests/PizzaDelivery.java +++ b/src/games/stendhal/server/maps/quests/PizzaDelivery.java @@ -68,7 +68,13 @@ public DeliverItemQuestBuilder story() { .whenNpcWasMet("I met Leander, the baker of Semos.") .whenQuestWasRejected("He asked me to deliver pizza but I rejected his request.") .whenQuestWasAccepted("I agreed to help with pizza delivery") - .whenQuestWasCompleted("I delivered the last pizza Leander gave to me."); + .whenItemWasGiven("Leander gave me a [flavor] for [customerName].") + .whenToldAboutCustomer("Leander told me: \"[customerDescription]\"") + .whenInTime("If I hurry, I might still get there, with the pizza hot.") + .whenOutOfTime("The pizza has already gone cold.") + .whenQuestWasCompleted("I delivered the last pizza Leander gave to me.") + .whenQuestCanBeRepeated("But I'd bet, Leander has more orders."); +; quest.offer() .respondToRequest("I need you to quickly deliver a hot pizza. If you're fast enough, you might get quite a nice tip. So, will you do it?") @@ -79,7 +85,6 @@ public DeliverItemQuestBuilder story() { .remind(null); - // Don't add Sally here, as it would conflict with Leander telling // about his daughter. quest.task().order()