Skip to content

Commit

Permalink
Blacklist seeds & bulbs from being sold with Harold
Browse files Browse the repository at this point in the history
Closes: #454
  • Loading branch information
AntumDeluge committed Oct 12, 2023
1 parent 60b57dd commit 1b388f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
***************************************************************************/
package games.stendhal.server.maps.semos.tavern.market;

import java.util.Arrays;
import java.util.List;

import games.stendhal.common.constants.SoundID;
import games.stendhal.common.constants.SoundLayer;
import games.stendhal.common.grammar.Grammar;
Expand Down Expand Up @@ -42,6 +45,10 @@ public class PrepareOfferHandler {
private int price;
private int quantity;

/** Items that Harold will not accept. */
private static final List<String> items_blacklist = Arrays.asList("bulb", "seed");


public void add(SpeakerNPC npc) {
npc.add(ConversationStates.ATTENDING, "sell",
new LevelLessThanCondition(6),
Expand Down Expand Up @@ -136,6 +143,9 @@ private void handleSentence(Player player, Sentence sentence, EventRaiser npc) {
if (itemName.equals("money")) {
npc.say("Oh, offering money for money? That sounds rather fishy. I am sorry, I cannot do that");
return;
} else if (items_blacklist.contains(itemName)) {
npc.say("Sorry, that item has no market value and cannot be sold here.");
return;
} else if ((number > 1) && !(item instanceof StackableItem)) {
npc.say("Sorry, you can only put those for sale as individual items.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public void testCreateInvalidOffer() {
assertTrue(en.step(player, "sell vampire cloak 100"));
assertEquals("Sorry, but I don't think you have any vampire cloaks.", getReply(npc));

// blacklisted items
PlayerTestHelper.equipWithItem(player, "seed");
PlayerTestHelper.equipWithItem(player, "bulb");

assertTrue(en.step(player, "sell seed 100"));
assertEquals("Sorry, that item has no market value and cannot be sold here.", getReply(npc));
assertTrue(en.step(player, "sell bulb 200"));
assertEquals("Sorry, that item has no market value and cannot be sold here.", getReply(npc));

assertTrue(en.step(player, "bye"));
assertEquals(
"Visit me again to see available offers, make a new offer or fetch your earnings!", getReply(npc));
Expand Down

0 comments on commit 1b388f3

Please sign in to comment.