Commit b0fe18174e4bb2b89ae0668e044b9cb8d41ca952

Authored by zhouahaihai
1 parent bedca62d

冒险分数

src/GlobalVar.lua
... ... @@ -99,4 +99,12 @@ AdvBackEventType = {
99 99 BlockChange = 9, -- 块改变
100 100 PowerChange = 10, --体力改变
101 101 Dead = 11, --怪死亡
  102 +}
  103 +
  104 +AdvScoreType = {
  105 + Level = 1,
  106 + Kill = 2,
  107 + Item = 3,
  108 + Hurt = 4,
  109 + Block = 5,
102 110 }
103 111 \ No newline at end of file
... ...
src/adv/Adv.lua
... ... @@ -104,9 +104,12 @@ local function randomAdvMap(role, chapterId, level, notNotify)
104 104 --随出地图
105 105 local raw_pool = chapterData.mapid:toArray(true, "=")
106 106 local advInfo = role:getProperty("advInfo")
  107 +
107 108 local lastMapId = advInfo.mapId --非同一层不连续随出同一张类似的地图
108 109 local lastChapterId = advInfo.chapter
  110 + local lastScore = advInfo.score or {} -- 分数
109 111 local power = advInfo.power or 100 --体力
  112 +
110 113 local pool = {}
111 114 for _, mapId in ipairs(raw_pool) do
112 115 local temp = csvdb["mapCsv"][mapId]
... ... @@ -128,12 +131,12 @@ local function randomAdvMap(role, chapterId, level, notNotify)
128 131 return
129 132 end
130 133  
131   -
132 134 table.clear(advInfo)
133 135 advInfo.chapter = chapterId
134 136 advInfo.level = level
135 137 advInfo.mapId = mapId
136 138 advInfo.power = power
  139 + advInfo.score = lastScore
137 140 advInfo.enemyId = 1 --怪递增的索引
138 141 advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁
139 142 --事件随机
... ... @@ -425,6 +428,8 @@ function Room:openBlock(block, adv)
425 428 self.info.open[block.blockId] = 1
426 429 end
427 430  
  431 + adv:scoreChange(AdvScoreType.Block)
  432 +
428 433 if not self.isShow then
429 434 self.isShow = true
430 435 --首次展示房间
... ... @@ -459,11 +464,10 @@ end
459 464  
460 465 --关卡通关,非层 score < 0 失败
461 466 function Adv:over(success)
462   - local score = -1
  467 + local score = self:getScore()
  468 + local scoreInfo = self.advInfo.score
463 469 local reward
464 470 if success then
465   - -- todo success 计算分数
466   - score = 1
467 471 self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.advInfo.chapter, score)})
468 472 reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap(), {})
469 473 end
... ... @@ -473,7 +477,7 @@ function Adv:over(success)
473 477  
474 478 self.owner:updateProperty({field = "advItems", value = ""})
475 479  
476   - self:backEnd(score, reward)
  480 + self:backEnd(success, score, scoreInfo, reward)
477 481 end
478 482  
479 483 function Adv:exit()
... ... @@ -531,6 +535,10 @@ end
531 535 function Adv:initByChapter(chapterId, level, notNotify)
532 536 level = level or 1
533 537 randomAdvMap(self.owner, chapterId, level, notNotify)
  538 + if not next(self.advInfo) then return end
  539 + if level > 1 then
  540 + self:scoreChange(AdvScoreType.Level)
  541 + end
534 542 self:initByInfo() --初始化
535 543 self.owner:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam}, notNotify)
536 544 end
... ... @@ -645,6 +653,9 @@ function Adv:award(gift, params)
645 653 end
646 654 local items = self.owner:getProperty("advItems")
647 655 for itemId, count in pairs(tgift) do
  656 + if count > 0 then
  657 + self:scoreChange(AdvScoreType.Item, {itemId, count})
  658 + end
648 659 local origin = items:getv(itemId, 0)
649 660 local nums = origin + count
650 661 if nums <= 0 then
... ... @@ -947,12 +958,14 @@ function Adv:enemyDead(roomId, blockId, escape)
947 958 if escape then
948 959 room:clearBEvent(block)
949 960 else
  961 + local monsterData = csvdb["event_monsterCsv"][block.event.id]
  962 + self:scoreChange(AdvScoreType.Kill, monsterData.type)
  963 +
950 964 local item = block.event.item
951 965 if not item then
952 966 if block.event.etype == AdvEventType.BOSS then
953 967 item = {ItemId.AdvKey, 1}
954 968 else
955   - local monsterData = csvdb["event_monsterCsv"][block.event.id]
956 969 local dropData = csvdb["event_dropCsv"][monsterData.dropid]
957 970 item = dropData["range"]:randWeight(true)
958 971 end
... ... @@ -1010,8 +1023,8 @@ function Adv:backNext()
1010 1023 self:pushBackEvent(AdvBackEventType.Next, {})
1011 1024 end
1012 1025  
1013   -function Adv:backEnd(score, reward)
1014   - self:pushBackEvent(AdvBackEventType.End, {score = score, reward = reward})
  1026 +function Adv:backEnd(success, score, scoreInfo, reward)
  1027 + self:pushBackEvent(AdvBackEventType.End, {success = success, score = score, scoreInfo = scoreInfo, reward = reward})
1015 1028 end
1016 1029  
1017 1030 function Adv:backBlockChange(roomId, blockId)
... ... @@ -1027,6 +1040,43 @@ function Adv:backDead(enemyId)
1027 1040 end
1028 1041  
1029 1042  
  1043 +function Adv:scoreChange(scoreType, pms)
  1044 + local cutTypes = {}
  1045 + local score = 0
  1046 + cutTypes[AdvScoreType.Level] = function()
  1047 + score = globalCsv.adv_score_floor
  1048 + end
  1049 + cutTypes[AdvScoreType.Kill] = function()
  1050 + local chapterData = csvdb["adv_chapterCsv"][self.advInfo.chapter]
  1051 + score = globalCsv.adv_score_monster[pms] * chapterData["monRatio"]
  1052 + end
  1053 + cutTypes[AdvScoreType.Item] = function()
  1054 + score = csvdb["itemCsv"][pms[1]].adv_score_item * pms[2]
  1055 + end
  1056 + cutTypes[AdvScoreType.Hurt] = function()
  1057 + score = globalCsv.adv_score_hurt * pms
  1058 + end
  1059 + cutTypes[AdvScoreType.Block] = function()
  1060 + score = globalCsv.adv_score_block
  1061 + end
  1062 + if cutTypes[scoreType] then
  1063 + cutTypes[scoreType]()
  1064 + else
  1065 + return
  1066 + end
  1067 + self.advInfo.score[scoreType] = self.advInfo.score[scoreType] or 0
  1068 + self.advInfo.score[scoreType] = self.advInfo.score[scoreType] + score
  1069 +end
  1070 +
  1071 +function Adv:getScore()
  1072 + return math.floor(math.max(
  1073 + (self.advInfo.score[AdvScoreType.Level] or 0) +
  1074 + (self.advInfo.score[AdvScoreType.Block] or 0) +
  1075 + (self.advInfo.score[AdvScoreType.Hurt] or 0),
  1076 + 0) + (self.advInfo.score[AdvScoreType.Kill] or 0) +
  1077 + (self.advInfo.score[AdvScoreType.Item] or 0))
  1078 +end
  1079 +
1030 1080 function Adv:popBackEvents()
1031 1081 local events = self.backEvents
1032 1082 self.backEvents = {}
... ...
src/adv/AdvPlayer.lua
... ... @@ -230,6 +230,11 @@ function BaseObject:hurt(value, releaser, params)
230 230 --受伤了~
231 231 self.battle.adv:backHpChange(self.id, -value)
232 232 self.hp = math.max(0, self.hp - value)
  233 +
  234 + if self.cutHp then
  235 + self:cutHp(value)
  236 + end
  237 +
233 238 if self.hp == 0 then
234 239 self:triggerPassive(Passive.SELF_DEAD)
235 240 for _, team in ipairs(self:getTeam(1, true)) do
... ... @@ -432,4 +437,8 @@ function Player:ctor(battle, data)
432 437 self:initData(data)
433 438 end
434 439  
  440 +function Player:cutHp(value)
  441 + self.battle.adv:scoreChange(AdvScoreType.Hurt, value)
  442 +end
  443 +
435 444 return table.pack(Player, Enemy)
436 445 \ No newline at end of file
... ...