Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _addon.name = 'foil'
- _addon.version = '1.0.1'
- _addon.command = ''
- _addon.author = ''
- debugging = {}
- debugging.windower = nil
- packets = require('packets')
- res = require('resources')
- helpers = require('helper_functions')
- -- some stuff stolen from gearswap (read: most stolen from gearswap)
- handlers = {}
- handlers.i = {}
- handlers.o = {}
- language = "en"
- buffactive = {}
- _ExtraData = {
- player = {buff_details = {}},
- pet = {},
- world = {in_mog_house = false,conquest=false},
- }
- player = make_user_table()
- player.buffs = {}
- player.recasts={}
- function incoming_chunk(id,data,modified,injected,blocked)
- if handlers.i[id] then
- handlers.i[id](data,modified)
- end
- end
- windower.register_event("incoming chunk",incoming_chunk)
- function convert_buff_list(bufflist)
- local buffarr = {}
- for i,id in pairs(bufflist) do
- if res.buffs[id] then -- For some reason we always have buff 255 active, which doesn't have an entry.
- local buff = res.buffs[id][language]:lower()
- if buffarr[buff] then
- buffarr[buff] = buffarr[buff] +1
- else
- buffarr[buff] = 1
- end
- if buffarr[id] then
- buffarr[id] = buffarr[id] +1
- else
- buffarr[id] = 1
- end
- end
- end
- return buffarr
- end
- last_foil = -1
- function buff_applied(id, buff_name, new)
- local buff_name = buff_name:lower()
- if buff_name:lower() == "foil" then
- if new then
- last_foil = os.time()
- else
- last_foil = os.time()
- end
- end
- end
- function buff_lost(id,name,new)
- if name:lower() == "foil" then
- last_foil = -1
- end
- end
- files = require('files')
- file = nil
- windower.register_event('action',function (act)
- if act == nil or #act.targets == 0 then
- return
- end
- local actor = windower.ffxi.get_mob_by_id(act.actor_id)
- local self = windower.ffxi.get_player()
- local target_count = act.target_count
- local category = act.category
- local param = act.param
- local targets = act.targets
- local primarytarget = windower.ffxi.get_mob_by_id(targets[1].id)
- if actor and actor.name ~= self.name and target_count > 0 and primarytarget.name == self.name then
- 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?
- local hit = false
- if targets[1].actions[1].message == 188 then --miss
- hit = false
- end
- if targets[1].actions[1].message == 185 then --hit
- hit = true
- end
- if last_foil ~= -1 then -- valid foil
- if file == nil then
- local opened_date = os.date('*t')
- 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.
- end
- file:write('%d,%s,%d\n':format(os.time()-last_foil, hit and "hit" or "miss",act.param))
- file:flush()
- end
- end
- end
- end)
- inspect = require('inspect')
- -- jacked from gearswap. thanks Byrth!
- handlers.i[0x063] = function (data, modified)
- if data:byte(0x05) == 0x09 and blank_0x063_v9_inc then
- -- After zoning, players receive a blank 0x063 v9 packet
- -- (because their buff line is temporarily empty)
- -- So this flag is set in 0x00A
- blank_0x063_v9_inc = false
- -- However, players can also reload gearswap and fail to get a 0x063 v9 packet from
- -- windower.packets.last_incoming, which leaves them without buff information but with a
- -- informative 0x063 v9 packet coming next. So this step checks confirms the packet is
- -- empty before returning
- if data:sub(0x49,0xC8) == string.char(0):rep(128) then
- return
- end
- end
- if data:byte(0x05) == 0x09 then
- local newbuffs = {}
- for i=1,32 do
- local buff_id = data:unpack('H',i*2+7)
- if buff_id ~= 255 and buff_id ~= 0 then -- 255 is used for "no buff"
- local t = data:unpack('I',i*4+0x45)/60+572662306+1009810800
- newbuffs[i] = setmetatable({
- name=res.buffs[buff_id].name,
- buff=copy_entry(res.buffs[buff_id]),
- id = buff_id,
- time=t,
- date=os.date('*t',t),
- },
- {__index=function(t,k)
- if k and k=='duration' then
- return rawget(t,'time')-os.time()
- else
- return rawget(t,k)
- end
- end})
- end
- end
- if seen_0x063_type9 then
- -- Look for exact matches
- for n,new in pairs(newbuffs) do
- newbuffs[n].matched_exactly = nil
- for i,old in pairs(_ExtraData.player.buff_details) do
- -- Find unchanged buffs
- if old.id == new.id and math.abs(old.time-new.time) < 1 and not old.matched_exactly then
- newbuffs[n].matched_exactly = true
- _ExtraData.player.buff_details[i].matched_exactly = true
- break
- end
- end
- end
- -- Look for time-independent matches, which are assumedly a spell overwriting itself
- for n,new in pairs(newbuffs) do
- newbuffs[n].matched_imprecisely = nil
- if not new.matched_exactly then
- for i,old in pairs(_ExtraData.player.buff_details) do
- -- Buffs can be overwritten
- if old.id == new.id and not (old.matched_exactly or old.matched_imprecisely) then
- newbuffs[n].matched_imprecisely = true
- _ExtraData.player.buff_details[i].matched_imprecisely = true
- break
- end
- end
- end
- end
- for n,new in pairs(newbuffs) do
- if new.matched_exactly then
- newbuffs[n].matched_exactly = nil
- elseif new.matched_imprecisely then
- newbuffs[n].matched_imprecisely = nil
- -- Matched a previous buff, but the time didn't jive so it's assumed
- -- that it was overwritten with the same status effect
- if not res.buffs[new.id] then
- error('GearSwap: No known status for buff id #'..tostring(new.id))
- end
- local buff_name = res.buffs[new.id][language]
- windower.debug('refresh buff '..buff_name..' ('..tostring(new.id)..')')
- if not gearswap_disabled then
- table.reassign(buffactive,convert_buff_list(player.buffs))
- buff_applied(new.id,buff_name,false)
- --refresh_globals()
- --equip_sets('buff_refresh',nil,buff_name,new)
- end
- else
- -- Not matched, so it's assumed the buff is new
- if not res.buffs[new.id] then
- error('GearSwap: No known status for buff id #'..tostring(new.id))
- end
- local buff_name = res.buffs[new.id][language]
- --windower.add_to_chat(4,tostring(new))
- windower.debug('gain buff '..buff_name..' ('..tostring(new.id)..')')
- -- Need to figure out what I'm going to do with this:
- --if T{'terror','sleep','stun','petrificatio--n','charm','weakness'}:contains(buff_name:lower()) then
- --for ts,v in pairs(command_registry) do
- --if v.midaction then
- --command_registry:delete_entry(ts)
- --end
- --end
- --end
- if not gearswap_disabled then
- table.reassign(buffactive,convert_buff_list(player.buffs))
- buff_applied(new.id,buff_name,true)
- --refresh_globals()
- --equip_sets('buff_change',nil,buff_name,true,new)
- end
- end
- end
- for i,old in pairs(_ExtraData.player.buff_details) do
- if not (old.matched_exactly or old.matched_imprecisely) then
- -- Old status was not matched to any new status, so it's assumed it was lost
- if not res.buffs[old.id] then
- error('GearSwap: No known status for buff id #'..tostring(old.id))
- end
- local buff_name = res.buffs[old.id][language]
- windower.debug('lose buff '..buff_name..' ('..tostring(old.id)..')')
- if not gearswap_disabled then
- --refresh_globals()
- buff_lost(old.id,buff_name,true)
- table.reassign(buffactive,convert_buff_list(player.buffs))
- --equip_sets('buff_change',nil,buff_name,false,old)
- end
- end
- end
- end
- table.reassign(_ExtraData.player.buff_details,newbuffs)
- for i=1,32 do
- player.buffs[i] = (newbuffs[i] and newbuffs[i].id) or nil
- end
- -- Cannot reliably recall this packet using last_incoming on load because there
- -- are 9 version of it and you only get the last one. Hence, this flag:
- seen_0x063_type9 = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement