Skip to content

Commit

Permalink
Track completions of Kill Dhohr Nuggetcutter
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 29, 2024
1 parent 173e547 commit b5aba43
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/games/stendhal/server/maps/quests/KillDhohrNuggetcutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* </ul>
*/

public class KillDhohrNuggetcutter extends AbstractQuest {
public class KillDhohrNuggetcutter extends CompletionsTrackingQuest {

private static final String QUEST_SLOT = "kill_dhohr_nuggetcutter";

Expand All @@ -86,7 +86,7 @@ private void step_1() {
new ChatAction() {
@Override
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
if (!player.hasQuest(QUEST_SLOT) || player.getQuest(QUEST_SLOT).equals("rejected")) {
if (!player.hasQuest(QUEST_SLOT) || player.getQuest(QUEST_SLOT, 0).equals("rejected")) {
raiser.say("We are unable to rid our area of dwarves. Especially one mighty one named Dhohr Nuggetcutter. Would you please kill them?");
} else if (player.getQuest(QUEST_SLOT, 0).equals("start")) {
raiser.say("I already asked you to kill Dhohr Nuggetcutter!");
Expand Down Expand Up @@ -131,7 +131,7 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser
null,
ConversationStates.ATTENDING,
"Ok, I will await someone having the guts to have the job done.",
new SetQuestAndModifyKarmaAction(QUEST_SLOT, "rejected", -5.0));
new SetQuestAndModifyKarmaAction(QUEST_SLOT, 0, "rejected", -5.0));
}

private void step_2() {
Expand Down Expand Up @@ -169,7 +169,9 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser
player.equipOrPutOnGround(mithrilnug);
player.addKarma(25.0);
player.addXP(4000);
player.setQuest(QUEST_SLOT, "killed;" + System.currentTimeMillis());
incrementCompletions(player);
player.setQuest(QUEST_SLOT, 0, "killed");
player.setQuest(QUEST_SLOT, 1, String.valueOf(System.currentTimeMillis()));
}
});
}
Expand All @@ -179,7 +181,7 @@ public void addToWorld() {
fillQuestInfo(
"Kill Dhohr Nuggetcutter",
"Zogfang, the orc who guards the entrance of the Abandoned Keep, isn't feeling safe while some dwarves still remain in the Keep.",
false);
false, 2);
step_1();
step_2();
step_3();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2011 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -20,6 +20,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import games.stendhal.common.MathHelper;
import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.entity.npc.SpeakerNPC;
import games.stendhal.server.entity.npc.fsm.Engine;
Expand Down Expand Up @@ -67,13 +68,24 @@ public void testQuest() {
npc = SingletonRepository.getNPCList().get("Zogfang");
en = npc.getEngine();

final int completions = MathHelper.parseIntDefault(player.getQuest(questSlot, 2), 0);
String[] responses = new String[] {
"We are unable to rid our area of dwarves. Especially one mighty one named Dhohr"
+ " Nuggetcutter. Would you please kill them?"
};
if (completions > 0) {
responses = new String[] {
"Would you like to help again clearing this Keep of our enemies, those dwarves?"
};
}

en.step(player, "hi");
assertEquals("Hello my fine fellow. Welcome to Ados Abandoned Keep, our humble dwelling!", getReply(npc));
en.step(player, "task");
assertEquals("We are unable to rid our area of dwarves. Especially one mighty one named Dhohr Nuggetcutter. Would you please kill them?", getReply(npc));
assertEquals(responses[0], getReply(npc));
en.step(player, "no");
assertEquals("Ok, I will await someone having the guts to have the job done.", getReply(npc));
assertEquals("rejected", player.getQuest(questSlot));
assertEquals("rejected", player.getQuest(questSlot, 0));
en.step(player, "bye");
assertEquals("I wish you well on your journeys.", getReply(npc));

Expand All @@ -82,6 +94,8 @@ public void testQuest() {
en.step(player, "hi");
assertEquals("Hello my fine fellow. Welcome to Ados Abandoned Keep, our humble dwelling!", getReply(npc));
en.step(player, "task");
// when rejected he uses response as if quest was never completed
//assertEquals(responses[0], getReply(npc));
assertEquals("We are unable to rid our area of dwarves. Especially one mighty one named Dhohr Nuggetcutter. Would you please kill them?", getReply(npc));
en.step(player, "yes");
assertEquals("Great! Please find all wandering #dwarves somewhere in this level of the keep and make them pay for their tresspassing!", getReply(npc));
Expand Down Expand Up @@ -142,14 +156,39 @@ public void testQuest() {
player.setSoloKill("mountain dwarf");
player.setSoloKill("mountain dwarf");

final int xpBefore = player.getXP();

en.step(player, "hi");
assertEquals("Thank you so much. You are a warrior, indeed! Here, have one of these. We have found them scattered about. We have no idea what they are.", getReply(npc));
assertEquals(4000, player.getXP());
assertEquals(xpBefore+4000, player.getXP());
assertEquals("killed", player.getQuest(questSlot, 0));

en.step(player, "task");
assertEquals("Thank you for helping us. Maybe you could come back later. The dwarves might return. Try coming back in 2 weeks.", getReply(npc));
en.step(player, "bye");
assertEquals("I wish you well on your journeys.", getReply(npc));
}

@Test
public void testCompletions() {
for (int count = 0; count < 5; count++) {
assertEquals(count, MathHelper.parseIntDefault(player.getQuest(questSlot, 2), 0));
testQuest();
// reset so can be repeated
player.setQuest(questSlot, 1, "0");
}
assertEquals("5", player.getQuest(questSlot, 2));

// check that completions count is retained after quest is rejected & started
en.step(player, "hi");
en.step(player, "task");
en.step(player, "no");
assertEquals("rejected", player.getQuest(questSlot, 0));
assertEquals("5", player.getQuest(questSlot, 2));
en.step(player, "task");
en.step(player, "yes");
assertEquals("start", player.getQuest(questSlot, 0));
assertEquals("5", player.getQuest(questSlot, 2));
en.step(player, "bye");
}
}

0 comments on commit b5aba43

Please sign in to comment.