Commit 219e9654096977e48b01d4efb6f2710dc3e107c7

Authored by zhouhaihai
1 parent cc9f29c5

拾荒增加选择类型

Showing 2 changed files with 173 additions and 137 deletions   Show diff stats
@@ -224,6 +224,7 @@ AdvBackEventType = { @@ -224,6 +224,7 @@ AdvBackEventType = {
224 LinkChooseOver = 26, -- 连锁事件结束 224 LinkChooseOver = 26, -- 连锁事件结束
225 BuffEffect = 27, -- buff 效果 225 BuffEffect = 27, -- buff 效果
226 PassiveEffect = 28, -- 被动 效果 226 PassiveEffect = 28, -- 被动 效果
  227 + ChooseDice = 29, -- 选择点随机效果
227 } 228 }
228 229
229 AdvScoreType = { 230 AdvScoreType = {
@@ -1286,24 +1286,22 @@ local function clickMonster(self, room, block, params) @@ -1286,24 +1286,22 @@ local function clickMonster(self, room, block, params)
1286 return true 1286 return true
1287 end 1287 end
1288 1288
1289 -local function chooseCommon(self, room, block, chooseData, choose, tag)  
1290 - if not choose then return end  
1291 - if not chooseData or not chooseData["button".. choose .."cond"] then return end  
1292 1289
1293 - local conds = chooseData["button".. choose .."cond"]:toTableArray(true) 1290 +local function checkChooseCondFunc(self, condStr, room, block, tag, chooseData)
  1291 + chooseData = chooseData or {}
1294 local checkCond = { 1292 local checkCond = {
1295 -- 没有条件 1293 -- 没有条件
1296 [0] = function() 1294 [0] = function()
1297 return true 1295 return true
1298 end, 1296 end,
1299 -- 拥有道具 1297 -- 拥有道具
1300 - [1] = function(_, itemId, count) 1298 + [1] = function(itemId, count)
1301 if self:cost({[itemId] = count}, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, true) then 1299 if self:cost({[itemId] = count}, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, true) then
1302 return true 1300 return true
1303 end 1301 end
1304 end, 1302 end,
1305 -- xx角色(todo 队长) 1303 -- xx角色(todo 队长)
1306 - [2] = function(_, heroType) 1304 + [2] = function(heroType)
1307 for slot, heroId in pairs(self.owner:getProperty("advTeam").heros) do 1305 for slot, heroId in pairs(self.owner:getProperty("advTeam").heros) do
1308 local hero = self.owner.heros[heroId] 1306 local hero = self.owner.heros[heroId]
1309 if hero and hero:getProperty("type") == heroType then 1307 if hero and hero:getProperty("type") == heroType then
@@ -1323,38 +1321,38 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1323,38 +1321,38 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1323 return true 1321 return true
1324 end, 1322 end,
1325 --制定属性 1323 --制定属性
1326 - [4] = function(_, attrType, value) 1324 + [4] = function(attrType, value)
1327 if (self.battle.player[AttsEnumEx[attrType]] or 0) >= value then 1325 if (self.battle.player[AttsEnumEx[attrType]] or 0) >= value then
1328 return true 1326 return true
1329 end 1327 end
1330 end, 1328 end,
1331 -- 提交一个物品 1329 -- 提交一个物品
1332 - [5] = function (_, itemId, count) 1330 + [5] = function (itemId, count)
1333 if self:cost({[itemId] = count}, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}) then 1331 if self:cost({[itemId] = count}, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}) then
1334 self:backCost({[itemId] = count}) 1332 self:backCost({[itemId] = count})
1335 return true 1333 return true
1336 end 1334 end
1337 end, 1335 end,
1338 -- sp 到达指定值 1336 -- sp 到达指定值
1339 - [6] = function(_, value) 1337 + [6] = function(value)
1340 if self.battle.player.sp >= value then 1338 if self.battle.player.sp >= value then
1341 self.battle.player:changeSp(-value) 1339 self.battle.player:changeSp(-value)
1342 return true 1340 return true
1343 end 1341 end
1344 end, 1342 end,
1345 --7=拥有指定buff指定层数 1343 --7=拥有指定buff指定层数
1346 - [7] = function(_, buffId, layer) 1344 + [7] = function(buffId, layer)
1347 local buff = self.battle.player:getBuffById(buffId) 1345 local buff = self.battle.player:getBuffById(buffId)
1348 if buff and buff:getLayer() >= layer then 1346 if buff and buff:getLayer() >= layer then
1349 return true 1347 return true
1350 end 1348 end
1351 end, 1349 end,
1352 --8=拥有x神器 1350 --8=拥有x神器
1353 - [8] = function(_, artifactId) 1351 + [8] = function(artifactId)
1354 return self:isHaveArtifact(artifactId) 1352 return self:isHaveArtifact(artifactId)
1355 end, 1353 end,
1356 -- 9 = 生命值大于x% 1354 -- 9 = 生命值大于x%
1357 - [9] = function (_, value) 1355 + [9] = function (value)
1358 local cost = value / 100 * self.battle.player.hpMax 1356 local cost = value / 100 * self.battle.player.hpMax
1359 if self.battle.player.hp > cost then 1357 if self.battle.player.hp > cost then
1360 self.battle.player:hurt(cost, nil, {hurtType = 6, buffId = -1}) 1358 self.battle.player:hurt(cost, nil, {hurtType = 6, buffId = -1})
@@ -1362,11 +1360,11 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1362,11 +1360,11 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1362 end 1360 end
1363 end, 1361 end,
1364 -- 10 = 未获得x神器 1362 -- 10 = 未获得x神器
1365 - [10] = function(_, artifactId) 1363 + [10] = function(artifactId)
1366 return not self:isHaveArtifact(artifactId) 1364 return not self:isHaveArtifact(artifactId)
1367 end, 1365 end,
1368 -- 11 = 地图上没有指定id 的怪 1366 -- 11 = 地图上没有指定id 的怪
1369 - [11] = function(_, monsterId, size) 1367 + [11] = function(monsterId, size)
1370 if not size or size == 0 then 1368 if not size or size == 0 then
1371 for _, room in pairs(self:getCurMap().rooms) do 1369 for _, room in pairs(self:getCurMap().rooms) do
1372 for _, block in pairs(room.blocks) do 1370 for _, block in pairs(room.blocks) do
@@ -1391,7 +1389,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1391,7 +1389,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1391 return true 1389 return true
1392 end, 1390 end,
1393 -- 12 = 地图上没有指定id 的建筑 1391 -- 12 = 地图上没有指定id 的建筑
1394 - [12] = function(_, buildId, size) 1392 + [12] = function(buildId, size)
1395 if not size or size == 0 then 1393 if not size or size == 0 then
1396 for _, room in pairs(self:getCurMap().rooms) do 1394 for _, room in pairs(self:getCurMap().rooms) do
1397 for _, block in pairs(room.blocks) do 1395 for _, block in pairs(room.blocks) do
@@ -1416,7 +1414,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1416,7 +1414,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1416 return true 1414 return true
1417 end, 1415 end,
1418 -- 13 = 地图上没有指定的 选择点 1416 -- 13 = 地图上没有指定的 选择点
1419 - [13] = function(_, chooseId, size) 1417 + [13] = function(chooseId, size)
1420 if not size or size == 0 then 1418 if not size or size == 0 then
1421 for _, room in pairs(self:getCurMap().rooms) do 1419 for _, room in pairs(self:getCurMap().rooms) do
1422 for _, block in pairs(room.blocks) do 1420 for _, block in pairs(room.blocks) do
@@ -1441,138 +1439,175 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1441,138 +1439,175 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1441 return true 1439 return true
1442 end, 1440 end,
1443 } 1441 }
1444 - for _, cond in ipairs(conds) do 1442 +
  1443 + local status, count = true, 0
  1444 + for _, cond in ipairs(condStr:toTableArray(true)) do
1445 assert(not cond[1] or checkCond[cond[1]], "error cond, event_" .. (tag or "choose") .. "Csv id :" .. block.event.id) 1445 assert(not cond[1] or checkCond[cond[1]], "error cond, event_" .. (tag or "choose") .. "Csv id :" .. block.event.id)
1446 - if cond[1] and not checkCond[cond[1]](table.unpack(cond)) then return end 1446 + if not checkCond[cond[1]](select(2, table.unpack(cond))) then
  1447 + status = false
  1448 + else
  1449 + count = count + 1
  1450 + end
1447 end 1451 end
1448 -  
1449 - local clearBlock = chooseData.keep ~= 1  
1450 - local effects = chooseData["button".. choose .."effect"]:toTableArray(true)  
1451 - for _, effect in ipairs(effects) do  
1452 - local doEffect = {  
1453 - [1] = function() -- 获得某道具N个  
1454 - local count = effect[3] or 1  
1455 - local reward = {}  
1456 - for i = 1, count do  
1457 - local dropData = csvdb["event_dropCsv"][effect[2]]  
1458 - if dropData then  
1459 - local item = dropData["range"]:randWeight(true)  
1460 - reward[item[1]] = (reward[item[1]] or 0) + item[2]  
1461 - else  
1462 - skynet.error(string.format("[ERROR]: event_dropCsv no id %s in %s id: %s", effect[2], tag, chooseData.id))  
1463 - end  
1464 - end  
1465 - self:award(reward, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, {roomId = room.roomId, blockId = block.blockId})  
1466 - end,  
1467 - [2] = function() --获得冒险buff  
1468 - local layer = effect[3] or 1  
1469 - for i = 1, layer do  
1470 - self.battle.player:addBuff(effect[2])  
1471 - end  
1472 - end,  
1473 - [3] = function() --发现怪物  
1474 - self:getCurMap():addNewMonsterRand(effect[2], {room, block})  
1475 - self:pushBackEvent(AdvBackEventType.Monster, {id = effect[2]})  
1476 - clearBlock = false  
1477 - end,  
1478 - [4] = function() --无事发生  
1479 - end,  
1480 - [5] = function() --5=属性枚举=数值;直接增加玩家属性  
1481 - local attr  
1482 - if effect[3] == 0 then  
1483 - attr = "sp" 1452 + return status, count
  1453 +end
  1454 +
  1455 +local function doChooseEffect(self, effectStr, room, block, tag, chooseData)
  1456 + chooseData = chooseData or {}
  1457 + local clearBlock = true
  1458 + local doEffect = {
  1459 + [1] = function(dropId, count) -- 获得某道具N个
  1460 + count = count or 1
  1461 + local reward = {}
  1462 + for i = 1, count do
  1463 + local dropData = csvdb["event_dropCsv"][dropId]
  1464 + if dropData then
  1465 + local item = dropData["range"]:randWeight(true)
  1466 + reward[item[1]] = (reward[item[1]] or 0) + item[2]
1484 else 1467 else
1485 - attr = AttsEnumEx[effect[3]]  
1486 - if not AdvAttsEnum[attr] then return end 1468 + skynet.error(string.format("[ERROR]: event_dropCsv no id %s in %s id: %s", dropId, tag, chooseData.id))
1487 end 1469 end
1488 - self.battle.player:addBaseAttr(attr, effect[4], effect[2])  
1489 - end,  
1490 - [6] = function() -- 商店  
1491 - block:updateEvent({  
1492 - etype = AdvEventType.Trader,  
1493 - id = effect[2]  
1494 - })  
1495 - self:pushBackEvent(AdvBackEventType.Trader, {id = effect[2]})  
1496 - clearBlock = false  
1497 - end,  
1498 - [7] = function() -- 建筑  
1499 - block:updateEvent({  
1500 - etype = AdvEventType.Build,  
1501 - id = effect[2]  
1502 - })  
1503 - clearBlock = false  
1504 - end,  
1505 - [8] = function() -- 选择  
1506 - block:updateEvent({  
1507 - etype = AdvEventType.Choose,  
1508 - id = effect[2]  
1509 - })  
1510 - clearBlock = false  
1511 - end,  
1512 - [9] = function() -- click  
1513 - block:updateEvent({  
1514 - etype = AdvEventType.Click,  
1515 - id = effect[2]  
1516 - })  
1517 - clearBlock = false  
1518 - end,  
1519 - [10] = function() -- 陷阱  
1520 - block:updateEvent({  
1521 - etype = AdvEventType.Trap,  
1522 - id = effect[2]  
1523 - })  
1524 - clearBlock = false  
1525 - end,  
1526 - [11] = function() -- 获得神器  
1527 - self:waitChooseArtifact() --等待获取神器  
1528 - end,  
1529 - [12] = function()  
1530 - -- buffId  
1531 - local targers = self.battle.player:getTeam(2, nil, nil, true)  
1532 - for _, target in pairs(targers) do  
1533 - target:addBuff(effect[2]) 1470 + end
  1471 + self:award(reward, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, {roomId = room.roomId, blockId = block.blockId})
  1472 + end,
  1473 + [2] = function(buffId, layer) --获得冒险buff
  1474 + self.battle.player:addBuff(buffId, nil, layer or 1)
  1475 + end,
  1476 + [3] = function(id) --发现怪物
  1477 + self:getCurMap():addNewMonsterRand(id, {room, block})
  1478 + self:pushBackEvent(AdvBackEventType.Monster, {id = id})
  1479 + clearBlock = false
  1480 + end,
  1481 + [4] = function() --无事发生
  1482 + end,
  1483 + [5] = function(addType, attrType, value) --5=属性枚举=数值;直接增加玩家属性
  1484 + local attr
  1485 + if attrType == 0 then
  1486 + attr = "sp"
  1487 + else
  1488 + attr = AttsEnumEx[attrType]
  1489 + if not AdvAttsEnum[attr] then return end
  1490 + end
  1491 + self.battle.player:addBaseAttr(attr, value, addType)
  1492 + end,
  1493 + [6] = function(id) -- 商店
  1494 + block:updateEvent({
  1495 + etype = AdvEventType.Trader,
  1496 + id = id
  1497 + })
  1498 + self:pushBackEvent(AdvBackEventType.Trader, {id = id})
  1499 + clearBlock = false
  1500 + end,
  1501 + [7] = function(id) -- 建筑
  1502 + block:updateEvent({
  1503 + etype = AdvEventType.Build,
  1504 + id = id
  1505 + })
  1506 + clearBlock = false
  1507 + end,
  1508 + [8] = function(id) -- 选择
  1509 + block:updateEvent({
  1510 + etype = AdvEventType.Choose,
  1511 + id = id
  1512 + })
  1513 + clearBlock = false
  1514 + end,
  1515 + [9] = function(id) -- click
  1516 + block:updateEvent({
  1517 + etype = AdvEventType.Click,
  1518 + id = id
  1519 + })
  1520 + clearBlock = false
  1521 + end,
  1522 + [10] = function(id) -- 陷阱
  1523 + block:updateEvent({
  1524 + etype = AdvEventType.Trap,
  1525 + id = id
  1526 + })
  1527 + clearBlock = false
  1528 + end,
  1529 + [11] = function() -- 获得神器
  1530 + self:waitChooseArtifact() --等待获取神器
  1531 + end,
  1532 + [12] = function(id)
  1533 + -- buffId
  1534 + local targers = self.battle.player:getTeam(2, nil, nil, true)
  1535 + for _, target in pairs(targers) do
  1536 + target:addBuff(id)
  1537 + end
  1538 + end,
  1539 + [13] = function() -- 显示地图
  1540 + self:getCurMap():showMap()
  1541 + self:backMapShow()
  1542 + end,
  1543 + [14] = function(eventType, eventId, count, stage) -- 指定地块召唤 指定类型的id
  1544 + local change = self:getCurMap():layEventToStage(eventType, eventId, count, stage)
  1545 + for _, one in ipairs(change) do
  1546 + if one[1].roomId == room.roomId and one[2].blockId == block.blockId then
  1547 + clearBlock = false
  1548 + else
  1549 + self:backBlockChange(one[1].roomId, one[2].blockId)
1534 end 1550 end
1535 - end,  
1536 - [13] = function() -- 显示地图  
1537 - self:getCurMap():showMap()  
1538 - self:backMapShow()  
1539 - end,  
1540 - [14] = function() -- 指定地块召唤 指定类型的id  
1541 - local change = self:getCurMap():layEventToStage(effect[2], effect[3], effect[4], effect[5])  
1542 - for _, one in ipairs(change) do  
1543 - if one[1].roomId == room.roomId and one[2].blockId == block.blockId then  
1544 - clearBlock = false  
1545 - else  
1546 - self:backBlockChange(one[1].roomId, one[2].blockId)  
1547 - end 1551 + end
  1552 + end,
  1553 + [15] = function(eventType, eventId, count) -- 移除指定事件
  1554 + local change = self:getCurMap():clearEventById(eventType, eventId, count)
  1555 + for _, one in ipairs(change) do
  1556 + if one[1].roomId == room.roomId and one[2].blockId == block.blockId then
  1557 + clearBlock = false
  1558 + else
  1559 + self:backBlockChange(one[1].roomId, one[2].blockId)
1548 end 1560 end
1549 - end,  
1550 - [15] = function() -- 移除指定事件  
1551 - local change = self:getCurMap():clearEventById(effect[2], effect[3], effect[4])  
1552 - for _, one in ipairs(change) do  
1553 - if one[1].roomId == room.roomId and one[2].blockId == block.blockId then  
1554 - clearBlock = false  
1555 - else  
1556 - self:backBlockChange(one[1].roomId, one[2].blockId)  
1557 - end 1561 + end
  1562 + end,
  1563 + [16] = function(eventTypeF, eventIdF, eventTypeT, eventIdT, count) -- 指定事件转移
  1564 + local change = self:getCurMap():eventChangeToOther(eventTypeF, eventIdF, eventTypeT, eventIdT, count)
  1565 + for _, one in ipairs(change) do
  1566 + if one[1].roomId == room.roomId and one[2].blockId == block.blockId then
  1567 + clearBlock = false
  1568 + else
  1569 + self:backBlockChange(one[1].roomId, one[2].blockId)
1558 end 1570 end
1559 - end,  
1560 - [16] = function() -- 指定事件转移  
1561 - local change = self:getCurMap():eventChangeToOther(effect[2], effect[3], effect[4], effect[5], effect[6])  
1562 - for _, one in ipairs(change) do  
1563 - if one[1].roomId == room.roomId and one[2].blockId == block.blockId then  
1564 - clearBlock = false  
1565 - else  
1566 - self:backBlockChange(one[1].roomId, one[2].blockId)  
1567 - end 1571 + end
  1572 + end,
  1573 + [17] = function(eventId)
  1574 + local diceCsv = csvdb["event_choose_diceCsv"][eventId]
  1575 + if not diceCsv then return end
  1576 + local weight = math.randomInt(1, 12)
  1577 + local sum = 0
  1578 + local needEffect = nil
  1579 + local pool = {}
  1580 + for _, v in ipairs(diceCsv) do
  1581 + local status, okCount = checkChooseCondFunc(self, v.cond, room, block, tag .. " dice", chooseData)
  1582 + pool[#pool + 1] = v.weight + okCount * v.weightUp
  1583 + sum = sum + pool[#pool + 1]
  1584 + if sum >= weight and not needEffect then
  1585 + -- 达成效果
  1586 + needEffect = v.effect
1568 end 1587 end
1569 - end,  
1570 - } 1588 + end
  1589 + if needEffect then
  1590 + self:pushBackEvent(AdvBackEventType.ChooseDice, {id = eventId, pool = pool, result = weight})
  1591 + clearBlock = doChooseEffect(self, needEffect, room, block, tag .. " dice", chooseData)
  1592 + end
  1593 + end,
  1594 + }
  1595 +
  1596 + for _, effect in ipairs(effectStr:toTableArray(true)) do
1571 assert(doEffect[effect[1]], "error effect, event_" .. (tag or "choose") .. "Csv id :" .. (block.event and block.event.id or 0) .. "effect " .. effect[1]) 1597 assert(doEffect[effect[1]], "error effect, event_" .. (tag or "choose") .. "Csv id :" .. (block.event and block.event.id or 0) .. "effect " .. effect[1])
1572 - doEffect[effect[1]]() 1598 + doEffect[effect[1]](select(2, table.unpack(effect)))
1573 end 1599 end
1574 - self:scoreChange(AdvScoreType.Event, chooseData.advScore) --增加加分 1600 + return clearBlock
  1601 +end
1575 1602
  1603 +
  1604 +local function chooseCommon(self, room, block, chooseData, choose, tag)
  1605 + if not choose then return end
  1606 + if not chooseData or not chooseData["button".. choose .."cond"] then return end
  1607 + if not checkChooseCondFunc(self, chooseData["button".. choose .."cond"], room, block, tag, chooseData) then return end
  1608 + local clearBlock = chooseData.keep ~= 1
  1609 + clearBlock = clearBlock and doChooseEffect(self, chooseData["button".. choose .."effect"], room, block, tag, chooseData)
  1610 + self:scoreChange(AdvScoreType.Event, chooseData.advScore) --增加加分
1576 return true, clearBlock 1611 return true, clearBlock
1577 end 1612 end
1578 1613