Skip to content

Commit

Permalink
simplified text and use variable substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
nhnb committed Sep 15, 2023
1 parent 7112080 commit 30248c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
33 changes: 14 additions & 19 deletions src/games/stendhal/server/entity/npc/quest/DeliverItemTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,18 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser
final String name = Rand.rand(getAllowedCustomers(player));
final DeliverItemOrder data = orders.get(name);

Map<String, String> params = new HashMap<>();
params.put("flavor", data.getFlavor());
params.put("customerName", Grammar.quoteHash("#" + name));
params.put("time", Grammar.quantityplnoun(data.getExpectedMinutes(), "minute", "one"));

final Item pizza = SingletonRepository.getEntityManager().getItem("pizza");
pizza.setInfoString(data.getFlavor());
pizza.setDescription("You see a " + data.getFlavor() + ".");
pizza.setBoundTo(name);
pizza.setDescription(StringUtils.substitute("You see a [flavor].", params));
pizza.setBoundTo(player.getName());

if (player.equipToInventoryOnly(pizza)) {
npc.say("You must bring this "
+ data.getFlavor()
+ " to "
+ Grammar.quoteHash("#" + name)
+ " within "
+ Grammar.quantityplnoun(data.getExpectedMinutes(), "minute", "one")
+ ". Say \"pizza\" so that "
+ name
+ " knows that I sent you. Oh, and please wear this uniform on your way and don't drop this " + data.getFlavor() + " on the ground! Our customers want it fresh.");
npc.say(StringUtils.substitute("You must bring this [flavor] to [customerName] within [time]. Say \"pizza\" so that [customerName] knows that I sent you. Oh, and please wear this uniform on your way.", params));
player.setOutfit(UNIFORM, true);
player.setQuest(QUEST_SLOT, 0, name);
new SetQuestToTimeStampAction(questSlot, 1).fire(player, null, npc);
Expand Down Expand Up @@ -162,13 +159,14 @@ ChatAction buildRemindQuestAction(String questSlot) {
return new ChatAction() {
@Override
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
final String[] questData = player.getQuest(QUEST_SLOT)
.split(";");
final String customerName = questData[0];
final String customerName = player.getQuest(QUEST_SLOT, 0);
if (customerName.equals("rejected")) {
buildStartQuestAction(questSlot).fire(player, sentence, npc);
return;
}
Map<String, String> params = new HashMap<>();
params.put("customerName", Grammar.quoteHash("#" + customerName));

if (isDeliveryTooLate(player)) {
// If the player still carries any pizza due for an NPC,
// take it away because the baker is angry,
Expand All @@ -179,13 +177,10 @@ public void fire(final Player player, final Sentence sentence, final EventRaiser
player.drop(pizza);
}
}
npc.say("I see you failed to deliver the pizza to "
+ customerName
+ " in time. Are you sure you will be more reliable this time?");
npc.say(StringUtils.substitute("I see you failed to deliver the pizza to [customerName] in time. Are you sure you will be more reliable this time?", params));
npc.setCurrentState(ConversationStates.QUEST_OFFERED);
} else {
npc.say("You still have to deliver a pizza to "
+ customerName + ", and hurry!");
npc.say(StringUtils.substitute("You still have to deliver a pizza to [customerName], and hurry!", params));
npc.setCurrentState(ConversationStates.ATTENDING);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public void testQuest() {
en.step(player, "pizza");
assertEquals("I need someone who helps me delivering pizza. Maybe you could do that #task.", getReply(npc1));
en.step(player, "task");
assertEquals("You still have to deliver a pizza to Cyk, and hurry!", getReply(npc1));
assertEquals("You still have to deliver a pizza to #Cyk, and hurry!", getReply(npc1));
en.step(player, "bye");
assertEquals("Bye.", getReply(npc1));

Expand Down Expand Up @@ -491,7 +491,7 @@ public void testQuest() {
en.step(player, "hi");
assertEquals("Hallo! Glad to see you in my kitchen where I make #pizza and #sandwiches.", getReply(leander));
en.step(player, "task");
assertEquals("I see you failed to deliver the pizza to Haizen in time. Are you sure you will be more reliable this time?", getReply(leander));
assertEquals("I see you failed to deliver the pizza to #Haizen in time. Are you sure you will be more reliable this time?", getReply(leander));
// Leander will take the pizza
List<Item> pizzas = player.getAllEquipped("pizza");
assertEquals(pizzas.size(), 1);
Expand Down

0 comments on commit 30248c3

Please sign in to comment.