63 lines
No EOL
1.9 KiB
Lua
63 lines
No EOL
1.9 KiB
Lua
local CharacterEquip = Object:extend()
|
|
local itemutils = require "game.utils.items"
|
|
|
|
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
|
|
game.loot:addItem(category, self.equip[category], 1)
|
|
end
|
|
self.equip[category] = name
|
|
game.loot:removeItem(category, name, 1)
|
|
self.stats = self:createStats()
|
|
end
|
|
|
|
function CharacterEquip:removeEquip(category)
|
|
if (not utils.string.isEmpty(self.equip[category])) then
|
|
game.loot:addItem(category, self.equip[category], 1)
|
|
self.equip[category] = ""
|
|
self.stats = self:createStats()
|
|
end
|
|
end
|
|
|
|
function CharacterEquip:predictStat(statName, category, name)
|
|
local data = itemutils.getItemData(category, name)
|
|
local boost = data.statsBoost[statName] or 0
|
|
return self:getStat(statName, category) + boost
|
|
end
|
|
|
|
function CharacterEquip:getEquipStats(stat, ignore)
|
|
local boost = 0
|
|
local ignore = ignore or ""
|
|
for _, category in ipairs(categories) do
|
|
if (category ~= ignore) then
|
|
boost = boost + self:getStatByType(stat, category)
|
|
end
|
|
end
|
|
return boost
|
|
end
|
|
|
|
function CharacterEquip:getStatByType(stat, category)
|
|
if (not utils.string.isEmpty(self.equip[category])) then
|
|
local data = itemutils.getItemData(category, self.equip[category])
|
|
local boost = data.statsBoost[stat] or 0
|
|
return boost
|
|
end
|
|
return 0
|
|
end
|
|
|
|
return CharacterEquip |