Mercurial > wow > mylilpony
view libMyLilPony/libMyLilPony_miscFunctions.lua @ 50:22011265a16f 1.2.0-b1
Updated and fixed for draenor xpack (patch 6.0) API changes
author | syzler |
---|---|
date | Sat, 07 Mar 2015 02:52:57 -0500 |
parents | 21764271e02f |
children | 64e8f8e5fa41 |
line wrap: on
line source
-- Copyright (c) 2011, Syzler -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- * Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in -- the documentation and/or other materials provided with the -- distribution. -- * Neither the name of the MyLilPony Project nor the names of its -- contributors may be used to endorse or promote products derived -- from this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------ -- Project: libMyLilPony -- Project Version: @project-version@ -- Last Author: @file-author@ -- Last Updated: @file-date-iso@ -- -- Misc helper functions used in the library ------------------------------------------------------------------------ --- Gets a hashtable of buffs on the specified unit. -- @param unit The unit frame name (e.g. "target", "player", "focus") of the unit whose buffs are to be retrieved. -- @returns a hashtable of buff spell IDs keyed on the ID. function MyLilPony.GetUnitBuffs(unit) local buffs = {}; for i = 1, 40 do local _, _, _, _, _, _, _, _, _, _, id = UnitAura(unit, i, "HELPFUL"); if id ~= nil then buffs[id] = id; end end return buffs; end --- Performs case-sensitive string pattern matching. -- @param subject The string on which the pattern matching is performed. -- @param pattern The pattern to be matched. -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match. function MyLilPony.StringMatch(subject, pattern) if subject == nil and pattern == nil then return true end if subject == nil or pattern == nil then return false end return string.match(subject, pattern); end --- Performs case-insensitive string pattern matching. -- @param subject The string on which the pattern matching is performed. -- @param pattern The pattern to be matched. -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match. function MyLilPony.StringMatchIgnoreCase(subject, pattern) if subject == nil and pattern == nil then return true end if subject == nil or pattern == nil then return false end local lSub = string.lower(subject); local lPat = string.lower(pattern); return string.match(lSub, lPat); end --- Calls a mount if a specified condition checks out. -- @param unused The type of companion to be called (e.g. "MOUNT"). -- @param slotID The slot ID of the mount to be called. -- @param condition An optional Boolean condition. function MyLilPony.CallCompanion(unused, slotID, condition) if condition == nil or condition then C_MountJournal.Summon(slotID); end end --- Iterates over all known and non-hidden (i.e. not dead or opposite faction) mount slot IDs. -- @return A list of valid mount slot IDs. function MyLilPony.EnumerateKnownMountSlotIDs() local countMounts = C_MountJournal.GetNumMounts(); local x = 1; return function() for i = x, countMounts do local _, _, _, _, _, _, _, _, _, hidden, known = C_MountJournal.GetMountInfo(i); if known and not hidden then x = i + 1; return i; end end end end --- Gets a value indicating whether or not the current character is able to fly at the current location. -- This function checks whether or not the current location is a flyable area, and then additionally checks for knowledge of the proper flying skill (e.g. Cold Weather Flying for Northrend). -- @returns A Boolean value indicating whether or not the current character is able to fly at the current location. function MyLilPony.CanFlyHere() if IsFlyableArea() then SetMapToCurrentZone(); local continent = GetCurrentMapContinent(); if continent == 4 then -- Northrend: requires Cold Weather Flying return IsSpellKnown(54197); elseif (continent == 1 or continent == 2) then -- Old World: requires Flight Master's License return IsSpellKnown(90267); end return true; end return false; end function MyLilPony.Print(msg) DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..msg); end function MyLilPony.Log(msg) if MYLILPONY_DEBUG_LOGGING then DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..format("MyLilPony: %s", msg)); end end