diff --git a/addons/GearSwap/flow.lua b/addons/GearSwap/flow.lua index 0ac688d83..16967de26 100644 --- a/addons/GearSwap/flow.lua +++ b/addons/GearSwap/flow.lua @@ -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 @@ -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' @@ -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 @@ -250,22 +247,7 @@ 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 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 @@ -273,11 +255,12 @@ function equip_sets_exit(swap_type, ts, val1) 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 @@ -285,7 +268,6 @@ function equip_sets_exit(swap_type, ts, val1) 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 diff --git a/addons/GearSwap/triggers.lua b/addons/GearSwap/triggers.lua index 32ed962ef..27bb062bb 100644 --- a/addons/GearSwap/triggers.lua +++ b/addons/GearSwap/triggers.lua @@ -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 @@ -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 @@ -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