syzler@1: -- libMyLilPony syzler@1: -- Copyright (c) 2011 Syzler syzler@1: -- syzler@1: -- This program is free software: you can redistribute it and/or modify syzler@1: -- it under the terms of the GNU General Public License as published by syzler@1: -- the Free Software Foundation, either version 3 of the License, or syzler@1: -- (at your option) any later version. syzler@1: -- syzler@1: -- This program is distributed in the hope that it will be useful, syzler@1: -- but WITHOUT ANY WARRANTY; without even the implied warranty of syzler@1: -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the syzler@1: -- GNU General Public License for more details. syzler@1: -- syzler@1: -- You should have received a copy of the GNU General Public License syzler@1: -- along with this program. If not, see . syzler@1: syzler@1: -- Misc helper functions used in the library syzler@1: syzler@7: --- Gets a hashtable of buffs on the specified unit. syzler@7: -- @param unit The unit frame name (e.g. "target", "player", "focus") of the unit whose buffs are to be retrieved. syzler@7: -- @returns a hashtable of buff spell IDs keyed on the ID. syzler@1: function MyLilPony.GetUnitBuffs(unit) syzler@1: local buffs = {}; syzler@1: for i = 1, 40 do syzler@1: local _, _, _, _, _, _, _, _, _, _, id = UnitAura(unit, i, "HELPFUL"); syzler@1: if id ~= nil then syzler@1: buffs[id] = id; syzler@1: end syzler@1: end syzler@1: return buffs; syzler@1: end syzler@1: syzler@7: --- Performs case-insensitive string pattern matching. syzler@7: -- @param subject The string on which the pattern matching is performed. syzler@7: -- @param pattern The pattern to be matched. syzler@7: -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match. syzler@1: function MyLilPony.StringMatchIgnoreCase(subject, pattern) syzler@1: if subject == nil and pattern == nil then return true end syzler@1: if subject == nil or pattern == nil then return false end syzler@1: local lSub = string.lower(subject); syzler@1: local lPat = string.lower(pattern); syzler@1: return string.match(lSub, lPat); syzler@1: end syzler@1: syzler@7: --- Calls a companion if a specified condition checks out. syzler@7: -- @param companionType The type of companion to be called (e.g. "MOUNT"). syzler@7: -- @param companionNumber The slot number of the companion to be called. syzler@7: -- @param condition An optional Boolean condition. syzler@1: function MyLilPony.CallCompanion(companionType, companionNumber, condition) syzler@1: if condition == nil or condition then syzler@1: CallCompanion(companionType, companionNumber); syzler@1: end syzler@1: end syzler@1: syzler@7: --- Gets a value indicating whether or not the current character is able to fly at the current location. syzler@7: -- 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). syzler@7: -- @returns A Boolean value indicating whether or not the current character is able to fly at the current location. syzler@1: function MyLilPony.CanFlyHere() syzler@1: if IsFlyableArea() then syzler@1: SetMapToCurrentZone(); syzler@1: local continent = GetCurrentMapContinent(); syzler@1: if continent == 4 then syzler@1: -- Northrend: requires Cold Weather Flying syzler@1: return IsSpellKnown(54197); syzler@1: elseif (continent == 1 or continent == 2) then syzler@1: -- Old World: requires Flight Master's License syzler@1: return IsSpellKnown(90267); syzler@1: end syzler@1: return true; syzler@1: end syzler@1: return false; syzler@1: end syzler@1: syzler@1: function MyLilPony.Print(msg) syzler@1: DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..msg); syzler@1: end syzler@1: syzler@1: function MyLilPony.Log(msg) syzler@1: if MYLILPONY_DEBUG_LOGGING then syzler@1: DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..format("MyLilPony: %s", msg)); syzler@1: end syzler@1: end