-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcombatlog.js
61 lines (60 loc) · 2.49 KB
/
combatlog.js
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
window.AddonBundleScriptVersion = "1.31";
window.AddonBundleScriptName = "CombatLog";
var idToName = {};
var inCombatWith = {};
function addCombatMessage(txt){
var msg = "*"+txt+"*";
var color = "redA";
jQuery('<div class="list-message color-'+color+' rep">' + msg + '</div>').appendTo(jQuery(".uiMessages .list"));
jQuery(".uiMessages .list").scrollTop(9999999);
}
addons.register({
init: function(events) {
events.on('onGetDamage',this.onGetDamage.bind(this));
events.on('onGetObject',this.onGetObject.bind(this));
events.on('onGetSpellCooldowns', this.onGetSpellCooldowns.bind(this));
},
onGetDamage: function(dmg) {
if(dmg.crit !== undefined){
if(dmg.id !== undefined && dmg.source !== undefined){
var enemyName;
var action="hit";
if(dmg.heal !== undefined && dmg.heal == true){
action="heal";
}
if(window.player !== undefined && dmg.source == window.player.id){
inCombatWith[dmg.id] = true;
enemyName = idToName[dmg.id];
addCombatMessage("You "+(dmg.crit == true ? "critically ":"")+action+" "+enemyName+" for "+ (~~dmg.amount) +" damage.");
} else if(window.player !== undefined && dmg.id == window.player.id){
enemyName = idToName[dmg.source];
inCombatWith[dmg.source] = true;
addCombatMessage(enemyName+(dmg.crit == true ? " critically":"")+" "+action+"s you for "+ (~~dmg.amount) +" damage.");
}
}
} else{
if(dmg.event !== undefined){
if(window.player !== undefined && dmg.id == window.player.id && dmg.text.indexOf(" xp") != -1){
addCombatMessage("You gained "+dmg.text+".");
}
}
}
},
onGetObject: function(obj) {
if(obj.name !== undefined){
idToName[obj.id]=obj.name;
}
if(obj.destroyed !== undefined && obj.destroyed == true){
//delete idToName[obj.id];
if(obj.id in inCombatWith){
addCombatMessage(idToName[obj.id] + " has been killed.");
delete inCombatWith[obj.id];
}
}
},
onGetSpellCooldowns: function(spell) {
if(spell.id !== undefined && window.player !== undefined && spell.id == window.player.id && spell.spell !== undefined){
addCombatMessage("You cast "+window.player.spellbook.getSpell(spell.spell).name);
}
}
});