* @param cost
* The price which can be positive for a lump sum cost, 0 for free healing
* or negative for a price dependent on level of player.
*/
public void addHealer(final SpeakerNPC npc, final int cost) {
final HealerBehaviour healerBehaviour = new HealerBehaviour(cost);
final Engine engine = npc.getEngine();
engine.add(ConversationStates.ATTENDING,
ConversationPhrases.OFFER_MESSAGES, null,
false, ConversationStates.ATTENDING, "I can #heal you.", null);
engine.add(ConversationStates.ATTENDING, "heal", null,
false, ConversationStates.ATTENDING,
null, new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
ItemParserResult res = new ItemParserResult(true, "heal", 1, null);
int cost = healerBehaviour.getCharge(res, player);
currentBehavRes = res;
String badboymsg = "";
if (player.isBadBoy()) {
cost = cost * 2;
currentBehavRes.setAmount(2);
badboymsg = " Healing costs more for those who slay others.";
}
if (cost > 0) {
raiser.say("Healing costs " + cost
+ "." + badboymsg + " Do you have that much?");
raiser.setCurrentState(ConversationStates.HEAL_OFFERED); // success
} else if (cost < 0) {
// price depends on level if cost was set at -1
// where the factor is |cost| and we have a +1
// to avoid 0 charge.
cost = player.getLevel() * Math.abs(cost) + 1;
raiser.say("Healing someone of your abilities costs "
+ cost
+ " money." + badboymsg + " Do you have that much?");
raiser.setCurrentState(ConversationStates.HEAL_OFFERED); // success
} else {
if ((player.getAtk() > 35) || (player.getDef() > 35)) {
raiser.say("Sorry, I cannot heal you because you are way too strong for my limited powers.");
} else if ((!player.isNew()
&& (player.getLastPVPActionTime() > System
.currentTimeMillis()
- 2
* MathHelper.MILLISECONDS_IN_ONE_HOUR) || player.isBadBoy())) {
// ignore the PVP flag for very young
// characters
// (low atk, low def AND low level)
raiser.say("Sorry, but you have a bad aura, so that I am unable to heal you right now.");
} else {
raiser.say("There, you are healed. How else may I help you?");
healerBehaviour.heal(player);
}
}
}
});
engine.add(ConversationStates.HEAL_OFFERED,
ConversationPhrases.YES_MESSAGES, null,
false, ConversationStates.ATTENDING,
null, new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
int cost = healerBehaviour.getCharge(currentBehavRes, player);
if (cost < 0) {
cost = player.getLevel() * Math.abs(cost) + 1;
}
if (player.drop("money",
cost)) {
healerBehaviour.heal(player);
raiser.say("There, you are healed. How else may I help you?");
} else {
raiser.say("I'm sorry, but it looks like you can't afford it.");
}