11local client = require (' shared.client' )
22local resources = require (' resources' )
3+ local bit = require (' bit' )
34local packets = require (' packets' )
45
56local data , ftype = client .new (' items_service' , ' equipment' )
@@ -16,37 +17,61 @@ ftype.base.fields.equip = {
1617 data = function (equipment_slot , item )
1718 local bag = item .bag
1819 local index = item .index
19- assert (equippable [bag ], ' Cannot equip from this bag (bag = ' .. bag .. ' )' )
20- assert (item .id ~= 0 , ' Cannot equip from an empty bag slot (bag = ' .. bag .. ' , index = ' .. index .. ' )' )
20+ if equipment_slot .item .bag ~= bag or equipment_slot .item .index ~= index then
21+ local slot = equipment_slot .slot
22+ assert (equippable [bag ], ' Cannot equip from this bag (bag = ' .. bag .. ' )' )
23+ assert (item .id ~= 0 , ' Cannot equip from an empty bag slot (bag = ' .. bag .. ' , index = ' .. index .. ' )' )
24+ assert (item .status == 0 , ' Cannot equip an item with this status (status = ' .. item .status .. ' )' )
25+ assert (bit .band (bit .lshift (1 , slot ), item .item .slots ) ~= 0 , ' Cannot equip that item in this slot (slot = ' .. slot .. ' item.id = ' .. item .id .. ' )' )
2126
22- packets .outgoing [0x050 ]:inject ({bag_index = index , slot_id = equipment_slot .slot , bag_id = bag })
27+ packets .outgoing [0x050 ]:inject ({bag_index = index , slot_id = slot , bag_id = bag })
28+ end
2329 end ,
2430}
2531
2632ftype .base .fields .unequip = {
2733 data = function (equipment_slot )
28- packets .outgoing [0x050 ]:inject ({bag_index = 0 , slot_id = equipment_slot .slot , bag_id = 0 })
34+ if equipment_slot .item .bag ~= 0 or equipment_slot .item .index ~= 0 then
35+ packets .outgoing [0x050 ]:inject ({bag_index = 0 , slot_id = equipment_slot .slot , bag_id = 0 })
36+ end
2937 end ,
3038}
3139
3240local equipment = {}
3341
3442equipment .equip = function (_ , slot_items )
43+ local ear1 = slot_items [11 ]
44+ local ear2 = slot_items [12 ]
45+ if ear1 and ear2 and ear1 .index == ear2 .index and ear1 .id == ear2 .id then
46+ slot_items [11 ] = nil
47+ end
48+
49+ local ring1 = slot_items [13 ]
50+ local ring2 = slot_items [14 ]
51+ if ring1 and ring2 and ring1 .index == ring2 .index and ring1 .id == ring2 .id then
52+ slot_items [13 ] = nil
53+ end
54+
3555 local count = 0
3656 local items = {}
3757 for i = 0 , 15 do
3858 local item = slot_items [i ]
3959 if item then
4060 local bag = item .bag
4161 local index = item .index
42- assert (equippable [bag ], ' Cannot equip from this bag (bag = ' .. bag .. ' )' )
43- assert (bag == 0 and index == 0 or item .id ~= 0 , ' Cannot equip from an empty bag slot (bag = ' .. bag .. ' , index = ' .. index .. ' )' )
62+ if bag ~= 0 or index ~= 0 then
63+ assert (equippable [bag ], ' Cannot equip from this bag (bag = ' .. bag .. ' )' )
64+ assert (item .id ~= 0 , ' Cannot equip from an empty bag slot (bag = ' .. bag .. ' , index = ' .. index .. ' )' )
65+ assert (bit .band (bit .lshift (1 , i ), item .item .slots ) ~= 0 , ' Cannot equip that item in this slot (slot = ' .. i .. ' item.id = ' .. item .id .. ' )' )
66+ end
4467 items [count ] = {bag_index = index , slot_id = i , bag_id = bag }
4568 count = count + 1
4669 end
4770 end
4871
49- packets .outgoing [0x051 ]:inject ({count = count , equipment = items })
72+ if count > 0 then
73+ packets .outgoing [0x051 ]:inject ({count = count , equipment = items })
74+ end
5075end
5176
5277equipment .slot = {
0 commit comments