-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemycastbar.lua
167 lines (153 loc) · 6.18 KB
/
enemycastbar.lua
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
addon.name = 'EnemyCastBar';
addon.author = 'Shiyo';
addon.version = '1.0.0.1';
addon.desc = 'Shows enemy cast bars';
addon.link = 'https://github.com/ShiyoKozuki';
require('common');
require ('enemycastbarlibs')
local fonts = require('fonts');
local settings = require('settings');
local textDuration = 0
local monsterIndex
local tpId
local tpString
local monsterId
local monsterName
local spellId
local tpName
local windowWidth = AshitaCore:GetConfigurationManager():GetFloat('boot', 'ffxi.registry', '0001', 1024);
local windowHeight = AshitaCore:GetConfigurationManager():GetFloat('boot', 'ffxi.registry', '0002', 768);
local default_settings = T{
font = T{
visible = true,
font_family = 'Arial',
font_height = 18,
color = 0xFFFFFFFF,
position_x = 785,
position_y = 470,
background = T{
visible = true,
color = 0x80000000,
}
}
};
local function CheckString(string)
if (string ~= nil) then
textDuration = os.time() + 5 -- Only display text for 5 seconds
end
end
local enemycastbar = T{
settings = settings.load(default_settings)
};
local UpdateSettings = function(settings)
enemycastbar.settings = settings;
if (enemycastbar.font ~= nil) then
enemycastbar.font:apply(enemycastbar.settings.font)
end
end
ashita.events.register('load', 'load_cb', function ()
enemycastbar.font = fonts.new(enemycastbar.settings.font);
settings.register('settings', 'settingchange', UpdateSettings);
end);
ashita.events.register('packet_in', 'packet_in_cb', function (e)
local myTarget = AshitaCore:GetMemoryManager():GetTarget():GetTargetIndex(AshitaCore:GetMemoryManager():GetTarget():GetIsSubTargetActive())
-- Packet: Action
if (e.id == 0x028) then
local actionPacket = ParseActionPacket(e);
if (actionPacket.Type == 7) and IsMonster(actionPacket.UserIndex) and (myTarget == actionPacket.UserIndex) then -- Mobskill Start
local actionMessage = actionPacket.Targets[1].Actions[1].Message
monsterId = struct.unpack('L', e.data, 0x05 + 0x01);
monsterIndex = bit.band(monsterId, 0x7FF);
tpId = ashita.bits.unpack_be(e.data:totable(), 0, 213, 17);
if (tpId < 256) then
tpName = AshitaCore:GetResourceManager():GetAbilityById(tpId)
tpString = ' readies ' .. tpName.Name[1]
else
local tempName = AshitaCore:GetResourceManager():GetString('monsters.abilities', tpId - 256);
if (tempName ~= nil) then
tpName = tempName;
tpString = ' readies ' .. tpName
end
end
monsterName = AshitaCore:GetMemoryManager():GetEntity():GetName(monsterIndex);
textDuration = 0
CheckString(tpString)
if (actionMessage == 0) then -- Mob Skill interrupted
-- print('Enemy mob ability interrupted!!');
monsterId = struct.unpack('L', e.data, 0x05 + 0x01);
monsterIndex = bit.band(monsterId, 0x7FF);
textDuration = 0
tpId = 0
tpString = '\'s TP move interrupted!!!'
monsterName = AshitaCore:GetMemoryManager():GetEntity():GetName(monsterIndex);
CheckString(tpString)
end
end
if (actionPacket.Type == 8) and IsMonster(actionPacket.UserIndex) and (myTarget == actionPacket.UserIndex) then -- Magic start
local actionMessage = actionPacket.Targets[1].Actions[1].Message
monsterId = struct.unpack('L', e.data, 0x05 + 0x01);
monsterIndex = bit.band(monsterId, 0x7FF);
spellId = actionPacket.Targets[1].Actions[1].Param
local spellResource = AshitaCore:GetResourceManager():GetSpellById(spellId);
if spellResource then
-- print(string.format('Enemy started casting %s.', spellResource.Name[1]));
if (spellResource.Name[1] ~= nil) then
spellString = ' casting ' .. spellResource.Name[1]
end
monsterName = AshitaCore:GetMemoryManager():GetEntity():GetName(monsterIndex);
textDuration = 0
-- print(string.format('monsterName: %s', monsterName));
CheckString(spellString)
end
if (actionMessage == 0) then -- Magic Interrupted
-- print('Enemy spell interrupted!!');
textDuration = 0
spellString = '\'s spell interrupted!!!'
monsterName = AshitaCore:GetMemoryManager():GetEntity():GetName(monsterIndex);
CheckString(spellString)
end
end
end
end);
ashita.events.register('d3d_present', 'present_cb', function ()
local fontObject = enemycastbar.font;
if (fontObject.position_x > windowWidth) then
fontObject.position_x = 0;
end
if (fontObject.position_y > windowHeight) then
fontObject.position_y = 0;
end
if (fontObject.position_x ~= enemycastbar.settings.font.position_x) or (fontObject.position_y ~= enemycastbar.settings.font.position_y) then
enemycastbar.settings.font.position_x = fontObject.position_x;
enemycastbar.settings.font.position_y = fontObject.position_y;
settings.save()
end
if (os.time() > textDuration ) then
-- Hide text, reset variables to nil
enemycastbar.font.visible = false;
monsterIndex = nil
tpId = nil
tpString = nil
monsterName = nil
spellId = nil
return;
end
if monsterName then
if tpString and (tpId ~= nil) then
enemycastbar.font.text = ('%s%s'):fmt(monsterName, tpString);
enemycastbar.font.visible = true;
elseif monsterName and (spellId ~= nil) then
enemycastbar.font.text = ('%s%s'):fmt(monsterName, spellString);
enemycastbar.font.visible = true;
else
enemycastbar.font.visible = false;
return;
end
end
end);
ashita.events.register('unload', 'unload_cb', function ()
if (enemycastbar.font ~= nil) then
enemycastbar.font:destroy();
end
settings.save();
end);