From e2cf3477315d6075dc07bdb11ee6904a35306497 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 15 Jul 2024 15:34:07 -0700 Subject: [PATCH] New NPC: Maple, a clover hunter --- data/conf/zones/deniran.xml | 5 +- doc/CHANGES.txt | 1 + .../deniran/cityoutside/CloverHunterNPC.java | 64 +++++++++++++++++ .../cityoutside/CloverHunterNPCTest.java | 71 +++++++++++++++++++ 4 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 src/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPC.java create mode 100644 tests/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPCTest.java diff --git a/data/conf/zones/deniran.xml b/data/conf/zones/deniran.xml index 043d84d280c..c06bef3c0b8 100644 --- a/data/conf/zones/deniran.xml +++ b/data/conf/zones/deniran.xml @@ -277,14 +277,13 @@ - - + time varying + diff --git a/doc/CHANGES.txt b/doc/CHANGES.txt index 696ded0e579..4cf54074044 100644 --- a/doc/CHANGES.txt +++ b/doc/CHANGES.txt @@ -14,6 +14,7 @@ Changelog - added wander behavior to crab in addition to patrol - new item: four-leaf clover - new achievement: Luck O' the Irish: Find the lucky four-leaf clover +- new NPC: Maple, a clover hunter *chat* - new offers with Harold are announced in chat diff --git a/src/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPC.java b/src/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPC.java new file mode 100644 index 00000000000..2d3beace13d --- /dev/null +++ b/src/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPC.java @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright © 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.deniran.cityoutside; + +import java.util.Map; + +import games.stendhal.server.core.config.ZoneConfigurator; +import games.stendhal.server.core.engine.StendhalRPZone; +import games.stendhal.server.entity.npc.ConversationPhrases; +import games.stendhal.server.entity.npc.ConversationStates; +import games.stendhal.server.entity.npc.SpeakerNPC; +import games.stendhal.server.entity.npc.behaviour.impl.idle.WanderIdleBehaviour; +import games.stendhal.server.entity.npc.condition.NotCondition; +import games.stendhal.server.entity.npc.condition.QuestRegisteredCondition; + + +public class CloverHunterNPC implements ZoneConfigurator { + + @Override + public void configureZone(StendhalRPZone zone, Map attributes) { + zone.add(buildNPC()); + } + + private SpeakerNPC buildNPC() { + SpeakerNPC npc = new SpeakerNPC("Maple"); + npc.setEntityClass("cloverhunternpc"); + npc.setDescription("You see a young woman scanning the ground with her magnifying glass."); + npc.setPosition(68, 67); + npc.setIdleBehaviour(new WanderIdleBehaviour()); + + buildDialogue(npc); + + return npc; + } + + private void buildDialogue(SpeakerNPC npc) { + npc.addGreeting("Hello fellow clover hunter!"); + npc.addGoodbye("May luck shine brightly o'er you!"); + npc.addJob("I'm a clover hunter. I'm searching for the lucky four-leaf #clover."); + npc.addHelp("Four-leaf #clovers are extremely rare. If you find one, it is said you will have" + + " excellent luck!"); + npc.addOffer("I can tell you a little about #clovers."); + npc.addReply("clover", "Clovers can grow just about anywhere in the sunlight. So don't go" + + " looking for any underground. Ones with four leaves are especially rare and are a" + + " challenging #task to find."); + + npc.add( + ConversationStates.ATTENDING, + ConversationPhrases.QUEST_MESSAGES, + new NotCondition(new QuestRegisteredCondition("lucky_four_leaf_clover")), + ConversationStates.ATTENDING, + "No, no thank you. I can find a four-leaf clover on my own.", + null); + } +} diff --git a/tests/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPCTest.java b/tests/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPCTest.java new file mode 100644 index 00000000000..4e3afad8fe5 --- /dev/null +++ b/tests/games/stendhal/server/maps/deniran/cityoutside/CloverHunterNPCTest.java @@ -0,0 +1,71 @@ +/*************************************************************************** + * Copyright © 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.deniran.cityoutside; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; +import static utilities.SpeakerNPCTestHelper.getReply; + +import org.junit.Before; +import org.junit.Test; + +import games.stendhal.server.entity.npc.ConversationStates; +import games.stendhal.server.entity.npc.SpeakerNPC; +import games.stendhal.server.entity.npc.fsm.Engine; +import utilities.ZonePlayerAndNPCTestImpl; + + +public class CloverHunterNPCTest extends ZonePlayerAndNPCTestImpl { + + @Override + @Before + public void setUp() throws Exception { + setupZone("test_zone", new CloverHunterNPC()); + setNpcNames("Maple"); + setZoneForPlayer("test_zone"); + + super.setUp(); + } + + @Test + public void testDialogue() { + assertThat(player, notNullValue()); + SpeakerNPC npc = getNPC("Maple"); + Engine en = npc.getEngine(); + + en.step(player, "hi"); + assertThat(getReply(npc), is("Hello fellow clover hunter!")); + en.step(player, "job"); + assertThat(getReply(npc), + is("I'm a clover hunter. I'm searching for the lucky four-leaf #clover.")); + en.step(player, "help"); + assertThat(getReply(npc), is("Four-leaf #clovers are extremely rare. If you find one, it is" + + " said you will have excellent luck!")); + en.step(player, "offer"); + assertThat(getReply(npc), is("I can tell you a little about #clovers.")); + en.step(player, "clover"); + assertThat(getReply(npc), is("Clovers can grow just about anywhere in the sunlight. So don't go" + + " looking for any underground. Ones with four leaves are especially rare and are a" + + " challenging #task to find.")); + en.step(player, "clovers"); + assertThat(getReply(npc), is("Clovers can grow just about anywhere in the sunlight. So don't go" + + " looking for any underground. Ones with four leaves are especially rare and are a" + + " challenging #task to find.")); + en.step(player, "task"); + // reply when quest is not loaded + assertThat(getReply(npc), is("No, no thank you. I can find a four-leaf clover on my own.")); + en.step(player, "bye"); + assertThat(getReply(npc), is("May luck shine brightly o'er you!")); + assertThat(en.getCurrentState(), is(ConversationStates.IDLE)); + } +}