--HunterBindings: HunterBindings = {}; HunterBindings.setup = { debuffSlots = 0; }; HunterBindings.setup.spells = {}; function HunterBindings_OnEvent() if ( event == "SPELLS_UPDATED" ) then HunterBindings_UpdateSpells(); return; end if ( event == "RAID_ROSTER" ) then HunterBindings.setup.debuffSlots = HunterBindings_CalculateDebuffSlots() return; end end function HunterBindings_UpdateSpells() end function HunterBindings_GetSpellId(name, rank, spellBook) local i = 1; if ( not spellBook ) then spellBook = "spell"; if ( rank == "pet" ) then spellBook = rank; rank = nil; end if ( rank == "spell" ) then spellBook = rank; rank = nil; end end local rankNumber = tonumber(rank); local spellName,rankName = "",""; local tmp; for i = 1, HUNTERBINDINGS_MAX_SPELLS, 1 do spellName, rankName = GetSpellName(i, spellBook); if ( not spellName ) then break; end if ( name == spellName ) then if ( not rank ) or ( rank == rankName ) then return i, spellBook; elseif ( rankNumber ) then _,_, tmp = string.find(HUNTERBINDINGS_RANK_FORMAT, rankName) end end end return nil, nil; end function HunterBindings_GetTargetByChain(baseUnit) local unit = baseUnit; while ( UnitIsFriendly(unit) ) do unit = unit .. "target"; if ( not UnitExists(unit) ) then return nil; end end return unit; end function HunterBindings_MarkPetAttackUnit(unit, startToShoot) local realUnit = HunterBindings_GetTargetByChain(unit); if ( not realUnit ) then -- ERROR message? return; end if ( realUnit ~= unit ) then TargetUnit(realUnit); end local hasAttemptedToCast = false; if ( not HunterBindings_IsUnitMarked(realUnit) ) then CastSpellName(HUNTERBINDINGS_HUNTERS_MARK); hasAttemptedToCast = true; --SpellTargetUnit(realUnit); end if ( UnitExists("pet") ) then PetAttack(); end if ( startToShoot ) and ( not HunterBindings_IsAutoShooting() ) then CastSpellName(HUNTERBINDINGS_AUTO_SHOT); hasAttemptedToCast = true; -- really? end if ( startToShoot ) and ( not hasAttemptedToCast ) then hasAttemptedToCast = HunterBindings_StingUnit(unit); end if ( realUnit ~= unit ) then TargetUnit(unit); end end function HunterBindings_IsAutoShooting() return false; end function HunterBindings_GoodToUseSerpentSting() local raidMembers = GetNumRaidMembers(); if ( raidMembers <= 0 ) then return true; else return ( HunterBindings.setup.debuffSlots < 16 ); end end HunterBindings_RaidDebuffSlots = {}; function HunterBindings_CalculateDebuffSlots() local members = GetNumRaidMembers(); local idList = HUNTERBINDINGS_RAID_IDS; if ( members <= 0 ) then members = GetNumPartyMembers(); idList = HUNTERBINDINGS_PARTY_IDS; end if ( members <= 0 ) then return 0; end local debuffs = 0; local class = ""; for k, v in pairs(HunterBindings_GlobalDebuffSlots) do HunterBindings_RaidDebuffSlots[k] = 0; end for i = 1, members, 1 do _, class = UnitClass(idList[i]); debuffs = debuffs + HUNTERBINDINGS_DEBUFFS_PER_CLASS[class]; HunterBindings_RaidDebuffSlots[class] = HUNTERBINDINGS_DEBUFFS_PER_CLASS_GLOBAL[class]; end for k, v in pairs(HunterBindings_RaidDebuffSlots) do debuffs = debuffs + v; end return debuffs; end function HunterBindings_StingUnit(unit) if ( UnitPowerType(unit) == 0 ) then if ( not HunterBindings_HasUnitDebuff(unit, HUNTERBINDINGS_VIPER_STING_ICON, HUNTERBINDINGS_VIPER_STING) ) then CastSpellByName(HUNTERBINDINGS_VIPER_STING); return true; end end if ( not HunterBindings_HasUnitDebuff(unit, HUNTERBINDINGS_SCORPID_STING_ICON, HUNTERBINDINGS_SCORPID_STING) ) then CastSpellByName(HUNTERBINDINGS_SCORPID_STING); return true; end if ( HunterBindings_GoodToUseSerpentSting() ) then CastSpellByName(HUNTERBINDINGS_SERPENT_STING); return true; end return false; end function HunterBindings_IsUnitMarked(unit) return HunterBindings_HasUnitDebuff(unit, HUNTERBINDINGS_HUNTERS_MARK_ICON, HUNTERBINDINGS_HUNTERS_MARK); end function HunterBindings_HasUnitDebuff(unit, texture, name) local index = 1; while ( index ) do index = HunterBindings_GetUnitDebuffIndex(unit, texture, index); if ( index ) then HunterBindingsTooltip:SetUnitDebuff(unit, index); if ( name == HunterBindingsTooltipTextLeft1:GetText() ) then return true; end index = index + 1; end end return false; end function HunterBindings_GetUnitDebuffIndex(unit, texture, startIndex) if ( not unit ) or ( not texture ) or ( not UnitExists(unit) ) then return nil; end if ( not startIndex ) then startIndex = 1; end local tmp; for i = startIndex, MAX_TARGET_DEBUFFS, 1 do tmp = UnitDebuff(unit, i); if ( not tmp ) then return nil; elseif ( tmp == texture ) then return i; end end return nil; end function HunterBindings_PetAttackUnit(unit) local realUnit = HunterBindings_GetTargetByChain(unit); if ( unit ~= realUnit ) and ( realUnit ) then TargetUnit(realUnit); PetAttack(); TargetUnit(unit); else PetAttack(); end end --[[ Macros for Hunter: Assist ]]--