var scriptName = "Skyrim!"; 
var scriptVersion = 1.1; 
var scriptAuthor = "soulplexis";

var mobs = Java.type("net.minecraft.entity.EntityCreature");
var players = Java.type("net.minecraft.entity.player.EntityPlayer");

function randomIntFrom(min,max) {
    return Math.floor(Math.random()*(max-min+1)+min);
} 

var autoMessage = new autoMessage();
var autoMessageClient;
	
var aggroquotes = ["Thought I heard something.", "What was that?", "By the nine divines, assault! assault!", "You won't get away with this!", "Never should have come here!", "Well well, another maggot to squash beneath my boot.", "Picked a bad time to get lost, friend", "You won't get the best of me!", "My money's on the big one.", "A fight!", "A challenger is near."];
var quotes = ["Why.. Won't.. You.. DIE!", "This what you want, huh?!", "Skyrim belongs to the nords!", "I've fought colds tougher than you!", "Victory, or sovngarde!", "That the best you can do?!", "My ancestors are smiling upon me Imperial, can you say the same?!", "Hahaha, I love a challenge!!", "By Ysmir you won't leave here alive!"];
var deadquotes = ["No sign of em.", "Wait.. I know you.", "Oh, what happened?", "Must've run off.", "Must've been my imagination.", "Cleared out I guess.", "You can't hide from me.", "Where'd you go?", "I guess I was just hearing things.", "That's close enough.", "Best offense is a good defense, am I right?"];

function autoMessage() {
	var delay = value.createInteger("HitsBeforeQuote", 12, 1, 100);
    this.getName = function() {
        return "Skyrim";
    };

    this.getDescription = function() {
        return "Shouts out skyrim quotes when fighting someone.";
    };

    this.getCategory = function() {
        return "Fun";
    };
	var hits = 0;
	var target;
	var dead = false;
	var aggrohit = 0;
	this.onUpdate = function() {
		if(mc.thePlayer.hurtTime == 5) {
			aggrohit++;
			if(aggrohit >= delay.get()) {
			mc.thePlayer.sendChatMessage(aggroquotes[randomIntFrom(0,(aggroquotes.length - 1))]);
			aggrohit = 0;
			}
		}
		if(target.getHealth == 0 || target.isDead) {
			dead = true;
			if(dead && target != undefined) {
				mc.thePlayer.sendChatMessage(deadquotes[randomIntFrom(0,(deadquotes.length - 1))]);
				target = undefined;
			}
		}
	}
	
    this.onAttack = function (event) {
			target = event.getTargetEntity();
			hits++;
			if(hits >= delay.get()) {
				mc.thePlayer.sendChatMessage(quotes[randomIntFrom(0,(quotes.length - 1))]);
				hits = 0;
			}
    }
	this.addValues = function(alduin) {
	alduin.add(delay);
	}
}

function onLoad() {
};

function onEnable() {
    autoMessageClient = moduleManager.registerModule(autoMessage);
};

function onDisable() {
    moduleManager.unregisterModule(autoMessageClient);
};