2021-04-22 20:03:46 +02:00
|
|
|
local CharacterEquip = Object:extend()
|
|
|
|
|
|
|
|
local categories = {"gloves", "shoes", "accessories"}
|
|
|
|
|
|
|
|
function CharacterEquip:initEquip()
|
|
|
|
self.equip = {}
|
|
|
|
if self.data.inventory == nil then
|
|
|
|
core.debug:warning("character/equip", "Initial equip not set for " .. self.simplename)
|
|
|
|
for _, category in ipairs(categories) do
|
|
|
|
self.equip[category] = ""
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for _, category in ipairs(categories) do
|
|
|
|
self.equip[category] = self.data.inventory[category] or ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CharacterEquip:setEquip(category, name)
|
|
|
|
if (not utils.string.isEmpty(self.equip[category])) then
|
2021-04-22 23:41:20 +02:00
|
|
|
game.loot:addItem(category, self.equip[category], 1)
|
2021-04-22 20:03:46 +02:00
|
|
|
end
|
|
|
|
self.equip[category] = name
|
2021-04-22 23:41:20 +02:00
|
|
|
game.loot:removeItem(category, name, 1)
|
2021-07-03 10:41:16 +02:00
|
|
|
self:updateHPPP()
|
2021-04-22 20:03:46 +02:00
|
|
|
end
|
|
|
|
|
2021-04-23 09:23:13 +02:00
|
|
|
function CharacterEquip:removeEquip(category)
|
|
|
|
if (not utils.string.isEmpty(self.equip[category])) then
|
|
|
|
game.loot:addItem(category, self.equip[category], 1)
|
|
|
|
self.equip[category] = ""
|
2021-07-03 10:41:16 +02:00
|
|
|
self:updateHPPP()
|
2021-04-23 09:23:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-22 23:41:20 +02:00
|
|
|
function CharacterEquip:predictStat(statName, category, name)
|
2021-07-03 10:34:13 +02:00
|
|
|
return self.stats:predictStat(statName, category, name)
|
2021-04-22 20:03:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function CharacterEquip:getEquipStats(stat, ignore)
|
|
|
|
local boost = 0
|
|
|
|
local ignore = ignore or ""
|
|
|
|
for _, category in ipairs(categories) do
|
|
|
|
if (category ~= ignore) then
|
2021-06-12 10:29:46 +02:00
|
|
|
boost = boost + self:getEquipStatByType(stat, category)
|
2021-04-22 20:03:46 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return boost
|
|
|
|
end
|
|
|
|
|
2021-06-12 10:29:46 +02:00
|
|
|
function CharacterEquip:getEquipStatByType(stat, category)
|
2021-04-22 20:03:46 +02:00
|
|
|
if (not utils.string.isEmpty(self.equip[category])) then
|
2021-05-15 21:43:15 +02:00
|
|
|
local data = core.datas:get("items", self.equip[category])
|
2021-04-22 20:03:46 +02:00
|
|
|
local boost = data.statsBoost[stat] or 0
|
|
|
|
return boost
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
return CharacterEquip
|