var utils = implement("fiskheroes:external/utils");

function init(hero) {
    hero.setName("Wonder Woman");
    hero.setVersion("item.superhero_armor.version.comics");
    hero.setAliases("ww");
    hero.setTier(8);
    
    hero.setHelmet("Tiara");
    hero.setChestplate("Armor");
    hero.setBoots("item.superhero_armor.piece.boots"); 
	hero.addPrimaryEquipment("fiskheroes:captain_americas_shield{display:{Name:\"Themysciran Shield\"}}", true);
    hero.addPrimaryEquipment("fisktag:weapon{WeaponType:skarlet:magical_sword}", true, item => item.nbt().getString("WeaponType") == 'skarlet:magical_sword');
    
    hero.addPowers("skarlet:divine_empowerment_comics", "skarlet:lasso_of_truth", "fiskheroes:shield_throwing");
    hero.addAttribute("PUNCH_DAMAGE", 10.5, 0);
    hero.addAttribute("WEAPON_DAMAGE", 3.5, 0);
    hero.addAttribute("JUMP_HEIGHT", 1.5, 0);
    hero.addAttribute("SPRINT_SPEED", 0.8, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 2.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    
    hero.addKeyBind("SHIELD_THROW", "key.shieldThrow", 1);
    hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 4);
    hero.addKeyBindFunc("func_WEB_SWINGING", webSwingingKey, "Lasso of Truth", 2);
    
    hero.addSoundOverrides("CAPELESS", {
		"powers": {
			"skarlet:lasso_of_truth": {
				"fiskheroes:web_swinging": {
                    "RELEASE": ["fiskheroes:web_swinging_whoosh", "fiskheroes:web_swinging_fall_loop"],
                    "SWING": ["fiskheroes:web_swinging", "fiskheroes:web_stress_loop"]
				}
			},
            "skarlet:divine_empowerment_comics": {
                "fiskheroes:controlled_flight": {
                    "ENABLE": ["fiskheroes:flight_loop"]
                },
                "fiskheroes:super_speed": {
                    "MOVE": ["fiskheroes:super_speed_move_loop_shazam_dceu"]
                }
            }
		}
    });
    
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setModifierEnabled(isModifierEnabled);
    hero.setHasPermission(hasPermission);
    
    hero.setTickHandler((entity, manager) => {
    });
}

function webSwingingKey(player, manager) {
    var flag = player.getData("fiskheroes:web_swinging");
    
    if (!flag) {
        manager.setDataWithNotify(player, "fiskheroes:prev_utility_belt_type", player.getData("fiskheroes:utility_belt_type"));
        manager.setDataWithNotify(player, "fiskheroes:utility_belt_type", -1);
    }
    
    manager.setDataWithNotify(player, "fiskheroes:web_swinging", !flag);
    return true;
}

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

function isKeyBindEnabled(entity, keyBind) {
	switch (keyBind) {
    case "SHIELD_THROW":
        return entity.getHeldItem().name() == "fiskheroes:captain_americas_shield"
    case "SUPER_SPEED":
        return !entity.getData("fiskheroes:flying");
    default:
        return true;
    }
}

function hasPermission(entity, permission) {
    return permission == "USE_SHIELD";
}
