From de18fd08e2f7cc7a671d457567c01c174b2bb8d5 Mon Sep 17 00:00:00 2001 From: Hendrik Brummermann Date: Fri, 15 Sep 2023 21:59:08 +0200 Subject: [PATCH] Created subclasses of QuestOfferBuilder --- .../core/scripting/lua/LuaQuestHelper.java | 4 +- .../npc/quest/BringItemQuestBuilder.java | 3 +- .../server/entity/npc/quest/BuiltQuest.java | 4 +- .../npc/quest/DeliverItemQuestBuilder.java | 3 +- .../quest/DeliverItemQuestOfferBuilder.java | 5 ++ .../npc/quest/KillCreaturesQuestBuilder.java | 3 +- .../server/entity/npc/quest/QuestBuilder.java | 6 +-- .../entity/npc/quest/QuestManuscript.java | 2 +- .../entity/npc/quest/QuestOfferBuilder.java | 52 +++++++++++-------- .../npc/quest/SimpleQuestOfferBuilder.java | 5 ++ 10 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 src/games/stendhal/server/entity/npc/quest/DeliverItemQuestOfferBuilder.java create mode 100644 src/games/stendhal/server/entity/npc/quest/SimpleQuestOfferBuilder.java diff --git a/src/games/stendhal/server/core/scripting/lua/LuaQuestHelper.java b/src/games/stendhal/server/core/scripting/lua/LuaQuestHelper.java index 40aed9b5439..a6e95ca3d92 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 2c2dcc97b2b..73d48f88a48 100644 --- a/src/games/stendhal/server/entity/npc/quest/BringItemQuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/BringItemQuestBuilder.java @@ -11,10 +11,11 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; -public class BringItemQuestBuilder extends QuestBuilder { +public class BringItemQuestBuilder extends QuestBuilder { public BringItemQuestBuilder() { super(new BringItemTask()); + offer = new SimpleQuestOfferBuilder(); 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 b010a0df354..6f56bb98205 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(); } diff --git a/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java index e80e398252b..50ba00d9349 100644 --- a/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestBuilder.java @@ -11,10 +11,11 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; -public class DeliverItemQuestBuilder extends QuestBuilder { +public class DeliverItemQuestBuilder extends QuestBuilder { public DeliverItemQuestBuilder() { super(new DeliverItemTask()); + offer = new DeliverItemQuestOfferBuilder(); complete = new DeliverItemQuestCompleteBuilder(task()); history = new DeliverItemQuestHistoryBuilder(); } diff --git a/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestOfferBuilder.java b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestOfferBuilder.java new file mode 100644 index 00000000000..d9472d9d80e --- /dev/null +++ b/src/games/stendhal/server/entity/npc/quest/DeliverItemQuestOfferBuilder.java @@ -0,0 +1,5 @@ +package games.stendhal.server.entity.npc.quest; + +public class DeliverItemQuestOfferBuilder extends QuestOfferBuilder { + +} diff --git a/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java b/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java index 5f1fa21114d..b7b8b31e2bc 100644 --- a/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/KillCreaturesQuestBuilder.java @@ -11,10 +11,11 @@ ***************************************************************************/ package games.stendhal.server.entity.npc.quest; -public class KillCreaturesQuestBuilder extends QuestBuilder { +public class KillCreaturesQuestBuilder extends QuestBuilder { public KillCreaturesQuestBuilder() { super(new KillCreaturesTask()); + offer = new SimpleQuestOfferBuilder(); 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 5cee8e86cc6..c63c6cb9c47 100644 --- a/src/games/stendhal/server/entity/npc/quest/QuestBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/QuestBuilder.java @@ -17,11 +17,11 @@ * @author hendrik * @param QuestTaskBuilder */ -public class QuestBuilder { +public class QuestBuilder, C extends QuestCompleteBuilder, H extends QuestHistoryBuilder> { private QuestInfoBuilder info = new QuestInfoBuilder(); @SuppressWarnings("unchecked") - private QuestOfferBuilder offer = new QuestOfferBuilder(); + protected O offer; private T task = null; protected C complete; protected H history = null; @@ -58,7 +58,7 @@ public H history() { * * @return QuestOfferBuilder */ - public QuestOfferBuilder offer() { + public O offer() { return offer; } diff --git a/src/games/stendhal/server/entity/npc/quest/QuestManuscript.java b/src/games/stendhal/server/entity/npc/quest/QuestManuscript.java index 7f3e531eff2..d9b8a4c1fe4 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/QuestOfferBuilder.java b/src/games/stendhal/server/entity/npc/quest/QuestOfferBuilder.java index 883125c4445..7263b156482 100644 --- a/src/games/stendhal/server/entity/npc/quest/QuestOfferBuilder.java +++ b/src/games/stendhal/server/entity/npc/quest/QuestOfferBuilder.java @@ -37,7 +37,7 @@ * * @author hendrik */ -public class QuestOfferBuilder { +public class QuestOfferBuilder> { private String respondToFailedPreCondition = "I am sorry, I don't have a task for your right now."; private String respondToRequest = null; private String respondToUnrepeatableRequest = "Thanks for your help. I have no new task for you."; @@ -49,57 +49,67 @@ public class QuestOfferBuilder { private List lastRespondTo = null; private Map, String> additionalReplies = new HashMap<>(); - public QuestOfferBuilder respondToFailedPreCondition(String respondToFailedPreCondition) { + @SuppressWarnings("unchecked") + public T respondToFailedPreCondition(String respondToFailedPreCondition) { this.respondToFailedPreCondition = respondToFailedPreCondition; - return this; + return (T) this; } - public QuestOfferBuilder respondToRequest(String respondToRequest) { + @SuppressWarnings("unchecked") + public T respondToRequest(String respondToRequest) { this.respondToRequest = respondToRequest; if (this.respondToRepeatedRequest == null) { this.respondToRepeatedRequest = respondToRequest; } - return this; + return (T) this; } - public QuestOfferBuilder respondToUnrepeatableRequest(String respondToUnrepeatableRequest) { + @SuppressWarnings("unchecked") + public T respondToUnrepeatableRequest(String respondToUnrepeatableRequest) { this.respondToUnrepeatableRequest = respondToUnrepeatableRequest; - return this; + return (T) this; } - public QuestOfferBuilder respondToRepeatedRequest(String respondToRepeatedRequest) { + @SuppressWarnings("unchecked") + public T respondToRepeatedRequest(String respondToRepeatedRequest) { this.respondToRepeatedRequest = respondToRepeatedRequest; - return this; + return (T) this; } - public QuestOfferBuilder respondToAccept(String respondToAccept) { + @SuppressWarnings("unchecked") + public T respondToAccept(String respondToAccept) { this.respondToAccept = respondToAccept; - return this; + return (T) this; } - public QuestOfferBuilder respondToReject(String respondToReject) { + @SuppressWarnings("unchecked") + public T respondToReject(String respondToReject) { this.respondToReject = respondToReject; - return this; + return (T) this; } - public QuestOfferBuilder respondTo(String... respondTo) { + @SuppressWarnings("unchecked") + public T respondTo(String... respondTo) { this.lastRespondTo = Arrays.asList(respondTo); - return this; + return (T) this; } - public QuestOfferBuilder saying(String reply) { + @SuppressWarnings("unchecked") + public T saying(String reply) { additionalReplies.put(lastRespondTo, reply); - return this; + return (T) this; } - public QuestOfferBuilder remind(String remind) { + @SuppressWarnings("unchecked") + public T remind(String remind) { this.remind = remind; - return this; + return (T) this; } - public QuestOfferBuilder rejectionKarmaPenalty(double rejectionKarmaPenalty) { + @SuppressWarnings("unchecked") + public T rejectionKarmaPenalty(double rejectionKarmaPenalty) { this.rejectionKarmaPenalty = rejectionKarmaPenalty; - return this; + return (T) this; } void simulateFirst(String npc, QuestSimulator simulator) { diff --git a/src/games/stendhal/server/entity/npc/quest/SimpleQuestOfferBuilder.java b/src/games/stendhal/server/entity/npc/quest/SimpleQuestOfferBuilder.java new file mode 100644 index 00000000000..22bb56e25a6 --- /dev/null +++ b/src/games/stendhal/server/entity/npc/quest/SimpleQuestOfferBuilder.java @@ -0,0 +1,5 @@ +package games.stendhal.server.entity.npc.quest; + +public class SimpleQuestOfferBuilder extends QuestOfferBuilder { + +}