vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | local mod = klhtm |
||
3 | local me = { } |
||
4 | mod.table = me |
||
5 | |||
6 | me.mydata = { } -- personal threat table data |
||
7 | me.raiddata = { } -- raid's threat table data |
||
8 | me.raidthreatoffset = 0 -- difference between your total threat and your raid threat |
||
9 | |||
10 | me.raidclasses = { } -- list of classes by player name. e.g. { ["Kenco"] = "Warrior", } |
||
11 | me.raidupdatetimes = { } -- list of last update times by player, e.g. { ["Kenco"] = GetTime(), } |
||
12 | |||
13 | ------------------------------------ |
||
14 | -- Special Core.lua Methods -- |
||
15 | ------------------------------------ |
||
16 | |||
17 | me.onload = function() |
||
18 | |||
19 | -- initialise me.mydata . This refers to static methods from me.string, so goes in our onload(). |
||
20 | me.mydata[mod.string.get("threatsource", "total")] = me.newdatastruct() |
||
21 | |||
22 | end |
||
23 | |||
24 | --[[ |
||
25 | We have the list me.raiddata, key = name, value = threat. Then the list me.raidupdatetimes, key = value, name = time. |
||
26 | We want to remove people from raiddata who are not in the raid / party, and also to reset the threat of people who are |
||
27 | in the party, but who haven't updated for a while. |
||
28 | ]] |
||
29 | |||
30 | me.lastonupdate = 0 -- value of GetTime() |
||
31 | me.updateinterval = 1.0 -- at most once every second |
||
32 | me.idlereset = 15.0 -- seconds before we reset someone's threat |
||
33 | |||
34 | me.onupdate = function() |
||
35 | |||
36 | -- 1) check for update time |
||
37 | local timenow = GetTime() |
||
38 | if timenow > me.lastonupdate + me.updateinterval then |
||
39 | me.lastonupdate = timenow |
||
40 | else |
||
41 | return |
||
42 | end |
||
43 | |||
44 | local x |
||
45 | |||
46 | -- 2) Remove people who aren't in the raid group |
||
47 | for x, _ in me.raiddata do |
||
48 | |||
49 | if (x ~= mod.string.get("misc", "aggrogain")) and (mod.unit.isplayeringroup(x) == nil) then |
||
50 | |||
51 | if mod.out.checktrace("info", me, "idleplayer") then |
||
52 | mod.out.printtrace(string.format("Removing %s from the table, since he isn't in the raid group.", x)) |
||
53 | end |
||
54 | |||
55 | me.raiddata[x] = nil |
||
56 | me.raidupdatetimes[x] = nil |
||
57 | |||
58 | end |
||
59 | end |
||
60 | |||
61 | -- 3) Reset inactive people |
||
62 | for x, _ in me.raiddata do |
||
63 | if me.raidupdatetimes[x] == nil then |
||
64 | me.raidupdatetimes[x] = timenow |
||
65 | |||
66 | elseif (timenow > me.raidupdatetimes[x] + me.idlereset) and (me.raiddata[x] ~= 0) then |
||
67 | me.raiddata[x] = 0 |
||
68 | me.raidupdatetimes[x] = timenow |
||
69 | |||
70 | if mod.out.checktrace("info", me, "idleplayer") then |
||
71 | mod.out.printtrace(string.format("Resetting %s's threat, since he hasn't updated for a while.", x)) |
||
72 | end |
||
73 | end |
||
74 | end |
||
75 | |||
76 | |||
77 | end |
||
78 | |||
79 | |||
80 | -- to save lots of writing! |
||
81 | me.newdatastruct = function() |
||
82 | |||
83 | return |
||
84 | { |
||
85 | ["hits"] = 0, |
||
86 | ["damage"] = 0, |
||
87 | ["threat"] = 0, |
||
88 | ["rage"] = 0, |
||
89 | } |
||
90 | |||
91 | end |
||
92 | |||
93 | |||
94 | ----------------------------------------------------- |
||
95 | |||
96 | --[[ |
||
97 | mod.table.getraidthreat() |
||
98 | Returns the value you would post to the raid group as your threat. |
||
99 | ]] |
||
100 | me.getraidthreat = function() |
||
101 | |||
102 | return me.mydata[mod.string.get("threatsource", "total")].threat + me.raidthreatoffset |
||
103 | |||
104 | end |
||
105 | |||
106 | --[[ |
||
107 | mod.table.resetraidthreat() |
||
108 | Set your threat for the rest of the raid group to 0. Used for a complete threat wipe. |
||
109 | ]] |
||
110 | me.resetraidthreat = function() |
||
111 | |||
112 | me.raidthreatoffset = - me.mydata[mod.string.get("threatsource", "total")].threat |
||
113 | |||
114 | end |
||
115 | |||
116 | --[[ |
||
117 | mod.table.updateplayerthreat(player, threat) |
||
118 | Updates a raid threat entry. |
||
119 | <player> is the name of the player whose threat is updated |
||
120 | <threat> is the new amount |
||
121 | TODO: add code to change aggrogain here, if player is master target??? |
||
122 | ]] |
||
123 | me.updateplayerthreat = function(player, threat) |
||
124 | |||
125 | me.raiddata[player] = threat |
||
126 | me.raidupdatetimes[player] = GetTime() |
||
127 | |||
128 | end |
||
129 | |||
130 | |||
131 | --[[ |
||
132 | mod.table.redoraidclasses() |
||
133 | Checks the raid / party and finds the class of every player. |
||
134 | ]] |
||
135 | me.redoraidclasses = function() |
||
136 | |||
137 | local numraiders = GetNumRaidMembers() |
||
138 | local class |
||
139 | |||
140 | if (numraiders == 0) then |
||
141 | -- we're not in a raid. check party |
||
142 | |||
143 | local numparty = GetNumPartyMembers() |
||
144 | |||
145 | for x = 1, numparty do |
||
146 | _, class = UnitClass("party" .. x) |
||
147 | me.raidclasses[UnitName("party" .. x)] = string.lower(class) |
||
148 | end |
||
149 | |||
150 | -- also do yourself |
||
151 | me.raidclasses[UnitName("player")] = mod.my.class |
||
152 | |||
153 | else -- we're in a raid |
||
154 | |||
155 | local class |
||
156 | local name |
||
157 | |||
158 | for x = 1, numraiders do |
||
159 | _, class = UnitClass("raid" .. x) |
||
160 | me.raidclasses[UnitName("raid" .. x)] = string.lower(class) |
||
161 | end |
||
162 | end |
||
163 | end |
||
164 | |||
165 | --[[ |
||
166 | mod.table.resetmytable() |
||
167 | Clears all the data in your personal threat table. |
||
168 | ]] |
||
169 | me.resetmytable = function() |
||
170 | |||
171 | -- reset raid offset |
||
172 | me.raidthreatoffset = me.getraidthreat() |
||
173 | |||
174 | -- clear table |
||
175 | local key |
||
176 | local value |
||
177 | local key2 |
||
178 | |||
179 | for key, value in me.mydata do |
||
180 | for key2 in value do |
||
181 | value[key2] = 0 |
||
182 | end |
||
183 | end |
||
184 | |||
185 | end |
||
186 | |||
187 | --[[ |
||
188 | mod.table.resetraidtable() |
||
189 | Clears all the data in the raid table. |
||
190 | ]] |
||
191 | me.clearraidtable = function() |
||
192 | |||
193 | local key |
||
194 | |||
195 | for key, _ in me.raiddata do |
||
196 | me.raiddata[key] = nil; |
||
197 | end |
||
198 | |||
199 | me.raiddata[UnitName("player")] = 0 |
||
200 | |||
201 | end |