Skip to content
Open
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
92 changes: 91 additions & 1 deletion equipment/equipment.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local client = require('shared.client')
local resources = require('resources')
local bit = require('bit')
local packets = require('packets')

local data, ftype = client.new('items_service', 'equipment')

Expand All @@ -9,7 +11,95 @@ ftype.base.fields.item.type.fields.item = {
end,
}

return data
local equippable = {[0] = true, [8] = true, [10] = true, [11] = true, [12] = true}

ftype.base.fields.equip = {
data = function(equipment_slot, item)
local bag = item.bag
local index = item.index
if equipment_slot.item.bag ~= bag or equipment_slot.item.index ~= index then
local slot = equipment_slot.slot
assert(equippable[bag], 'Cannot equip from this bag (bag = ' .. bag .. ')')
assert(item.id ~= 0, 'Cannot equip from an empty bag slot (bag = ' .. bag .. ', index = ' .. index .. ')')
assert(item.status == 0, 'Cannot equip an item with this status (status = ' .. item.status .. ')')
assert(bit.band(bit.lshift(1, slot), item.item.slots) ~= 0, 'Cannot equip that item in this slot (slot = ' .. slot .. ', item.id = ' .. item.id .. ')')

packets.outgoing[0x050]:inject({bag_index = index, slot_id = slot, bag_id = bag})
end
end,
}

ftype.base.fields.unequip = {
data = function(equipment_slot)
if equipment_slot.item.bag ~= 0 or equipment_slot.item.index ~= 0 then
packets.outgoing[0x050]:inject({bag_index = 0, slot_id = equipment_slot.slot, bag_id = 0})
end
end,
}

local equipment = {}

equipment.equip = function(_, slot_items)
local ear1 = slot_items[11]
local ear2 = slot_items[12]
if ear1 and ear2 and ear1.index == ear2.index and ear1.id == ear2.id then
slot_items[11] = nil
end

local ring1 = slot_items[13]
local ring2 = slot_items[14]
if ring1 and ring2 and ring1.index == ring2.index and ring1.id == ring2.id then
slot_items[13] = nil
end

local count = 0
local items = {}
for i = 0, 15 do
local item = slot_items[i]
if item then
local bag = item.bag
local index = item.index
if bag ~= 0 or index ~= 0 then
assert(equippable[bag], 'Cannot equip from this bag (bag = ' .. bag .. ')')
assert(item.id ~= 0, 'Cannot equip from an empty bag slot (bag = ' .. bag .. ', index = ' .. index .. ')')
assert(bit.band(bit.lshift(1, i), item.item.slots) ~= 0, 'Cannot equip that item in this slot (slot = ' .. i .. ', item.id = ' .. item.id .. ')')
end
items[count] = {bag_index = index, slot_id = i, bag_id = bag}
count = count + 1
end
end

if count > 0 then
packets.outgoing[0x051]:inject({count = count, equipment = items})
end
end

equipment.slot = {
main = 0, sub = 1, range = 2, ammo = 3,
head = 4, neck = 9, ear1 = 11, ear2 = 12,
body = 5, hands = 6, ring1 = 13, ring2 = 14,
back = 15, waist = 10, legs = 7, feet = 8,
}

local equipment_mt = {
__index = function(_, k)
return data[k]
end,
__newindex = function(_, k, v)
data[k] = v
end,
__pairs = function(_)
return pairs(data)
end,
__ipairs = function(_)
return ipairs(data)
end,
__len = function(_)
return #data
end
}

return setmetatable(equipment, equipment_mt)

--[[
Copyright © 2018, Windower Dev Team
Expand Down
3 changes: 2 additions & 1 deletion equipment/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<package>
<name>equipment</name>
<version>1.1.0.2</version>
<version>2.0.0.0</version>
<type>library</type>
<dependencies>
<dependency>items_service</dependency>
<dependency>resources</dependency>
<dependency>shared</dependency>
<dependency>packets</dependency>
</dependencies>
</package>