annotate 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
rev   line source
syzler@14 1 -- Copyright (c) 2011, Syzler
syzler@14 2 -- All rights reserved.
syzler@1 3 --
syzler@14 4 -- Redistribution and use in source and binary forms, with or without
syzler@14 5 -- modification, are permitted provided that the following conditions
syzler@14 6 -- are met:
syzler@1 7 --
syzler@14 8 -- * Redistributions of source code must retain the above copyright
syzler@14 9 -- notice, this list of conditions and the following disclaimer.
syzler@14 10 -- * Redistributions in binary form must reproduce the above copyright
syzler@14 11 -- notice, this list of conditions and the following disclaimer in
syzler@14 12 -- the documentation and/or other materials provided with the
syzler@14 13 -- distribution.
syzler@14 14 -- * Neither the name of the MyLilPony Project nor the names of its
syzler@14 15 -- contributors may be used to endorse or promote products derived
syzler@14 16 -- from this software without specific prior written permission.
syzler@1 17 --
syzler@14 18 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
syzler@14 19 -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
syzler@14 20 -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
syzler@14 21 -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
syzler@14 22 -- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
syzler@14 23 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
syzler@14 24 -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
syzler@14 25 -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
syzler@14 26 -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
syzler@14 27 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
syzler@14 28 -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
syzler@14 29 -- POSSIBILITY OF SUCH DAMAGE.
syzler@1 30
syzler@15 31 ------------------------------------------------------------------------
syzler@15 32 -- Project: libMyLilPony
syzler@15 33 -- Project Version: @project-version@
syzler@15 34 -- Last Author: @file-author@
syzler@15 35 -- Last Updated: @file-date-iso@
syzler@15 36 --
syzler@1 37 -- Misc helper functions used in the library
syzler@15 38 ------------------------------------------------------------------------
syzler@1 39
syzler@7 40 --- Gets a hashtable of buffs on the specified unit.
syzler@7 41 -- @param unit The unit frame name (e.g. "target", "player", "focus") of the unit whose buffs are to be retrieved.
syzler@7 42 -- @returns a hashtable of buff spell IDs keyed on the ID.
syzler@1 43 function MyLilPony.GetUnitBuffs(unit)
syzler@1 44 local buffs = {};
syzler@1 45 for i = 1, 40 do
syzler@1 46 local _, _, _, _, _, _, _, _, _, _, id = UnitAura(unit, i, "HELPFUL");
syzler@1 47 if id ~= nil then
syzler@1 48 buffs[id] = id;
syzler@1 49 end
syzler@1 50 end
syzler@1 51 return buffs;
syzler@1 52 end
syzler@1 53
syzler@50 54 --- Performs case-sensitive string pattern matching.
syzler@50 55 -- @param subject The string on which the pattern matching is performed.
syzler@50 56 -- @param pattern The pattern to be matched.
syzler@50 57 -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match.
syzler@50 58 function MyLilPony.StringMatch(subject, pattern)
syzler@50 59 if subject == nil and pattern == nil then return true end
syzler@50 60 if subject == nil or pattern == nil then return false end
syzler@50 61 return string.match(subject, pattern);
syzler@50 62 end
syzler@50 63
syzler@7 64 --- Performs case-insensitive string pattern matching.
syzler@7 65 -- @param subject The string on which the pattern matching is performed.
syzler@7 66 -- @param pattern The pattern to be matched.
syzler@7 67 -- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match.
syzler@1 68 function MyLilPony.StringMatchIgnoreCase(subject, pattern)
syzler@1 69 if subject == nil and pattern == nil then return true end
syzler@1 70 if subject == nil or pattern == nil then return false end
syzler@1 71 local lSub = string.lower(subject);
syzler@1 72 local lPat = string.lower(pattern);
syzler@1 73 return string.match(lSub, lPat);
syzler@1 74 end
syzler@1 75
syzler@50 76 --- Calls a mount if a specified condition checks out.
syzler@50 77 -- @param unused The type of companion to be called (e.g. "MOUNT").
syzler@50 78 -- @param slotID The slot ID of the mount to be called.
syzler@7 79 -- @param condition An optional Boolean condition.
syzler@50 80 function MyLilPony.CallCompanion(unused, slotID, condition)
syzler@1 81 if condition == nil or condition then
syzler@50 82 C_MountJournal.Summon(slotID);
syzler@50 83 end
syzler@50 84 end
syzler@50 85
syzler@50 86 --- Iterates over all known and non-hidden (i.e. not dead or opposite faction) mount slot IDs.
syzler@50 87 -- @return A list of valid mount slot IDs.
syzler@50 88 function MyLilPony.EnumerateKnownMountSlotIDs()
syzler@50 89 local countMounts = C_MountJournal.GetNumMounts();
syzler@50 90 local x = 1;
syzler@50 91 return function()
syzler@50 92 for i = x, countMounts do
syzler@50 93 local _, _, _, _, _, _, _, _, _, hidden, known = C_MountJournal.GetMountInfo(i);
syzler@50 94 if known and not hidden then
syzler@50 95 x = i + 1;
syzler@50 96 return i;
syzler@50 97 end
syzler@50 98 end
syzler@1 99 end
syzler@1 100 end
syzler@1 101
syzler@7 102 --- Gets a value indicating whether or not the current character is able to fly at the current location.
syzler@7 103 -- 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 104 -- @returns A Boolean value indicating whether or not the current character is able to fly at the current location.
syzler@1 105 function MyLilPony.CanFlyHere()
syzler@1 106 if IsFlyableArea() then
syzler@1 107 SetMapToCurrentZone();
syzler@1 108 local continent = GetCurrentMapContinent();
syzler@1 109 if continent == 4 then
syzler@1 110 -- Northrend: requires Cold Weather Flying
syzler@1 111 return IsSpellKnown(54197);
syzler@1 112 elseif (continent == 1 or continent == 2) then
syzler@1 113 -- Old World: requires Flight Master's License
syzler@1 114 return IsSpellKnown(90267);
syzler@1 115 end
syzler@1 116 return true;
syzler@1 117 end
syzler@1 118 return false;
syzler@1 119 end
syzler@1 120
syzler@1 121 function MyLilPony.Print(msg)
syzler@1 122 DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..msg);
syzler@1 123 end
syzler@1 124
syzler@1 125 function MyLilPony.Log(msg)
syzler@1 126 if MYLILPONY_DEBUG_LOGGING then
syzler@1 127 DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..format("MyLilPony: %s", msg));
syzler@1 128 end
syzler@1 129 end