voices = ["\u00A77\u00A7oThe \u00A77\u00A7oItsy \u00A77\u00A7oBitsy \u00A77\u00A7oSpider \u00A77\u00A7oWent \u00A77\u00A7oUp \u00A77\u00A7oThe \u00A77\u00A7oWater \u00A77\u00A7oSpout. \u00A77\u00A7oDown \u00A77\u00A7oCame \u00A77\u00A7oThe \u00A77\u00A7oGoblin \u00A77\u00A7oAnd \u00A77\u00A7oTook \u00A77\u00A7oThe \u00A77\u00A7oSpider \u00A77\u00A7oOut.",
 "\u00A77\u00A7oThe \u00A77\u00A7oHEART \u00A77\u00A7oOsborn! \u00A77\u00A7oFirst, \u00A77\u00A7owe \u00A77\u00A7oattack \u00A77\u00A7ohis \u00A77\u00A7oheart!", "\u00A77\u00A7oCan \u00A77\u00A7oThe \u00A77\u00A7oSpider-Man \u00A77\u00A7oCome \u00A77\u00A7oOut \u00A77\u00A7oTo \u00A77\u00A7oPlay?",
 "\u00A77\u00A7oBack \u00A77\u00A7oTo \u00A77\u00A7oFormula.", "\u00A77\u00A7oOut, \u00A77\u00A7oAm \u00A77\u00A7oI?", "\u00A77\u00A7oIn \u00A77\u00A7oSpite \u00A77\u00A7oOf \u00A77\u00A7oEverything \u00A77\u00A7oYou've \u00A77\u00A7oDone \u00A77\u00A7oFor \u00A77\u00A7oThem, \u00A77\u00A7oEventually \u00A77\u00A7oThey \u00A77\u00A7oWill \u00A77\u00A7oHate \u00A77\u00A7oYou.",
 "\u00A77\u00A7oSpider-Man \u00A77\u00A7ois \u00A77\u00A7oall \u00A77\u00A7obut \u00A77\u00A7oinvincible; \u00A77\u00A7obut \u00A77\u00A7oParker, \u00A77\u00A7owe \u00A77\u00A7ocan \u00A77\u00A7odestroy \u00A77\u00A7ohim.", "\u00A77\u00A7oBetrayal \u00A77\u00A7omust \u00A77\u00A7onot \u00A77\u00A7obe \u00A77\u00A7ocountenanced. \u00A77\u00A7oParker \u00A77\u00A7omust \u00A77\u00A7obe \u00A77\u00A7oeducated.",
 "\u00A77\u00A7oThe \u00A77\u00A7ocunning \u00A77\u00A7owarrior \u00A77\u00A7oattacks \u00A77\u00A7oneither \u00A77\u00A7obody \u00A77\u00A7onor \u00A77\u00A7omind.", "\u00A77\u00A7oCoward! \u00A77\u00A7oWe \u00A77\u00A7ohave \u00A77\u00A7oa \u00A77\u00A7onew \u00A77\u00A7oworld \u00A77\u00A7oto \u00A77\u00A7oconquer. \u00A77\u00A7oYou \u00A77\u00A7omake \u00A77\u00A7ome \u00A77\u00A7osick.",
 "\u00A77\u00A7oHiding \u00A77\u00A7oin \u00A77\u00A7othe \u00A77\u00A7oshadows. \u00A77\u00A7oHiding \u00A77\u00A7ofrom \u00A77\u00A7owho \u00A77\u00A7oyou \u00A77\u00A7otruly \u00A77\u00A7oare! \u00A77\u00A7oYou \u00A77\u00A7ocan't \u00A77\u00A7oescape \u00A77\u00A7oyourself!", "\u00A77\u00A7oMcRib.", "\u00A77\u00A7oEmbrace \u00A77\u00A7othe \u00A77\u00A7oRiblin."]
 
function init(hero) {
    hero.setName("Green Goblin");
    hero.setAliases("gobby", "riblin", "mcrib");
	hero.setVersion("Raimi");
    hero.setTier(7);

    hero.setHelmet("item.superhero_armor.piece.helmet");
    hero.setChestplate("item.superhero_armor.piece.chestplate");
    hero.setLeggings("item.superhero_armor.piece.leggings");
    hero.setBoots("item.superhero_armor.piece.boots");

    hero.addPowers("skarlet:goblin_glider", "skarlet:goblin_formula");
    hero.addAttribute("PUNCH_DAMAGE", 7.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", 4.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 6.0, 0);
    hero.addAttribute("IMPACT_DAMAGE", 7.0, 1);

    hero.addKeyBind("BLADE", "Toggle Glider Blades", 1);
    hero.addKeyBind("CHARGED_BEAM", "Twin Machine Guns", 2);
    hero.addKeyBindFunc("PROJECTILE", projectile, "Throw Razor Bats", 3);
	
    hero.addAttributeProfile("BLADE", bladeProfile);
	hero.setModifierEnabled(isModifierEnabled);
    hero.setHasProperty(hasProperty);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setHasProperty((entity, property) => property == "MASK_TOGGLE");

    hero.addSoundEvent("MASK_OPEN", "skarlet:goblin_mask_open");
    hero.addSoundEvent("MASK_CLOSE", "skarlet:goblin_mask_close");

    hero.addSoundOverrides("UPGRADED", {
		"suit": {
            "MASK_OPEN" : "fiskheroes:utility_belt_switch",
            "MASK_CLOSE" : "fiskheroes:utility_belt_switch"
		}
    });
	
    hero.setTickHandler((entity, manager) => { 
        //projectile 
        if (entity.getData("skarlet:dyn/throw") != entity.getData("fiskheroes:heat_vision")) {
            manager.setData(entity, "fiskheroes:heat_vision", entity.getData("skarlet:dyn/throw"));
        }
        if (entity.getData("skarlet:dyn/throw_timer") == 1) {
            manager.setData(entity, "skarlet:dyn/throw_cooldown", true);
            manager.setData(entity, "skarlet:dyn/throw_animation", false);
            manager.setData(entity, "skarlet:dyn/throw", false);
        }
        if (entity.getData("skarlet:dyn/throw_animation_timer") == 1 && entity.getData("skarlet:dyn/throw_timer") == 0 && !entity.getData("skarlet:dyn/throw_cooldown")) {
            entity.playSound("skarlet:razor.bats.throw", 0.5, 0.9);
            manager.setData(entity, "skarlet:dyn/throw", true);
        }
        
        //flight
		if (entity.getData("fiskheroes:flight_boost_timer")) {
			manager.setData(entity, "fiskheroes:flight_boost_timer", 0.001);
        }
        manager.incrementData(entity, "fiskheroes:dyn/booster_timer", 2, entity.getData("fiskheroes:flying"));

        //goblin personality
		if (entity.is("PLAYER") && !entity.is("DISPLAY")) {
			var randomVal = Math.floor(Math.random() * 15000);
			if (randomVal % 15000 == 0) {
				entity.as("PLAYER").addChatMessage("\u00A77\u00A7oThe Goblin whispers to you: " + voices[Math.floor(Math.random() * voices.length)]);
			}
		}
    });
}

function bladeProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("IMPACT_DAMAGE", 1.0, 1);
}

function getProfile(entity) {
    return entity.getData("fiskheroes:blade") ? "BLADE" : null;
}

function isKeyBindEnabled(entity, keyBind) {
	switch (keyBind) {
		case "CHARGED_BEAM":
			return entity.getData("fiskheroes:flying") && !entity.isSprinting();
        case "BLADE":
            return entity.getData("fiskheroes:flying");
        case "PROJECTILE":
            return entity.getData("fiskheroes:flying") && !entity.isSprinting() && entity.getData("skarlet:dyn/throw_timer") == 0 && !entity.getData("skarlet:dyn/throw_cooldown");
        default:
            return true;
    }
}

function hasProperty(entity, property) {
    switch (property) {
        case "BREATHE_SPACE":
            return !entity.getData("fiskheroes:mask_open");
        default:
            return false;
    }
}

function isModifierEnabled(entity, modifier) {
	switch (modifier.name()) {
		case "fiskheroes:blade":
			return entity.getData("fiskheroes:flying");
        case "fiskheroes:water_breathing":
            return !entity.getData("fiskheroes:mask_open");
        case "fiskheroes:fireball":
            return entity.getData("fiskheroes:flying");
		default:
			return true;
	}
}

function projectile(entity, manager) {
    if (entity.getData("skarlet:dyn/throw_animation_timer") == 0 && !entity.getData("skarlet:dyn/throw_cooldown")) {
        manager.setData(entity, "skarlet:dyn/throw_animation", true);
    }
    return true;
}

