218 lines
5.3 KiB
Lua
218 lines
5.3 KiB
Lua
local RunesData = class("RunesData", BaseData)
|
|
local RunesEntity = require "app/userdata/runes/runes_entity"
|
|
|
|
function RunesData:ctor()
|
|
self.data.isDirty = false
|
|
end
|
|
|
|
function RunesData:clear()
|
|
DataManager:unregisterTryOpenFunc("RunesData")
|
|
end
|
|
|
|
function RunesData:init(data)
|
|
data = data or GConst.EMPTY_TABLE
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("符文初始化数据")
|
|
Logger.printTable(data)
|
|
end
|
|
|
|
self.level = data.level or 1
|
|
self.exp = data.exp or 0
|
|
if data.heroes_grids then
|
|
for heroId, grids in pairs(data.heroes_grids) do
|
|
self:addEquip(heroId, grids.grids)
|
|
end
|
|
end
|
|
|
|
-- 活动开启
|
|
DataManager:registerTryOpenFunc("RunesData", function()
|
|
if self:isOpen() then
|
|
DataManager:unregisterTryOpenFunc("RunesData")
|
|
self:setDirty()
|
|
end
|
|
end)
|
|
self:setDirty()
|
|
end
|
|
|
|
function RunesData:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
function RunesData:isOpen(showToast)
|
|
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.RUNES_OPEN, not showToast) then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
function RunesData:addEquip(heroId, grids)
|
|
if self.runes == nil then
|
|
self.runes = {}
|
|
end
|
|
|
|
if self.runes[heroId] == nil then
|
|
self.runes[heroId] = self:createEntity(heroId, grids)
|
|
else
|
|
self.runes[heroId]:updateGrids(grids)
|
|
end
|
|
end
|
|
|
|
function RunesData:createEntity(heroId, grids)
|
|
return RunesEntity:create(heroId, grids)
|
|
end
|
|
|
|
function RunesData:getRunes(heroId)
|
|
if self.runes == nil then
|
|
self.runes = {}
|
|
end
|
|
if self.runes[heroId] == nil then
|
|
self.runes[heroId] = self:createEntity(heroId)
|
|
end
|
|
|
|
return self.runes[heroId]
|
|
end
|
|
|
|
-- 获取当前等级配置
|
|
function RunesData:getLevelConfig()
|
|
return ConfigManager:getConfig("runes_level")
|
|
end
|
|
|
|
-- 获取铸台最大等级
|
|
function RunesData:getMaxLevel()
|
|
return #self:getLevelConfig()
|
|
end
|
|
|
|
-- 获取符文铸台等级
|
|
function RunesData:getLevel()
|
|
return self.level
|
|
end
|
|
|
|
-- 获取等级当前经验
|
|
function RunesData:getLevelExp()
|
|
return self.exp - (self:getLevelConfig()[self:getLevel()].cost or 0)
|
|
end
|
|
|
|
-- 获取到下一档的总经验
|
|
function RunesData:getNextLevelTotalExp()
|
|
local cfg = self:getLevelConfig()[self:getLevel() + 1]
|
|
if cfg then
|
|
return cfg.cost or 0
|
|
end
|
|
|
|
return 0
|
|
end
|
|
|
|
-- 获取相应铸台等级的品质概率
|
|
function RunesData:getQualityRate(level, quality)
|
|
local cfg = self:getLevelConfig()[level]
|
|
|
|
local total = 0
|
|
for i = 1, GConst.RunesConst.MAX_QUALITY_COUNT do
|
|
total = total + (cfg["weight_"..i] or 0)
|
|
end
|
|
|
|
local value = cfg["weight_"..quality]
|
|
if value then
|
|
return string.format("%.2f",(value / total) * 100)
|
|
else
|
|
return 0
|
|
end
|
|
end
|
|
|
|
-- 获取相应套装的相应属性
|
|
function RunesData:getSuitAttr(id, heroType, suitLevel)
|
|
local data = ConfigManager:getConfig("runes_suit")[id]
|
|
local attrs
|
|
if heroType == GConst.HeroConst.MATCH_TYPE.RED then
|
|
attrs = data.red_suit_attr
|
|
elseif heroType == GConst.HeroConst.MATCH_TYPE.YELLOW then
|
|
attrs = data.yellow_suit_attr
|
|
elseif heroType == GConst.HeroConst.MATCH_TYPE.GREEN then
|
|
attrs = data.green_suit_attr
|
|
elseif heroType == GConst.HeroConst.MATCH_TYPE.BLUE then
|
|
attrs = data.blue_suit_attr
|
|
elseif heroType == GConst.HeroConst.MATCH_TYPE.PURPLE then
|
|
attrs = data.purple_suit_attr
|
|
end
|
|
|
|
if attrs ~= nil and attrs[suitLevel] then
|
|
return attrs[suitLevel]
|
|
end
|
|
|
|
return nil
|
|
end
|
|
|
|
-- 获取锻造材料个数
|
|
function RunesData:getMaterialCount()
|
|
return DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_RUNES)
|
|
end
|
|
|
|
-- 是否可以一键铸造
|
|
function RunesData:canAutoMake()
|
|
local cfg = self:getLevelConfig()[self:getLevel()]
|
|
return cfg.auto and cfg.auto == 1
|
|
end
|
|
|
|
-- 符文栏是否解锁
|
|
function RunesData:isUnlock(index)
|
|
local level = self:getLevel()
|
|
return index <= self:getLevelConfig()[level].grid
|
|
end
|
|
|
|
-- 获取符文栏解锁个数
|
|
function RunesData:getUnlockCount()
|
|
local unlock = 0
|
|
for i = 1, GConst.RunesConst.MAX_ATTR_GRID_COUNT do
|
|
if self:isUnlock(i) then
|
|
unlock = unlock + 1
|
|
end
|
|
end
|
|
|
|
return unlock
|
|
end
|
|
|
|
-- 获取符文栏解锁等级要求
|
|
function RunesData:getUnlockLevel(index)
|
|
for level, data in ipairs(self:getLevelConfig()) do
|
|
if data.grid >= index then
|
|
return level
|
|
end
|
|
end
|
|
|
|
return 0
|
|
end
|
|
|
|
-- 获取套装名
|
|
function RunesData:getSuitName(index)
|
|
if index == 1 then
|
|
return I18N:getGlobalText(I18N.GlobalConst.RUNES_DESC_10)
|
|
elseif index == 2 then
|
|
return I18N:getGlobalText(I18N.GlobalConst.RUNES_DESC_11)
|
|
elseif index == 3 then
|
|
return I18N:getGlobalText(I18N.GlobalConst.RUNES_DESC_12)
|
|
elseif index == 4 then
|
|
return I18N:getGlobalText(I18N.GlobalConst.RUNES_DESC_13)
|
|
elseif index == 5 then
|
|
return I18N:getGlobalText(I18N.GlobalConst.RUNES_DESC_14)
|
|
end
|
|
|
|
return nil
|
|
end
|
|
|
|
-- 改变属性栏锁定状态成功
|
|
function RunesData:onGridLockSuccess(heroId, grids)
|
|
self.runes[heroId]:updateGrids(grids)
|
|
|
|
self:setDirty()
|
|
end
|
|
|
|
-- 淬炼成功
|
|
function RunesData:onQuenchingSuccess(level, exp, heroId, grids)
|
|
self.level = level
|
|
self.exp = exp
|
|
self.runes[heroId]:updateGrids(grids)
|
|
|
|
self:setDirty()
|
|
end
|
|
|
|
return RunesData |