From b0fe18174e4bb2b89ae0668e044b9cb8d41ca952 Mon Sep 17 00:00:00 2001 From: zhouahaihai Date: Tue, 16 Apr 2019 21:01:01 +0800 Subject: [PATCH] 冒险分数 --- src/GlobalVar.lua | 8 ++++++++ src/adv/Adv.lua | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/adv/AdvPlayer.lua | 9 +++++++++ 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index e7a11a6..3e27da7 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -99,4 +99,12 @@ AdvBackEventType = { BlockChange = 9, -- 块改变 PowerChange = 10, --体力改变 Dead = 11, --怪死亡 +} + +AdvScoreType = { + Level = 1, + Kill = 2, + Item = 3, + Hurt = 4, + Block = 5, } \ No newline at end of file diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 1119366..74d6837 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -104,9 +104,12 @@ local function randomAdvMap(role, chapterId, level, notNotify) --随出地图 local raw_pool = chapterData.mapid:toArray(true, "=") local advInfo = role:getProperty("advInfo") + local lastMapId = advInfo.mapId --非同一层不连续随出同一张类似的地图 local lastChapterId = advInfo.chapter + local lastScore = advInfo.score or {} -- 分数 local power = advInfo.power or 100 --体力 + local pool = {} for _, mapId in ipairs(raw_pool) do local temp = csvdb["mapCsv"][mapId] @@ -128,12 +131,12 @@ local function randomAdvMap(role, chapterId, level, notNotify) return end - table.clear(advInfo) advInfo.chapter = chapterId advInfo.level = level advInfo.mapId = mapId advInfo.power = power + advInfo.score = lastScore advInfo.enemyId = 1 --怪递增的索引 advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁 --事件随机 @@ -425,6 +428,8 @@ function Room:openBlock(block, adv) self.info.open[block.blockId] = 1 end + adv:scoreChange(AdvScoreType.Block) + if not self.isShow then self.isShow = true --首次展示房间 @@ -459,11 +464,10 @@ end --关卡通关,非层 score < 0 失败 function Adv:over(success) - local score = -1 + local score = self:getScore() + local scoreInfo = self.advInfo.score local reward if success then - -- todo success 计算分数 - score = 1 self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.advInfo.chapter, score)}) reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap(), {}) end @@ -473,7 +477,7 @@ function Adv:over(success) self.owner:updateProperty({field = "advItems", value = ""}) - self:backEnd(score, reward) + self:backEnd(success, score, scoreInfo, reward) end function Adv:exit() @@ -531,6 +535,10 @@ end function Adv:initByChapter(chapterId, level, notNotify) level = level or 1 randomAdvMap(self.owner, chapterId, level, notNotify) + if not next(self.advInfo) then return end + if level > 1 then + self:scoreChange(AdvScoreType.Level) + end self:initByInfo() --初始化 self.owner:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam}, notNotify) end @@ -645,6 +653,9 @@ function Adv:award(gift, params) end local items = self.owner:getProperty("advItems") for itemId, count in pairs(tgift) do + if count > 0 then + self:scoreChange(AdvScoreType.Item, {itemId, count}) + end local origin = items:getv(itemId, 0) local nums = origin + count if nums <= 0 then @@ -947,12 +958,14 @@ function Adv:enemyDead(roomId, blockId, escape) if escape then room:clearBEvent(block) else + local monsterData = csvdb["event_monsterCsv"][block.event.id] + self:scoreChange(AdvScoreType.Kill, monsterData.type) + local item = block.event.item if not item then if block.event.etype == AdvEventType.BOSS then item = {ItemId.AdvKey, 1} else - local monsterData = csvdb["event_monsterCsv"][block.event.id] local dropData = csvdb["event_dropCsv"][monsterData.dropid] item = dropData["range"]:randWeight(true) end @@ -1010,8 +1023,8 @@ function Adv:backNext() self:pushBackEvent(AdvBackEventType.Next, {}) end -function Adv:backEnd(score, reward) - self:pushBackEvent(AdvBackEventType.End, {score = score, reward = reward}) +function Adv:backEnd(success, score, scoreInfo, reward) + self:pushBackEvent(AdvBackEventType.End, {success = success, score = score, scoreInfo = scoreInfo, reward = reward}) end function Adv:backBlockChange(roomId, blockId) @@ -1027,6 +1040,43 @@ function Adv:backDead(enemyId) end +function Adv:scoreChange(scoreType, pms) + local cutTypes = {} + local score = 0 + cutTypes[AdvScoreType.Level] = function() + score = globalCsv.adv_score_floor + end + cutTypes[AdvScoreType.Kill] = function() + local chapterData = csvdb["adv_chapterCsv"][self.advInfo.chapter] + score = globalCsv.adv_score_monster[pms] * chapterData["monRatio"] + end + cutTypes[AdvScoreType.Item] = function() + score = csvdb["itemCsv"][pms[1]].adv_score_item * pms[2] + end + cutTypes[AdvScoreType.Hurt] = function() + score = globalCsv.adv_score_hurt * pms + end + cutTypes[AdvScoreType.Block] = function() + score = globalCsv.adv_score_block + end + if cutTypes[scoreType] then + cutTypes[scoreType]() + else + return + end + self.advInfo.score[scoreType] = self.advInfo.score[scoreType] or 0 + self.advInfo.score[scoreType] = self.advInfo.score[scoreType] + score +end + +function Adv:getScore() + return math.floor(math.max( + (self.advInfo.score[AdvScoreType.Level] or 0) + + (self.advInfo.score[AdvScoreType.Block] or 0) + + (self.advInfo.score[AdvScoreType.Hurt] or 0), + 0) + (self.advInfo.score[AdvScoreType.Kill] or 0) + + (self.advInfo.score[AdvScoreType.Item] or 0)) +end + function Adv:popBackEvents() local events = self.backEvents self.backEvents = {} diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index ef34173..667f57b 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -230,6 +230,11 @@ function BaseObject:hurt(value, releaser, params) --受伤了~ self.battle.adv:backHpChange(self.id, -value) self.hp = math.max(0, self.hp - value) + + if self.cutHp then + self:cutHp(value) + end + if self.hp == 0 then self:triggerPassive(Passive.SELF_DEAD) for _, team in ipairs(self:getTeam(1, true)) do @@ -432,4 +437,8 @@ function Player:ctor(battle, data) self:initData(data) end +function Player:cutHp(value) + self.battle.adv:scoreChange(AdvScoreType.Hurt, value) +end + return table.pack(Player, Enemy) \ No newline at end of file -- libgit2 0.21.2