local h=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\115\111\117\110\100\095\101\118\101\110\116\115")local Y={}local q={IDLE={STATUS=DOTA_MUSIC_STATUS_PRE_GAME_EXPLORATION,INTENSITY=1.0};BATTLE={STATUS=DOTA_MUSIC_STATUS_BATTLE,INTENSITY=5.0},VICTORY={STATUS=DOTA_MUSIC_STATUS_EXPLORATION,INTENSITY=10.0},DEFEAT={STATUS=DOTA_MUSIC_STATUS_DEAD;INTENSITY=10.0}}local function t(h)return h[RandomInt(1,#h)]end function Y.emitRandomEventOnEntity(Y,q)return h.EmitOnEntity(t(q),Y)end function Y.emitRandomEventOnPlayer(Y,q)return h.EmitOnPlayer(t(q),Y)end function Y.onDummyCreate(q)Y.emitRandomEventOnEntity(q.entity,h.SNDEVTS_DUMMY_CREATE)end function Y.onComboStart(h)h:SetMusicStatus(q.BATTLE.STATUS,q.BATTLE.INTENSITY)end function Y.onComboStop(h)h:SetMusicStatus(q.IDLE.STATUS,q.IDLE.INTENSITY)end function Y.onComboStepError(h)h:SetMusicStatus(q.DEFEAT.STATUS,q.DEFEAT.INTENSITY)end function Y.onComboFinished(h)h:SetMusicStatus(q.VICTORY.STATUS,q.VICTORY.INTENSITY)end return Y
--- Internal combos sound helpers.
-- @module invokation.combos.sound
local SoundEvents = require("invokation.dota2.sound_events")

local M = {}

local MUSIC = {
  IDLE = { STATUS = DOTA_MUSIC_STATUS_PRE_GAME_EXPLORATION, INTENSITY = 1.0 },
  BATTLE = { STATUS = DOTA_MUSIC_STATUS_BATTLE, INTENSITY = 5.0 },
  VICTORY = { STATUS = DOTA_MUSIC_STATUS_EXPLORATION, INTENSITY = 10.0 },
  DEFEAT = { STATUS = DOTA_MUSIC_STATUS_DEAD, INTENSITY = 10.0 },
}

local function randomSoundEvent(events)
  return events[RandomInt(1, #events)]
end

--- Emits a random event on entity.
-- @tparam CBaseEntity entity
-- @tparam {string,...} events Array of event names from which to get a random sample
function M.emitRandomEventOnEntity(entity, events)
  return SoundEvents.EmitOnEntity(randomSoundEvent(events), entity)
end

--- Emits a random event on player.
-- @tparam CDOTAPlayer player
-- @tparam {string,...} events Array of event names from which to get a random sample
function M.emitRandomEventOnPlayer(player, events)
  return SoundEvents.EmitOnPlayer(randomSoundEvent(events), player)
end

--- Sets up sound for when a dummy target unit is created.
-- @tparam dota2.DummyTarget dummy
function M.onDummyCreate(dummy)
  M.emitRandomEventOnEntity(dummy.entity, SoundEvents.SNDEVTS_DUMMY_CREATE)
end

--- Sets up sound for when a player starts a combo.
-- @tparam CDOTAPlayer player
function M.onComboStart(player)
  player:SetMusicStatus(MUSIC.BATTLE.STATUS, MUSIC.BATTLE.INTENSITY)
end

--- Sets up sound for when a player stops a combo.
-- @tparam CDOTAPlayer player
function M.onComboStop(player)
  player:SetMusicStatus(MUSIC.IDLE.STATUS, MUSIC.IDLE.INTENSITY)
end

--- Sets up sound for when a player commits an error in a combo.
-- @tparam CDOTAPlayer player
function M.onComboStepError(player)
  player:SetMusicStatus(MUSIC.DEFEAT.STATUS, MUSIC.DEFEAT.INTENSITY)
end

--- Sets up sound for when a player finishes a combo.
-- @tparam CDOTAPlayer player
function M.onComboFinished(player)
  player:SetMusicStatus(MUSIC.VICTORY.STATUS, MUSIC.VICTORY.INTENSITY)
end

return M
