/// <reference path="../Action.ts" />
/// <reference path="../Rule.ts" />
/// <reference path="../Rulebook.ts" />
/// <reference path="../Things/Person.ts" />
class ActionStand extends Action {
    public static check = new Rulebook<ActionStand>("Check Stand");
    public static carry = new Rulebook<ActionStand>("Carry out Stand");

    public constructor (actor : Thing, ...nouns : Array<any>) {
        super(actor, ...nouns);
        this.requiresNoun = false;
        this.requiresVisibility = false;
    }

    public getCommandText () {
        return "stand up"
    }

    public   static checkStand = ActionStand.check.createAndAddRule({
        name : "Stand - Can stand?",
        code : (rulebook) => {
            // TODO: Check if being held down
            // TODO: Check if incapacitated
        }
    });

    public  static carryStand = ActionStand.carry.createAndAddRule({
        name : "Stand - Rise up!",
        code : (runner : RulebookRunner<ActionStand>) => {
            let actor = runner.noun.actor;
            if (actor instanceof Person) {
                actor.stance = PersonStance.STANDING;

                if (actor == WorldState.player) {
                    runner.noun.say.add("You get up.");
                } else {
                    runner.noun.say.add(runner.noun.actor, " rises up.");
                }
            }
        }
    });
}

Elements.HyperlinkHandler.CommonActionsRulebook.addRule(new Rule(
    {
        name : "Hyperlink - Stand up!",
        firstPriority : Rule.PRIORITY_MEDIUM,
        code : (rulebook : RulebookRunner<void>) => {
            if (WorldState.player.stance == PersonStance.ALLFOURS) {
                Elements.HyperlinkHandler.addCommonAction("Get up", new ActionStand(WorldState.player));
            }
        }
    }
));