diff --git a/lua/app/common/data_manager.lua b/lua/app/common/data_manager.lua index 2756c7d5..d03b170a 100644 --- a/lua/app/common/data_manager.lua +++ b/lua/app/common/data_manager.lua @@ -66,6 +66,7 @@ function DataManager:clear() self.PlayerData:clear() self.BattleData:clear() self.ChapterData:clear() + self.HeroData:clear() ModuleManager.TaskManager:clear() end @@ -77,6 +78,7 @@ function DataManager:initWithServerData(data) self.PlayerData:init(data.PlayerData) self.ChapterData:init(data.ChapterData) + self.HeroData:init(data.HeroData) self:scheduleGlobal() self:checkDataBind() diff --git a/lua/app/global/global_const.lua b/lua/app/global/global_const.lua index 09cd6017..0b01624c 100644 --- a/lua/app/global/global_const.lua +++ b/lua/app/global/global_const.lua @@ -158,7 +158,7 @@ GConst.TYPEOF_LUA_CLASS = { -- cell ITEM_CELL = "app/ui/common/cell/item_cell", - EQUIP_CELL = "app/ui/common/cell/equip_cell", + HERO_CELL = "app/ui/common/cell/hero_cell", REWARD_CELL = "app/ui/common/cell/reward_cell", } @@ -370,84 +370,8 @@ GConst.ENTITY_TYPE = { } GConst.ATTR_TYPE = { - -- 血量 hp = 1, - -- 生命恢复 - -- recover = 2, - -- 攻击 atk = 2, - -- 速度 - -- spd = 4, - -- 暴击 - crit = 3, - -- 暴击伤害 - crit_time = 4, - -- 技能范围增加(百分比) - -- atk_range = 7, - -- 伤害减免,在伤害计算的最后按百分比减少 - dmg_dec_all = 5, - -- 对boss的伤害提升 - -- hurt_boss_time = 9, - -- 攻击力百分比 - atkp_1 = 6, - atkp_2 = 7, - atkp_3 = 8, - atkp_4 = 9, - atkp_5 = 10, - atkp_6 = 11, - atkp_7 = 12, - atkp_8 = 13, - atkp_9 = 14, - -- 生命百分比 - hpp_1 = 15, - hpp_2 = 16, - hpp_3 = 17, - hpp_4 = 18, - hpp_5 = 19, - hpp_6 = 20, - hpp_7 = 21, - -- 移动速度百分比 - -- spdp = 25, - -- 增加自身的伤害 - dmg_addition = 22, - -- 中毒伤害提高(比例) - -- hurt_poisonP = 27, - -- 对中毒单位伤害提高(比例) - -- dmg_addition_poicon = 28, - -- 闪避几率(受伤时有几率不掉血) - miss = 23, - -- 金币获取(百分比) - gold_gain = 24, - -- 技能伤害(百分比) - dmg_addition_skill = 25, - -- 普攻伤害(百分比) - dmg_addition_normal = 26, - -- 放置奖励(百分比) - idle_income = 27, - -- 矿镐回复速度(百分比) - pickaxe_recover_spd = 28, - -- 矿镐持有上限(固定值) - pickaxe_own_limit = 29, - -- 研究用矿石获取(百分比) - mineral_gain = 30, - -- 研究速度(百分比) - research_spd = 31, - -- 所有战斗中的攻击力百分比加成 - -- atkp_0 = 38, - -- 击飞伤害 - airborne_damage = 32, - -- 击飞数量 - airborne_num = 33, - -- 所有技能的伤害提升 - -- skill_all_damage = 41, - -- 武器技能1的伤害提升 - -- skill_1_damage = 42, - -- -- 武器技能2的伤害提升 - -- skill_2_damage = 43, - -- -- 武器技能3的伤害提升 - -- skill_3_damage = 44, - -- -- 普攻伤害提升 - -- attack_damage = 45, } GConst.GAMEOBJECT_LAYER = { diff --git a/lua/app/server/data/server_hero_data.lua b/lua/app/server/data/server_hero_data.lua new file mode 100644 index 00000000..2b53bc97 --- /dev/null +++ b/lua/app/server/data/server_hero_data.lua @@ -0,0 +1,3 @@ +local ServerHeroData = class("ServerHeroData", ServerBaseData) + +return ServerHeroData \ No newline at end of file diff --git a/lua/app/server/data/server_hero_data.lua.meta b/lua/app/server/data/server_hero_data.lua.meta new file mode 100644 index 00000000..cf2ead46 --- /dev/null +++ b/lua/app/server/data/server_hero_data.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 56a4a8f5d6118d74b9bb6971db3d030a +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/server_game_data.lua b/lua/app/server/server_game_data.lua index 132728d7..e64c1bcf 100644 --- a/lua/app/server/server_game_data.lua +++ b/lua/app/server/server_game_data.lua @@ -11,6 +11,7 @@ function ServerGameData:init() self.isInit = true self:initServerData("PlayerData", "app/server/data/server_player_data") self:initServerData("BagData", "app/server/data/server_bag_data") + self:initServerData("HeroData", "app/server/data/server_hero_data") self:initServerData("ChapterData", "app/server/data/server_chapter_data") end diff --git a/lua/app/ui/common/cell/hero_cell.lua b/lua/app/ui/common/cell/hero_cell.lua new file mode 100644 index 00000000..61526040 --- /dev/null +++ b/lua/app/ui/common/cell/hero_cell.lua @@ -0,0 +1,6 @@ +local HeroCell = class("HeroCell", BaseCell) + +function HeroCell:refresh() +end + +return HeroCell diff --git a/lua/app/ui/common/cell/hero_cell.lua.meta b/lua/app/ui/common/cell/hero_cell.lua.meta new file mode 100644 index 00000000..661c8c13 --- /dev/null +++ b/lua/app/ui/common/cell/hero_cell.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 2908445d9bae05b4fad51ac5eca0730e +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/ui/hero/cell.meta b/lua/app/ui/hero/cell.meta new file mode 100644 index 00000000..8a64b73b --- /dev/null +++ b/lua/app/ui/hero/cell.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d83268e262de62e478d7dd155698ccce +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/lua/app/ui/hero/cell/hero_list_cell.lua b/lua/app/ui/hero/cell/hero_list_cell.lua new file mode 100644 index 00000000..7ea45a26 --- /dev/null +++ b/lua/app/ui/hero/cell/hero_list_cell.lua @@ -0,0 +1,43 @@ +local HeroListCell = class("HeroListCell", BaseCell) + +local H = { + NORMAL = 112, + HAS_TITLE = 216 +} + +function HeroListCell:init() + self.uiMap = self:getUIMap() + self.heroCells = { + self.uiMap["hero_list_cell.prop_node.hero_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["hero_list_cell.prop_node.hero_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["hero_list_cell.prop_node.hero_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["hero_list_cell.prop_node.hero_cell_4"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["hero_list_cell.prop_node.hero_cell_5"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + } + self.title = self.uiMap["hero_list_cell.title"] + self.titleTx = self.uiMap["hero_list_cell.title.title_desc"] +end + +function HeroListCell:refresh(list) + -- for i, cell in ipairs(self.heroCells) do + -- local info = list.unitList and list.unitList[i] + -- cell:getBaseObject():setActive(info ~= nil) + -- if info and info.entity then + -- cell:refresh(info.entity) + -- end + -- end + + -- self.title:setActive(list.showTitle ~= nil) + -- if list.showTitle ~= nil then + -- self.titleTx:setText(list.showTitle) + -- self:getBaseObject():setSizeDeltaY(H.HAS_TITLE) + -- else + -- local h = H.NORMAL + -- if list.isFirstLine then + -- h = h + 30 + -- end + -- self:getBaseObject():setSizeDeltaY(h) + -- end +end + +return HeroListCell \ No newline at end of file diff --git a/lua/app/ui/hero/cell/hero_list_cell.lua.meta b/lua/app/ui/hero/cell/hero_list_cell.lua.meta new file mode 100644 index 00000000..2ba9ea77 --- /dev/null +++ b/lua/app/ui/hero/cell/hero_list_cell.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 65cefb44eced49b4ab01c650f89e976b +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/ui/hero/hero_comp.lua b/lua/app/ui/hero/hero_comp.lua index ee04bd31..2a08e5f0 100644 --- a/lua/app/ui/hero/hero_comp.lua +++ b/lua/app/ui/hero/hero_comp.lua @@ -1,6 +1,46 @@ local HeroComp = class("HeroComp", LuaComponent) +local HERO_LIST_CELL = "app/ui/hero/cell/hero_list_cell" + +function HeroComp:init() + self.uiMap = self:getBaseObject():genAllChildren() + self.scrollRect = self.uiMap["hero_ui.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) + self.scrollRect:addInitCallback(function() + return HERO_LIST_CELL + end) + self.scrollRect:addRefreshCallback(function(index, cell) + cell:refresh() + end) + self.heroList = {} +end + function HeroComp:refresh() + if #self.heroList <= 0 then + local heroes = DataManager.HeroData:getAllHeroes() + for k, v in pairs(heroes) do + table.insert(self.heroList, v) + end + end + self:refreshScrollRect() +end + +function HeroComp:refreshScrollRect() + local activeCount = DataManager.HeroData:getActiveHeroCount() + local lockCount = #self.heroList - activeCount + local cellCount = 0 + if activeCount > 0 then + cellCount = cellCount + math.ceil(activeCount / 5) + end + if lockCount > 0 then + cellCount = cellCount + math.ceil(lockCount / 5) + end + local currCount = self.scrollRect:getTotalCount() + if cellCount == currCount then + self.scrollRect:updateAllCell() + else + self.scrollRect:clearCells() + self.scrollRect:refillCells(cellCount) + end end return HeroComp \ No newline at end of file diff --git a/lua/app/userdata/hero/hero_data.lua b/lua/app/userdata/hero/hero_data.lua index 5294f216..f584464b 100644 --- a/lua/app/userdata/hero/hero_data.lua +++ b/lua/app/userdata/hero/hero_data.lua @@ -3,7 +3,7 @@ local HeroData = class("HeroData", BaseData) function HeroData:ctor() self.heroes = {} - self.heroCount = 0 + self.data.activeCount = 0 end function HeroData:clear() @@ -12,20 +12,22 @@ end function HeroData:init(data) self.heroes = {} - self.heroCount = 0 - data = data or {} - for id, info in pairs(data) do - self:_addHero(info) - self.heroCount = self.heroCount + 1 + local heroCfg = ConfigManager:getConfig("hero") + for heroId, heroInfo in pairs(heroCfg) do + self:createHeroById(heroId, heroInfo) end end -function HeroData:_addHero(heroInfo) - self.heroes[heroInfo.cfg_id] = HeroEntity:create(heroInfo) +function HeroData:createHeroById(heroId, heroInfo) + self.heroes[heroId] = HeroEntity:create(heroId, heroInfo) end -function HeroData:getHeroes() +function HeroData:getAllHeroes() return self.heroes end +function HeroData:getActiveHeroCount() + return self.data.activeCount +end + return HeroData \ No newline at end of file diff --git a/lua/app/userdata/hero/hero_entity.lua b/lua/app/userdata/hero/hero_entity.lua index 979c2bc7..597886ee 100644 --- a/lua/app/userdata/hero/hero_entity.lua +++ b/lua/app/userdata/hero/hero_entity.lua @@ -1,50 +1,21 @@ local HeroEntity = class("HeroEntity", BaseData) -function HeroEntity:ctor(heroInfo) - self.id = heroInfo.id or 1 - self.cfgId = heroInfo.cfg_id or self.id - self.data.lv = heroInfo.lv or 1 +function HeroEntity:ctor(cfgId, config) + self.id = cfgId + self.config = config + self.cfgId = cfgId + self.data.lv = 0 self.attrDirty = false - self.data.powerDirty = false - - self:_loadConfig() self.baseAttrOriginal = {} - self:initAttrTab() + self.allAttr = {} + self:initAttr() self:updateAttr() end -function HeroEntity:initAttrTab() - self.allAttr = {} - local cfg = ConfigManager:getConfig("attr") - for i = 1, #cfg do - self.allAttr[i] = {unit = 0, value = 0} - end -end - -function HeroEntity:_loadConfig() - self.config = ConfigManager:getConfig("hero")[self.cfgId] -end - -function HeroEntity:setHid(id) - self.id = id -end - -function HeroEntity:getHid() - return self.id -end - -function HeroEntity:getId() - return self.cfgId -end - -function HeroEntity:setId(id) - if not id then - return - end - self.cfgId = id - self:_loadConfig() - self:setDirty() +function HeroEntity:initAttr() + self.allAttr[GConst.ATTR_TYPE.hp] = 0 + self.allAttr[GConst.ATTR_TYPE.atk] = 0 end function HeroEntity:setLv(lv) @@ -74,8 +45,6 @@ end function HeroEntity:updateAttr() self:updateBaseAttr() - self:_updateAllAttr() - self:calculatePower() end function HeroEntity:updateBaseAttr()