if (!Rotation.isFacingEntity(player, npc.getEntity(), 45)) return new ChatContext(false);
Boolean ret = false;
// Denizen should be good to interact with. Let's get the script.
InteractScriptContainer script = npc.getInteractScript(denizenPlayer, ChatTrigger.class);
Map<String, dObject> context = new HashMap<String, dObject>();
context.put("message", new Element(message));
//
// Fire the Actions!
//
// If engaged or not cool, calls On Unavailable, if cool, calls On Chat
// If available (not engaged, and cool) sets cool down and returns true.
TriggerTrait.TriggerContext trigger = npc.getTriggerTrait()
.trigger(ChatTrigger.this, denizenPlayer, context);
// Return false if determine cancelled
if (trigger.hasDetermination()) {
if (trigger.getDetermination().equalsIgnoreCase("cancelled")) {
// Mark as handled, the event will cancel.
return new ChatContext(true);
}
}
// Return false if trigger was unable to fire
if (!trigger.wasTriggered()) {
// If the NPC is not interact-able, Settings may allow the chat to filter
// through. Check the Settings if this is enabled.
if (Settings.chatGloballyIfUninteractable()) {
dB.echoDebug(script, ChatColor.YELLOW + "Resuming. " + ChatColor.WHITE
+ "The NPC is currently cooling down or engaged.");
return new ChatContext(false);
} else
ret = true;
}
// Debugger
dB.report(script, name, aH.debugObj("Player", player.getName())
+ aH.debugObj("NPC", npc.toString())
+ aH.debugObj("Radius(Max)", npc.getLocation().distance(player.getLocation())
+ "(" + npc.getTriggerTrait().getRadius(name) + ")")
+ aH.debugObj("Trigger text", message)
+ aH.debugObj("LOS", String.valueOf(player.hasLineOfSight(npc.getEntity())))
+ aH.debugObj("Facing", String.valueOf(Rotation.isFacingEntity(player, npc.getEntity(), 45))));
// Change the text if it's in the determination
if (trigger.hasDetermination()) {
message = trigger.getDetermination();
}
if (script == null) return new ChatContext(message, false);
// Check if the NPC has Chat Triggers for this step.
if (!script.containsTriggerInStep(
InteractScriptHelper.getCurrentStep(denizenPlayer,
script.getName()), ChatTrigger.class)) {
// If this is a Chatbot, make it chat anything it wants if
// it has no chat triggers for this step
if (npc.getCitizen().hasTrait(ChatbotTrait.class)) {
Utilities.talkToNPC(message, denizenPlayer, npc, Settings.chatToNpcOverhearingRange());
npc.getCitizen().getTrait(ChatbotTrait.class).chatTo(player, message);
return new ChatContext(false);
}
// No chat trigger for this step.. do we chat globally, or to the NPC?
else if (!Settings.chatGloballyIfNoChatTriggers()) {
dB.echoDebug(script, player.getName() + " says to "
+ npc.getNicknameTrait().getNickname() + ", " + message);
return new ChatContext(false);
}
else return new ChatContext(message, ret);
}
// Parse the script and match Triggers.. if found, cancel the text! The
// parser will take care of everything else.
String id = null;
boolean matched = false;
String replacementText = null;
String regexId = null;
String regexMessage = null;
// Use TreeMap to sort chat triggers alphabetically
TreeMap<String, String> idMap = new TreeMap<String, String>();
idMap.putAll(script.getIdMapFor(ChatTrigger.class, denizenPlayer));
if (!idMap.isEmpty()) {
// Iterate through the different id entries in the step's chat trigger
for (Map.Entry<String, String> entry : idMap.entrySet()) {
// Check if the chat trigger specified in the specified id's 'trigger:' key
// matches the text the player has said
String triggerText = TagManager.tag(denizenPlayer, npc, entry.getValue());
Matcher matcher = triggerPattern.matcher(triggerText);
while (matcher.find ()) {
if (!script.checkSpecificTriggerScriptRequirementsFor(ChatTrigger.class,
denizenPlayer, npc, entry.getKey())) continue;
String keyword = TagManager.tag(denizenPlayer, npc, matcher.group().replace("/", ""));
String[] split = keyword.split("\\\\\\+REPLACE:", 2);
String replace = null;
if (split.length == 2) {