sonic-radiance/sonic-radiance.love/game/loot/init.lua

68 lines
1.7 KiB
Lua
Raw Normal View History

2021-05-08 12:54:07 +02:00
local Serializable = require "birb.classes.serializable"
local LootManager = Serializable:extend()
2020-09-13 10:03:43 +02:00
local Pocket = require "game.loot.pocket"
2020-09-13 13:25:44 +02:00
local EffectManager = require "game.loot.effectManager"
2020-08-15 22:43:46 +02:00
2020-08-02 15:56:36 +02:00
function LootManager:new(controller)
self.controller = controller
self.rings = 0
self.inventory = {}
2020-08-15 22:43:46 +02:00
self.pocketIndex = {}
2020-09-13 13:25:44 +02:00
self.effects = EffectManager()
2020-08-15 22:43:46 +02:00
self:generatePockets()
2021-05-08 12:54:07 +02:00
LootManager.super.new(self, {}, {"inventory"})
2020-08-15 22:43:46 +02:00
end
function LootManager:generatePockets()
local structure = require "datas.gamedata.items"
for i,pocketdata in ipairs(structure) do
local pocket = Pocket(pocketdata)
self.pocketIndex[pocketdata.name] = i
table.insert(self.inventory, pocket)
end
end
2021-03-13 13:51:43 +01:00
function LootManager:getPocketIdByName(name)
return self.pocketIndex[name]
end
2020-08-15 22:43:46 +02:00
function LootManager:getPocketById(id)
return self.inventory[id]
end
function LootManager:getPocketByName(name)
return self.inventory[self.pocketIndex[name]]
end
function LootManager:addItem(type, item, number)
local pocket = self:getPocketByName(type)
if (core.datas:exists("items", item)) then
2020-08-15 22:43:46 +02:00
pocket:addItem(item, number)
end
end
2021-03-12 20:54:45 +01:00
function LootManager:removeItem(type, item, number)
local pocket = self:getPocketByName(type)
if (core.datas:exists("items", item)) then
2021-03-12 20:54:45 +01:00
pocket:removeItem(item, number)
end
end
2020-08-15 22:43:46 +02:00
function LootManager:getItemNumber(type, item)
local pocket = self:getPocketByName(type)
return pocket:getItemNumber(item)
end
2020-09-13 13:25:44 +02:00
function LootManager:applyItemEffect(category, item, target)
self.effects:getItemData(category, item)
self.effects:applyItemEffect(target)
end
function LootManager:getEffectStrings(category, item)
self.effects:getItemData(category, item)
return self.effects:getEffectStrings(nil)
end
2020-08-02 15:56:36 +02:00
return LootManager