@@ -26,90 +26,111 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]]
2626
2727_addon .name = ' Dimmer'
2828_addon .author = ' Chiaia'
29- _addon .version = ' 1.1.1 '
30- _addon .commands = {' dim' ,' dimmer' }
29+ _addon .version = ' 1.1.2 '
30+ _addon .commands = {' dim' , ' dimmer' }
3131
3232require (' logger' )
33+ require (' tables' )
3334extdata = require (' extdata' )
3435res_bags = require (' resources' ).bags
3536
3637log_flag = true
3738
3839lang = string.lower (windower .ffxi .get_info ().language )
39- item_info = {
40- [1 ]= {id = 26176 ,japanese = ' D.ホラリング' ,english = ' "Dim. Ring (Holla)"' ,slot = 13 },
41- [2 ]= {id = 26177 ,japanese = ' D.デムリング' ,english = ' "Dim. Ring (Dem)"' ,slot = 13 },
42- [3 ]= {id = 26178 ,japanese = ' D.メアリング' ,english = ' "Dim. Ring (Mea)"' ,slot = 13 },
43- [4 ]= {id = 10385 ,japanese = " キュムラスマスク+1" ,english = " Cumulus Masque +1" ,slot = 4 },
40+ item_info = T {
41+ [26176 ]= {id = 26176 , japanese = ' D.ホラリング' , english = ' "Dim. Ring (Holla)"' , equip_slot = 13 , short_name = ' holla ' },
42+ [26177 ]= {id = 26177 , japanese = ' D.デムリング' , english = ' "Dim. Ring (Dem)"' , equip_slot = 13 , short_name = ' dem ' },
43+ [26178 ]= {id = 26178 , japanese = ' D.メアリング' , english = ' "Dim. Ring (Mea)"' , equip_slot = 13 , short_name = ' mea ' },
44+ [10385 ]= {id = 10385 , japanese = " キュムラスマスク+1" , english = " Cumulus Masque +1" , equip_slot = 4 , short_name = ' mask ' },
4445}
4546
46- function search_item ()
47+ get_items = windower .ffxi .get_items
48+ set_equip = windower .ffxi .set_equip
49+
50+ function search_item (name )
4751 if windower .ffxi .get_player ().status > 1 then
4852 log (' You cannot use items at this time.' )
4953 return
5054 end
5155
52- local item_array = {}
53- local get_items = windower .ffxi .get_items
54- local set_equip = windower .ffxi .set_equip
55-
56+ -- Wipe any previously-saved info
57+ for _ , stats in pairs (item_info ) do
58+ stats .bag = nil
59+ stats .bag_enabled = nil
60+ stats .inv_index = nil
61+ stats .status = nil
62+ stats .extdata = nil
63+ end
64+
65+ -- Get list of all equippable items player has
5666 for bag_id in pairs (res_bags :equippable (true )) do
5767 local bag = get_items (bag_id )
58- for _ ,item in ipairs (bag ) do
59- if item .id > 0 then
60- item_array [item .id ] = item
61- item_array [item .id ].bag = bag_id
62- item_array [item .id ].bag_enabled = bag .enabled
68+ for _ , item in ipairs (bag ) do
69+ if item_info [item .id ] then
70+ item_info [item .id ].bag = bag_id
71+ item_info [item .id ].bag_enabled = bag .enabled
72+ item_info [item .id ].inv_index = item .slot
73+ item_info [item .id ].status = item .status
74+ item_info [item .id ].extdata = item .extdata
6375 end
6476 end
6577 end
66- for index ,stats in pairs (item_info ) do
67- local item = item_array [stats .id ]
68- if item and item .bag_enabled then
69- local ext = extdata .decode (item )
70- local enchant = ext .type == ' Enchanted Equipment'
71- local recast = enchant and ext .charges_remaining > 0 and math.max (ext .next_use_time + 18000 - os.time (),0 )
72- local usable = recast and recast == 0
73- log (stats [lang ],usable and ' ' or recast and recast .. ' sec recast.' )
74- if usable or ext .type == ' General' then
75- if enchant and item .status ~= 5 then -- not equipped
76- set_equip (item .slot ,stats .slot ,item .bag )
77- repeat -- waiting cast delay
78- coroutine .sleep (1 )
79- local ext = extdata .decode (get_items (item .bag ,item .slot ))
80- local delay = ext .activation_time + 18000 - os.time ()
81- if delay > 0 then
82- log (stats [lang ],delay )
83- elseif log_flag then
84- log_flag = false
85- log (' Item use within 3 seconds..' )
86- end
87- until ext .usable or delay > 30
88- end
89- windower .chat .input (' /item ' .. windower .to_shift_jis (stats [lang ]).. ' <me>' )
90- break ;
78+
79+ -- If name of item is provided, process only that item
80+ if name then
81+ local _ , item = item_info :find (function (i ) return i .short_name == name end )
82+ process_item (item )
83+ else -- If name not provided, process all items
84+ for _ , item in pairs (item_info ) do
85+ if process_item (item ) then
86+ break
9187 end
92- elseif item and not item .bag_enabled then
93- log (' You cannot access ' .. stats [lang ].. ' from ' .. res_bags [item .bag ].name .. ' at this time.' )
94- else
95- log (' You don\' t have ' .. stats [lang ].. ' .' )
9688 end
9789 end
9890end
9991
100- windower .register_event (' addon command' ,function (...)
101- local args = T {... }
102- local cmd = args [1 ]
103- if cmd == ' all' then
104- windower .chat .input (' //dimmer' )
105- windower .send_ipc_message (' dimmer' )
92+ function process_item (item )
93+ if item .bag_enabled then
94+ local ext = extdata .decode (item )
95+ local enchant = ext .type == ' Enchanted Equipment'
96+ local recast = enchant and ext .charges_remaining > 0 and math.max (ext .next_use_time + 18000 - os.time (), 0 )
97+ local usable = recast and recast == 0
98+ log (item [lang ], usable and ' ' or recast and recast .. ' sec recast.' )
99+ if usable or ext .type == ' General' then
100+ if enchant and item .status ~= 5 then -- not equipped
101+ set_equip (item .inv_index , item .equip_slot , item .bag )
102+ repeat -- waiting cast delay
103+ coroutine .sleep (1 )
104+ local ext = extdata .decode (get_items (item .bag , item .inv_index ))
105+ local delay = ext .activation_time + 18000 - os.time ()
106+ if delay > 0 then
107+ log (item [lang ], delay )
108+ elseif log_flag then
109+ log_flag = false
110+ log (' Item use within 3 seconds..' )
111+ end
112+ until ext .usable or delay > 30
113+ end
114+ windower .chat .input (' /item ' .. windower .to_shift_jis (item [lang ]).. ' <me>' )
115+ return true
116+ end
117+ elseif item .bag and not item .bag_enabled then
118+ log (' You cannot access ' .. item [lang ].. ' from ' .. res_bags [item .bag ].name .. ' at this time.' )
119+ return false
106120 else
107- search_item ()
121+ log (' You don\' t have ' .. item [lang ].. ' .' )
122+ return false
108123 end
124+ end
125+
126+ windower .register_event (' addon command' , function (...)
127+ local args = T {... }
128+ search_item (args [1 ])
109129end )
110130
111- windower .register_event (' ipc message' ,function (msg )
112- if msg == ' dimmer' then
113- windower .chat .input (' //dimmer' )
131+ windower .register_event (' ipc message' , function (...)
132+ local args = T {... }
133+ if args [1 ] == ' dim' or args [1 ] == ' dimmer' then
134+ search_item (args [2 ])
114135 end
115136end )
0 commit comments