Advertisement
Guest User

foil.lua

a guest
May 19th, 2022
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1. _addon.name = 'foil'
  2. _addon.version = '1.0.1'
  3. _addon.command = ''
  4. _addon.author = ''
  5.  
  6. debugging = {}
  7. debugging.windower = nil
  8. packets = require('packets')
  9. res = require('resources')
  10. helpers = require('helper_functions')
  11.  
  12. -- some stuff stolen from gearswap (read: most stolen from gearswap)
  13. handlers = {}
  14. handlers.i = {}
  15. handlers.o = {}
  16. language = "en"
  17.  
  18. buffactive = {}
  19.  
  20. _ExtraData = {
  21. player = {buff_details = {}},
  22. pet = {},
  23. world = {in_mog_house = false,conquest=false},
  24. }
  25.  
  26. player = make_user_table()
  27. player.buffs = {}
  28. player.recasts={}
  29.  
  30. function incoming_chunk(id,data,modified,injected,blocked)
  31. if handlers.i[id] then
  32. handlers.i[id](data,modified)
  33. end
  34. end
  35.  
  36. windower.register_event("incoming chunk",incoming_chunk)
  37.  
  38.  
  39. function convert_buff_list(bufflist)
  40. local buffarr = {}
  41. for i,id in pairs(bufflist) do
  42. if res.buffs[id] then -- For some reason we always have buff 255 active, which doesn't have an entry.
  43. local buff = res.buffs[id][language]:lower()
  44. if buffarr[buff] then
  45. buffarr[buff] = buffarr[buff] +1
  46. else
  47. buffarr[buff] = 1
  48. end
  49.  
  50. if buffarr[id] then
  51. buffarr[id] = buffarr[id] +1
  52. else
  53. buffarr[id] = 1
  54. end
  55. end
  56. end
  57. return buffarr
  58. end
  59.  
  60. last_foil = -1
  61. function buff_applied(id, buff_name, new)
  62. local buff_name = buff_name:lower()
  63. if buff_name:lower() == "foil" then
  64.  
  65. if new then
  66. last_foil = os.time()
  67. else
  68. last_foil = os.time()
  69. end
  70. end
  71. end
  72.  
  73. function buff_lost(id,name,new)
  74. if name:lower() == "foil" then
  75. last_foil = -1
  76. end
  77. end
  78.  
  79. files = require('files')
  80. file = nil
  81. windower.register_event('action',function (act)
  82. if act == nil or #act.targets == 0 then
  83. return
  84. end
  85. local actor = windower.ffxi.get_mob_by_id(act.actor_id)
  86. local self = windower.ffxi.get_player()
  87. local target_count = act.target_count
  88. local category = act.category
  89. local param = act.param
  90. local targets = act.targets
  91. local primarytarget = windower.ffxi.get_mob_by_id(targets[1].id)
  92.  
  93. if actor and actor.name ~= self.name and target_count > 0 and primarytarget.name == self.name then
  94.  
  95. if category == 11 and (act.param == 2224 or act.param == 1064 or act.param == 733) then --head butt, third jump from Orc, first and second jump from orc?
  96. local hit = false
  97.  
  98. if targets[1].actions[1].message == 188 then --miss
  99. hit = false
  100. end
  101. if targets[1].actions[1].message == 185 then --hit
  102. hit = true
  103. end
  104.  
  105. if last_foil ~= -1 then -- valid foil
  106. if file == nil then
  107. local opened_date = os.date('*t')
  108. file = io.open(windower.addon_path .. '../../logs/foil_cap_testing_draketrader.log',"a+") -- open in append mode. we don't care about the log files contents if it exists.
  109. end
  110. file:write('%d,%s,%d\n':format(os.time()-last_foil, hit and "hit" or "miss",act.param))
  111. file:flush()
  112. end
  113. end
  114. end
  115. end)
  116.  
  117. inspect = require('inspect')
  118.  
  119. -- jacked from gearswap. thanks Byrth!
  120. handlers.i[0x063] = function (data, modified)
  121. if data:byte(0x05) == 0x09 and blank_0x063_v9_inc then
  122. -- After zoning, players receive a blank 0x063 v9 packet
  123. -- (because their buff line is temporarily empty)
  124. -- So this flag is set in 0x00A
  125. blank_0x063_v9_inc = false
  126. -- However, players can also reload gearswap and fail to get a 0x063 v9 packet from
  127. -- windower.packets.last_incoming, which leaves them without buff information but with a
  128. -- informative 0x063 v9 packet coming next. So this step checks confirms the packet is
  129. -- empty before returning
  130. if data:sub(0x49,0xC8) == string.char(0):rep(128) then
  131. return
  132. end
  133. end
  134. if data:byte(0x05) == 0x09 then
  135. local newbuffs = {}
  136. for i=1,32 do
  137. local buff_id = data:unpack('H',i*2+7)
  138. if buff_id ~= 255 and buff_id ~= 0 then -- 255 is used for "no buff"
  139. local t = data:unpack('I',i*4+0x45)/60+572662306+1009810800
  140. newbuffs[i] = setmetatable({
  141. name=res.buffs[buff_id].name,
  142. buff=copy_entry(res.buffs[buff_id]),
  143. id = buff_id,
  144. time=t,
  145. date=os.date('*t',t),
  146. },
  147. {__index=function(t,k)
  148. if k and k=='duration' then
  149. return rawget(t,'time')-os.time()
  150. else
  151. return rawget(t,k)
  152. end
  153. end})
  154. end
  155. end
  156. if seen_0x063_type9 then
  157.  
  158. -- Look for exact matches
  159. for n,new in pairs(newbuffs) do
  160. newbuffs[n].matched_exactly = nil
  161. for i,old in pairs(_ExtraData.player.buff_details) do
  162. -- Find unchanged buffs
  163. if old.id == new.id and math.abs(old.time-new.time) < 1 and not old.matched_exactly then
  164. newbuffs[n].matched_exactly = true
  165. _ExtraData.player.buff_details[i].matched_exactly = true
  166. break
  167. end
  168. end
  169. end
  170.  
  171. -- Look for time-independent matches, which are assumedly a spell overwriting itself
  172. for n,new in pairs(newbuffs) do
  173. newbuffs[n].matched_imprecisely = nil
  174. if not new.matched_exactly then
  175. for i,old in pairs(_ExtraData.player.buff_details) do
  176. -- Buffs can be overwritten
  177. if old.id == new.id and not (old.matched_exactly or old.matched_imprecisely) then
  178. newbuffs[n].matched_imprecisely = true
  179. _ExtraData.player.buff_details[i].matched_imprecisely = true
  180. break
  181. end
  182. end
  183. end
  184. end
  185.  
  186. for n,new in pairs(newbuffs) do
  187. if new.matched_exactly then
  188. newbuffs[n].matched_exactly = nil
  189. elseif new.matched_imprecisely then
  190. newbuffs[n].matched_imprecisely = nil
  191. -- Matched a previous buff, but the time didn't jive so it's assumed
  192. -- that it was overwritten with the same status effect
  193. if not res.buffs[new.id] then
  194. error('GearSwap: No known status for buff id #'..tostring(new.id))
  195. end
  196. local buff_name = res.buffs[new.id][language]
  197. windower.debug('refresh buff '..buff_name..' ('..tostring(new.id)..')')
  198. if not gearswap_disabled then
  199. table.reassign(buffactive,convert_buff_list(player.buffs))
  200. buff_applied(new.id,buff_name,false)
  201. --refresh_globals()
  202. --equip_sets('buff_refresh',nil,buff_name,new)
  203. end
  204. else
  205. -- Not matched, so it's assumed the buff is new
  206. if not res.buffs[new.id] then
  207. error('GearSwap: No known status for buff id #'..tostring(new.id))
  208. end
  209. local buff_name = res.buffs[new.id][language]
  210. --windower.add_to_chat(4,tostring(new))
  211. windower.debug('gain buff '..buff_name..' ('..tostring(new.id)..')')
  212. -- Need to figure out what I'm going to do with this:
  213. --if T{'terror','sleep','stun','petrificatio--n','charm','weakness'}:contains(buff_name:lower()) then
  214. --for ts,v in pairs(command_registry) do
  215. --if v.midaction then
  216. --command_registry:delete_entry(ts)
  217. --end
  218. --end
  219. --end
  220. if not gearswap_disabled then
  221. table.reassign(buffactive,convert_buff_list(player.buffs))
  222. buff_applied(new.id,buff_name,true)
  223. --refresh_globals()
  224. --equip_sets('buff_change',nil,buff_name,true,new)
  225. end
  226. end
  227. end
  228. for i,old in pairs(_ExtraData.player.buff_details) do
  229. if not (old.matched_exactly or old.matched_imprecisely) then
  230. -- Old status was not matched to any new status, so it's assumed it was lost
  231. if not res.buffs[old.id] then
  232. error('GearSwap: No known status for buff id #'..tostring(old.id))
  233. end
  234. local buff_name = res.buffs[old.id][language]
  235. windower.debug('lose buff '..buff_name..' ('..tostring(old.id)..')')
  236. if not gearswap_disabled then
  237. --refresh_globals()
  238. buff_lost(old.id,buff_name,true)
  239. table.reassign(buffactive,convert_buff_list(player.buffs))
  240. --equip_sets('buff_change',nil,buff_name,false,old)
  241. end
  242. end
  243. end
  244. end
  245.  
  246. table.reassign(_ExtraData.player.buff_details,newbuffs)
  247. for i=1,32 do
  248. player.buffs[i] = (newbuffs[i] and newbuffs[i].id) or nil
  249. end
  250. -- Cannot reliably recall this packet using last_incoming on load because there
  251. -- are 9 version of it and you only get the last one. Hence, this flag:
  252. seen_0x063_type9 = true
  253. end
  254. end
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement