/// <reference path="../Action.ts" />
/// <reference path="../../../Elements/Modules/HyperlinkHandler.ts" />
/// <reference path="../../../Elements/Classes/Say/SayHeSheIt.ts" />

class ActionTalk extends Action {
    public static PRIORITY_SITUATION_DIALOGUE = 9;
    public static PRIORITY_POSSESSION_DIALOGUE = 7;
    public static PRIORITY_LOCATION_DIALOGUE = 5;
    public static PRIORITY_COMMON_DIALOGUE = 3;
    public static PRIORITY_GLOBAL_DIALOGUE = 1;

    public static check: Rulebook<ActionTalk> = new Rulebook("Check Talking");
    public static carry: Rulebook<ActionTalk> = new Rulebook("Carry out Talking");

    public static defaultCarryTalkingRule = ActionTalk.carry.createAndAddRule({
        name : "Talking - Doesn't want to talk",
        firstPriority : -1,
        priority : -1,
        code : (rulebook : RulebookRunner<ActionTake>) => {
            let action = <ActionGo> rulebook.noun;
            //let actor = action.actor;
            let thing = (<Thing>action.getNoun(0));

            if (thing instanceof Person) {
                action.say = new Say("It doesn't look like ", new SayHeSheIt(thing), " wants to talk.");
            } else {
                action.say = new Say("How are you going to talk to that?")
            }
        }
    });

    public getCommandText () {
        return "talk to " + (this.getNoun(0) != undefined ? this.getNoun(0).getPrintedName() : "");
    }
}

Elements.HyperlinkHandler.HyperlinkingRulebook.addRule(new Rule(
    {
        name : "Hyperlink - Talk",
        firstPriority : Rule.PRIORITY_HIGHEST,
        code : (rulebook : RulebookRunner<Thing>) => {
            let thing = <Thing> rulebook.noun;

            if (thing instanceof Person && thing.getRoom() == WorldState.player.getRoom()) {
                Elements.HyperlinkHandler.addAvailableAction("Talk", new ActionTalk(WorldState.player, thing));
            }
        }
    }
));