syzler@52: -- Copyright (c) 2015, Syzler syzler@14: -- All rights reserved. syzler@1: -- syzler@14: -- Redistribution and use in source and binary forms, with or without syzler@14: -- modification, are permitted provided that the following conditions syzler@14: -- are met: syzler@1: -- syzler@14: -- * Redistributions of source code must retain the above copyright syzler@14: -- notice, this list of conditions and the following disclaimer. syzler@14: -- * Redistributions in binary form must reproduce the above copyright syzler@14: -- notice, this list of conditions and the following disclaimer in syzler@14: -- the documentation and/or other materials provided with the syzler@14: -- distribution. syzler@14: -- * Neither the name of the MyLilPony Project nor the names of its syzler@14: -- contributors may be used to endorse or promote products derived syzler@14: -- from this software without specific prior written permission. syzler@1: -- syzler@14: -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS syzler@14: -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT syzler@14: -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS syzler@14: -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE syzler@14: -- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, syzler@14: -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, syzler@14: -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; syzler@14: -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER syzler@14: -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT syzler@14: -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN syzler@14: -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE syzler@14: -- POSSIBILITY OF SUCH DAMAGE. syzler@1: syzler@15: ------------------------------------------------------------------------ syzler@15: -- Project: libMyLilPony syzler@15: -- Project Version: @project-version@ syzler@15: -- Last Author: @file-author@ syzler@15: -- Last Updated: @file-date-iso@ syzler@15: -- syzler@1: -- Misc helper functions used in the library syzler@15: ------------------------------------------------------------------------ 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@52: -- @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@50: --- Performs case-sensitive string pattern matching. syzler@50: -- @param subject The string on which the pattern matching is performed. syzler@50: -- @param pattern The pattern to be matched. syzler@50: -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match. syzler@50: function MyLilPony.StringMatch(subject, pattern) syzler@50: if subject == nil and pattern == nil then return true end syzler@50: if subject == nil or pattern == nil then return false end syzler@50: return string.match(subject, pattern); syzler@50: end syzler@50: 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@50: --- Calls a mount if a specified condition checks out. syzler@52: -- @param slotID The slot ID of the mount to be called. syzler@52: -- @param condition An optional Boolean condition. syzler@52: -- @returns True if a mount was summoned, or False otherwise. syzler@52: function MyLilPony.CallMount(slotID, condition) syzler@52: if condition == nil or condition then syzler@60: C_MountJournal.SummonByID(slotID); syzler@52: return true; syzler@52: end syzler@52: return false; syzler@52: end syzler@52: syzler@52: --- OBSOLETE. Calls a mount if a specified condition checks out. syzler@50: -- @param unused The type of companion to be called (e.g. "MOUNT"). syzler@50: -- @param slotID The slot ID of the mount to be called. syzler@7: -- @param condition An optional Boolean condition. syzler@50: function MyLilPony.CallCompanion(unused, slotID, condition) syzler@52: MyLilPony.CallMount(slotID, condition); syzler@50: end syzler@50: syzler@50: --- Iterates over all known and non-hidden (i.e. not dead or opposite faction) mount slot IDs. syzler@50: -- @return A list of valid mount slot IDs. syzler@50: function MyLilPony.EnumerateKnownMountSlotIDs() syzler@50: local countMounts = C_MountJournal.GetNumMounts(); syzler@50: local x = 1; syzler@50: return function() syzler@50: for i = x, countMounts do syzler@60: local _, _, _, _, _, _, _, _, _, hidden, known = C_MountJournal.GetMountInfoByID(i); syzler@50: if known and not hidden then syzler@50: x = i + 1; syzler@50: return i; syzler@50: end syzler@50: end 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