public MakingFabric(final MithrilCloakQuestInfo mithrilcloak) {
this.mithrilcloak = mithrilcloak;
}
private void makeThreadStep() {
final SpeakerNPC npc = npcs.get("Vincento Price");
npc.addReply("silk", "Keep this quiet, ok? I'll spin silk thread from the silk glands of a giant spider. Just ask me to #make it.");
npc.addReply("silk gland", "Like I said, they come from giant spiders.");
final Map<String, Integer> requiredResources = new TreeMap<String, Integer>();
requiredResources.put("silk gland", Integer.valueOf(1));
// we want to add something to the beginning of quest slot so override classes using it.
class SpecialProducerBehaviour extends ProducerBehaviour {
SpecialProducerBehaviour(final String productionActivity,
final String productName, final Map<String, Integer> requiredResourcesPerItem,
final int productionTimePerItem) {
super(mithrilcloak.getQuestSlot(), productionActivity, productName,
requiredResourcesPerItem, productionTimePerItem, false);
}
/**
* Tries to take all the resources required to produce the agreed amount of
* the product from the player. If this is possible, initiates an order.
*
* @param npc
* the involved NPC
* @param player
* the involved player
*/
@Override
public boolean transactAgreedDeal(ItemParserResult res, final EventRaiser npc, final Player player) {
int amount = res.getAmount();
if (getMaximalAmount(player) < amount) {
// The player tried to cheat us by placing the resource
// onto the ground after saying "yes"
npc.say("Hey! I'm over here! You'd better not be trying to trick me...");
return false;
} else {
for (final Map.Entry<String, Integer> entry : getRequiredResourcesPerItem().entrySet()) {
final int amountToDrop = amount * entry.getValue();
player.drop(entry.getKey(), amountToDrop);
}
final long timeNow = new Date().getTime();
player.setQuest(mithrilcloak.getQuestSlot(), "makingthread;" + amount + ";" + getProductName() + ";"
+ timeNow);
npc.say("It's unorthodox, but I will "
+ getProductionActivity()
+ " "
+ amount
+ " "
+ getProductName()
+ " for you. Please be discreet and come back in "
+ TimeUtil.approxTimeUntil((int) ((long)REQUIRED_MINUTES_THREAD * amount * MathHelper.MILLISECONDS_IN_ONE_MINUTE / 1000L)) + ".");
return true;
}
}
/**
* This method is called when the player returns to pick up the finished
* product. It checks if the NPC is already done with the order. If that is
* the case, the player is told to get the product from another NPC.
* Otherwise, the NPC asks the player to come back later.
*
* @param npc
* The producing NPC
* @param player
* The player who wants to fetch the product
*/
@Override
public void giveProduct(final EventRaiser npc, final Player player) {
final String orderString = player.getQuest(mithrilcloak.getQuestSlot());
final String[] order = orderString.split(";");
final int numberOfProductItems = Integer.parseInt(order[1]);
// String productName = order[1];
final long orderTime = Long.parseLong(order[3]);
final long timeNow = new Date().getTime();
final long timeRemaining = orderTime + ((long)REQUIRED_MINUTES_THREAD * numberOfProductItems * MathHelper.MILLISECONDS_IN_ONE_MINUTE) - timeNow;
if (timeRemaining > 0L) {
npc.say("Shhhh, I'm still working on your request to "
+ getProductionActivity() + " " + getProductName()
+ " for you. I'll be done in " + TimeUtil.approxTimeUntil((int) (timeRemaining / 1000L)) + ".");
} else {
npc.say("Oh, I gave your "
+ Grammar.quantityplnoun(numberOfProductItems,
getProductName(), "") + " to my research student Boris Karlova. Go collect them from him.");
player.notifyWorldAboutChanges();
}
}
}
final ProducerBehaviour behaviour = new SpecialProducerBehaviour("make", "silk thread",
requiredResources, REQUIRED_MINUTES_THREAD);
npc.add(ConversationStates.ATTENDING,
"make",
new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_fabric"), ConversationStates.ATTENDING, null,
new ProducerBehaviourAction(behaviour) {
@Override
public void fireRequestOK(final ItemParserResult res, Player player, Sentence sentence, EventRaiser npc) {
// Find out how much items we shall produce.
if (res.getAmount() < 40) {
npc.say("Do you really want so few? I'm not wasting my time with that! Any decent sized pieces of fabric needs at least 40 spools of thread! You should at least #make #40.");
return;
} else if (res.getAmount() > 1000) {
/*logger.warn("Decreasing very large amount of "
* + behaviour.getAmount()
* + " " + behaviour.getChosenItemName()
* + " to 40 for player "
* + player.getName() + " talking to "
* + npc.getName() + " saying " + sentence);
*/
res.setAmount(40);
}
if (behaviour.askForResources(res, npc, player)) {
currentBehavRes = res;
npc.setCurrentState(ConversationStates.PRODUCTION_OFFERED);
}
}
@Override
public void fireRequestError(final ItemParserResult res, final Player player, final Sentence sentence, final EventRaiser raiser) {
raiser.say(behaviour.getErrormessage(res, "#make", "produce"));
}
});
npc.add(ConversationStates.PRODUCTION_OFFERED,
ConversationPhrases.YES_MESSAGES, null,
ConversationStates.ATTENDING, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
behaviour.transactAgreedDeal(currentBehavRes, npc, player);
currentBehavRes = null;
}
});
npc.add(ConversationStates.PRODUCTION_OFFERED,
ConversationPhrases.NO_MESSAGES, null,
ConversationStates.ATTENDING, "OK, no problem.", null);
npc.add(ConversationStates.ATTENDING,
behaviour.getProductionActivity(),
new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "makingthread;"),
ConversationStates.ATTENDING, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence,
final EventRaiser npc) {
npc.say("I still haven't finished your last order!");
}
});
// player returns and says hi while sacs being made
npc.add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "makingthread;")),
ConversationStates.ATTENDING, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence,
final EventRaiser npc) {
behaviour.giveProduct(npc, player);
}
});
// player returns and doesn't need fabric and sacs not being made
npc.add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new NotCondition(
new OrCondition(
new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_fabric"),
new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "makingthread;")
)
)),
ConversationStates.IDLE, "Ha ha he he woo hoo!!!",
null);
// player returns and needs fabric
npc.add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_fabric")),
ConversationStates.ATTENDING, "Ha ha he he woo hoo ... ha ... Sorry, I get carried away sometimes. What do you want?",
null);