diff --git a/src/games/stendhal/server/entity/item/Seed.java b/src/games/stendhal/server/entity/item/Seed.java index 7ef6b5c1132..b560fa5363a 100644 --- a/src/games/stendhal/server/entity/item/Seed.java +++ b/src/games/stendhal/server/entity/item/Seed.java @@ -14,6 +14,7 @@ import java.util.Map; +import games.stendhal.common.grammar.Grammar; import games.stendhal.server.core.engine.StendhalRPZone; import games.stendhal.server.core.events.TurnNotifier; import games.stendhal.server.entity.Entity; @@ -105,14 +106,14 @@ public boolean onUsed(final RPEntity user) { @Override public String describe() { - final String flowerName = getItemData(); - - if (flowerName != null) { - return "You see a " + flowerName + " " + this.getName() - + ". It can be planted in fertile ground where it will thrive."; - } else { - return "You see a seed. It can be planted in fertile ground where it will thrive."; + String seed_desc = getDescription(); + final String flower_name = getItemData(); + if (flower_name != null) { + final String seed_type = getName(); + final String seed_name = flower_name + " " + seed_type; + seed_desc = seed_desc.replaceFirst(Grammar.a_noun(seed_type), Grammar.a_noun(seed_name)); } + return seed_desc; } /** diff --git a/tests/games/stendhal/server/entity/item/SeedTest.java b/tests/games/stendhal/server/entity/item/SeedTest.java index a741302d1d3..31c545dc7f7 100644 --- a/tests/games/stendhal/server/entity/item/SeedTest.java +++ b/tests/games/stendhal/server/entity/item/SeedTest.java @@ -1,6 +1,6 @@ /* $Id$ */ /*************************************************************************** - * (C) Copyright 2003-2010 - Stendhal * + * (C) Copyright 2003-2023 - Stendhal * *************************************************************************** *************************************************************************** * * @@ -12,13 +12,17 @@ ***************************************************************************/ package games.stendhal.server.entity.item; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Arrays; + import org.junit.BeforeClass; import org.junit.Test; +import games.stendhal.common.grammar.Grammar; import games.stendhal.server.core.engine.SingletonRepository; import games.stendhal.server.core.engine.StendhalRPZone; import games.stendhal.server.entity.Entity; @@ -164,4 +168,47 @@ public void testExecuteDaisiesSeed() { assertFalse(player.getZone().getEntitiesAt(1, 0).contains(flg)); assertTrue("player has daisies", player.isEquipped("daisies")); } + + @Test + public void testSeedInfo() { + // seeds + final Seed base_seed = (Seed) SingletonRepository.getEntityManager().getItem("seed"); + assertNotNull(base_seed); + assertEquals("You see a seed. It can be planted in fertile ground where it will thrive.", + base_seed.describe()); + assertEquals("seed", base_seed.get("subclass")); + + for (final String flower_name: Arrays.asList("daisies", "lilia", "pansy")) { + final Seed seed = new Seed(base_seed); + seed.setItemData(flower_name); + final String seed_name = flower_name + " seed"; + assertEquals("You see " + Grammar.a_noun(seed_name) + + ". It can be planted in fertile ground where it will thrive.", seed.describe()); + if ("daisies".equals(flower_name)) { + assertEquals("seed", seed.get("subclass")); + } else { + assertEquals("seed_" + flower_name, seed.get("subclass")); + } + } + + // bulbs + final Seed base_bulb = (Seed) SingletonRepository.getEntityManager().getItem("bulb"); + assertNotNull(base_bulb); + assertEquals("You see a bulb. It can be planted in fertile ground where it will thrive.", + base_bulb.describe()); + assertEquals("bulb", base_bulb.get("subclass")); + + for (final String flower_name: Arrays.asList("zantedeschia")) { + final Seed bulb = new Seed(base_bulb); + bulb.setItemData(flower_name); + final String bulb_name = flower_name + " bulb"; + assertEquals("You see " + Grammar.a_noun(bulb_name) + + ". It can be planted in fertile ground where it will thrive.", bulb.describe()); + if ("zantedeschia".equals(flower_name)) { + assertEquals("bulb", bulb.get("subclass")); + } else { + assertEquals("bulb_" + flower_name, bulb.get("subclass")); + } + } + } }