local h=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\099\117\115\116\111\109\095\101\118\101\110\116\115")local Y={}local function q(h)return{count=h.count;damage=h.damage,duration=h.duration}end function Y.sendAbilityUsed(Y,q)local t={ability=q.name}return h.SendPlayer(h.EVENT_COMBAT_LOG_ABILITY_USED,Y,t)end function Y.sendStarted(Y,q)local t={id=q.id,next=q:NextStepsIds()}return h.SendPlayer(h.EVENT_COMBO_STARTED,Y,t)end function Y.sendStopped(Y,q)local t={id=q.id}return h.SendPlayer(h.EVENT_COMBO_STOPPED,Y,t)end function Y.sendInProgress(Y,q)local t={id=q.id}return h.SendPlayer(h.EVENT_COMBO_IN_PROGRESS,Y,t)end function Y.sendProgress(Y,t)local I={id=t.id,metrics=q(t),next=t:NextStepsIds()}return h.SendPlayer(h.EVENT_COMBO_PROGRESS,Y,I)end function Y.sendStepError(Y,q,t)local I={id=q.id;expected=q:NextStepsIds();ability=t.name}return h.SendPlayer(h.EVENT_COMBO_STEP_ERROR,Y,I)end function Y.sendPreFinish(Y,t)local I={id=t.id,metrics=q(t);wait=t.waitDuration}return h.SendPlayer(h.EVENT_COMBO_PRE_FINISH,Y,I)end function Y.sendFinished(Y,t)local I={id=t.id,metrics=q(t)}return h.SendPlayer(h.EVENT_COMBO_FINISHED,Y,I)end return Y
--- Internal combos communication helpers.
-- @module invokation.combos.communication
local CustomEvents = require("invokation.dota2.custom_events")

local M = {}

local function comboMetrics(combo)
  return { count = combo.count, damage = combo.damage, duration = combo.duration }
end

--- Sends a custom event notifying that an ability was used.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam dota2.Ability ability Ability
function M.sendAbilityUsed(player, ability)
  local payload = { ability = ability.name }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBAT_LOG_ABILITY_USED, player, payload)
end

--- Sends a custom event notifying that a combo started.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
function M.sendStarted(player, combo)
  local payload = { id = combo.id, next = combo:NextStepsIds() }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_STARTED, player, payload)
end

--- Sends a custom event notifying that a combo stopped.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
function M.sendStopped(player, combo)
  local payload = { id = combo.id }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_STOPPED, player, payload)
end

--- Sends a custom event notifying that a combo is in progress.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
function M.sendInProgress(player, combo)
  local payload = { id = combo.id }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_IN_PROGRESS, player, payload)
end

--- Sends a custom event notifying that a combo progressed.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
function M.sendProgress(player, combo)
  local payload = { id = combo.id, metrics = comboMetrics(combo), next = combo:NextStepsIds() }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_PROGRESS, player, payload)
end

--- Sends a custom event notifying about a combo step error.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
-- @tparam dota2.Ability ability Ability used that caused the error
function M.sendStepError(player, combo, ability)
  local payload = { id = combo.id, expected = combo:NextStepsIds(), ability = ability.name }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_STEP_ERROR, player, payload)
end

--- Sends a custom event notifying that a combo entered pre-finish state.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
function M.sendPreFinish(player, combo)
  local payload = { id = combo.id, metrics = comboMetrics(combo), wait = combo.waitDuration }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_PRE_FINISH, player, payload)
end

--- Sends a custom event notifying that a combo finished.
-- @tparam CDOTAPlayer player Player to send the event to
-- @tparam Combo combo Combo
function M.sendFinished(player, combo)
  local payload = { id = combo.id, metrics = comboMetrics(combo) }

  return CustomEvents.SendPlayer(CustomEvents.EVENT_COMBO_FINISHED, player, payload)
end

return M
