local P=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")function GameMode.OnPlayerQuitRequest(C,P,E)C:d("\079\110\080\108\097\121\101\114\081\117\105\116\082\101\113\117\101\115\116",{player=P:GetPlayerID(),payload=E})SendToServerConsole("\100\105\115\099\111\110\110\101\099\116")end function GameMode.OnCombosReload(C,P,E)C:d("\079\110\067\111\109\098\111\115\082\101\108\111\097\100",{player=P:GetPlayerID(),payload=E})C.combos:load()end function GameMode.OnComboStart(C,P,E)C:d("\079\110\067\111\109\098\111\083\116\097\114\116",{player=P:GetPlayerID();payload=E})local u=C.combos:Create(E.id)C.combos:Start(P,u)end function GameMode.OnComboStop(C,P,E)C:d("\079\110\067\111\109\098\111\083\116\111\112",{player=P:GetPlayerID(),payload=E})C.combos:Stop(P)end function GameMode.OnComboRestart(C,P,E)C:d("\079\110\067\111\109\098\111\082\101\115\116\097\114\116",{player=P:GetPlayerID();payload=E})local u={hardReset=E.hardReset==1}C.combos:Restart(P,u)end function GameMode.OnFreestyleHeroLevelUp(C,P,E)C:d("\079\110\070\114\101\101\115\116\121\108\101\072\101\114\111\076\101\118\101\108\085\112",{player=P:GetPlayerID(),payload=E})local u={level=E.level;maxLevel=E.maxLevel==1}C.combos:FreestyleHeroLevelUp(P,u)end function GameMode.OnCombatLogCaptureStart(C,P,E)C:d("\079\110\067\111\109\098\097\116\076\111\103\067\097\112\116\117\114\101\083\116\097\114\116",{player=P:GetPlayerID();payload=E})C.combos:StartCapturingAbilities(P)end function GameMode.OnCombatLogCaptureStop(C,P,E)C:d("\079\110\067\111\109\098\097\116\076\111\103\067\097\112\116\117\114\101\083\116\111\112",{player=P:GetPlayerID(),payload=E})C.combos:StopCapturingAbilities(P)end function GameMode.OnItemPickerQuery(u,E,C)u:d("\079\110\073\116\101\109\080\105\099\107\101\114\081\117\101\114\121",{player=E:GetPlayerID(),payload=C})local F={items=u.itemsKV:Search(C.query)}P.SendPlayer(P.EVENT_ITEM_PICKER_QUERY_RESPONSE,E,F)end
--- Custom Events Listeners
-- @submodule invokation.GameMode
local CustomEvents = require("invokation.dota2.custom_events")

--- Custom Events Listeners
-- @section custom_events

--- Handles player quit request events.
-- @tparam CDOTAPlayerController player
-- @tparam const.custom_events.PlayerQuitRequest payload
function GameMode:OnPlayerQuitRequest(player, payload)
  self:d("OnPlayerQuitRequest", { player = player:GetPlayerID(), payload = payload })

  SendToServerConsole("disconnect")
end

--- Handles combos reload events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.CombosReloadPayload payload
function GameMode:OnCombosReload(player, payload)
  self:d("OnCombosReload", { player = player:GetPlayerID(), payload = payload })
  self.combos:load()
end

--- Handles combo start events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.ComboStartPayload payload
function GameMode:OnComboStart(player, payload)
  self:d("OnComboStart", { player = player:GetPlayerID(), payload = payload })

  local combo = self.combos:Create(payload.id)

  self.combos:Start(player, combo)
end

--- Handles combo stop events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.ComboStopPayload payload
function GameMode:OnComboStop(player, payload)
  self:d("OnComboStop", { player = player:GetPlayerID(), payload = payload })

  self.combos:Stop(player)
end

--- Handles combo restart events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.ComboRestartPayload payload
function GameMode:OnComboRestart(player, payload)
  self:d("OnComboRestart", { player = player:GetPlayerID(), payload = payload })

  local options = { hardReset = payload.hardReset == 1 }

  self.combos:Restart(player, options)
end

--- Handles freestyle hero level up events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.FreestyleHeroLevelUpPayload payload
function GameMode:OnFreestyleHeroLevelUp(player, payload)
  self:d("OnFreestyleHeroLevelUp", { player = player:GetPlayerID(), payload = payload })

  local options = { level = payload.level, maxLevel = payload.maxLevel == 1 }

  self.combos:FreestyleHeroLevelUp(player, options)
end

--- Handles combat log capture start events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.CombatLogCaptureStartPayload payload
function GameMode:OnCombatLogCaptureStart(player, payload)
  self:d("OnCombatLogCaptureStart", { player = player:GetPlayerID(), payload = payload })

  self.combos:StartCapturingAbilities(player)
end

--- Handles combat log capture stop events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.CombatLogCaptureStopPayload payload
function GameMode:OnCombatLogCaptureStop(player, payload)
  self:d("OnCombatLogCaptureStop", { player = player:GetPlayerID(), payload = payload })

  self.combos:StopCapturingAbilities(player)
end

--- Handles item picker query events.
-- @tparam CDOTAPlayer player
-- @tparam const.custom_events.ItemPickerQueryPayload payload
function GameMode:OnItemPickerQuery(player, payload)
  self:d("OnItemPickerQuery", { player = player:GetPlayerID(), payload = payload })

  local response = { items = self.itemsKV:Search(payload.query) }

  CustomEvents.SendPlayer(CustomEvents.EVENT_ITEM_PICKER_QUERY_RESPONSE, player, response)
end
