local CollectBaseEntity = require "app/userdata/collection/collection_base_entity" local CollectionHeroEntity = class("CollectionHeroEntity", CollectBaseEntity) -- 英雄图鉴数据 -- 初始化服务器数据 function CollectionHeroEntity:init(data) if data then self.curlevel = data.level or 0 self.curPoint = data.point or 0 else self.curlevel = 0 self.curPoint = 0 end end -- 是否有红点 function CollectionHeroEntity:hasRedPoint() -- 可领点数 for idx, data in pairs(self:getCollectList()) do if self:getCanCollectPoint(data.id) > 0 then return true end end -- 可领奖励 for id, data in pairs(self:getRewardList()) do if self:isMeetTargetPoint(id) and not self:isRewardReceived(id) then return true end end return false end -- 获取当前收集值 function CollectionHeroEntity:getCurCollectPoint() return self.curPoint end -- 获取当前已领取奖励图鉴等级 function CollectionHeroEntity:getCurCollectLevel() return self.curlevel end -- 获取总收集值 function CollectionHeroEntity:getTotalCollectPoint() local list = self:getRewardList() if not list or #list <= 0 then return 0 end return list[#list].point end -- 获取收集目标列表 function CollectionHeroEntity:getCollectList() if self.heroList == nil then self.heroList = {} for id, data in pairs(ConfigManager:getConfig("hero")) do data.id = id table.insert(self.heroList, data) end table.sort(self.heroList, function(a, b) if a.qlt ~= b.qlt then return a.qlt > b.qlt end return a.id > b.id end) -- Logger.printTable(self.heroList) end return self.heroList end -- 获取收集奖励列表 function CollectionHeroEntity:getRewardList() if self.cfgRewards == nil then self.cfgRewards = ConfigManager:getConfig("collection") end return self.cfgRewards end -- 获取当前收集点数所在档位id function CollectionHeroEntity:getCurTargetId() for id, data in pairs(self:getRewardList()) do local prog = self:getRewardTargetProgress(id) if prog >= 0 and prog < 1 then -- 在进度条范围内 return id end end return nil end -- 获取奖励档位收集进度 function CollectionHeroEntity:getRewardTargetProgress(id) local cur = self:getCurCollectPoint() local rangeMin = self:getTargetMinPoint(id) local rangeMax = self:getTargetMaxPoint(id) -- Logger.logHighlight(id.."档位范围:"..rangeMin.."->"..rangeMax) if cur >= rangeMax then -- 超过进度条 return 1 elseif cur < rangeMin then --低于进度条 return -1 elseif cur == rangeMin then -- 进度最低值 return 0 else -- 在进度条范围内 return (cur - rangeMin) / (rangeMax - rangeMin) end end -- 获取当前可领奖or正在进行中的目标 function CollectionHeroEntity:getCanGetOrCollectingTargetId() for id, data in pairs(self:getRewardList()) do if not self:isMeetTargetPoint(id) then return id end if not self:isRewardReceived(id) then return id end end return nil end -- 获取收集目标点数 function CollectionHeroEntity:getTargetPoint(id) local targetPoint = self:getRewardList()[id].point local lastTarget = self:getLastTarget(id) if lastTarget then return targetPoint - lastTarget.point end return targetPoint end -- 获取基于目标收集点数的当前收集值 function CollectionHeroEntity:getTargetOwnedPoint(id) local curPoint = self:getCurCollectPoint() local lastTarget = self:getLastTarget(id) if lastTarget then return curPoint - lastTarget.point end return curPoint end -- 获取可领取收集值 function CollectionHeroEntity:getCanCollectPoint(id) -- 基础奖励值 * 升级可领取次数 -- 小于等于0为无点数,反之有可领取点数 local result = 0 local heroEntity = DataManager.HeroData:getHeroById(id) if heroEntity then local curLevel = heroEntity:getLv() local collectedLevel = heroEntity:getCollectionLevel() result = (curLevel - collectedLevel) * heroEntity:getCollectionPoint() end return result end -- 获取一级可领取收集值 function CollectionHeroEntity:getOneLevelCanCollectPoint(id) local heroEntity = DataManager.HeroData:getHeroById(id) if heroEntity then return heroEntity:getCollectionPoint() end return nil end -- 奖励是否已领取 function CollectionHeroEntity:isRewardReceived(id) return self.curlevel >= id end -- 是否满足奖励领取条件 function CollectionHeroEntity:isMeetTargetPoint(id) return self.curPoint >= self:getRewardList()[id].point end -- 领取收集点数成功 function CollectionHeroEntity:onGetedPointSuccess(id, point) DataManager.HeroData:getHeroById(id):updateCollectionLevel() self.curPoint = point end -- 领取图鉴奖励成功 function CollectionHeroEntity:onGetedPointRewardSuccess() self.curlevel = self.curlevel + 1 end -- 独有逻辑 ----------------------------------------------------------------------------------------------- -- 获取档位范围最低值 function CollectionHeroEntity:getTargetMinPoint(id) local rangeMin = 0 local curPoint = self:getRewardList()[id].point local lastTarget = self:getLastTarget(id) if lastTarget then rangeMin = curPoint - math.floor((curPoint - lastTarget.point) / 2) end return rangeMin end -- 获取档位范围最高值 function CollectionHeroEntity:getTargetMaxPoint(id) local rangeMax = 0 local curPoint = self:getRewardList()[id].point local nextTarget = self:getNextTarget(id) if nextTarget then rangeMax = curPoint + math.floor((nextTarget.point - curPoint) / 2) else rangeMax = curPoint end return rangeMax end -- 获取上一个低档位 function CollectionHeroEntity:getLastTarget(targetId) local result = nil for id, data in pairs(self:getRewardList()) do if id == targetId then return result end result = data end return nil end -- 获取下一个高档位 function CollectionHeroEntity:getNextTarget(targetId) local finded = false for id, data in pairs(self:getRewardList()) do if finded then return data end if id == targetId then finded = true end end return nil end return CollectionHeroEntity