diff --git a/src/games/stendhal/server/maps/quests/FindRatChildren.java b/src/games/stendhal/server/maps/quests/FindRatChildren.java index da80e0084e..c17f81defd 100644 --- a/src/games/stendhal/server/maps/quests/FindRatChildren.java +++ b/src/games/stendhal/server/maps/quests/FindRatChildren.java @@ -69,7 +69,7 @@ *
  • Once every 24 hours.
  • * */ -public class FindRatChildren extends AbstractQuest { +public class FindRatChildren extends CompletionsTrackingQuest { private static final String QUEST_SLOT = "find_rat_kids"; @@ -366,6 +366,7 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser npc.say(reply); player.setQuest(QUEST_SLOT, 0, "done"); player.setQuest(QUEST_SLOT, 1, String.valueOf(System.currentTimeMillis())); + incrementCompletions(player); player.notifyWorldAboutChanges(); npc.setCurrentState(ConversationStates.ATTENDING); } @@ -406,7 +407,7 @@ public void addToWorld() { fillQuestInfo( "Find Rat Children", "Agnus, who lives in Rat City, asks young heroes to find her children and look after them. They went down into the dark tunnels and haven't returned ...", - true); + true, 2); askingStep(); findingStep(); retrievingStep(); diff --git a/tests/games/stendhal/server/maps/quests/FindRatChildrenTest.java b/tests/games/stendhal/server/maps/quests/FindRatChildrenTest.java index d26dcba19f..fe8c70edb9 100644 --- a/tests/games/stendhal/server/maps/quests/FindRatChildrenTest.java +++ b/tests/games/stendhal/server/maps/quests/FindRatChildrenTest.java @@ -14,6 +14,8 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; @@ -25,8 +27,10 @@ import org.junit.BeforeClass; import org.junit.Test; +import games.stendhal.common.MathHelper; import games.stendhal.server.core.engine.SingletonRepository; import games.stendhal.server.core.engine.StendhalRPZone; +import games.stendhal.server.entity.npc.NPCList; import games.stendhal.server.entity.npc.SpeakerNPC; import games.stendhal.server.entity.npc.fsm.Engine; import games.stendhal.server.entity.player.Player; @@ -98,23 +102,31 @@ public void testStartQuest() { npc = SingletonRepository.getNPCList().get("Agnus"); en = npc.getEngine(); + final int completions = MathHelper.parseIntDefault(player.getQuest(QUEST_SLOT, 2), 0); en.step(player, "hi"); - assertEquals("Hello there.", getReply(npc)); - en.step(player, "help"); - assertEquals("I have no help to offer you.", getReply(npc)); - en.step(player, "job"); - assertEquals("Leave it to my children to not check in once in a while.", getReply(npc)); - en.step(player, "task"); - assertEquals("I feel so worried. If I only knew my #children were safe I would feel better.", getReply(npc)); - en.step(player, "children"); - assertEquals("My children have gone to play in the sewers. They have been gone for a long time. Will you find them and see if they are ok?", getReply(npc)); - en.step(player, "no"); - assertEquals("Oh. Never mind. I'm sure someone else would be glad to help me.", getReply(npc)); - en.step(player, "bye"); + if (completions == 0) { + assertEquals("Hello there.", getReply(npc)); + en.step(player, "help"); + assertEquals("I have no help to offer you.", getReply(npc)); + en.step(player, "job"); + assertEquals("Leave it to my children to not check in once in a while.", getReply(npc)); + en.step(player, "task"); + assertEquals("I feel so worried. If I only knew my #children were safe I would feel better.", getReply(npc)); + en.step(player, "children"); + assertEquals("My children have gone to play in the sewers. They have been gone for a long time. Will you find them and see if they are ok?", getReply(npc)); + en.step(player, "no"); + assertEquals("Oh. Never mind. I'm sure someone else would be glad to help me.", getReply(npc)); + en.step(player, "bye"); + } else { + assertThat(getReply(npc), is("Do you think you could find my children again?")); + en.step(player, "no"); + assertThat(getReply(npc), is("Oh. Never mind. I'm sure someone else would be glad to help me.")); + en.step(player, "bye"); + } assertEquals("Bye", getReply(npc)); // check quest slot - assertEquals(player.getQuest(QUEST_SLOT),"rejected"); + assertThat(player.getQuest(QUEST_SLOT, 0), is("rejected")); en.step(player, "hi"); assertEquals("Hello there.", getReply(npc)); @@ -130,7 +142,7 @@ public void testStartQuest() { assertEquals("Bye", getReply(npc)); // check quest slot - assertThat(player.getQuest(QUEST_SLOT), is("found=;said=")); + assertThat(player.getQuest(QUEST_SLOT), startsWith("found=;said=")); } @Test @@ -365,4 +377,47 @@ public void testUpdates() { assertThat(player.getQuest(QUEST_SLOT), is(foundResult + ";" + saidResult)); } } + + private void finishQuestAfterStart() { + final NPCList npcs = NPCList.get(); + SpeakerNPC npc; + Engine en; + final String[] names = new String[] {"Avalon", "Cody", "Mariel", "Opal"}; + for (final String name: names) { + npc = npcs.get(name); + assertThat(npc, notNullValue()); + en = npc.getEngine(); + en.step(player, "hi"); + } + npc = npcs.get("Agnus"); + assertThat(npc, notNullValue()); + en = npc.getEngine(); + en.step(player, "hi"); + for (final String name: names) { + en.step(player, name); + } + en.step(player, "bye"); + assertThat(player.getQuest(QUEST_SLOT, 0), is("done")); + } + + @Test + public void testCompletions() { + for (int count = 0; count < 5; count++) { + assertThat(MathHelper.parseIntDefault(player.getQuest(QUEST_SLOT, 2), 0), is(count)); + testStartQuest(); + finishQuestAfterStart(); + // reset so can be repeated + player.setQuest(QUEST_SLOT, 1, "0"); + } + assertEquals("5", player.getQuest(QUEST_SLOT, 2)); + + // check that completions count is retained after quest is rejected & started + en.step(player, "hi"); + en.step(player, "no"); + assertThat(player.getQuest(QUEST_SLOT), is("rejected;0;5")); + en.step(player, "task"); + en.step(player, "yes"); + assertThat(player.getQuest(QUEST_SLOT), is("found=;said=;5")); + en.step(player, "bye"); + } }