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