diff --git a/src/games/stendhal/server/maps/quests/ThePiedPiper.java b/src/games/stendhal/server/maps/quests/ThePiedPiper.java
index e5c92be27c8..93a7f72fb82 100644
--- a/src/games/stendhal/server/maps/quests/ThePiedPiper.java
+++ b/src/games/stendhal/server/maps/quests/ThePiedPiper.java
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
- * (C) Copyright 2003-2023 - Stendhal *
+ * (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
@@ -63,7 +63,7 @@
*
* REPETITIONS:
- once between a week and two weeks.
*/
-public class ThePiedPiper extends AbstractQuest implements ITPPQuestConstants {
+public class ThePiedPiper extends CompletionsTrackingQuest implements ITPPQuestConstants {
protected static final Logger logger = Logger.getLogger(ThePiedPiper.class);
@@ -256,7 +256,7 @@ public void addToWorld() {
fillQuestInfo(
"The Pied Piper",
"Ados City has a rat problem from time to time.",
- true);
+ true, 7, 1);
startQuest();
}
diff --git a/src/games/stendhal/server/maps/quests/piedpiper/InvasionPhase.java b/src/games/stendhal/server/maps/quests/piedpiper/InvasionPhase.java
index 26c058f0795..28c998cc80f 100644
--- a/src/games/stendhal/server/maps/quests/piedpiper/InvasionPhase.java
+++ b/src/games/stendhal/server/maps/quests/piedpiper/InvasionPhase.java
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
- * Copyright (C) 2003-2023 - Arianne *
+ * Copyright (C) 2003-2024 - Arianne *
***************************************************************************
***************************************************************************
* *
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
+import games.stendhal.common.MathHelper;
import games.stendhal.common.Rand;
import games.stendhal.common.grammar.Grammar;
import games.stendhal.common.parser.Sentence;
@@ -295,6 +296,22 @@ public void update (Observable obj, Object arg) {
}
}
+ /**
+ * Initializes quest state string after player kills first rat.
+ *
+ * @param player
+ * Player doing quest.
+ */
+ private void initQuestState(final Player player) {
+ int index = 7;
+ if ("done".equals(player.getQuest(QUEST_SLOT, 0))) {
+ index = 1;
+ }
+ // preserve completions count
+ final int completions = MathHelper.parseIntDefault(player.getQuest(QUEST_SLOT, index), 0);
+ player.setQuest(QUEST_SLOT, "rats;0;0;0;0;0;0;" + completions);
+ }
+
/**
* method for making records about killing rats
* in player's quest slot.
@@ -316,17 +333,17 @@ private void killsRecorder(Player player, final RPEntity victim) {
}
if((player.getQuest(QUEST_SLOT)==null)||
- (player.getQuest(QUEST_SLOT).equals("done")||
+ (player.getQuest(QUEST_SLOT, 0).equals("done")||
(player.getQuest(QUEST_SLOT).equals("")))){
// player just killed his first creature.
- player.setQuest(QUEST_SLOT, "rats;0;0;0;0;0;0");
+ initQuestState(player);
}
// we using here and after "i+1" because player's quest index 0
// is occupied by quest stage description.
if ("".equals(player.getQuest(QUEST_SLOT,i+1))){
// something really wrong, will correct this...
- player.setQuest(QUEST_SLOT,"rats;0;0;0;0;0;0");
+ initQuestState(player);
}
int kills;
try {
diff --git a/src/games/stendhal/server/maps/quests/piedpiper/RewardPlayerAction.java b/src/games/stendhal/server/maps/quests/piedpiper/RewardPlayerAction.java
index 05420345673..b1794daf502 100644
--- a/src/games/stendhal/server/maps/quests/piedpiper/RewardPlayerAction.java
+++ b/src/games/stendhal/server/maps/quests/piedpiper/RewardPlayerAction.java
@@ -1,5 +1,17 @@
+/***************************************************************************
+ * Copyright © 2003-2024 - 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.maps.quests.piedpiper;
+import games.stendhal.common.MathHelper;
import games.stendhal.common.parser.Sentence;
import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.entity.item.StackableItem;
@@ -27,6 +39,18 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser
moneys.setQuantity(quantity);
player.equipOrPutOnGround(moneys);
mayor.say("Please take "+quantity+" money, thank you very much for your help.");
- player.setQuest(QUEST_SLOT, "done");
+ setQuestDone(player);
+ }
+
+ /**
+ * Sets quest state to done and increments number of completions.
+ *
+ * @param player
+ * Player completing quest.
+ */
+ private void setQuestDone(final Player player) {
+ // preserve completions count
+ final int completions = MathHelper.parseIntDefault(player.getQuest(QUEST_SLOT, 7), 0);
+ player.setQuest(QUEST_SLOT, "done;" + (completions + 1));
}
}
diff --git a/src/games/stendhal/server/maps/quests/piedpiper/TPPQuestHelperFunctions.java b/src/games/stendhal/server/maps/quests/piedpiper/TPPQuestHelperFunctions.java
index 3587a614eaa..ca83405c28d 100644
--- a/src/games/stendhal/server/maps/quests/piedpiper/TPPQuestHelperFunctions.java
+++ b/src/games/stendhal/server/maps/quests/piedpiper/TPPQuestHelperFunctions.java
@@ -1,3 +1,14 @@
+/***************************************************************************
+ * Copyright © 2003-2024 - 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.maps.quests.piedpiper;
@@ -31,6 +42,11 @@ public static SpeakerNPC getMainNPC() {
* gold amount for hunting rats.
*/
public static int calculateReward(Player player) {
+ if (player.isQuestInState(QUEST_SLOT, 0, "done")) {
+ // information for previous raid is no longer available
+ return 0;
+ }
+
int moneys = 0;
int kills = 0;
for(int i=0; i tempReward));
assertEquals(questHistory, quest.getHistory(player));
- en.step(player, "reward");
- assertEquals("Please take "+ rewardMoneys +" money, thank you very much for your help.", getReply(npc));
+ collectReward();
questHistory.clear();
questHistory.add("I have killed some rats in Ados city and got a reward from Mayor Chalmers!");
assertEquals(questHistory, quest.getHistory(player));
- en.step(player, "bye");
- assertEquals("Good day to you.", getReply(npc));
}
}
diff --git a/tests/games/stendhal/server/maps/quests/thepiedpiper/TPPTestHelper.java b/tests/games/stendhal/server/maps/quests/thepiedpiper/TPPTestHelper.java
index 0ad81210338..9e24ca38fee 100644
--- a/tests/games/stendhal/server/maps/quests/thepiedpiper/TPPTestHelper.java
+++ b/tests/games/stendhal/server/maps/quests/thepiedpiper/TPPTestHelper.java
@@ -1,3 +1,14 @@
+/***************************************************************************
+ * Copyright © 2003-2024 - 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.maps.quests.thepiedpiper;
import org.apache.log4j.Logger;
@@ -112,7 +123,7 @@ private void killRat(Creature rat, int count) {
* function for killing creatures.
* @param numb - number of creatures to kill.
*/
- protected void killRats(int numb) {
+ public void killRats(int numb) {
int count=0;
logger.info("number of rats to kill: "+numb);
for (int i=0; i