Go to most recent revision | Compare with Previous | Blame | View Log
--[[ Addon: Taos Group Ultimate Author: TProg Taonnor Created by @Taonnor ]]-- --[[ Global variables ]]-- local DEBUG_ACTIVE = true local REFRESHRATE = 1000 -- ms; RegisterForUpdate is in miliseconds local REFRESHTIME = 1 -- seconds; GetTimeStamp() difference is in seconds local ACTION_BAR_ULTIMATE_SLOT_INDEX = ACTION_BAR_ULTIMATE_SLOT_INDEX + 1 -- 8, the constant is 7, but its wrong local ABILITY_COEFFICIENT = 100000 local ULTIMATE_COEFFICIENT = 1000 --[[ Class MapPingHandler ]]-- MapPingHandler = {} --[[ Class Members ]]-- MapPingHandler.Name = "TGU-MapPingHandler" MapPingHandler.LastMapPingTimestamp = GetTimeStamp() -- Timestamp is in seconds --[[ Called on map ping ]]-- function MapPingHandler.OnMapPing(eventCode, pingEventType, pingType, pingTag, offsetX, offsetY, isLocalPlayerOwner) logDebug("MapPingHandler.OnMapPing()") logDebug("pingType", pingType) logDebug("pingTag", pingTag) logDebug("offsetX", offsetX) logDebug("offsetY", offsetY) if (pingType == MAP_PIN_TYPE_PING and MapPingHandler.IsPossiblePing(offsetX, offsetY)) then local senderGroupNumber = string.sub(pingTag, string.len(pingTag)) local isUnitDead = IsUnitDead(pingTag) local abilityID = math.floor((offsetX * ABILITY_COEFFICIENT) + 0.5) local relativeUltimate = math.floor((offsetY * ULTIMATE_COEFFICIENT) + 0.5) local ultimateName = GetAbilityName(abilityID):gsub("%^n", ""):gsub("%^f", ""):gsub("%^m", "") -- GetAbilityIcon(number abilityId) -> Icon?! logDebug("senderGroupNumber", senderGroupNumber) logDebug("isUnitDead", isUnitDead) logDebug("abilityID", abilityID) logDebug("relativeUltimate", relativeUltimate) logDebug("ultimateName", ultimateName) CALLBACK_MANAGER:FireCallbacks("TGU-MapPingChanged", senderGroupNumber, ultimateName, relativeUltimate, isUnitDead) end end --[[ Called on refresh of timer ]]-- function MapPingHandler.OnTimedUpdate(eventCode) if (IsUnitGrouped("player") == false) then return end -- only if player is in group local current, max, effective_max = GetUnitPower("player", POWERTYPE_ULTIMATE) local currentTimestamp = GetTimeStamp() -- Timestamp is in seconds if ((currentTimestamp - MapPingHandler.LastMapPingTimestamp) > REFRESHTIME) then local abilityID = MapPingHandler.GetConfiguratedUltimate() local abilityCost = math.max(1, GetAbilityCost(abilityID)) local relativeUltimate = math.floor((current / abilityCost) * 100) if (relativeUltimate > 100) then relativeUltimate = 100 end local abilityPing = abilityID / ABILITY_COEFFICIENT local ultimatePing = relativeUltimate / ULTIMATE_COEFFICIENT logDebug("abilityPing", abilityPing) logDebug("ultimatePing", ultimatePing) PingMap(MAP_PIN_TYPE_PING, MAP_TYPE_LOCATION_CENTERED, abilityPing, ultimatePing) MapPingHandler.LastMapPingTimestamp = GetTimeStamp() end end --[[ Check if map ping is in possible range ]]-- function MapPingHandler.IsPossiblePing(offsetX, offsetY) local isValidPing = (offsetX ~= 0 and offsetY ~= 0) local isCorrectOffsetX = (offsetX >= 0.01 and offsetX <= 1.00) local isCorrectOffsetY = (offsetY >= 0.00 and offsetY <= 0.11) return isValidPing and (isCorrectOffsetX and isCorrectOffsetY) end function MapPingHandler.GetConfiguratedUltimate() return GetSlotBoundId(ACTION_BAR_ULTIMATE_SLOT_INDEX) end --[[ Initialize initializes MapPingHandler ]]-- function MapPingHandler.Initialize() -- Register events EVENT_MANAGER:RegisterForEvent(MapPingHandler.Name, EVENT_MAP_PING, MapPingHandler.OnMapPing) -- Start timer EVENT_MANAGER:RegisterForUpdate(MapPingHandler.Name, REFRESHRATE, MapPingHandler.OnTimedUpdate) end