Mercurial > wow > crossrealmassist
comparison CrossRealmAssist.lua @ 27:42a70f4b2ff5
New beta features:
- Quick join stoplist (Ignore key words)
- Create group button
- Experimental auto create group
| author | ShadowTheAge |
|---|---|
| date | Sun, 27 Sep 2015 16:03:43 +0300 |
| parents | e0a1917e571f |
| children | 7267ae761cb9 |
comparison
equal
deleted
inserted
replaced
| 26:521897e5e0b9 | 27:42a70f4b2ff5 |
|---|---|
| 10 local settingsMenu | 10 local settingsMenu |
| 11 local hintShown | 11 local hintShown |
| 12 local cbHideGroups, cbHideRaids, cbHideNoAutoinv | 12 local cbHideGroups, cbHideRaids, cbHideNoAutoinv |
| 13 | 13 |
| 14 local tabs = {} | 14 local tabs = {} |
| 15 local curRealmStat, curPartyStat | 15 local curRealmStat |
| 16 local scanstate=0 | 16 local scanstate=0 |
| 17 local recentRealms={} | 17 local recentRealms={} |
| 18 local recentgroups={} | 18 local recentgroups={} |
| 19 local autoScanGroups={} | 19 local autoScanGroups={} |
| 20 local active=false | 20 local active=false |
| 42 local SettingsDefaults={ | 42 local SettingsDefaults={ |
| 43 global={ | 43 global={ |
| 44 minimap = {}, | 44 minimap = {}, |
| 45 widgetPos=DefaultWidgetPos, | 45 widgetPos=DefaultWidgetPos, |
| 46 quickJoinHint = true, | 46 quickJoinHint = true, |
| 47 quickJoin={[6]=1,[10]=1}, | 47 quickJoin={[6]=1}, |
| 48 allLanguages = true | 48 allLanguages = true, |
| 49 stoplist = {"no hop","kick"} | |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 | 53 |
| 53 -- Utils functions | 54 -- Utils functions |
| 163 | 164 |
| 164 local function WeightLfgItem(id, forAutoJoin) | 165 local function WeightLfgItem(id, forAutoJoin) |
| 165 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) | 166 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) |
| 166 if delisted then return 0 end | 167 if delisted then return 0 end |
| 167 local name,realm = PlayerName(fullname); | 168 local name,realm = PlayerName(fullname); |
| 169 local stoplist = db.global.stoplist or {} | |
| 170 local ldesc = string.lower(caption) .. "|" .. string.lower(desc); | |
| 171 local isHopGroup = string.find(ldesc, "realm hop") | |
| 172 for i=1, #stoplist do | |
| 173 if string.find(ldesc, stoplist[i], 1, true) then return 0 end | |
| 174 end | |
| 168 if forAutoJoin then | 175 if forAutoJoin then |
| 169 if not autoinv or pcount >= 35 or pcount <= 5 or recentgroups[fullname] then return 0 end | 176 if not autoinv or recentgroups[fullname] or (not isHopGroup and (pcount >= 35 or pcount <= 5)) then return 0 end |
| 170 end | 177 end |
| 171 | 178 |
| 172 local autoinvWeight = autoinv and 5 or 2 | 179 local autoinvWeight = autoinv and 5 or 2 |
| 180 local hopCoef = isHopGroup and 3 or 1 | |
| 173 | 181 |
| 174 local visCoef = 1 | 182 local visCoef = 1 |
| 175 if recentgroups[fullname] then | 183 if recentgroups[fullname] then |
| 176 local ago = GetTime() - recentgroups[fullname].time; | 184 local ago = GetTime() - recentgroups[fullname].time; |
| 177 visCoef = math.min(1,ago/600) | 185 visCoef = math.min(1,ago/600) |
| 184 local ago = GetTime() - realmVis | 192 local ago = GetTime() - realmVis |
| 185 leaderRealm = 1 + 2*math.min(1,ago/600); | 193 leaderRealm = 1 + 2*math.min(1,ago/600); |
| 186 end | 194 end |
| 187 | 195 |
| 188 local countWeight = 4 -- count weight | 196 local countWeight = 4 -- count weight |
| 189 if pcount >= 39 or pcount <= 1 then countWeight = 1 | 197 if not isHopGroup then |
| 190 elseif pcount >= 35 or pcount <= 5 then countWeight = 2 | 198 if pcount >= 39 or pcount <= 1 then countWeight = 1 |
| 191 elseif pcount >= 30 or pcount <= 10 then countWeight = 3 | 199 elseif pcount >= 35 or pcount <= 5 then countWeight = 2 |
| 192 else countWeight = 4 end | 200 elseif pcount >= 30 or pcount <= 10 then countWeight = 3 end |
| 201 end | |
| 193 | 202 |
| 194 local ageWeight = 2 | 203 local ageWeight = 2 |
| 195 if time > 1200 then ageWeight = 4 | 204 if time > 1200 then ageWeight = 4 |
| 196 elseif time > 300 then ageWeight = 3 end | 205 elseif time > 300 then ageWeight = 3 end |
| 197 | 206 |
| 198 return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight; | 207 return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight * hopCoef; |
| 199 end | 208 end |
| 200 | 209 |
| 201 local function AddLfgGroupInfo(id, short) | 210 local function AddLfgGroupInfo(id, short) |
| 202 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) | 211 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) |
| 203 local friends = bnetfr+charfr+guild | 212 local friends = bnetfr+charfr+guild |
| 340 function addon.ShowMmTooltip(tooltip) | 349 function addon.ShowMmTooltip(tooltip) |
| 341 tooltip:AddLine("Cross Realm Assist",1,1,1) | 350 tooltip:AddLine("Cross Realm Assist",1,1,1) |
| 342 tooltip:Show() | 351 tooltip:Show() |
| 343 end | 352 end |
| 344 | 353 |
| 345 --[[function addon.MmClick(self, button) | |
| 346 if button == "RightButton" then | |
| 347 addon.ShowSettings(self) | |
| 348 else | |
| 349 addon:Activate() | |
| 350 end | |
| 351 end]] | |
| 352 | |
| 353 function addon:OnInitialize() | 354 function addon:OnInitialize() |
| 354 db = LibStub("AceDB-3.0"):New("CrossRealmAssistDB", SettingsDefaults) | 355 db = LibStub("AceDB-3.0"):New("CrossRealmAssistDB", SettingsDefaults) |
| 355 local minimapData = ldb:NewDataObject("CrossRealmAssistMinimapIcon",{ | 356 local minimapData = ldb:NewDataObject("CrossRealmAssistMinimapIcon",{ |
| 356 type = "data source", | 357 type = "data source", |
| 357 text = "Cross Realm Assist", | 358 text = "Cross Realm Assist", |
| 366 realmSep = _G.REALM_SEPARATORS | 367 realmSep = _G.REALM_SEPARATORS |
| 367 playerName = UnitName("player") | 368 playerName = UnitName("player") |
| 368 homeRealm = GetRealmName() | 369 homeRealm = GetRealmName() |
| 369 addon:RegisterChatCommand("cra", "Activate") | 370 addon:RegisterChatCommand("cra", "Activate") |
| 370 addon:RegisterChatCommand("crossrealmassist", "Activate") | 371 addon:RegisterChatCommand("crossrealmassist", "Activate") |
| 372 if db.global.autoCreateHopGroup then | |
| 373 addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") | |
| 374 end | |
| 371 end | 375 end |
| 372 | 376 |
| 373 function addon:OnDisable() | 377 function addon:OnDisable() |
| 374 addon:Deactivate() | 378 addon:Deactivate() |
| 375 end | 379 end |
| 619 function addon:RealmVisited(realm, head) | 623 function addon:RealmVisited(realm, head) |
| 620 recentRealms[realm] = GetTime() | 624 recentRealms[realm] = GetTime() |
| 621 end | 625 end |
| 622 | 626 |
| 623 function addon:updatePartyInfo() | 627 function addon:updatePartyInfo() |
| 624 curPartyStat = {} | 628 if IsInGroup() ~= wasInGroup then |
| 625 local inGroup = IsInGroup() | |
| 626 if inGroup then | |
| 627 if IsInRaid() then | |
| 628 for i=1, MAX_RAID_MEMBERS do | |
| 629 addon:AddUnitIdStat("raid"..i, curPartyStat) | |
| 630 end | |
| 631 else | |
| 632 for i=1, MAX_PARTY_MEMBERS do | |
| 633 addon:AddUnitIdStat("party"..i, curPartyStat) | |
| 634 end | |
| 635 end | |
| 636 end | |
| 637 if inGroup ~= wasInGroup then | |
| 638 addon:RefreshZone(true) | 629 addon:RefreshZone(true) |
| 639 wasInGroup = inGroup | 630 wasInGroup = IsInGroup() |
| 640 addon:UpdateAutoButtonStatus() | 631 addon:UpdateAutoButtonStatus() |
| 641 end | 632 end |
| 642 end | 633 end |
| 643 | 634 |
| 644 | 635 |
| 667 else | 658 else |
| 668 inInstance = false; | 659 inInstance = false; |
| 669 if scanstate == 0 then | 660 if scanstate == 0 then |
| 670 addon:ScanRealm() | 661 addon:ScanRealm() |
| 671 elseif shedule == true and scanstate == 2 then | 662 elseif shedule == true and scanstate == 2 then |
| 672 addon:SetStatus("Rescan sheduled...") | 663 addon:SetStatus("Rescan scheduled...") |
| 673 scanstate = 3 | 664 scanstate = 3 |
| 674 end | 665 end |
| 675 end | 666 end |
| 676 addon:UpdateAutoButtonStatus() | 667 addon:UpdateAutoButtonStatus() |
| 677 end | 668 end |
| 679 function addon:ScanRealm() | 670 function addon:ScanRealm() |
| 680 if scanstate > 0 then return end | 671 if scanstate > 0 then return end |
| 681 if InCombatLockdown() then | 672 if InCombatLockdown() then |
| 682 addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat") | 673 addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat") |
| 683 scanstate = 1 | 674 scanstate = 1 |
| 684 addon:SetStatus("Scan sheduled after combat..."); | 675 addon:SetStatus("Scan scheduled after combat..."); |
| 685 return | 676 return |
| 686 end | 677 end |
| 687 scanstate = 2 | 678 scanstate = 2 |
| 688 addon:SetStatus("Scanning current realm..."); | 679 addon:SetStatus("Scanning current realm..."); |
| 689 local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"'; | 680 local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"'; |
| 773 | 764 |
| 774 -- Auto action button | 765 -- Auto action button |
| 775 | 766 |
| 776 local action | 767 local action |
| 777 | 768 |
| 769 local function getPartyStat() | |
| 770 local curPartyStat = {} | |
| 771 if IsInGroup() then | |
| 772 if IsInRaid() then | |
| 773 for i=1, MAX_RAID_MEMBERS do | |
| 774 addon:AddUnitIdStat("raid"..i, curPartyStat) | |
| 775 end | |
| 776 else | |
| 777 for i=1, MAX_PARTY_MEMBERS do | |
| 778 addon:AddUnitIdStat("party"..i, curPartyStat) | |
| 779 end | |
| 780 end | |
| 781 end | |
| 782 return curPartyStat | |
| 783 end | |
| 784 | |
| 778 local LeaveGroup = { | 785 local LeaveGroup = { |
| 779 func = LeaveParty; | 786 func = LeaveParty; |
| 780 tooltip = function(self) | 787 tooltip = function(self) |
| 781 local partyStat = addon:GetRealmStat(curPartyStat) | 788 local partyStat = addon:GetRealmStat(getPartyStat()) |
| 782 GameTooltip:AddLine("Players in party "..partyStat.players) | 789 GameTooltip:AddLine("Players in party "..partyStat.players) |
| 783 local max = partyStat.max; | 790 local max = partyStat.max; |
| 784 for i=1,#partyStat do | 791 for i=1,#partyStat do |
| 785 local data = partyStat[i] | 792 local data = partyStat[i] |
| 786 local percent = math.ceil(100 * data.count / partyStat.players - 0.5) .. "%"; | 793 local percent = math.ceil(100 * data.count / partyStat.players - 0.5) .. "%"; |
| 934 end | 941 end |
| 935 | 942 |
| 936 | 943 |
| 937 | 944 |
| 938 | 945 |
| 939 | 946 -- Realm hop group |
| 947 | |
| 948 local function CreateHopGroup() | |
| 949 if canJoinGroup() then | |
| 950 C_LFGList.CreateListing(16,"Realm hopping - "..homeRealm,0,"","",true) | |
| 951 addon:ScheduleTimer(ConvertToRaid, 5) | |
| 952 end | |
| 953 end | |
| 954 | |
| 955 function addon:PlayerFlagsUpdate(event, target) | |
| 956 if target == "player" and UnitIsAFK("player") and C_Garrison.IsOnGarrisonMap() and db.global.autoCreateHopGroup then | |
| 957 CreateHopGroup() | |
| 958 end | |
| 959 end | |
| 940 | 960 |
| 941 -- Settings | 961 -- Settings |
| 942 | 962 |
| 943 local function toggleMinimapIcon(btn, arg1, arg2, checked) | 963 local function toggleMinimapIcon(btn, arg1, arg2, checked) |
| 944 local hidden = not checked; | 964 local hidden = not checked; |
| 965 | 985 |
| 966 local function toggleApplyAsDD(btn, arg1, arg2, checked) | 986 local function toggleApplyAsDD(btn, arg1, arg2, checked) |
| 967 db.global.applyAsDD = checked | 987 db.global.applyAsDD = checked |
| 968 end | 988 end |
| 969 | 989 |
| 990 local function toggleCreateHopGroup(btn, arg1, arg2, checked) | |
| 991 db.global.autoCreateHopGroup = checked | |
| 992 if checked then addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") end | |
| 993 end | |
| 994 | |
| 970 local function ClearJoinHistory() | 995 local function ClearJoinHistory() |
| 971 recentgroups = {} | 996 recentgroups = {} |
| 972 addon:UpdateAutoButtonStatus() | 997 addon:UpdateAutoButtonStatus() |
| 973 if lfgTable then lfgTable:Refresh() end | 998 if lfgTable then lfgTable:Refresh() end |
| 974 end | 999 end |
| 975 | 1000 |
| 976 --[[local function resetPos() | 1001 local function QuickJoinStoplist() |
| 977 db.global.widgetPos = DefaultWidgetPos | 1002 StaticPopupDialogs["CROSS_REALM_ASSIST_STOPLIST"] = { |
| 978 if gui then | 1003 OnShow = function (self, data) |
| 979 gui:ClearAllPoints() | 1004 self.editBox:SetText(table.concat(db.global.stoplist or {}, ",")) |
| 980 gui:SetPoint(DefaultWidgetPos.to,DefaultWidgetPos.x,DefaultWidgetPos.y) | 1005 end, |
| 981 end | 1006 OnAccept=function(self) |
| 982 end]] | 1007 local text = self.editBox:GetText(); |
| 1008 local stoplist = {} | |
| 1009 for item in string.gmatch(text, "[^, ][^,]*") do | |
| 1010 table.insert(stoplist,string.lower(item)) | |
| 1011 end | |
| 1012 db.global.stoplist = stoplist | |
| 1013 end, | |
| 1014 button1 = OKAY, | |
| 1015 button2 = CANCEL, | |
| 1016 editBoxWidth = 350, | |
| 1017 hasEditBox=true, | |
| 1018 text = "Ignore groups containing following words:\nSeparated by comma", | |
| 1019 preferredIndex = 3 | |
| 1020 } | |
| 1021 StaticPopup_Show("CROSS_REALM_ASSIST_STOPLIST") | |
| 1022 end | |
| 983 | 1023 |
| 984 local function initMenu(self, level) | 1024 local function initMenu(self, level) |
| 985 if not level then return end | 1025 if not level then return end |
| 986 if level == 1 then | 1026 if level == 1 then |
| 987 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level) | 1027 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level) |
| 988 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level) | 1028 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level) |
| 989 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) | 1029 |
| 990 UIDropDownMenu_AddButton({isTitle=1,text="Settings",notCheckable=1}, level) | 1030 if canJoinGroup() then |
| 991 UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level) | 1031 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) |
| 992 UIDropDownMenu_AddButton({text="All language groups",checked=db.global.allLanguages, func=toggleAllLanguages,keepShownOnClick=true,isNotRadio=true}, level) | 1032 UIDropDownMenu_AddButton({text="Create a group for realm hoppers",notCheckable=1,func=CreateHopGroup}, level) |
| 993 UIDropDownMenu_AddButton({text="Apply to groups as DD only",checked=db.global.applyAsDD, func=toggleApplyAsDD,keepShownOnClick=true,isNotRadio=true}, level) | 1033 end |
| 994 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level) | 1034 |
| 995 UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level) | 1035 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) |
| 1036 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level) | |
| 1037 UIDropDownMenu_AddButton({text="Settings",notCheckable=1,hasArrow=1,value="settings",keepShownOnClick=true}, level) | |
| 996 elseif level == 2 then | 1038 elseif level == 2 then |
| 997 if UIDROPDOWNMENU_MENU_VALUE == "qjc" then | 1039 if UIDROPDOWNMENU_MENU_VALUE == "settings" then |
| 1040 UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level) | |
| 1041 UIDropDownMenu_AddButton({text="All language groups",checked=db.global.allLanguages, func=toggleAllLanguages,keepShownOnClick=true,isNotRadio=true}, level) | |
| 1042 UIDropDownMenu_AddButton({text="Apply to groups as DD only",checked=db.global.applyAsDD, func=toggleApplyAsDD,keepShownOnClick=true,isNotRadio=true}, level) | |
| 1043 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) | |
| 1044 UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level) | |
| 1045 UIDropDownMenu_AddButton({text="Edit Quick Join Stoplist",notCheckable=1,func=QuickJoinStoplist}, level) | |
| 1046 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) | |
| 1047 UIDropDownMenu_AddButton({text="Experimental features",notCheckable=1,hasArrow=1,value="experimental",keepShownOnClick=true}, level) | |
| 1048 end | |
| 1049 elseif level == 3 then | |
| 1050 if UIDROPDOWNMENU_MENU_VALUE == "qjc" then | |
| 998 for i=1,#lfgGroups do | 1051 for i=1,#lfgGroups do |
| 999 local groupId = lfgGroups[i] | 1052 local groupId = lfgGroups[i] |
| 1000 UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level) | 1053 UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level) |
| 1001 end | 1054 end |
| 1002 end | 1055 elseif UIDROPDOWNMENU_MENU_VALUE == "experimental" then |
| 1003 end | 1056 UIDropDownMenu_AddButton({isTitle=1,text="Use at your own risk!",notCheckable=1}, level) |
| 1057 UIDropDownMenu_AddButton({text="Auto create group for realm hopping when AFK at garrison",checked=db.global.autoCreateHopGroup,keepShownOnClick=true,isNotRadio=true,func=toggleCreateHopGroup}, level) | |
| 1058 end | |
| 1059 end | |
| 1004 end | 1060 end |
| 1005 | 1061 |
| 1006 function addon.ShowSettings(frame) | 1062 function addon.ShowSettings(frame) |
| 1007 if not settingsMenu then | 1063 if not settingsMenu then |
| 1008 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu") | 1064 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu") |
