251 lines
10 KiB
Lua
251 lines
10 KiB
Lua
function WyntrWear_OnLoad(frame)
|
|
SlashCmdList["WYNTRWEAR"] = WyntrWear_CmdHandler;
|
|
SLASH_WYNTRWEAR1 = "/wyntrwear";
|
|
SLASH_WYNTRWEAR2 = "/ww";
|
|
NEUTRAL_MIN = 0;
|
|
NEUTRAL_MAX = 3000;
|
|
FRIENDLY_MIN = 3001;
|
|
FRIENDLY_MAX = 9000;
|
|
HONORED_MIN = 9001;
|
|
HONORED_MAX = 21000;
|
|
REVERED_MIN = 21001;
|
|
REVERED_MAX = 42000;
|
|
EXALTED_MIN = 42001;
|
|
EXALTED_MAX = 43000;
|
|
HORDE_EXPEDITION = "Horde Expedition";
|
|
startRep = nil;
|
|
totalEarned = nil;
|
|
oldTabard = nil;
|
|
atExalted = false;
|
|
wrathNames = {"Argent Crusade", "Knights of the Ebon Blade", "Kirin Tor", "The Wyrmrest Accord", "Horde Expedition"};
|
|
|
|
if (IsEquippedItemType("Tabard")) then
|
|
tabardName = GetInventoryItemLink("player", GetInventorySlotInfo("TabardSlot"));
|
|
else
|
|
tabardName = HORDE_EXPEDITION;
|
|
end
|
|
oldTabard = tabardName;
|
|
startRep = getRepData(tabardName, false);
|
|
|
|
frame:Hide();
|
|
frame:RegisterForDrag("leftButton");
|
|
frame:RegisterEvent("ADDON_LOADED");
|
|
frame:RegisterEvent("PLAYER_ENTERING_WORLD");
|
|
frame:RegisterEvent("UNIT_INVENTORY_CHANGED");
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: wyntrwear loaded...");
|
|
end
|
|
|
|
function processTabardName(tabardName)
|
|
local found, _, itemString = string.find(tabardName, "^|c%x+|H(.+)|h%[.*%]");
|
|
if (found) then
|
|
local linkType, itemID = strsplit(":", itemString);
|
|
local itemName = GetItemInfo(itemID);
|
|
itemName = string.gsub(itemName, "Tabard", "");
|
|
itemName = string.gsub(itemName, "of", "");
|
|
itemName = string.gsub(itemName, "the", "");
|
|
itemName = string.gsub(itemName, "^%s*(.-)%s*$", "%1"); -- trim()
|
|
itemName = string.gsub(itemName, " ", " "); -- eliminate x2 spaces
|
|
return itemName;
|
|
else
|
|
return tabardName;
|
|
end
|
|
end
|
|
|
|
function getRepData(tabardName, printRep)
|
|
local itemName = tabardName;
|
|
local factionIndex = 1;
|
|
local lastFactionName = nil;
|
|
local repString;
|
|
local basePoints;
|
|
local demoninator;
|
|
local repLevel;
|
|
local foundName = false;
|
|
local oldTabardIsWrath = false;
|
|
local factionColor;
|
|
local colorTemplate = "|cff%02x%02x%02x";
|
|
local r, g, b;
|
|
if (printRep == nil) then printRep = true; end
|
|
--DEFAULT_CHAT_FRAME:AddMessage("WWDB: getRepData(" .. tabardName .. ")");
|
|
if (tabardName ~= HORDE_EXPEDITION) then
|
|
itemName = processTabardName(tabardName);
|
|
end
|
|
if (oldTabard ~= HORDE_EXPEDITION) then
|
|
oldTabard = processTabardName(oldTabard);
|
|
end
|
|
--DEFAULT_CHAT_FRAME:AddMessage("WWDB: Processed itemName = " .. itemName);
|
|
repeat
|
|
local name, description, standingId, bottomValue, topValue, earnedValue, atWarWith,
|
|
canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild = GetFactionInfo(factionIndex);
|
|
if (name == lastFactionName) then
|
|
break;
|
|
elseif (name == nil) then
|
|
break;
|
|
else
|
|
lastFactionName = name;
|
|
for i = 1, #wrathNames do
|
|
if (name == wrathNames[i]) then
|
|
foundName = true; -- is this a wotlk faction name?
|
|
end
|
|
oVal = string.find(wrathNames[i], oldTabard);
|
|
if (oVal ~= nil) then
|
|
oldTabardIsWrath = true;
|
|
end
|
|
end
|
|
oVal = string.find(name, oldTabard);
|
|
if (oVal ~= nil and startRep ~= nil and oldTabardIsWrath) then
|
|
totalEarned = earnedValue - startRep;
|
|
if (totalEarned ~= nil and totalEarned > 0) then
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: You earned " .. totalEarned .. " reputation with " .. oldTabard ..".");
|
|
end
|
|
--DEFAULT_CHAT_FRAME:AddMessage("WWDB: start rep: " .. startRep ..", earnedValue: " .. earnedValue);
|
|
else
|
|
totalEarned = 0;
|
|
end
|
|
if (itemName ~= nil and name ~= nil) then
|
|
tVal = string.find(name, itemName);
|
|
if (tVal ~= nil and foundName) then
|
|
--DEFAULT_CHAT_FRAME:AddMessage("earnedValue = " .. earnedValue);
|
|
if (earnedValue > EXALTED_MIN) then
|
|
repLevel = "exalted";
|
|
atExalted = true;
|
|
basePoints = earnedValue - REVERED_MAX;
|
|
denominator = EXALTED_MAX - EXALTED_MIN;
|
|
r = 0.6;
|
|
g = 0.2;
|
|
b = 0.8;
|
|
elseif (earnedValue > REVERED_MIN) then
|
|
repLevel = "revered";
|
|
basePoints = earnedValue - HONORED_MAX;
|
|
denominator = REVERED_MAX - REVERED_MIN;
|
|
r = 0.25;
|
|
g = 0.4;
|
|
b = 0.9;
|
|
elseif (earnedValue > HONORED_MIN) then
|
|
repLevel = "honored";
|
|
basePoints = earnedValue - FRIENDLY_MAX;
|
|
denominator = HONORED_MAX - HONORED_MIN
|
|
r = 0;
|
|
g = 1;
|
|
b = 0;
|
|
elseif (earnedValue > FRIENDLY_MIN) then
|
|
repLevel = "friendly";
|
|
basePoints = earnedValue - NEUTRAL_MAX;
|
|
denominator = FRIENDLY_MAX - FRIENDLY_MIN;
|
|
r = 1;
|
|
g = 1;
|
|
b = 1;
|
|
elseif (earnedValue > NEUTRAL_MIN) then
|
|
repLevel = "neutral";
|
|
basePoints = earnedValue;
|
|
denominator = topvalue;
|
|
r = 0.75;
|
|
g = 0.75;
|
|
b = 0.75;
|
|
else
|
|
repLevel = "bad";
|
|
end
|
|
if (repLevel ~= "bad") then
|
|
if (printRep) then
|
|
repString = string.format("%.2f", tostring((basePoints/denominator)*100));
|
|
colorString = format(colorTemplate, r * 255, g * 255, b * 255);
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: Currently at " .. repString .. "% of " .. colorString .. repLevel .. "|r reputation with " .. name .. ".");
|
|
end
|
|
return earnedValue, totalEarned;
|
|
end
|
|
end
|
|
else
|
|
return; -- error trap: for some reason itemName got zapped to nil...fuggit - return
|
|
end
|
|
end
|
|
factionIndex = factionIndex + 1;
|
|
until (factionIndex > 200)
|
|
end
|
|
|
|
function checkRep()
|
|
if (startRep == nil) then
|
|
startRep = getRepData(tabardName, true);
|
|
oldTabard = tabardName;
|
|
else
|
|
startRep = getRepData(tabardName, true);
|
|
oldTabard = tabardName;
|
|
end
|
|
end
|
|
|
|
|
|
function WyntrWear_OnEvent(frame, event, ...)
|
|
if (event == "PLAYER_ENTERING_WORLD") then
|
|
if ((UnitLevel("player") > 79) and not wynWearLoad) then
|
|
inInstance, instanceType = IsInInstance();
|
|
if (instanceType == "party") then
|
|
if (not IsEquippedItemType("Tabard")) then
|
|
frame:Show();
|
|
else -- check to see which tabard is being worn and if it generates rep
|
|
tabardName = GetInventoryItemLink("player", GetInventorySlotInfo("TabardSlot"));
|
|
local found, _, itemString = string.find(tabardName, "^|c%x+|H(.+)|h%[.*%]");
|
|
tabardFaction = strsub(itemString, 15);
|
|
end
|
|
end
|
|
end
|
|
if (IsEquippedItemType("Tabard")) then
|
|
tabardName = GetInventoryItemLink("player", GetInventorySlotInfo("TabardSlot"));
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: Wearing: " .. tabardName .. ".");
|
|
if (atExalted) then
|
|
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000WyntrWear: You are at exalted with this faction and should consider using a different tabard.");
|
|
end
|
|
else
|
|
tabardName = HORDE_EXPEDITION;
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: Not wearing a tabard.");
|
|
end
|
|
elseif (event == "ADDON_LOADED") then
|
|
if (wynWearLoad == nil) then
|
|
wynWearLoad = false;
|
|
end
|
|
elseif (event == "UNIT_INVENTORY_CHANGED") then
|
|
local repEarnedThisTabard = 0;
|
|
local newTabard = GetInventoryItemLink("player", GetInventorySlotInfo("TabardSlot"));
|
|
if (newTabard ~= tabardName) then -- if this evaluates true - the tabard change triggered the event
|
|
atExalted = false;
|
|
if (IsEquippedItemType("Tabard")) then
|
|
tabardName = newTabard;
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: Tabard equipped: " .. tabardName);
|
|
checkRep();
|
|
elseif (UnitLevel("player") > 67 and oldTabard ~= HORDE_EXPEDITION) then
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: Tabard unequipped.");
|
|
tabardName = HORDE_EXPEDITION;
|
|
checkRep();
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function wynCheckBoxFunction()
|
|
wynWearLoad = wynCheckBox1:GetChecked();
|
|
end
|
|
|
|
function WyntrWear_CmdHandler(str)
|
|
frame = getglobal("wynFrame1");
|
|
|
|
if (frame) then
|
|
if (frame:IsVisible()) then
|
|
frame:Hide();
|
|
end
|
|
end
|
|
|
|
if (str == "status") then
|
|
if (IsEquippedItemType("Tabard")) then
|
|
tabardName = GetInventoryItemLink("player", GetInventorySlotInfo("TabardSlot"));
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: You are wearing " .. tabardName .. ".");
|
|
getRepData(tabardName, true);
|
|
else
|
|
if (UnitLevel("player") > 67) then
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: You are not wearing a tabard.");
|
|
getRepData(HORDE_EXPEDITION, true);
|
|
end
|
|
end
|
|
elseif (str == "check") then
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear check forced for next time you enter an instance.");
|
|
wynWearLoad = false;
|
|
else
|
|
DEFAULT_CHAT_FRAME:AddMessage("WyntrWear: Usage: /{ww}|{wyntrwear} {status}|{check}\nstatus: tells if you are currently wearing a tabard.\ncheck - forces check to be performed upon entering instance.");
|
|
end
|
|
end |