forked from Bestoriop/QuickHeal-Turtle-Wow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraveyard.lua
More file actions
611 lines (523 loc) · 24.3 KB
/
Graveyard.lua
File metadata and controls
611 lines (523 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
function QuickHoTSingle(playerName, forceMaxRank)
local _, class = UnitClass('player');
class = string.lower(class);
if class == "druid" then
--
elseif class == "paladin" then
return;
elseif class == "priest" then
--
elseif class == "shaman" then
return;
end
-- Only one instance of QuickHeal allowed at a time
if QuickHealBusy then
if HealingTarget and MassiveOverhealInProgress then
QuickHeal_debug("Massive overheal aborted.");
SpellStopCasting();
else
QuickHeal_debug("Healing in progress, command ignored");
end
return ;
end
QuickHealBusy = true;
local AutoSelfCast = GetCVar("autoSelfCast");
SetCVar("autoSelfCast", 0);
-- Protect against invalid extParam
if not (type(extParam) == "table") then
extParam = {}
end
Target = FindSingleToHOT(playerName);
--QuickHeal_debug("********** BREAKPOINT: Well, we got this far. **********");
--QuickHeal_debug(string.format(" Healing target grr: (%s)", Target));
QuickHeal_debug(string.format(" Healing target grr: " .. tostring(Target)));
if (Target == nil) or (Target == false) then
jgpprint("ain't nobody to heal dude")
SetCVar("autoSelfCast", AutoSelfCast);
QuickHealBusy = false;
return;
end
-- Target acquired
--QuickHeal_debug(string.format(" Healing target: %s (%s)", UnitFullName(Target), Target));
HealingSpellSize = 0;
SpellID, HealingSpellSize = FindHoTSpellToUse(Target, "hot", forceMaxRank);
if (SpellID == nil) then
--jgpprint("ain't nobody to heal dude")
SetCVar("autoSelfCast", AutoSelfCast);
QuickHealBusy = false;
return;
end
if SpellID then
ExecuteHOT(Target, SpellID);
QuickHealBusy = false;
else
Message("You have no healing spells to cast", "Error", 2);
end
SetCVar("autoSelfCast", AutoSelfCast);
end
function FindSingleToHOT(playerName)
local playerIds = {};
local petIds = {};
local i;
local AllPlayersAreFull = true;
local AllPetsAreFull = true;
QuickHeal_debug("********** HoT Single **********");
local healingTarget = nil;
local healingTargetHealth = 100000;
local healingTargetHealthPct = 1;
local healingTargetMissinHealth = 0;
local unit;
--jgpprint("forceApplication == " .. tostring(forceApplication))
if (InRaid()) then
for i = 1, GetNumRaidMembers() do
if UnitIsHealable("raid" .. i, true) then
jgpprint("considering raid" .. i .. ":" .. UnitName("raid" .. i))
if IsSingleTarget("raid" .. i, playerName) then
--if not UnitHasRenew("raid" .. i) then
--jgpprint("AAAAAAAAAAAAAAAAAAAAAAAAAA" .. UnitName("raid" .. i) .. " doesn't have renew.")
--playerIds["raid" .. i] = i;
healingTarget = "raid" .. i;
--end
--elseif forceApplication then
-- healingTarget = "raid" .. i;
--end
--healingTarget = "raid" .. 1;
--return healingTarget;
jgpprint(UnitName("raid" .. i) .. " :: " .. "raid" .. i)
end
end
end
else
for i = 1, GetNumPartyMembers() do
if UnitIsHealable("party" .. i, true) then
if IsSingleTarget("party" .. i, playerName) then
--playerIds["party" .. i] = i;
--if not UnitHasRenew("party" .. i) then
healingTarget = "party" .. i;
--end
jgpprint(UnitName("party" .. i))
end
end
end
end
--QuickHeal_debug("********** Done Scanning for single-target HoT **********");
-- Clear any healable target
local OldPlaySound = PlaySound;
PlaySound = function()
end
local TargetWasCleared = false;
if UnitIsHealable('target') then
TargetWasCleared = true;
ClearTarget();
end
--QuickHeal_debug("********** in the middle **********");
-- Cast the checkspell
CastCheckSpellHOT();
if not SpellIsTargeting() then
-- Reacquire target if it was cleared
if TargetWasCleared then
TargetLastTarget();
end
-- Reinsert the PlaySound
PlaySound = OldPlaySound;
return false;
end
--QuickHeal_debug("********** And then this happens **********");
-- Examine Healable Players
--for unit, i in playerIds do
-- QuickHeal_debug(string.format("%s (%s) : %d/%d", UnitFullName(unit), unit, UnitHealth(unit), UnitHealthMax(unit)));
-- local SubGroup = false;
-- if InRaid() and not RestrictParty and RestrictSubgroup and i <= GetNumRaidMembers() then
-- _, _, SubGroup = GetRaidRosterInfo(i);
-- end
-- if not RestrictSubgroup or RestrictParty or not InRaid() or (SubGroup and not QHV["FilterRaidGroup" .. SubGroup]) then
-- if not IsBlacklisted(UnitFullName(unit)) then
-- if SpellCanTargetUnit(unit) then
-- QuickHeal_debug(string.format("%s (%s) : %d/%d", UnitFullName(unit), unit, UnitHealth(unit), UnitHealthMax(unit)));
--
-- --Get who to heal for different classes
-- local IncHeal = HealComm:getHeal(UnitName(unit))
-- local PredictedHealth = (UnitHealth(unit) + IncHeal)
-- local PredictedHealthPct = (UnitHealth(unit) + IncHeal) / UnitHealthMax(unit);
-- local PredictedMissingHealth = UnitHealthMax(unit) - UnitHealth(unit) - IncHeal;
--
-- if PredictedHealthPct < QHV.RatioFull then
-- local _, PlayerClass = UnitClass('player');
-- PlayerClass = string.lower(PlayerClass);
--
-- --if PlayerClass == "shaman" then
-- -- if PredictedHealthPct < healingTargetHealthPct then
-- -- healingTarget = unit;
-- -- healingTargetHealthPct = PredictedHealthPct;
-- -- AllPlayersAreFull = false;
-- -- end
-- if PlayerClass == "priest" then
-- --writeLine("Find who to heal for Priest");
-- if healPlayerWithLowestPercentageOfLife == 1 then
-- if PredictedHealthPct < healingTargetHealthPct then
-- --if not UnitHasRenew(unit) then
-- --QuickHeal_debug("********** Hot target don't got HoT **********");
-- healingTarget = unit;
-- healingTargetHealthPct = PredictedHealthPct;
-- AllPlayersAreFull = false;
-- --else
-- -- QuickHeal_debug("********** Hot target got HoT **********");
-- --end
-- end
-- else
-- if PredictedMissingHealth > healingTargetMissinHealth then
-- --if not UnitHasRenew(unit) then
-- --QuickHeal_debug("********** Hot target don't got HoT **********");
-- healingTarget = unit;
-- healingTargetMissinHealth = PredictedMissingHealth;
-- AllPlayersAreFull = false;
-- --else
-- -- QuickHeal_debug("********** Hot target got HoT **********");
-- --end
-- end
-- end
-- --elseif PlayerClass == "paladin" then
-- -- --writeLine("Find who to heal for Paladin")
-- -- if healPlayerWithLowestPercentageOfLife == 1 then
-- -- if PredictedHealthPct < healingTargetHealthPct then
-- -- healingTarget = unit;
-- -- healingTargetHealthPct = PredictedHealthPct;
-- -- AllPlayersAreFull = false;
-- -- end
-- -- else
-- -- if PredictedHealth < healingTargetHealth then
-- -- healingTarget = unit;
-- -- healingTargetHealth = PredictedHealth;
-- -- AllPlayersAreFull = false;
-- -- end
-- -- end
-- elseif PlayerClass == "druid" then
-- if PredictedHealthPct < healingTargetHealthPct then
-- healingTarget = unit;
-- healingTargetHealthPct = PredictedHealthPct;
-- AllPlayersAreFull = false;
-- end
-- else
-- writeLine(QuickHealData.name .. " " .. QuickHealData.version .. " does not support " .. UnitClass('player') .. ". " .. QuickHealData.name .. " not loaded.")
-- return ;
-- end
-- end
--
--
-- --writeLine("Values for "..UnitName(unit)..":")
-- --writeLine("Health: "..UnitHealth(unit) / UnitHealthMax(unit).." | IncHeal: "..IncHeal / UnitHealthMax(unit).." | PredictedHealthPct: "..PredictedHealthPct) --Edelete
-- else
-- QuickHeal_debug(UnitFullName(unit) .. " (" .. unit .. ")", "is out-of-range or unhealable");
-- end
-- else
-- QuickHeal_debug(UnitFullName(unit) .. " (" .. unit .. ")", "is blacklisted");
-- end
-- end
--end
--healPlayerWithLowestPercentageOfLife = 0
-- Reacquire target if it was cleared earlier, and stop CheckSpell
SpellStopTargeting();
if TargetWasCleared then
TargetLastTarget();
end
PlaySound = OldPlaySound;
---- Examine External Target
--if AllPlayersAreFull and (AllPetsAreFull or QHV.PetPriority == 0) then
-- if not QuickHeal_UnitHasHealthInfo('target') and UnitIsHealable('target', true) then
-- QuickHeal_debug(string.format("%s (%s) : %d/%d", UnitFullName('target'), 'target', UnitHealth('target'), UnitHealthMax('target')));
-- local Health;
-- Health = UnitHealth('target') / 100;
-- if Health < QHV.RatioFull then
-- return 'target';
-- end
-- end
--end
if UnitHasRenew(healingTarget) then
healingTarget = nil;
end
return healingTarget;
end
function QuickHealSingle(playerName, multiplier)
if multiplier == nil then
multiplier = 1.0;
end
-- Only one instance of QuickHeal allowed at a time
if QuickHealBusy then
if HealingTarget and MassiveOverhealInProgress then
QuickHeal_debug("Massive overheal aborted.");
SpellStopCasting();
else
QuickHeal_debug("Healing in progress, command ignored");
end
return ;
end
QuickHealBusy = true;
local AutoSelfCast = GetCVar("autoSelfCast");
SetCVar("autoSelfCast", 0);
-- Protect against invalid extParam
if not (type(extParam) == "table") then
extParam = {}
end
Target = FindSingleToHeal(playerName, multiplier);
if (Target == nil) then
--jgpprint("ain't nobody to heal dude")
SetCVar("autoSelfCast", AutoSelfCast);
QuickHealBusy = false;
return;
end
-- Target acquired
QuickHeal_debug(string.format(" Healing target: %s (%s)", UnitFullName(Target), Target));
HealingSpellSize = 0;
SpellID, HealingSpellSize = FindHealSpellToUse(Target, "channel", multiplier, nil);
if (SpellID == nil) then
--jgpprint("ain't nobody to heal dude")
SetCVar("autoSelfCast", AutoSelfCast);
QuickHealBusy = false;
return;
end
-- Spell acquired
QuickHeal_debug(string.format(" Spell & Size: %s (%s)", SpellID, HealingSpellSize));
if SpellID then
ExecuteSingleHeal(Target, SpellID, multiplier);
else
Message("You have no healing spells to cast", "Error", 2);
end
SetCVar("autoSelfCast", AutoSelfCast);
end
function FindSingleToHeal(playerName, multiplier)
local playerIds = {};
local petIds = {};
local i;
local AllPlayersAreFull = true;
local AllPetsAreFull = true;
QuickHeal_debug("********** Heal Single **********");
local healingTarget = nil;
local healingTargetHealth = 100000;
local healingTargetHealthPct = 1;
local healingTargetMissinHealth = 0;
local unit;
if (InRaid()) then
for i = 1, GetNumRaidMembers() do
if UnitIsHealable("raid" .. i, true) then
jgpprint("considering raid" .. i .. ":" .. UnitName("raid" .. i))
if IsSingleTarget("raid" .. i, playerName) then
--playerIds["raid" .. i] = i; -- every one that will be considered for heal
healingTarget = "raid" .. i;
--jgpprint(UnitName("raid" .. i))
end
end
end
else
for i = 1, GetNumPartyMembers() do
if UnitIsHealable("party" .. i, true) then
if IsSingleTarget("party" .. i, playerName) then
--playerIds["party" .. i] = i; -- every one that will be considered for heal
healingTarget = "party" .. i;
--jgpprint(UnitName("party" .. i))
end
end
end
end
QuickHeal_debug("********** Done Scanning for single-target Heal **********");
-- Clear any healable target
local OldPlaySound = PlaySound;
PlaySound = function()
end
local TargetWasCleared = false;
if UnitIsHealable('target') then
TargetWasCleared = true;
ClearTarget();
end
-- Cast the checkspell
CastCheckSpell();
if not SpellIsTargeting() then
-- Reacquire target if it was cleared
if TargetWasCleared then
TargetLastTarget();
end
-- Reinsert the PlaySound
PlaySound = OldPlaySound;
return false;
end
--for unit, i in playerIds do
-- local SubGroup = false;
-- if InRaid() and not RestrictParty and RestrictSubgroup and i <= GetNumRaidMembers() then
-- _, _, SubGroup = GetRaidRosterInfo(i);
-- end
-- if not RestrictSubgroup or RestrictParty or not InRaid() or (SubGroup and not QHV["FilterRaidGroup" .. SubGroup]) then
-- if not IsBlacklisted(UnitFullName(unit)) then
-- if SpellCanTargetUnit(unit) then
-- QuickHeal_debug(string.format("%s (%s) : %d/%d", UnitFullName(unit), unit, UnitHealth(unit), UnitHealthMax(unit)));
--
-- --Get who to heal for different classes
-- local IncHeal = HealComm:getHeal(UnitName(unit))
-- local PredictedHealth = (UnitHealth(unit) + IncHeal)
-- local PredictedHealthPct = (UnitHealth(unit) + IncHeal) / UnitHealthMax(unit);
-- local PredictedMissingHealth = UnitHealthMax(unit) - UnitHealth(unit) - IncHeal;
--
-- if PredictedHealthPct < QHV.RatioFull then
-- local _, PlayerClass = UnitClass('player');
-- PlayerClass = string.lower(PlayerClass);
--
-- if PlayerClass == "shaman" then
-- if PredictedHealthPct < healingTargetHealthPct then
-- healingTarget = unit;
-- healingTargetHealthPct = PredictedHealthPct;
-- AllPlayersAreFull = false;
-- end
-- elseif PlayerClass == "priest" then
-- --writeLine("Find who to heal for Priest");
-- if healPlayerWithLowestPercentageOfLife == 1 then
-- if PredictedHealthPct < healingTargetHealthPct then
-- healingTarget = unit;
-- healingTargetHealthPct = PredictedHealthPct;
-- AllPlayersAreFull = false;
-- end
-- else
-- if PredictedMissingHealth > healingTargetMissinHealth then
-- healingTarget = unit;
-- healingTargetMissinHealth = PredictedMissingHealth;
-- AllPlayersAreFull = false;
-- end
-- end
-- elseif PlayerClass == "paladin" then
-- --writeLine("Find who to heal for Paladin")
-- if healPlayerWithLowestPercentageOfLife == 1 then
-- if PredictedHealthPct < healingTargetHealthPct then
-- healingTarget = unit;
-- healingTargetHealthPct = PredictedHealthPct;
-- AllPlayersAreFull = false;
-- end
-- else
-- if PredictedHealth < healingTargetHealth then
-- healingTarget = unit;
-- healingTargetHealth = PredictedHealth;
-- AllPlayersAreFull = false;
-- end
-- end
-- elseif PlayerClass == "druid" then
-- if PredictedHealthPct < healingTargetHealthPct then
-- healingTarget = unit;
-- healingTargetHealthPct = PredictedHealthPct;
-- AllPlayersAreFull = false;
-- end
-- else
-- writeLine(QuickHealData.name .. " " .. QuickHealData.version .. " does not support " .. UnitClass('player') .. ". " .. QuickHealData.name .. " not loaded.")
-- return ;
-- end
-- end
--
--
-- --writeLine("Values for "..UnitName(unit)..":")
-- --writeLine("Health: "..UnitHealth(unit) / UnitHealthMax(unit).." | IncHeal: "..IncHeal / UnitHealthMax(unit).." | PredictedHealthPct: "..PredictedHealthPct) --Edelete
-- else
-- QuickHeal_debug(UnitFullName(unit) .. " (" .. unit .. ")", "is out-of-range or unhealable");
-- end
-- else
-- QuickHeal_debug(UnitFullName(unit) .. " (" .. unit .. ")", "is blacklisted");
-- end
-- end
--end
healPlayerWithLowestPercentageOfLife = 0
-- Reacquire target if it was cleared earlier, and stop CheckSpell
SpellStopTargeting();
if TargetWasCleared then
TargetLastTarget();
end
PlaySound = OldPlaySound;
---- Examine External Target
--if AllPlayersAreFull and (AllPetsAreFull or QHV.PetPriority == 0) then
-- if not QuickHeal_UnitHasHealthInfo('target') and UnitIsHealable('target', true) then
-- QuickHeal_debug(string.format("%s (%s) : %d/%d", UnitFullName('target'), 'target', UnitHealth('target'), UnitHealthMax('target')));
-- local Health;
-- Health = UnitHealth('target') / 100;
-- if Health < QHV.RatioFull then
-- return 'target';
-- end
-- end
--end
return healingTarget;
end
-- Returns true if the unit matches playerName string
function IsSingleTarget(unit, playerName)
if playerName == UnitName(unit) then
return true;
end
end
function ExecuteSingleHeal(Target, SpellID, multiplier)
local TargetWasChanged = false;
-- Setup the monitor and related events
StartMonitor(Target, multiplier);
-- Supress sound from target-switching
local OldPlaySound = PlaySound;
PlaySound = function()
end
-- If the current target is healable, take special measures
if UnitIsHealable('target') then
-- If the healing target is targettarget change current healable target to targettarget
if Target == 'targettarget' then
local old = UnitFullName('target');
TargetUnit('targettarget');
Target = 'target';
TargetWasChanged = true;
QuickHeal_debug("Healable target preventing healing, temporarily switching target to target's target", old, '-->', UnitFullName('target'));
end
-- If healing target is not the current healable target clear the healable target
if not (Target == 'target') then
QuickHeal_debug("Healable target preventing healing, temporarily clearing target", UnitFullName('target'));
ClearTarget();
TargetWasChanged = true;
end
end
-- Get spell info
local SpellName, SpellRank = GetSpellName(SpellID, BOOKTYPE_SPELL);
if SpellRank == "" then
SpellRank = nil
end
local SpellNameAndRank = SpellName .. (SpellRank and " (" .. SpellRank .. ")" or "");
QuickHeal_debug(" Casting: " .. SpellNameAndRank .. " on " .. UnitFullName(Target) .. " (" .. Target .. ")" .. ", ID: " .. SpellID);
-- Clear any pending spells
if SpellIsTargeting() then
SpellStopTargeting()
end
-- Cast the spell
CastSpell(SpellID, BOOKTYPE_SPELL);
-- Target == 'target'
-- Instant channeling --> succesful cast
-- Instant channeling --> instant 'out of range' fail
-- Instant channeling --> delayed 'line of sight' fail
-- No channeling --> SpellStillTargeting (unhealable NPC's, duelists etc.)
-- Target ~= 'target'
-- SpellCanTargetUnit == true
-- Channeling --> succesful cast
-- Channeling --> instant 'out of range' fail
-- Channeling --> delayed 'line of sight' fail
-- No channeling --> SpellStillTargeting (unknown circumstances)
-- SpellCanTargetUnit == false
-- Duels/unhealable NPC's etc.
-- The spell is awaiting target selection, write to screen if the spell can actually be cast
if SpellCanTargetUnit(Target) or ((Target == 'target') and HealingTarget) then
Notification(Target, SpellNameAndRank);
-- Write to center of screen
if UnitIsUnit(Target, 'player') then
Message(string.format("Casting %s on yourself", SpellNameAndRank), "Healing", 3)
else
Message(string.format("Casting %s on %s", SpellNameAndRank, UnitFullName(Target)), "Healing", 3)
end
end
-- Assign the target of the healing spell
SpellTargetUnit(Target);
-- just in case something went wrong here (Healing people in duels!)
if SpellIsTargeting() then
StopMonitor("Spell cannot target " .. (UnitFullName(Target) or "unit"));
SpellStopTargeting()
end
-- Reacquire target if it was changed earlier
if TargetWasChanged then
local old = UnitFullName('target') or "None";
TargetLastTarget();
QuickHeal_debug("Reacquired previous target", old, '-->', UnitFullName('target'));
end
-- Enable sound again
PlaySound = OldPlaySound;
end