-- name: [CS] Bob Belcher
-- description: It's not that bad just do it bro\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] Bob Belcher"

-- 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_MODEL_CUSTOM_MODEL = smlua_model_util_get_id("bob_geo") -- Located in "actors"

local TEX_CUSTOM_LIFE_ICON = get_texture_info("bob_icon") -- Located in "textures"

-- All Located in "sound"
local VOICETABLE_BOB = {
    --[CHAR_SOUND_OKEY_DOKEY] = 'Silent.ogg', -- Starting game
	[CHAR_SOUND_LETS_A_GO] = 'lets go.ogg', -- Starting level
	[CHAR_SOUND_PUNCH_YAH] = 'yah.ogg', -- Punch 1
	[CHAR_SOUND_PUNCH_WAH] = 'wah.ogg', -- Punch 2
	[CHAR_SOUND_PUNCH_HOO] = 'hoo kick.ogg', -- Punch 3
	[CHAR_SOUND_YAH_WAH_HOO] = {'yah.ogg', 'wah.ogg', 'hoo jump.ogg'}, -- First/Second jump sounds
	[CHAR_SOUND_HOOHOO] = 'double jump.ogg', -- Third jump sound
	[CHAR_SOUND_YAHOO_WAHA_YIPPEE] = {'waha.ogg', 'yippee.ogg'}, -- Triple jump sounds
	[CHAR_SOUND_UH] = 'ungh.ogg', -- Wall bonk
	[CHAR_SOUND_UH2] = 'ungh.ogg', -- Landing after long jump
	[CHAR_SOUND_UH2_2] = 'ungh.ogg', -- Same sound as UH2; jumping onto ledge
	[CHAR_SOUND_HAHA] = 'haha.ogg', -- Landing triple jump
	[CHAR_SOUND_YAHOO] = 'yahoo.ogg', -- Long jump
	[CHAR_SOUND_DOH] = 'aah.ogg', -- Long jump wall bonk
	[CHAR_SOUND_WHOA] = 'woah.ogg', -- Grabbing ledge
	[CHAR_SOUND_EEUH] = 'eeyugh.ogg', -- Climbing over ledge
	[CHAR_SOUND_WAAAOOOW] = 'falling.ogg', -- Falling a long distance
	[CHAR_SOUND_TWIRL_BOUNCE] = 'boing.ogg', -- Bouncing off of a flower spring
	[CHAR_SOUND_GROUND_POUND_WAH] = 'ungh.ogg', 
	[CHAR_SOUND_HRMM] = 'picking up.ogg', -- Lifting something
	[CHAR_SOUND_HERE_WE_GO] = 'here we go.ogg', -- Star get
	[CHAR_SOUND_SO_LONGA_BOWSER] = 'its me bob burger.ogg', -- Throwing Bowser
--DAMAGE
	[CHAR_SOUND_ATTACKED] = 'aah.ogg', -- Damaged
	[CHAR_SOUND_PANTING] = 'low health.ogg', -- Low health
	[CHAR_SOUND_ON_FIRE] = 'burning.ogg', -- Burned
--SLEEP SOUNDS
	[CHAR_SOUND_IMA_TIRED] = 'Silent.ogg', -- Mario feeling tired
	[CHAR_SOUND_YAWNING] = 'wii.ogg', -- Mario yawning before he sits down to sleep
	[CHAR_SOUND_SNORING1] = 'wii.ogg', -- Snore Inhale
	[CHAR_SOUND_SNORING2] = 'wii.ogg', -- Exhale
	[CHAR_SOUND_SNORING3] = 'Silent.ogg', -- Sleep talking / mumbling
--COUGHING (USED IN THE GAS MAZE)
	[CHAR_SOUND_COUGHING1] = 'wii.ogg', -- Cough take 1
	[CHAR_SOUND_COUGHING2] = 'wii.ogg', -- Cough take 2
	[CHAR_SOUND_COUGHING3] = 'wiit.ogg', -- Cough take 3
--DEATH
	[CHAR_SOUND_DYING] = 'oh my god death.ogg', -- Dying from damage
	[CHAR_SOUND_DROWNING] = 'oh my god death.ogg', -- Running out of air underwater
	[CHAR_SOUND_MAMA_MIA] = 'oh my god get up.ogg' -- Booted out of level
}

local CSloaded = false
local function on_character_select_load()
    CT_BOB = _G.charSelect.character_add("Bob Belcher", {"Don't feed a guy a sponge, Bobby"}, "packrcrackr", {r = 229, g = 229, b = 229}, E_MODEL_CUSTOM_MODEL, CT_MARIO, TEX_CUSTOM_LIFE_ICON)
    _G.charSelect.character_add_caps(E_MODEL_CUSTOM_MODEL, CAPTABLE_CHAR)
    _G.charSelect.character_add_voice(E_MODEL_CUSTOM_MODEL, VOICETABLE_BOB)
    _G.charSelect.character_add_celebration_star(E_MODEL_CUSTOM_MODEL, E_MODEL_CUSTOM_STAR, TEX_CUSTOM_STAR_ICON)

    CSloaded = true
end

local function on_character_sound(m, sound)
    if not CSloaded then return end
    if _G.charSelect.character_get_voice(m) == VOICETABLE_BOB 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_BOB 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)


local function stop_torso_tilt(m)
    if (CT_BOB == _G.charSelect.character_get_current_number(m.playerIndex)) then
        if m.action == ACT_WALKING then
            m.marioBodyState.torsoAngle.x = 0
            m.marioBodyState.torsoAngle.z = 0
            m.marioBodyState.torsoAngle.y = 0
        end
    end
end

hook_event(HOOK_MARIO_UPDATE, stop_torso_tilt)
