/// <reference path="../Clothing.ts" />
/// <reference path="../Person/Attribute.ts" />
interface WeaponOptions extends ClothingOptions {
    leftHand : boolean;
    rightHand : boolean;
    attribute? : Attribute;
    baseDamage? : number;
    attackCost? : number;
}

class Weapon extends Clothing {
    private baseDamage : number = 0;
    private attribute = undefined;
    public attackCost = 1;

    constructor (t : WeaponOptions) {
        super(t);
        if (t.leftHand) {
            this.slots.push(Humanoid.SLOT_LEFTHAND);
        }
        if (t.rightHand) {
            this.slots.push(Humanoid.SLOT_RIGHTHAND);
        }
        this.baseDamage = t.baseDamage == undefined ? 0 : t.baseDamage;
        this.attackCost = t.attackCost == undefined ? 1 : t.attackCost;
        this.attribute = t.attribute;
    }

    public getDamage () {
        let damage = this.baseDamage;
        let wielder = <Person> this.getWearOne();
        let attrValue : number;
        if (this.attribute != undefined) {
            attrValue = wielder.getStat(this.attribute);
        } else {
            attrValue = 0;
        }
        // TODO: Reconsider RNG.
        let result = attrValue + (1 + Math.floor(Math.random() * damage));

        if (this.slots.length == 2) {
            return Math.floor(result * 5 / 3); // Twohanded modifier
        } else {
            return Math.floor(result * 2 / 3); // One-handed modifier
        }
    }
}