Advertisement
Guest User

Untitled

a guest
Oct 27th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.54 KB | None | 0 0
  1. -- List of talent spec displays
  2. local displays = {
  3.     ["DEATHKNIGHT"] = {
  4.         ["Blood"]         = "Blood DK",
  5.         ["Frost"]         = "Frost DK",
  6.         ["Unholy"]        = "Unholy DK",
  7.     },
  8.     ["DRUID"] = {
  9.         ["Balance"]       = "Moonkin",
  10.         ["Feral"]         = "Cat Druid",
  11.         ["Guardian"]      = "Bear Druid",
  12.         ["Restoration"]   = "Resto Druid",
  13.     },
  14.     ["HUNTER"] = {
  15.         ["Beast Mastery"] = "BM Hunter",
  16.         ["Marksmanship"]  = "MM Hunter",
  17.         ["Survival"]      = "Surv Hunter",
  18.     },
  19.     ["MAGE"] = {
  20.         ["Arcane"]        = "Arcane Mage",
  21.         ["Fire"]          = "Fire Mage",
  22.         ["Frost"]         = "Frost Mage",
  23.     },
  24.     ["MONK"] = {
  25.         ["Brewmaster"]    = "Brew Monk",
  26.         ["Mistweaver"]    = "Mist Monk",
  27.         ["Windwalker"]    = "Wind Monk",
  28.     },
  29.     ["PALADIN"] = {
  30.         ["Holy"]          = "Holy Pally",
  31.         ["Protection"]    = "Prot Pally",
  32.         ["Retribution"]   = "Ret Pally",
  33.     },
  34.     ["PRIEST"] = {
  35.         ["Discipline"]    = "Disc Priest",
  36.         ["Holy"]          = "Holy Priest",
  37.         ["Shadow"]        = "Shadow Priest",
  38.     },
  39.     ["ROGUE"] = {
  40.         ["Assassination"] = "Mute Rogue",
  41.         ["Combat"]        = "Combat Rogue",
  42.         ["Subtlety"]      = "Sub Rogue",
  43.     },
  44.     ["SHAMAN"] = {
  45.         ["Elemental"]     = "Ele Shaman",
  46.         ["Enhancement"]   = "Enhance Shaman",
  47.         ["Restoration"]   = "Resto Shaman",
  48.     },
  49.     ["WARLOCK"] = {
  50.         ["Affliction"]    = "Aff Lock",
  51.         ["Demonology"]    = "Demo Lock",
  52.         ["Destruction"]   = "Destro Lock",
  53.     },
  54.     ["WARRIOR"] = {
  55.         ["Arms"]          = "Arms Warr",
  56.         ["Fury"]          = "Fury Warr",
  57.         ["Protection"]    = "Prot Warr",
  58.     },
  59.     ["AMBIGUOUS"] = {
  60.         ["Frost"]         = "Frost Something",
  61.         ["Holy"]          = "Holy Something",
  62.         ["Protection"]    = "Prot Something",
  63.         ["Restoration"]   = "Resto Something",
  64.     },
  65. }
  66.  
  67. -- List of talent spec roles
  68. local roles = {
  69.     ["DEATHKNIGHT"] = {
  70.         ["Blood"]         = "Tank",
  71.         ["Frost"]         = "Melee",
  72.         ["Unholy"]        = "Melee",
  73.     },
  74.     ["DRUID"] = {
  75.         ["Balance"]       = "Knockback",
  76.         ["Feral"]         = "Melee",
  77.         ["Guardian"]      = "Tank",
  78.         ["Restoration"]   = "Healer",
  79.     },
  80.     ["HUNTER"] = {
  81.         ["Beast Mastery"] = "Knockback",
  82.         ["Marksmanship"]  = "Ranged",
  83.         ["Survival"]      = "Ranged",
  84.     },
  85.     ["MAGE"] = {
  86.         ["Arcane"]        = "Knockback",
  87.         ["Fire"]          = "Ranged",
  88.         ["Frost"]         = "Ranged",
  89.     },
  90.     ["MONK"] = {
  91.         ["Brewmaster"]    = "Tank",
  92.         ["Mistweaver"]    = "Healer",
  93.         ["Windwalker"]    = "Melee",
  94.     },
  95.     ["PALADIN"] = {
  96.         ["Holy"]          = "Healer",
  97.         ["Protection"]    = "Tank",
  98.         ["Retribution"]   = "Melee",
  99.     },
  100.     ["PRIEST"] = {
  101.         ["Discipline"]    = "Healer",
  102.         ["Holy"]          = "Healer",
  103.         ["Shadow"]        = "Ranged",
  104.     },
  105.     ["ROGUE"] = {
  106.         ["Assassination"] = "Melee",
  107.         ["Combat"]        = "Melee",
  108.         ["Subtlety"]      = "Melee",
  109.     },
  110.     ["SHAMAN"] = {
  111.         ["Elemental"]     = "Knockback",
  112.         ["Enhancement"]   = "Melee",
  113.         ["Restoration"]   = "Healer",
  114.     },
  115.     ["WARLOCK"] = {
  116.         ["Affliction"]    = "Knockback",
  117.         ["Demonology"]    = "Knockback",
  118.         ["Destruction"]   = "Knockback",
  119.     },
  120.     ["WARRIOR"] = {
  121.         ["Arms"]          = "Melee",
  122.         ["Fury"]          = "Melee",
  123.         ["Protection"]    = "Tank",
  124.     },
  125.     ["AMBIGUOUS"] = {
  126.         ["Frost"]         = "Ranged", -- Ranged Frost DKs?
  127.         ["Holy"]          = "Healer",
  128.         ["Protection"]    = "Tank",
  129.         ["Restoration"]   = "Healer",
  130.     },
  131. }
  132.  
  133. -- List of talent spec classes
  134. local classes = {
  135.     ["Blood"]         = "DEATHKNIGHT",
  136.     ["Unholy"]        = "DEATHKNIGHT",
  137.     ["Balance"]       = "DRUID",
  138.     ["Feral"]         = "DRUID",
  139.     ["Guardian"]      = "DRUID",
  140.     ["Beast Mastery"] = "HUNTER",
  141.     ["Marksmanship"]  = "HUNTER",
  142.     ["Survival"]      = "HUNTER",
  143.     ["Arcane"]        = "MAGE",
  144.     ["Fire"]          = "MAGE",
  145.     ["Brewmaster"]    = "MONK",
  146.     ["Mistweaver"]    = "MONK",
  147.     ["Windwalker"]    = "MONK",
  148.     ["Retribution"]   = "PALADIN",
  149.     ["Discipline"]    = "PRIEST",
  150.     ["Shadow"]        = "PRIEST",
  151.     ["Assassination"] = "ROGUE",
  152.     ["Combat"]        = "ROGUE",
  153.     ["Subtlety"]      = "ROGUE",
  154.     ["Elemental"]     = "SHAMAN",
  155.     ["Enhancement"]   = "SHAMAN",
  156.     ["Affliction"]    = "WARLOCK",
  157.     ["Demonology"]    = "WARLOCK",
  158.     ["Destruction"]   = "WARLOCK",
  159.     ["Arms"]          = "WARRIOR",
  160.     ["Fury"]          = "WARRIOR",
  161.     ["Frost"]         = "AMBIGUOUS",
  162.     ["Holy"]          = "AMBIGUOUS",
  163.     ["Protection"]    = "AMBIGUOUS",
  164.     ["Restoration"]   = "AMBIGUOUS",
  165. }
  166.  
  167. -- List of class colours
  168. local colours = {
  169.     ["DEATHKNIGHT"] = "|cFFC41F3B",
  170.     ["DRUID"]       = "|cFFFF7D0A",
  171.     ["HUNTER"]      = "|cFFABD473",
  172.     ["MAGE"]        = "|cFF69CCF0",
  173.     ["MONK"]        = "|cFF00FF96",
  174.     ["PALADIN"]     = "|cFFF58CBA",
  175.     ["PRIEST"]      = "|cFFFFFFFF",
  176.     ["ROGUE"]       = "|cFFFFF569",
  177.     ["SHAMAN"]      = "|cFF0070DE",
  178.     ["WARLOCK"]     = "|cFF9482C9",
  179.     ["WARRIOR"]     = "|cFFC79C6E",
  180.     ["AMBIGUOUS"]   = "|cFF7F7F7F",
  181. }
  182.  
  183. local function charcount(s, c)
  184.     local _, n = gsub(s, c, c)
  185.     return n
  186. end
  187.  
  188. local function charselect(s, i)
  189.     -- Returns false on no character
  190.     local c = strsub(s, i, i)
  191.     return c ~= "" and c
  192. end
  193.  
  194. local realm = GetRealmName()
  195. local function ParseName(identifier)
  196.     -- Pattern assumes identifier is formatted as "name" or "name-server"
  197.     -- Name is composed of every character except for '-'
  198.     -- Server is any characters after an optional '-' character
  199.     -- When no '-' character is present, the player is from the local realm
  200.     local name, server = strmatch(identifier, "^([^%-]+)-?(.*)")
  201.     return name, server == "" and realm or server
  202. end
  203.  
  204. local function DisplayMessage(report, message, ...)
  205.     if report then
  206.         SendChatMessage(gsub(message, "%%s", ""), "BATTLEGROUND")
  207.     else
  208.         print(format(message, ...))
  209.     end
  210. end
  211.  
  212.  
  213.  
  214. local function BuildList(side)
  215.     -- Show scores for players of both factions
  216.     RequestBattlefieldScoreData()
  217.     SetBattlefieldScoreFaction()
  218.    
  219.     -- Build list of players
  220.     local players, specless = {}, 0
  221.     for i = 1, GetNumBattlefieldScores() do
  222.         local identifier, _, _, _, _, faction, race, _, classToken, _, _, _, _, _, _, talentSpec = GetBattlefieldScore(i)
  223.         if faction == side then
  224.             if talentSpec then
  225.                 local name, server = ParseName(identifier)
  226.                 local player = {
  227.                     ["name"]   = name,
  228.                     ["server"] = server,
  229.                     ["spec"]   = talentSpec,
  230.                 }
  231.                 -- GetBattlefieldScore occasionally returns nil for race, class, and classToken
  232.                 -- Assume all three are absent together
  233.                 if race then
  234.                     player["race"]    = race
  235.                     player["class"]   = classToken
  236.                     player["colour"]  = colours[classToken]
  237.                     player["display"] = displays[classToken][talentSpec]
  238.                     player["role"]    = roles[classToken][talentSpec]
  239.                 else
  240.                     player["race"]    = "Unknown"
  241.                     player["class"]   = classes[talentSpec]
  242.                     player["colour"]  = colours[classes[talentSpec]]
  243.                     player["display"] = displays[classes[talentSpec]][talentSpec]
  244.                     player["role"]    = roles[classes[talentSpec]][talentSpec]
  245.                 end
  246.                 tinsert(players, player)
  247.             else
  248.                 specless = specless+1
  249.             end
  250.         end
  251.     end
  252.    
  253.     -- Check for any talented players on the team
  254.     local n = #players
  255.     if n == 0 then
  256.         print(format("%s have 0 players with talents and %d players with no talents.", side == 0 and "Horde" or "Alliance", specless))
  257.         return
  258.     end
  259.    
  260.     -- Sort by class then spec then name
  261.     sort(players, function(a, b) return a.class == b.class and ( a.spec == b.spec and a.name < b.name or a.spec < b.spec ) or a.class < b.class end)
  262.    
  263.     return players, n, specless
  264. end
  265.  
  266. local function DisplaySummary(report)
  267.     DisplayMessage(report, "BG Spy: Team Summary")
  268.     for side = 0, 1 do
  269.         local players, n, specless = BuildList(side)
  270.         if not players then
  271.             return
  272.         end
  273.        
  274.         -- Role totals
  275.         local total = {
  276.             Tank      = 0,
  277.             Healer    = 0,
  278.             Melee     = 0,
  279.             Ranged    = 0,
  280.             Knockback = 0,
  281.         }
  282.        
  283.         -- Calculate the role totals
  284.         for i = 1, n do
  285.             total[players[i].role] = total[players[i].role]+1
  286.         end
  287.        
  288.         -- Display role totals
  289.         DisplayMessage(report, format("%s: %d melee, %d ranged, %d healer%s.%s", side == 0 and "Horde" or "Alliance", total.Tank+total.Melee, total.Ranged+total.Knockback, total.Healer, total.Healer == 1 and "" or "s", specless > 0 and format(" (%d with no talents)", specless) or ""))
  290.     end
  291. end
  292.  
  293. local function DisplaySpecs(side, report)
  294.     local players, n, specless = BuildList(side)
  295.     if not players then
  296.         return
  297.     end
  298.    
  299.     -- Role totals
  300.     local total = {
  301.         Tank      = 0,
  302.         Healer    = 0,
  303.         Melee     = 0,
  304.         Ranged    = 0,
  305.         Knockback = 0,
  306.     }
  307.    
  308.     -- Display list
  309.     local x, last, names = 1, players[1].display, players[1].name
  310.     total[players[1].role] = 1
  311.     local function out(i)
  312.         DisplayMessage(report, format("%dx %%s%s (%s)", x, last, names), players[i].colour)
  313.     end
  314.    
  315.     for i = 2, n do
  316.         local current = players[i].display
  317.         if current ~= last then
  318.             out(i-1)
  319.             x = 1
  320.             last = current
  321.             names = players[i].name
  322.         else
  323.             x = x+1
  324.             names = format("%s, %s", names, players[i].name)
  325.         end
  326.         total[players[i].role] = total[players[i].role]+1
  327.     end
  328.     out(n)
  329.    
  330.     -- Display role totals
  331.     DisplayMessage(report, format("%s: %d melee, %d ranged, %d healer%s.%s", side == 0 and "Horde" or "Alliance", total.Tank+total.Melee, total.Ranged+total.Knockback, total.Healer, total.Healer == 1 and "" or "s", specless > 0 and format(" (%d with no talents)", specless) or ""))
  332. end
  333.  
  334. -- Role listing tables
  335. local member = {
  336.     t = function(role)
  337.         return role == "Tank"
  338.     end,
  339.     h = function(role)
  340.         return role == "Healer"
  341.     end,
  342.     d = function(role)
  343.         return role == "Melee" or role == "Ranged" or role == "Knockback"
  344.     end,
  345.     k = function(role)
  346.         return role == "Knockback"
  347.     end,
  348. }
  349. local listname = {
  350.     t = "tank",
  351.     h = "healer",
  352.     d = "DPS",
  353.     k = "knockback",
  354. }
  355.  
  356. local function DisplayRole(side, report, list)
  357.     local players, n = BuildList(side)
  358.     if not players then
  359.         return
  360.     end
  361.    
  362.     -- Display list
  363.     local total = 0
  364.     for i = 1, n do
  365.         if member[list](players[i].role) then
  366.             DisplayMessage(report, format("%s - %s %%s%s", players[i].name, players[i].race, players[i].display), players[i].colour)
  367.             total = total+1
  368.         end
  369.     end
  370.     DisplayMessage(report, format("%s have %d %s%s.", side == 0 and "Horde" or "Alliance", total, listname[list], list ~= "d" and total ~= 1 and "s" or ""))
  371. end
  372.  
  373. SLASH_BGSPY1, SLASH_BGSPY2 = "/bgspy", "/bgs"
  374. SlashCmdList.BGSPY = function(msg)
  375.     -- Check for any invalid characters
  376.     msg = strlower(msg)
  377.     if not strfind(msg, "[^rfsthdk ]") then
  378.        
  379.         -- Check for invalid combinations of list types
  380.         local itype = strfind(msg, "[sthdk]") or 0
  381.         if not strfind(msg, "[sthdk]", itype+1) then
  382.            
  383.             -- Check for repetitions of control characters
  384.             local nf = charcount(msg, "f")
  385.             local nr = charcount(msg, "r")
  386.             if nf <= 1 and nr <= 1 then
  387.                
  388.                 -- Check if player is in a Battleground
  389.                 if GetNumBattlefieldScores() == 0 then
  390.                     print("BG Spy: Not in a Battleground.")
  391.                     return
  392.                 end
  393.                
  394.                 -- Set the arguments for the list functions
  395.                 local side = nf == GetBattlefieldArenaFaction() and 1 or 0
  396.                 local report = nr == 1
  397.                
  398.                 -- Run a list function
  399.                 local list = charselect(msg, itype)
  400.                 if list == "s" then
  401.                     DisplaySpecs(side, report)
  402.                 elseif list then
  403.                     DisplayRole(side, report, list)
  404.                 else
  405.                     DisplaySummary(report)
  406.                 end
  407.                 return
  408.             end
  409.         end
  410.     end
  411.    
  412.     print("BG Spy commands:")
  413.     print("/bgs - Include any additional commands.")
  414.     print("r - Report list to Battleground chat.")
  415.     print("f - List players of friendly team.")
  416.     print("s - List talent spec numbers on team.")
  417.     print("t - List tanks on team.")
  418.     print("h - List healers on team.")
  419.     print("d - List DPS on team.")
  420.     print("k - List players possible of knockback effects on team.")
  421.     print("Example - /bgs rfh - Report friendly healers.")
  422. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement