Skip to content

Commit

Permalink
Created subclasses of QuestOfferBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
nhnb committed Sep 15, 2023
1 parent 30248c3 commit de18fd0
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
***************************************************************************/
package games.stendhal.server.entity.npc.quest;

public class BringItemQuestBuilder extends QuestBuilder<BringItemTask, SimpleQuestCompleteBuilder, QuestHistoryBuilder> {
public class BringItemQuestBuilder extends QuestBuilder<BringItemTask, SimpleQuestOfferBuilder, SimpleQuestCompleteBuilder, QuestHistoryBuilder> {

public BringItemQuestBuilder() {
super(new BringItemTask());
offer = new SimpleQuestOfferBuilder();
complete = new SimpleQuestCompleteBuilder();
history = new QuestHistoryBuilder();
}
Expand Down
4 changes: 2 additions & 2 deletions src/games/stendhal/server/entity/npc/quest/BuiltQuest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
* @author hendrik
*/
public class BuiltQuest extends AbstractQuest {
private QuestBuilder<?, ?, ?> questBuilder;
private QuestBuilder<?, ?, ?, ?> questBuilder;
private String questSlot = null;

/**
* creates a Quest based on a builder
*
* @param questBuilder quest builder
*/
public BuiltQuest(QuestBuilder<?, ?, ?> questBuilder) {
public BuiltQuest(QuestBuilder<?, ?, ?, ?> questBuilder) {
this.questBuilder = questBuilder;
this.questSlot = questBuilder.info().getInternalName().toLowerCase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
***************************************************************************/
package games.stendhal.server.entity.npc.quest;

public class DeliverItemQuestBuilder extends QuestBuilder<DeliverItemTask, DeliverItemQuestCompleteBuilder, DeliverItemQuestHistoryBuilder> {
public class DeliverItemQuestBuilder extends QuestBuilder<DeliverItemTask, DeliverItemQuestOfferBuilder, DeliverItemQuestCompleteBuilder, DeliverItemQuestHistoryBuilder> {

public DeliverItemQuestBuilder() {
super(new DeliverItemTask());
offer = new DeliverItemQuestOfferBuilder();
complete = new DeliverItemQuestCompleteBuilder(task());
history = new DeliverItemQuestHistoryBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package games.stendhal.server.entity.npc.quest;

public class DeliverItemQuestOfferBuilder extends QuestOfferBuilder<DeliverItemQuestOfferBuilder> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
***************************************************************************/
package games.stendhal.server.entity.npc.quest;

public class KillCreaturesQuestBuilder extends QuestBuilder<KillCreaturesTask, SimpleQuestCompleteBuilder, QuestHistoryBuilder> {
public class KillCreaturesQuestBuilder extends QuestBuilder<KillCreaturesTask, SimpleQuestOfferBuilder, SimpleQuestCompleteBuilder, QuestHistoryBuilder> {

public KillCreaturesQuestBuilder() {
super(new KillCreaturesTask());
offer = new SimpleQuestOfferBuilder();
complete = new SimpleQuestCompleteBuilder();
history = new QuestHistoryBuilder();
}
Expand Down
6 changes: 3 additions & 3 deletions src/games/stendhal/server/entity/npc/quest/QuestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* @author hendrik
* @param <T> QuestTaskBuilder
*/
public class QuestBuilder<T extends QuestTaskBuilder, C extends QuestCompleteBuilder, H extends QuestHistoryBuilder> {
public class QuestBuilder<T extends QuestTaskBuilder, O extends QuestOfferBuilder<O>, 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;
Expand Down Expand Up @@ -58,7 +58,7 @@ public H history() {
*
* @return QuestOfferBuilder
*/
public QuestOfferBuilder offer() {
public O offer() {
return offer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface QuestManuscript {
*
* @return QuestBuilder
*/
public QuestBuilder<?, ?, ?> story();
public QuestBuilder<?, ?, ?, ?> story();
}
52 changes: 31 additions & 21 deletions src/games/stendhal/server/entity/npc/quest/QuestOfferBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author hendrik
*/
public class QuestOfferBuilder {
public class QuestOfferBuilder<T extends QuestOfferBuilder<T>> {
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.";
Expand All @@ -49,57 +49,67 @@ public class QuestOfferBuilder {
private List<String> lastRespondTo = null;
private Map<List<String>, 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package games.stendhal.server.entity.npc.quest;

public class SimpleQuestOfferBuilder extends QuestOfferBuilder<SimpleQuestOfferBuilder> {

}

0 comments on commit de18fd0

Please sign in to comment.