diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index f6cdc65..4bafebb 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -224,6 +224,7 @@ AdvBackEventType = { LinkChooseOver = 26, -- 连锁事件结束 BuffEffect = 27, -- buff 效果 PassiveEffect = 28, -- 被动 效果 + ChooseDice = 29, -- 选择点随机效果 } AdvScoreType = { diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 048613d..abdd8c3 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -1286,24 +1286,22 @@ local function clickMonster(self, room, block, params) return true end -local function chooseCommon(self, room, block, chooseData, choose, tag) - if not choose then return end - if not chooseData or not chooseData["button".. choose .."cond"] then return end - local conds = chooseData["button".. choose .."cond"]:toTableArray(true) +local function checkChooseCondFunc(self, condStr, room, block, tag, chooseData) + chooseData = chooseData or {} local checkCond = { -- 没有条件 [0] = function() return true end, -- 拥有道具 - [1] = function(_, itemId, count) + [1] = function(itemId, count) if self:cost({[itemId] = count}, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, true) then return true end end, -- xx角色(todo 队长) - [2] = function(_, heroType) + [2] = function(heroType) for slot, heroId in pairs(self.owner:getProperty("advTeam").heros) do local hero = self.owner.heros[heroId] if hero and hero:getProperty("type") == heroType then @@ -1323,38 +1321,38 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) return true end, --制定属性 - [4] = function(_, attrType, value) + [4] = function(attrType, value) if (self.battle.player[AttsEnumEx[attrType]] or 0) >= value then return true end end, -- 提交一个物品 - [5] = function (_, itemId, count) + [5] = function (itemId, count) if self:cost({[itemId] = count}, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}) then self:backCost({[itemId] = count}) return true end end, -- sp 到达指定值 - [6] = function(_, value) + [6] = function(value) if self.battle.player.sp >= value then self.battle.player:changeSp(-value) return true end end, --7=拥有指定buff指定层数 - [7] = function(_, buffId, layer) + [7] = function(buffId, layer) local buff = self.battle.player:getBuffById(buffId) if buff and buff:getLayer() >= layer then return true end end, --8=拥有x神器 - [8] = function(_, artifactId) + [8] = function(artifactId) return self:isHaveArtifact(artifactId) end, -- 9 = 生命值大于x% - [9] = function (_, value) + [9] = function (value) local cost = value / 100 * self.battle.player.hpMax if self.battle.player.hp > cost then self.battle.player:hurt(cost, nil, {hurtType = 6, buffId = -1}) @@ -1362,11 +1360,11 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) end end, -- 10 = 未获得x神器 - [10] = function(_, artifactId) + [10] = function(artifactId) return not self:isHaveArtifact(artifactId) end, -- 11 = 地图上没有指定id 的怪 - [11] = function(_, monsterId, size) + [11] = function(monsterId, size) if not size or size == 0 then for _, room in pairs(self:getCurMap().rooms) do for _, block in pairs(room.blocks) do @@ -1391,7 +1389,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) return true end, -- 12 = 地图上没有指定id 的建筑 - [12] = function(_, buildId, size) + [12] = function(buildId, size) if not size or size == 0 then for _, room in pairs(self:getCurMap().rooms) do for _, block in pairs(room.blocks) do @@ -1416,7 +1414,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) return true end, -- 13 = 地图上没有指定的 选择点 - [13] = function(_, chooseId, size) + [13] = function(chooseId, size) if not size or size == 0 then for _, room in pairs(self:getCurMap().rooms) do for _, block in pairs(room.blocks) do @@ -1441,138 +1439,175 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) return true end, } - for _, cond in ipairs(conds) do + + local status, count = true, 0 + for _, cond in ipairs(condStr:toTableArray(true)) do assert(not cond[1] or checkCond[cond[1]], "error cond, event_" .. (tag or "choose") .. "Csv id :" .. block.event.id) - if cond[1] and not checkCond[cond[1]](table.unpack(cond)) then return end + if not checkCond[cond[1]](select(2, table.unpack(cond))) then + status = false + else + count = count + 1 + end end - - local clearBlock = chooseData.keep ~= 1 - local effects = chooseData["button".. choose .."effect"]:toTableArray(true) - for _, effect in ipairs(effects) do - local doEffect = { - [1] = function() -- 获得某道具N个 - local count = effect[3] or 1 - local reward = {} - for i = 1, count do - local dropData = csvdb["event_dropCsv"][effect[2]] - if dropData then - local item = dropData["range"]:randWeight(true) - reward[item[1]] = (reward[item[1]] or 0) + item[2] - else - skynet.error(string.format("[ERROR]: event_dropCsv no id %s in %s id: %s", effect[2], tag, chooseData.id)) - end - end - self:award(reward, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, {roomId = room.roomId, blockId = block.blockId}) - end, - [2] = function() --获得冒险buff - local layer = effect[3] or 1 - for i = 1, layer do - self.battle.player:addBuff(effect[2]) - end - end, - [3] = function() --发现怪物 - self:getCurMap():addNewMonsterRand(effect[2], {room, block}) - self:pushBackEvent(AdvBackEventType.Monster, {id = effect[2]}) - clearBlock = false - end, - [4] = function() --无事发生 - end, - [5] = function() --5=属性枚举=数值;直接增加玩家属性 - local attr - if effect[3] == 0 then - attr = "sp" + return status, count +end + +local function doChooseEffect(self, effectStr, room, block, tag, chooseData) + chooseData = chooseData or {} + local clearBlock = true + local doEffect = { + [1] = function(dropId, count) -- 获得某道具N个 + count = count or 1 + local reward = {} + for i = 1, count do + local dropData = csvdb["event_dropCsv"][dropId] + if dropData then + local item = dropData["range"]:randWeight(true) + reward[item[1]] = (reward[item[1]] or 0) + item[2] else - attr = AttsEnumEx[effect[3]] - if not AdvAttsEnum[attr] then return end + skynet.error(string.format("[ERROR]: event_dropCsv no id %s in %s id: %s", dropId, tag, chooseData.id)) end - self.battle.player:addBaseAttr(attr, effect[4], effect[2]) - end, - [6] = function() -- 商店 - block:updateEvent({ - etype = AdvEventType.Trader, - id = effect[2] - }) - self:pushBackEvent(AdvBackEventType.Trader, {id = effect[2]}) - clearBlock = false - end, - [7] = function() -- 建筑 - block:updateEvent({ - etype = AdvEventType.Build, - id = effect[2] - }) - clearBlock = false - end, - [8] = function() -- 选择 - block:updateEvent({ - etype = AdvEventType.Choose, - id = effect[2] - }) - clearBlock = false - end, - [9] = function() -- click - block:updateEvent({ - etype = AdvEventType.Click, - id = effect[2] - }) - clearBlock = false - end, - [10] = function() -- 陷阱 - block:updateEvent({ - etype = AdvEventType.Trap, - id = effect[2] - }) - clearBlock = false - end, - [11] = function() -- 获得神器 - self:waitChooseArtifact() --等待获取神器 - end, - [12] = function() - -- buffId - local targers = self.battle.player:getTeam(2, nil, nil, true) - for _, target in pairs(targers) do - target:addBuff(effect[2]) + end + self:award(reward, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, {roomId = room.roomId, blockId = block.blockId}) + end, + [2] = function(buffId, layer) --获得冒险buff + self.battle.player:addBuff(buffId, nil, layer or 1) + end, + [3] = function(id) --发现怪物 + self:getCurMap():addNewMonsterRand(id, {room, block}) + self:pushBackEvent(AdvBackEventType.Monster, {id = id}) + clearBlock = false + end, + [4] = function() --无事发生 + end, + [5] = function(addType, attrType, value) --5=属性枚举=数值;直接增加玩家属性 + local attr + if attrType == 0 then + attr = "sp" + else + attr = AttsEnumEx[attrType] + if not AdvAttsEnum[attr] then return end + end + self.battle.player:addBaseAttr(attr, value, addType) + end, + [6] = function(id) -- 商店 + block:updateEvent({ + etype = AdvEventType.Trader, + id = id + }) + self:pushBackEvent(AdvBackEventType.Trader, {id = id}) + clearBlock = false + end, + [7] = function(id) -- 建筑 + block:updateEvent({ + etype = AdvEventType.Build, + id = id + }) + clearBlock = false + end, + [8] = function(id) -- 选择 + block:updateEvent({ + etype = AdvEventType.Choose, + id = id + }) + clearBlock = false + end, + [9] = function(id) -- click + block:updateEvent({ + etype = AdvEventType.Click, + id = id + }) + clearBlock = false + end, + [10] = function(id) -- 陷阱 + block:updateEvent({ + etype = AdvEventType.Trap, + id = id + }) + clearBlock = false + end, + [11] = function() -- 获得神器 + self:waitChooseArtifact() --等待获取神器 + end, + [12] = function(id) + -- buffId + local targers = self.battle.player:getTeam(2, nil, nil, true) + for _, target in pairs(targers) do + target:addBuff(id) + end + end, + [13] = function() -- 显示地图 + self:getCurMap():showMap() + self:backMapShow() + end, + [14] = function(eventType, eventId, count, stage) -- 指定地块召唤 指定类型的id + local change = self:getCurMap():layEventToStage(eventType, eventId, count, stage) + for _, one in ipairs(change) do + if one[1].roomId == room.roomId and one[2].blockId == block.blockId then + clearBlock = false + else + self:backBlockChange(one[1].roomId, one[2].blockId) end - end, - [13] = function() -- 显示地图 - self:getCurMap():showMap() - self:backMapShow() - end, - [14] = function() -- 指定地块召唤 指定类型的id - local change = self:getCurMap():layEventToStage(effect[2], effect[3], effect[4], effect[5]) - for _, one in ipairs(change) do - if one[1].roomId == room.roomId and one[2].blockId == block.blockId then - clearBlock = false - else - self:backBlockChange(one[1].roomId, one[2].blockId) - end + end + end, + [15] = function(eventType, eventId, count) -- 移除指定事件 + local change = self:getCurMap():clearEventById(eventType, eventId, count) + for _, one in ipairs(change) do + if one[1].roomId == room.roomId and one[2].blockId == block.blockId then + clearBlock = false + else + self:backBlockChange(one[1].roomId, one[2].blockId) end - end, - [15] = function() -- 移除指定事件 - local change = self:getCurMap():clearEventById(effect[2], effect[3], effect[4]) - for _, one in ipairs(change) do - if one[1].roomId == room.roomId and one[2].blockId == block.blockId then - clearBlock = false - else - self:backBlockChange(one[1].roomId, one[2].blockId) - end + end + end, + [16] = function(eventTypeF, eventIdF, eventTypeT, eventIdT, count) -- 指定事件转移 + local change = self:getCurMap():eventChangeToOther(eventTypeF, eventIdF, eventTypeT, eventIdT, count) + for _, one in ipairs(change) do + if one[1].roomId == room.roomId and one[2].blockId == block.blockId then + clearBlock = false + else + self:backBlockChange(one[1].roomId, one[2].blockId) end - end, - [16] = function() -- 指定事件转移 - local change = self:getCurMap():eventChangeToOther(effect[2], effect[3], effect[4], effect[5], effect[6]) - for _, one in ipairs(change) do - if one[1].roomId == room.roomId and one[2].blockId == block.blockId then - clearBlock = false - else - self:backBlockChange(one[1].roomId, one[2].blockId) - end + end + end, + [17] = function(eventId) + local diceCsv = csvdb["event_choose_diceCsv"][eventId] + if not diceCsv then return end + local weight = math.randomInt(1, 12) + local sum = 0 + local needEffect = nil + local pool = {} + for _, v in ipairs(diceCsv) do + local status, okCount = checkChooseCondFunc(self, v.cond, room, block, tag .. " dice", chooseData) + pool[#pool + 1] = v.weight + okCount * v.weightUp + sum = sum + pool[#pool + 1] + if sum >= weight and not needEffect then + -- 达成效果 + needEffect = v.effect end - end, - } + end + if needEffect then + self:pushBackEvent(AdvBackEventType.ChooseDice, {id = eventId, pool = pool, result = weight}) + clearBlock = doChooseEffect(self, needEffect, room, block, tag .. " dice", chooseData) + end + end, + } + + for _, effect in ipairs(effectStr:toTableArray(true)) do assert(doEffect[effect[1]], "error effect, event_" .. (tag or "choose") .. "Csv id :" .. (block.event and block.event.id or 0) .. "effect " .. effect[1]) - doEffect[effect[1]]() + doEffect[effect[1]](select(2, table.unpack(effect))) end - self:scoreChange(AdvScoreType.Event, chooseData.advScore) --增加加分 + return clearBlock +end + +local function chooseCommon(self, room, block, chooseData, choose, tag) + if not choose then return end + if not chooseData or not chooseData["button".. choose .."cond"] then return end + if not checkChooseCondFunc(self, chooseData["button".. choose .."cond"], room, block, tag, chooseData) then return end + local clearBlock = chooseData.keep ~= 1 + clearBlock = clearBlock and doChooseEffect(self, chooseData["button".. choose .."effect"], room, block, tag, chooseData) + self:scoreChange(AdvScoreType.Event, chooseData.advScore) --增加加分 return true, clearBlock end -- libgit2 0.21.2