Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions addons/GearSwap/flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ function equip_sets_exit(swap_type, ts, val1)

if command_registry[ts].cancel_spell then
msg.debugging('Action canceled (' .. storedcommand .. ' ' .. val1.target.raw .. ')')
storedcommand = nil
command_registry:delete_entry(ts)
return true
elseif not ts or not command_registry[ts] or not storedcommand then
Expand All @@ -218,7 +217,7 @@ function equip_sets_exit(swap_type, ts, val1)
val1.target = command_registry[ts].new_target -- Switch target, if it is requested.

if val1.prefix == '/item' then
if val1.target.type ~= 'NONE' and bit.band(val1.target.spawn_type, 2) == 2 then
if val1.target.type ~= 'NONE' and bit.band(val1.target.spawn_type, 2) == 2 and find_inventory_item(val1.id) then
val1.action_type = 'Trade'
else
val1.action_type = 'Item'
Expand All @@ -235,12 +234,10 @@ function equip_sets_exit(swap_type, ts, val1)
if filter_precast(val1) then
if val1.prefix == '/item' then
-- Item use packet handling here
if val1.action_type == 'Trade' and find_inventory_item(val1.id) then
if val1.action_type == 'Trade' then
-- 0x36 packet
if val1.target.distance <= 6 then
command_registry[ts].proposed_packet = assemble_menu_item_packet(val1.target.id, val1.target.index, val1.id)
else
windower.add_to_chat(67, 'Target out of range.')
end
elseif find_usable_item(val1.id) then
-- 0x37 packet
Expand All @@ -250,42 +247,27 @@ function equip_sets_exit(swap_type, ts, val1)
command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow)
end

if not command_registry[ts].proposed_packet then
command_registry:delete_entry(ts)
end
end

if ts and command_registry[ts] then
if not val1.target.name then
-- Spells with invalid pass_through_targs, like using <t> without a target
command_registry:delete_entry(ts)
msg.debugging('Change target was used to pick an invalid target (' .. storedcommand .. ' ' .. val1.target.raw .. ')')
local ret = storedcommand .. ' ' .. val1.target.raw
storedcommand = nil
return ret
else
-- Spells with complete target information
-- command_registry[ts] is deleted for cancelled spells
if command_registry[ts].proposed_packet then
if command_registry[ts].pretarget_cast_delay == 0 then
equip_sets('precast', ts, val1)
else
windower.send_command('@wait ' .. command_registry[ts].pretarget_cast_delay .. ';lua i ' .. _addon.name .. ' pretarget_delayed_cast ' .. ts)
end
return true
end
elseif not ts or not command_registry[ts] then
msg.debugging('This case should not be hittable - 2')
return true
end

msg.debugging('No valid target at end of pretarget (' .. storedcommand .. ' ' .. val1.target.raw .. ')')
command_registry:delete_entry(ts)
return storedcommand .. ' ' .. val1.target.raw

elseif swap_type == 'precast' then
-- Update the target_arrow
if val1.prefix ~= '/item' then
command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow)
end
return precast_send_check(ts)
elseif swap_type == 'filtered_action' and command_registry[ts] and command_registry[ts].cancel_spell then
storedcommand = nil
command_registry:delete_entry(ts)
return true
elseif swap_type == 'midcast' and _settings.demo_mode then
Expand Down
10 changes: 4 additions & 6 deletions addons/GearSwap/triggers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ windower.register_event('outgoing text', function(original, modified)
spell.target = temp_mob_arr
spell.action_type = action_type_map[command]

if spell.prefix == '/item' and spell.target.type ~= 'NONE' and bit.band(spell.target.spawn_type, 2) == 2 then
if spell.prefix == '/item' and spell.target.type ~= 'NONE' and bit.band(spell.target.spawn_type, 2) == 2 and find_inventory_item(spell.id) then
spell.action_type = 'Trade'
end

Expand All @@ -135,13 +135,10 @@ windower.register_event('outgoing text', function(original, modified)

if spell.prefix == '/item' then
-- Item use packet handling here
if spell.action_type == 'Trade' and find_inventory_item(spell.id) then
if spell.action_type == 'Trade' then
--0x36 packet
if spell.target.distance <= 6 then
command_registry[ts].proposed_packet = assemble_menu_item_packet(spell.target.id, spell.target.index, spell.id)
else
windower.add_to_chat(67, 'Target out of range.')
return true
end
elseif find_usable_item(spell.id) then
--0x37 packet
Expand All @@ -151,10 +148,11 @@ windower.register_event('outgoing text', function(original, modified)
command_registry[ts].proposed_packet = assemble_action_packet(spell.target.id, spell.target.index, outgoing_action_category_table[unify_prefix[spell.prefix]], spell.id, initialize_arrow_offset(spell.target))
end

-- The packets created above should not be used.
if command_registry[ts].proposed_packet then
equip_sets('precast', ts, spell)
return true
else
command_registry:delete_entry(ts)
end
end

Expand Down