-- name: [CS] Better Junio Sonic
-- description: Toot Toot Sonic Warrior!\n\n\\#ff7777\\This Pack requires Character Select\nto use as a Library!

--[[
    API Documentation for Character Select can be found below:
    https://github.com/Squishy6094/character-select-coop/wiki/API-Documentation

    Use this if you're curious on how anything here works >v<
]]

local TEXT_MOD_NAME = "[CS] Better Junio Sonic"

-- Stops mod from loading if Character Select isn't on
if not _G.charSelectExists then
    djui_popup_create("\\#ffffdc\\\n"..TEXT_MOD_NAME.."\nRequires the Character Select Mod\nto use as a Library!\n\nPlease turn on the Character Select Mod\nand Restart the Room!", 6)
    return 0
end

local E_SONIC_MODEL = smlua_model_util_get_id("tsonic_geo")
local E_WASH_MODEL = smlua_model_util_get_id("wash_geo")
local E_STAFF_MODEL = smlua_model_util_get_id("staff_geo")
local E_SUPER_MODEL = smlua_model_util_get_id("super_geo")

local TEX_SONIC_ICON = get_texture_info("tsonic_icon")

local VOICETABLE_TSONIC = {
    --[CHAR_SOUND_OKEY_DOKEY] = 'yiss.ogg', -- Starting game
	[CHAR_SOUND_LETS_A_GO] = 'alright.ogg', -- Starting level
	[CHAR_SOUND_PUNCH_YAH] = 'hih.ogg', -- Punch 1
	[CHAR_SOUND_PUNCH_WAH] = 'hah.ogg', -- Punch 2
	[CHAR_SOUND_PUNCH_HOO] = 'wah.ogg', -- Punch 3
	[CHAR_SOUND_YAH_WAH_HOO] = {'jump.ogg', 'jump.ogg', 'jump.ogg'}, -- First/Second jump sounds
	[CHAR_SOUND_HOOHOO] = 'yea.ogg', -- Third jump sound
	[CHAR_SOUND_YAHOO_WAHA_YIPPEE] = {'shoo.ogg', 'alright.ogg'}, -- Triple jump sounds
	[CHAR_SOUND_UH] = 'crunch.ogg', -- Wall bonk
	[CHAR_SOUND_UH2] = 'ghm.ogg', -- Landing after long jump
	[CHAR_SOUND_UH2_2] = 'ghm.ogg', -- Same sound as UH2; jumping onto ledge
	[CHAR_SOUND_HAHA] = 'yiss.ogg', -- Landing triple jump
	[CHAR_SOUND_YAHOO] = 'shoo.ogg', -- Long jump
	[CHAR_SOUND_DOH] = 'shit.ogg', -- Long jump wall bonk
	[CHAR_SOUND_WHOA] = 'wah.ogg', -- Grabbing ledge
	[CHAR_SOUND_EEUH] = 'aagh.ogg', -- Climbing over ledge
	[CHAR_SOUND_WAAAOOOW] = 'fall.ogg', -- Falling a long distance
	[CHAR_SOUND_TWIRL_BOUNCE] = 'jump.ogg', -- Bouncing off of a flower spring
	[CHAR_SOUND_GROUND_POUND_WAH] = 'ghm.ogg', 
	[CHAR_SOUND_HRMM] = 'grunt.ogg', -- Lifting something
	[CHAR_SOUND_HERE_WE_GO] = 'alright.ogg', -- Star get
	[CHAR_SOUND_SO_LONGA_BOWSER] = 'bowser.ogg', -- Throwing Bowser
--DAMAGE
	[CHAR_SOUND_ATTACKED] = 'shit.ogg', -- Damaged
	[CHAR_SOUND_PANTING] = 'pant.ogg', -- Low health
	[CHAR_SOUND_ON_FIRE] = 'gyatt.ogg', -- Burned
--SLEEP SOUNDS
	[CHAR_SOUND_IMA_TIRED] = 'outta.ogg', -- Mario feeling tired
	[CHAR_SOUND_YAWNING] = 'Silent.ogg', -- Mario yawning before he sits down to sleep
	[CHAR_SOUND_SNORING1] = 'Silent.ogg', -- Snore Inhale
	[CHAR_SOUND_SNORING2] = 'Silent.ogg', -- Exhale
	[CHAR_SOUND_SNORING3] = 'Silent.ogg', -- Sleep talking / mumbling
--COUGHING (USED IN THE GAS MAZE)
	[CHAR_SOUND_COUGHING1] = 'Silent.ogg', -- Cough take 1
	[CHAR_SOUND_COUGHING2] = 'Silent.ogg', -- Cough take 2
	[CHAR_SOUND_COUGHING3] = 'Silent.ogg', -- Cough take 3
--DEATH
	[CHAR_SOUND_DYING] = 'die.ogg', -- Dying from damage
	[CHAR_SOUND_DROWNING] = 'drown.ogg', -- Running out of air underwater
	[CHAR_SOUND_MAMA_MIA] = 'outta.ogg' -- Booted out of level
}

local CSloaded = false
local function on_character_select_load()
    CT_SONIC = _G.charSelect.character_add("Eguchi Sonic", {"Model by packrcrackr, voice and textures by Stick Nick"}, "packrcrackr", {r = 35, g = 75, b = 170}, E_SONIC_MODEL, CT_MARIO, TEX_SONIC_ICON)
    _G.charSelect.character_add_caps(E_SONIC_MODEL, CAPTABLE_CHAR)
    _G.charSelect.character_add_voice(E_SONIC_MODEL, VOICETABLE_TSONIC)
    
    _G.charSelect.character_add_costume(CT_SONIC, "Eguchi Sonic - alt", nil, "packrcrackr, Stick Nick", nil, E_WASH_MODEL, CT_MARIO, TEX_SONIC_ICON, nil, nil)
    _G.charSelect.character_add_voice(E_WASH_MODEL, VOICETABLE_TSONIC)

    _G.charSelect.character_add_costume(CT_SONIC, "Staff Room Sonic", nil, "packrcrackr, Stick Nick", nil, E_STAFF_MODEL, CT_MARIO, TEX_SONIC_ICON, nil, nil)
	_G.charSelect.character_add_voice(E_STAFF_MODEL, VOICETABLE_TSONIC)

	_G.charSelect.character_add_costume(CT_SONIC, "Super Sonic", nil, "packrcrackr, Stick Nick", nil, E_SUPER_MODEL, CT_MARIO, TEX_SONIC_ICON, nil, nil)
	_G.charSelect.character_add_voice(E_SUPER_MODEL, VOICETABLE_TSONIC)

    CSloaded = true
end

local function on_character_sound(m, sound)
    if not CSloaded then return end
    if _G.charSelect.character_get_voice(m) == VOICETABLE_TSONIC then return _G.charSelect.voice.sound(m, sound) end
end

local function on_character_snore(m)
    if not CSloaded then return end
    if _G.charSelect.character_get_voice(m) == VOICETABLE_TSONIC then return _G.charSelect.voice.snore(m) end
end

hook_event(HOOK_ON_MODS_LOADED, on_character_select_load)
hook_event(HOOK_CHARACTER_SOUND, on_character_sound)
hook_event(HOOK_MARIO_UPDATE, on_character_snore)