-
Notifications
You must be signed in to change notification settings - Fork 0
/
rwarnings.lua
208 lines (183 loc) · 7.69 KB
/
rwarnings.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
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
addon.name = 'rWarnings'
addon.author = 'Rag'
addon.version = '0.0.1'
addon.desc = 'Displays mobs beginning spellcasts and using abilities as UI text objects'
addon.link = 'https://github.com/yzyii'
require('common')
require ('rwarningslib')
local chat = require('chat')
local settings = require('settings')
local gdi = require('gdifonts.include')
local scaling = require('scaling')
local priority = require('priority')
local screenCenter = {
x = scaling.window.w / 2,
y = scaling.window.h / 2,
}
local defaultSettings = T{
fade_after = 4,
fade_duration = 1,
font_spacing = 1.5,
font_color_priority = 0xFFFFD700,
font_color_priority_alt = 0xFF3F00FF,
font_color_default = 0xFFFFFFFF,
display_priority_only = false,
use_alt_priority_font_color = false,
font = {
font_alignment = gdi.Alignment.Center,
font_family = 'Consolas',
font_flags = gdi.FontFlags.Bold,
font_height = 36,
outline_color = 0xFF000000,
outline_width = 2,
},
x_offset = 0,
y_offset = 50,
}
local loadedSettings = nil
local messages = {
[1] = nil,
[2] = nil,
[3] = nil,
[4] = nil,
[5] = nil,
}
local function copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
local function initialise()
for i = 1,5 do
local font = copy(loadedSettings.font)
font.position_x = screenCenter.x + loadedSettings.x_offset
font.position_y = screenCenter.y - loadedSettings.y_offset + (i - 1) * font.font_height * loadedSettings.font_spacing
messages[i] = { fontobj = gdi:create_object(font), expiry = nil }
end
end
local function updateFade(obj)
local maxAlpha = 1
local minAlpha = 0
local fadeDuration = loadedSettings.fade_duration
local fadeAfter = loadedSettings.fade_after
local elapsed = math.max(0, os.clock() - obj.expiry)
local alpha = math.max(minAlpha, maxAlpha - (maxAlpha * (elapsed / fadeDuration)))
obj.fontobj:set_opacity(alpha)
if alpha == minAlpha then
obj.expiry = nil
end
end
ashita.events.register('load', 'rwarnings_load', function()
loadedSettings = settings.load(defaultSettings)
initialise()
end)
ashita.events.register('unload', 'rwarnings_unload', function()
gdi:destroy_interface()
settings.save()
end)
ashita.events.register('packet_in', 'rwarnings_packet_in', function (e)
if (e.id == 0x028) then
local actionPacket = ParseActionPacket(e)
if (IsMonster(actionPacket.UserIndex) and (actionPacket.Type == 7 or actionPacket.Type == 8)) then
local actionMessage = actionPacket.Targets[1].Actions[1].Message
local monsterId = struct.unpack('L', e.data, 0x05 + 0x01)
local monsterIndex = bit.band(monsterId, 0x7FF)
local monsterName = AshitaCore:GetMemoryManager():GetEntity():GetName(monsterIndex)
local actionName = nil
if (actionPacket.Type == 7) then
local tpId = ashita.bits.unpack_be(e.data:totable(), 0, 213, 17)
if (tpId < 256) then
actionName = AshitaCore:GetResourceManager():GetAbilityById(tpId).Name[1]
else
local tempName = AshitaCore:GetResourceManager():GetString('monsters.abilities', tpId - 256)
if (tempName ~= nil) then
actionName = tempName
end
end
elseif (actionPacket.Type == 8) then
local spellId = actionPacket.Targets[1].Actions[1].Param
local spellResource = AshitaCore:GetResourceManager():GetSpellById(spellId)
if spellResource then
if (spellResource.Name[1] ~= nil) then
actionName = spellResource.Name[1]
end
end
end
if (actionMessage ~= 0 and monsterName ~= nil and actionName ~= nil and actionName ~= '') then
local isPrio = priority:contains(actionName)
if (isPrio or not loadedSettings.display_priority_only) then
for i = 1,5 do
if (messages[i].expiry == nil) then
if (isPrio) then
local fontColor = loadedSettings.font_color_priority
if (loadedSettings.use_alt_priority_font_color) then
fontColor = loadedSettings.font_color_priority_alt
end
messages[i].fontobj:set_font_color(fontColor)
else
messages[i].fontobj:set_font_color(loadedSettings.font_color_default)
end
local msg = monsterName .. ' - ' .. actionName
AshitaCore:GetChatManager():AddChatMessage(39, false, 'WARNING: ' .. msg)
messages[i].fontobj:set_text(msg)
messages[i].expiry = os.clock() + loadedSettings.fade_after
break
end
end
end
end
end
end
end)
ashita.events.register('d3d_present', 'rwarnings_d3d_present', function()
for i = 1,5 do
if (messages[i].expiry ~= nil) then
updateFade(messages[i])
end
end
end)
ashita.events.register('command', 'rwarnings_command', function (e)
local args = e.command:args()
if (#args == 0 or args[1] ~= '/rwarnings') then
return
end
e.blocked = true
if (#args == 4 and args[2]:any('pos')) then
local x = tonumber(args[3])
local y = tonumber(args[4])
if (x and y) then
loadedSettings.x_offset = x
loadedSettings.y_offset = y
for i = 1,5 do
local position_x = screenCenter.x + x
local position_y = screenCenter.y - y + (i - 1) * loadedSettings.font.font_height * loadedSettings.font_spacing
messages[i].fontobj:set_position_x(position_x)
messages[i].fontobj:set_position_y(position_y)
end
local expiry = os.clock() + loadedSettings.fade_after
messages[1].fontobj:set_font_color(loadedSettings.font_color_priority)
messages[1].fontobj:set_text('Messages will be displayed here')
messages[1].expiry = expiry
messages[5].fontobj:set_font_color(loadedSettings.font_color_priority)
messages[5].fontobj:set_text('Have Fun!')
messages[5].expiry = expiry
end
return
end
if (#args == 2 and args[2]:any('font')) then
loadedSettings.use_alt_priority_font_color = not loadedSettings.use_alt_priority_font_color
print(chat.header('rWarnings') .. chat.message('Use Alternate Priority Font Colour: ' .. tostring(loadedSettings.use_alt_priority_font_color)))
return
end
if (#args == 2 and args[2]:any('prio')) then
loadedSettings.display_priority_only = not loadedSettings.display_priority_only
print(chat.header('rWarnings') .. chat.message('Display Priority Actions Only: ' .. tostring(loadedSettings.display_priority_only)))
return
end
print(chat.header('rWarnings') .. chat.message('Note: Edit your list of priority actions in priority.lua'))
print(chat.header('rWarnings') .. chat.message('/rwarnings font - Toggle the colour of priority actions'))
print(chat.header('rWarnings') .. chat.message('/rwarnings prio - Toggle displaying priority messages only'))
print(chat.header('rWarnings') .. chat.message('/rwarnings pos [x_offset] [y_offset] - Reposition UI text (default is 0 50)'))
end)