annotate libMyLilPony/libMyLilPony_miscFunctions.lua @ 64:a8813eee6bb8 tip

Added tag 1.2.3 for changeset db0578847bb5
author syzler
date Tue, 27 Dec 2016 16:42:57 -0500
parents 81145a681a59
children
rev   line source
syzler@52 1 -- Copyright (c) 2015, 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@52 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@52 77 -- @param slotID The slot ID of the mount to be called.
syzler@52 78 -- @param condition An optional Boolean condition.
syzler@52 79 -- @returns True if a mount was summoned, or False otherwise.
syzler@52 80 function MyLilPony.CallMount(slotID, condition)
syzler@52 81 if condition == nil or condition then
syzler@60 82 C_MountJournal.SummonByID(slotID);
syzler@52 83 return true;
syzler@52 84 end
syzler@52 85 return false;
syzler@52 86 end
syzler@52 87
syzler@52 88 --- OBSOLETE. Calls a mount if a specified condition checks out.
syzler@50 89 -- @param unused The type of companion to be called (e.g. "MOUNT").
syzler@50 90 -- @param slotID The slot ID of the mount to be called.
syzler@7 91 -- @param condition An optional Boolean condition.
syzler@50 92 function MyLilPony.CallCompanion(unused, slotID, condition)
syzler@52 93 MyLilPony.CallMount(slotID, condition);
syzler@50 94 end
syzler@50 95
syzler@50 96 --- Iterates over all known and non-hidden (i.e. not dead or opposite faction) mount slot IDs.
syzler@50 97 -- @return A list of valid mount slot IDs.
syzler@50 98 function MyLilPony.EnumerateKnownMountSlotIDs()
syzler@50 99 local countMounts = C_MountJournal.GetNumMounts();
syzler@50 100 local x = 1;
syzler@50 101 return function()
syzler@50 102 for i = x, countMounts do
syzler@60 103 local _, _, _, _, _, _, _, _, _, hidden, known = C_MountJournal.GetMountInfoByID(i);
syzler@50 104 if known and not hidden then
syzler@50 105 x = i + 1;
syzler@50 106 return i;
syzler@50 107 end
syzler@50 108 end
syzler@1 109 end
syzler@1 110 end
syzler@1 111
syzler@7 112 --- Gets a value indicating whether or not the current character is able to fly at the current location.
syzler@7 113 -- 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 114 -- @returns A Boolean value indicating whether or not the current character is able to fly at the current location.
syzler@1 115 function MyLilPony.CanFlyHere()
syzler@1 116 if IsFlyableArea() then
syzler@1 117 SetMapToCurrentZone();
syzler@1 118 local continent = GetCurrentMapContinent();
syzler@1 119 if continent == 4 then
syzler@1 120 -- Northrend: requires Cold Weather Flying
syzler@1 121 return IsSpellKnown(54197);
syzler@1 122 elseif (continent == 1 or continent == 2) then
syzler@1 123 -- Old World: requires Flight Master's License
syzler@1 124 return IsSpellKnown(90267);
syzler@1 125 end
syzler@1 126 return true;
syzler@1 127 end
syzler@1 128 return false;
syzler@1 129 end
syzler@1 130
syzler@1 131 function MyLilPony.Print(msg)
syzler@1 132 DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..msg);
syzler@1 133 end
syzler@1 134
syzler@1 135 function MyLilPony.Log(msg)
syzler@1 136 if MYLILPONY_DEBUG_LOGGING then
syzler@1 137 DEFAULT_CHAT_FRAME:AddMessage("|cff8ed6f0"..format("MyLilPony: %s", msg));
syzler@1 138 end
syzler@1 139 end