annotate libMyLilPony/libMyLilPony_miscFunctions.lua @ 7:d96c15f7477b

Updated documentation for API.
author syzler
date Tue, 05 Apr 2011 02:05:57 +0000
parents 7dfbf42c2d60
children b1e344c17ab5
rev   line source
syzler@1 1 -- libMyLilPony
syzler@1 2 -- Copyright (c) 2011 Syzler
syzler@1 3 --
syzler@1 4 -- This program is free software: you can redistribute it and/or modify
syzler@1 5 -- it under the terms of the GNU General Public License as published by
syzler@1 6 -- the Free Software Foundation, either version 3 of the License, or
syzler@1 7 -- (at your option) any later version.
syzler@1 8 --
syzler@1 9 -- This program is distributed in the hope that it will be useful,
syzler@1 10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
syzler@1 11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
syzler@1 12 -- GNU General Public License for more details.
syzler@1 13 --
syzler@1 14 -- You should have received a copy of the GNU General Public License
syzler@1 15 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
syzler@1 16
syzler@1 17 -- Misc helper functions used in the library
syzler@1 18
syzler@7 19 --- Gets a hashtable of buffs on the specified unit.
syzler@7 20 -- @param unit The unit frame name (e.g. "target", "player", "focus") of the unit whose buffs are to be retrieved.
syzler@7 21 -- @returns a hashtable of buff spell IDs keyed on the ID.
syzler@1 22 function MyLilPony.GetUnitBuffs(unit)
syzler@1 23 local buffs = {};
syzler@1 24 for i = 1, 40 do
syzler@1 25 local _, _, _, _, _, _, _, _, _, _, id = UnitAura(unit, i, "HELPFUL");
syzler@1 26 if id ~= nil then
syzler@1 27 buffs[id] = id;
syzler@1 28 end
syzler@1 29 end
syzler@1 30 return buffs;
syzler@1 31 end
syzler@1 32
syzler@7 33 --- Performs case-insensitive string pattern matching.
syzler@7 34 -- @param subject The string on which the pattern matching is performed.
syzler@7 35 -- @param pattern The pattern to be matched.
syzler@7 36 -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match.
syzler@1 37 function MyLilPony.StringMatchIgnoreCase(subject, pattern)
syzler@1 38 if subject == nil and pattern == nil then return true end
syzler@1 39 if subject == nil or pattern == nil then return false end
syzler@1 40 local lSub = string.lower(subject);
syzler@1 41 local lPat = string.lower(pattern);
syzler@1 42 return string.match(lSub, lPat);
syzler@1 43 end
syzler@1 44
syzler@7 45 --- Calls a companion if a specified condition checks out.
syzler@7 46 -- @param companionType The type of companion to be called (e.g. "MOUNT").
syzler@7 47 -- @param companionNumber The slot number of the companion to be called.
syzler@7 48 -- @param condition An optional Boolean condition.
syzler@1 49 function MyLilPony.CallCompanion(companionType, companionNumber, condition)
syzler@1 50 if condition == nil or condition then
syzler@1 51 CallCompanion(companionType, companionNumber);
syzler@1 52 end
syzler@1 53 end
syzler@1 54
syzler@7 55 --- Gets a value indicating whether or not the current character is able to fly at the current location.
syzler@7 56 -- 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 57 -- @returns A Boolean value indicating whether or not the current character is able to fly at the current location.
syzler@1 58 function MyLilPony.CanFlyHere()
syzler@1 59 if IsFlyableArea() then
syzler@1 60 SetMapToCurrentZone();
syzler@1 61 local continent = GetCurrentMapContinent();
syzler@1 62 if continent == 4 then
syzler@1 63 -- Northrend: requires Cold Weather Flying
syzler@1 64 return IsSpellKnown(54197);
syzler@1 65 elseif (continent == 1 or continent == 2) then
syzler@1 66 -- Old World: requires Flight Master's License
syzler@1 67 return IsSpellKnown(90267);
syzler@1 68 end
syzler@1 69 return true;
syzler@1 70 end
syzler@1 71 return false;
syzler@1 72 end
syzler@1 73
syzler@1 74 function MyLilPony.Print(msg)
syzler@1 75 DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..msg);
syzler@1 76 end
syzler@1 77
syzler@1 78 function MyLilPony.Log(msg)
syzler@1 79 if MYLILPONY_DEBUG_LOGGING then
syzler@1 80 DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..format("MyLilPony: %s", msg));
syzler@1 81 end
syzler@1 82 end