From b33f6c1ba8ec286bb65268aee879b38953e2c244 Mon Sep 17 00:00:00 2001
From: Seth VanHeulen <533741+svanheulen@users.noreply.github.com>
Date: Sun, 9 Jun 2019 16:22:55 -0400
Subject: [PATCH 1/6] Equipment: add equip functions
---
equipment/equipment.lua | 66 ++++++++++++++++++++++++++++++++++++++++-
equipment/manifest.xml | 3 +-
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/equipment/equipment.lua b/equipment/equipment.lua
index 7134ca20..88dadca9 100644
--- a/equipment/equipment.lua
+++ b/equipment/equipment.lua
@@ -1,5 +1,6 @@
local client = require('shared.client')
local resources = require('resources')
+local packets = require('packets')
local data, ftype = client.new('items_service', 'equipment')
@@ -9,7 +10,70 @@ ftype.base.fields.item.type.fields.item = {
end,
}
-return data
+ftype.base.fields.equip = {
+ data = function(equipment_slot, item)
+ local bag = item.bag
+ local index = item.index
+ assert(resources.bags[bag].equippable, "Can not equip from this bag (bag = " .. bag .. ")")
+ assert(item.id ~= 0, "Can not equip from an empty bag slot (bag = " .. bag .. ", index = " .. index .. ")")
+
+ packets.outgoing[0x050]:inject({bag_index = index, slot_id = equipment_slot.slot, bag_id = bag})
+ end,
+}
+
+ftype.base.fields.unequip = {
+ data = function(equipment_slot)
+ packets.outgoing[0x050]:inject({bag_index = 0, slot_id = equipment_slot.slot, bag_id = 0})
+ end,
+}
+
+local equipment = {}
+
+equipment.equip = function(slot_items)
+ local count = 0
+ local items = {}
+ for slot, item in pairs(slot_items) do
+ if slot >= 0 and slot <= 15 then
+ local bag = item and item.bag or 0
+ local index = item and item.index or 0
+ assert(resources.bags[bag].equippable, "Can not equip from this bag (bag = " .. bag .. ")")
+ assert(not item or item.id ~= 0, "Can not equip from an empty bag slot (bag = " .. bag .. ", index = " .. index .. ")")
+ items[count] = {bag_index = index, slot_id = slot, bag_id = bag}
+ count = count + 1
+ end
+ end
+
+ packets.outgoing[0x051]:inject({count = count, equipment = items})
+end
+
+local slot_names = {
+ 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(t, k)
+ local index = slot_names[k] or k
+ return data[index]
+ end,
+ __newindex = function(t, k, v)
+ local index = slot_names[k] or k
+ data[index] = v
+ end,
+ __pairs = function(t)
+ return pairs(data)
+ end,
+ __ipairs = function(t)
+ return ipairs(data)
+ end,
+ __len = function(t)
+ return #data
+ end
+}
+
+return setmetatable(equipment, equipment_mt)
--[[
Copyright © 2018, Windower Dev Team
diff --git a/equipment/manifest.xml b/equipment/manifest.xml
index 054dd817..3700f11c 100644
--- a/equipment/manifest.xml
+++ b/equipment/manifest.xml
@@ -1,10 +1,11 @@
equipment
- 1.1.0.2
+ 1.1.1.0
library
items_service
resources
shared
+ packets
From 82d24fac8e5ab6cae2a3d98c2d8ebaebee2a782e Mon Sep 17 00:00:00 2001
From: Seth VanHeulen <533741+svanheulen@users.noreply.github.com>
Date: Tue, 18 Jun 2019 12:23:35 -0400
Subject: [PATCH 2/6] code standards clean up
---
equipment/equipment.lua | 22 ++++++++++++----------
equipment/manifest.xml | 2 +-
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/equipment/equipment.lua b/equipment/equipment.lua
index 88dadca9..c4caedef 100644
--- a/equipment/equipment.lua
+++ b/equipment/equipment.lua
@@ -10,12 +10,14 @@ ftype.base.fields.item.type.fields.item = {
end,
}
+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
- assert(resources.bags[bag].equippable, "Can not equip from this bag (bag = " .. bag .. ")")
- assert(item.id ~= 0, "Can not equip from an empty bag slot (bag = " .. bag .. ", index = " .. index .. ")")
+ 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 .. ')')
packets.outgoing[0x050]:inject({bag_index = index, slot_id = equipment_slot.slot, bag_id = bag})
end,
@@ -29,15 +31,15 @@ ftype.base.fields.unequip = {
local equipment = {}
-equipment.equip = function(slot_items)
+equipment.equip = function(_, slot_items)
local count = 0
local items = {}
for slot, item in pairs(slot_items) do
if slot >= 0 and slot <= 15 then
local bag = item and item.bag or 0
local index = item and item.index or 0
- assert(resources.bags[bag].equippable, "Can not equip from this bag (bag = " .. bag .. ")")
- assert(not item or item.id ~= 0, "Can not equip from an empty bag slot (bag = " .. bag .. ", index = " .. index .. ")")
+ assert(equippable[bag], 'Cannot equip from this bag (bag = ' .. bag .. ')')
+ assert(not item or item.id ~= 0, 'Cannot equip from an empty bag slot (bag = ' .. bag .. ', index = ' .. index .. ')')
items[count] = {bag_index = index, slot_id = slot, bag_id = bag}
count = count + 1
end
@@ -54,21 +56,21 @@ local slot_names = {
}
local equipment_mt = {
- __index = function(t, k)
+ __index = function(_, k)
local index = slot_names[k] or k
return data[index]
end,
- __newindex = function(t, k, v)
+ __newindex = function(_, k, v)
local index = slot_names[k] or k
data[index] = v
end,
- __pairs = function(t)
+ __pairs = function(_)
return pairs(data)
end,
- __ipairs = function(t)
+ __ipairs = function(_)
return ipairs(data)
end,
- __len = function(t)
+ __len = function(_)
return #data
end
}
diff --git a/equipment/manifest.xml b/equipment/manifest.xml
index 3700f11c..f7db22da 100644
--- a/equipment/manifest.xml
+++ b/equipment/manifest.xml
@@ -1,6 +1,6 @@
equipment
- 1.1.1.0
+ 2.0.0.0
library
items_service
From bcc5c2885352025f088a6445e223ffb3aecf89fa Mon Sep 17 00:00:00 2001
From: Seth VanHeulen <533741+svanheulen@users.noreply.github.com>
Date: Tue, 18 Jun 2019 21:09:27 -0400
Subject: [PATCH 3/6] accept an empty item instead of false
---
equipment/equipment.lua | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/equipment/equipment.lua b/equipment/equipment.lua
index c4caedef..baecffa6 100644
--- a/equipment/equipment.lua
+++ b/equipment/equipment.lua
@@ -34,13 +34,14 @@ local equipment = {}
equipment.equip = function(_, slot_items)
local count = 0
local items = {}
- for slot, item in pairs(slot_items) do
- if slot >= 0 and slot <= 15 then
- local bag = item and item.bag or 0
- local index = item and item.index or 0
+ for i = 0, 15 do
+ local item = slot_items[i]
+ if item then
+ local bag = item.bag
+ local index = item.index
assert(equippable[bag], 'Cannot equip from this bag (bag = ' .. bag .. ')')
- assert(not item or item.id ~= 0, 'Cannot equip from an empty bag slot (bag = ' .. bag .. ', index = ' .. index .. ')')
- items[count] = {bag_index = index, slot_id = slot, bag_id = bag}
+ assert(bag == 0 and index == 0 or item.id ~= 0, 'Cannot equip from an empty bag slot (bag = ' .. bag .. ', index = ' .. index .. ')')
+ items[count] = {bag_index = index, slot_id = i, bag_id = bag}
count = count + 1
end
end
From f2843956746e00634b3429a7c11611760f6a5f47 Mon Sep 17 00:00:00 2001
From: Seth VanHeulen <533741+svanheulen@users.noreply.github.com>
Date: Thu, 20 Jun 2019 10:15:55 -0400
Subject: [PATCH 4/6] remove indexing by slot name, add slot name table
---
equipment/equipment.lua | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/equipment/equipment.lua b/equipment/equipment.lua
index baecffa6..c0a15781 100644
--- a/equipment/equipment.lua
+++ b/equipment/equipment.lua
@@ -49,7 +49,7 @@ equipment.equip = function(_, slot_items)
packets.outgoing[0x051]:inject({count = count, equipment = items})
end
-local slot_names = {
+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,
@@ -58,12 +58,10 @@ local slot_names = {
local equipment_mt = {
__index = function(_, k)
- local index = slot_names[k] or k
- return data[index]
+ return data[k]
end,
__newindex = function(_, k, v)
- local index = slot_names[k] or k
- data[index] = v
+ data[k] = v
end,
__pairs = function(_)
return pairs(data)
From 760c41e6278c913ecc6eecaace3988d017b948ed Mon Sep 17 00:00:00 2001
From: Seth VanHeulen <533741+svanheulen@users.noreply.github.com>
Date: Thu, 20 Jun 2019 10:49:24 -0400
Subject: [PATCH 5/6] add extra checking to equip functions
---
equipment/equipment.lua | 39 ++++++++++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/equipment/equipment.lua b/equipment/equipment.lua
index c0a15781..08ab7937 100644
--- a/equipment/equipment.lua
+++ b/equipment/equipment.lua
@@ -1,5 +1,6 @@
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')
@@ -16,22 +17,41 @@ ftype.base.fields.equip = {
data = function(equipment_slot, item)
local bag = item.bag
local index = item.index
- 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 .. ')')
+ 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 = equipment_slot.slot, bag_id = bag})
+ packets.outgoing[0x050]:inject({bag_index = index, slot_id = slot, bag_id = bag})
+ end
end,
}
ftype.base.fields.unequip = {
data = function(equipment_slot)
- packets.outgoing[0x050]:inject({bag_index = 0, slot_id = equipment_slot.slot, bag_id = 0})
+ 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
@@ -39,14 +59,19 @@ equipment.equip = function(_, slot_items)
if item then
local bag = item.bag
local index = item.index
- assert(equippable[bag], 'Cannot equip from this bag (bag = ' .. bag .. ')')
- assert(bag == 0 and index == 0 or item.id ~= 0, 'Cannot equip from an empty bag slot (bag = ' .. bag .. ', index = ' .. 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
- packets.outgoing[0x051]:inject({count = count, equipment = items})
+ if count > 0 then
+ packets.outgoing[0x051]:inject({count = count, equipment = items})
+ end
end
equipment.slot = {
From f51d3c9b4747c26d99eb8370c9593e30261504cf Mon Sep 17 00:00:00 2001
From: Seth VanHeulen <533741+svanheulen@users.noreply.github.com>
Date: Thu, 20 Jun 2019 15:54:33 -0400
Subject: [PATCH 6/6] fixed typo in error message
---
equipment/equipment.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/equipment/equipment.lua b/equipment/equipment.lua
index 08ab7937..f43d5c47 100644
--- a/equipment/equipment.lua
+++ b/equipment/equipment.lua
@@ -22,7 +22,7 @@ ftype.base.fields.equip = {
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 .. ')')
+ 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
@@ -62,7 +62,7 @@ equipment.equip = function(_, slot_items)
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 .. ')')
+ 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