技能生成规则

This commit is contained in:
xiekaidong 2023-04-10 17:03:34 +08:00
parent 3a0e442a93
commit fb7de22e94
15 changed files with 490 additions and 152 deletions

View File

@ -1,6 +1,6 @@
local skill_hero = { local skill_hero = {
[10]={ [10]={
["energy"]=10, ["energy"]=3,
["position"]=3, ["position"]=3,
["method"]=2, ["method"]=2,
["skill_type"]=1, ["skill_type"]=1,
@ -14,10 +14,11 @@ local skill_hero = {
["range"]=1 ["range"]=1
} }
}, },
["icon"]=10 ["icon"]=10,
["battle_icon"]=1
}, },
[20]={ [20]={
["energy"]=10, ["energy"]=3,
["position"]=2, ["position"]=2,
["method"]=2, ["method"]=2,
["skill_type"]=0, ["skill_type"]=0,
@ -30,12 +31,13 @@ local skill_hero = {
} }
}, },
["obj"]=2, ["obj"]=2,
["icon"]=20 ["icon"]=20,
["battle_icon"]=2
}, },
[21]={ [21]={
["energy"]=10, ["energy"]=3,
["position"]=2, ["position"]=2,
["method"]=2, ["method"]=1,
["skill_type"]=2, ["skill_type"]=2,
["skill_type_parameter"]=2, ["skill_type_parameter"]=2,
["boardrange"]={ ["boardrange"]={
@ -64,10 +66,11 @@ local skill_hero = {
["round"]=0 ["round"]=0
} }
}, },
["icon"]=20 ["icon"]=20,
["battle_icon"]=2
}, },
[30]={ [30]={
["energy"]=10, ["energy"]=3,
["position"]=4, ["position"]=4,
["method"]=2, ["method"]=2,
["skill_type"]=1, ["skill_type"]=1,
@ -77,10 +80,11 @@ local skill_hero = {
["range"]=2 ["range"]=2
} }
}, },
["icon"]=30 ["icon"]=30,
["battle_icon"]=3
}, },
[40]={ [40]={
["energy"]=10, ["energy"]=3,
["position"]=5, ["position"]=5,
["method"]=2, ["method"]=2,
["skill_type"]=0, ["skill_type"]=0,
@ -93,10 +97,11 @@ local skill_hero = {
} }
}, },
["obj"]=1, ["obj"]=1,
["icon"]=40 ["icon"]=40,
["battle_icon"]=4
}, },
[50]={ [50]={
["energy"]=10, ["energy"]=3,
["position"]=1, ["position"]=1,
["method"]=2, ["method"]=2,
["skill_type"]=1, ["skill_type"]=1,
@ -110,10 +115,11 @@ local skill_hero = {
["range"]=2 ["range"]=2
} }
}, },
["icon"]=50 ["icon"]=50,
["battle_icon"]=5
}, },
[60]={ [60]={
["energy"]=10, ["energy"]=3,
["position"]=3, ["position"]=3,
["method"]=2, ["method"]=2,
["skill_type"]=0, ["skill_type"]=0,
@ -126,10 +132,11 @@ local skill_hero = {
} }
}, },
["obj"]=1, ["obj"]=1,
["icon"]=60 ["icon"]=60,
["battle_icon"]=6
}, },
[70]={ [70]={
["energy"]=10, ["energy"]=3,
["position"]=2, ["position"]=2,
["method"]=2, ["method"]=2,
["skill_type"]=0, ["skill_type"]=0,
@ -142,10 +149,11 @@ local skill_hero = {
} }
}, },
["obj"]=1, ["obj"]=1,
["icon"]=70 ["icon"]=70,
["battle_icon"]=7
}, },
[71]={ [71]={
["energy"]=10, ["energy"]=3,
["position"]=2, ["position"]=2,
["method"]=1, ["method"]=1,
["skill_type"]=2, ["skill_type"]=2,
@ -177,10 +185,11 @@ local skill_hero = {
} }
}, },
["obj"]=1, ["obj"]=1,
["icon"]=70 ["icon"]=70,
["battle_icon"]=7
}, },
[72]={ [72]={
["energy"]=10, ["energy"]=3,
["position"]=2, ["position"]=2,
["method"]=1, ["method"]=1,
["skill_type"]=2, ["skill_type"]=2,
@ -219,10 +228,11 @@ local skill_hero = {
["range"]=1 ["range"]=1
} }
}, },
["icon"]=70 ["icon"]=70,
["battle_icon"]=7
}, },
[80]={ [80]={
["energy"]=10, ["energy"]=3,
["position"]=4, ["position"]=4,
["method"]=2, ["method"]=2,
["skill_type"]=0, ["skill_type"]=0,
@ -240,10 +250,11 @@ local skill_hero = {
["round"]=1 ["round"]=1
} }
}, },
["icon"]=80 ["icon"]=80,
["battle_icon"]=8
}, },
[81]={ [81]={
["energy"]=10, ["energy"]=3,
["position"]=4, ["position"]=4,
["method"]=2, ["method"]=2,
["skill_type"]=1, ["skill_type"]=1,
@ -279,7 +290,8 @@ local skill_hero = {
["round"]=1 ["round"]=1
} }
}, },
["icon"]=80 ["icon"]=80,
["battle_icon"]=8
} }
} }
local config = { local config = {

View File

@ -168,6 +168,7 @@ GConst.ATLAS_PATH = {
BATTLE = "assets/arts/atlas/ui/battle.asset", BATTLE = "assets/arts/atlas/ui/battle.asset",
ICON_ITEM = "assets/arts/atlas/icon/item.asset", ICON_ITEM = "assets/arts/atlas/icon/item.asset",
UI_LOGIN = "assets/arts/atlas/ui/login.asset", UI_LOGIN = "assets/arts/atlas/ui/login.asset",
ICON_SKILL = "assets/arts/atlas/icon/skill.asset",
} }
GConst.TOUCH_EVENT = { GConst.TOUCH_EVENT = {

View File

@ -252,4 +252,9 @@ BattleConst.SKILL_TYPE = {
CHANGE_AROUND = 2, CHANGE_AROUND = 2,
} }
BattleConst.SKILL_METHOD_TYPE = {
ON_ENTER = 1,
ON_FINAL = 2,
}
return BattleConst return BattleConst

View File

@ -2,6 +2,8 @@
local BattleManager = class("BattleManager", BaseModule) local BattleManager = class("BattleManager", BaseModule)
local BattleConst = GConst.BattleConst local BattleConst = GConst.BattleConst
BattleManager.SKILL_HERO_CFG = ConfigManager:getConfig("skill_hero")
local BATTLE_CONTROLLER_BASE = "app/module/battle/controller/battle_controller" local BATTLE_CONTROLLER_BASE = "app/module/battle/controller/battle_controller"
local BATTLE_CONTROLLER = { local BATTLE_CONTROLLER = {

View File

@ -1,5 +1,7 @@
local BattleController = class("BattleController") local BattleController = class("BattleController")
local BATTLE_BOARD_SKILL_HANDLE = require "app/module/battle/skill/battle_board_skill_handle"
local ELIMINATION_TOUCH_EVENT = GConst.ELIMINATION_TOUCH_EVENT local ELIMINATION_TOUCH_EVENT = GConst.ELIMINATION_TOUCH_EVENT
local BattleConst = GConst.BattleConst local BattleConst = GConst.BattleConst
@ -26,20 +28,33 @@ function BattleController:initOther()
end end
function BattleController:onLinkChange() function BattleController:onLinkChange()
for posId, entity in pairs(DataManager.BattleData:getGridEnties()) do
if entity:getCell() then
entity:getCell():showHighLight(false)
end
end
local sequence = DataManager.BattleData:getGridSequence() local sequence = DataManager.BattleData:getGridSequence()
local elementTypeMap = {} local elementTypeMap = {}
for _, info in ipairs(sequence) do for _, info in ipairs(sequence) do
local entity = DataManager.BattleData:getGridEntity(info.posId) local entity = DataManager.BattleData:getGridEntity(info.posId)
if not entity:getSkillId() then if not entity:getSkillId() then
local elementType = entity:getElementType() local elementType = entity:getElementType()
elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1
end end
if entity:getCell() then
entity:getCell():showHighLight(true)
end
end end
self.battleUI:refreshSkill(elementTypeMap)
Logger.logHighlight("---------onLinkChange--------------") Logger.logHighlight("---------onLinkChange--------------")
Logger.printTable(elementTypeMap) Logger.printTable(elementTypeMap)
end end
-- *************各个子模块的战斗需要重写的方法 START************* -- *************各个子模块的战斗需要重写的方法 END*************
function BattleController:ctor() function BattleController:ctor()
@ -68,8 +83,8 @@ function BattleController:onTouchEvent(eventType, posId)
end end
DataManager.BattleData:insertGridSequence(posId, self:snapshotBoard()) DataManager.BattleData:insertGridSequence(posId, self:snapshotBoard())
self.battleUI:showBoardMask(entity:getElementType()) self.battleUI:showBoardMask(entity:getElementType())
self:onLinkChange()
self:findSkillInfluenceGrids() self:findSkillInfluenceGrids()
self:onLinkChange()
elseif eventType == ELIMINATION_TOUCH_EVENT.ENTER then elseif eventType == ELIMINATION_TOUCH_EVENT.ENTER then
local sequence = DataManager.BattleData:getGridSequence() local sequence = DataManager.BattleData:getGridSequence()
local info = sequence[#sequence] local info = sequence[#sequence]
@ -106,8 +121,8 @@ function BattleController:onTouchEvent(eventType, posId)
end end
else else
DataManager.BattleData:insertGridSequence(posId, self:snapshotBoard()) DataManager.BattleData:insertGridSequence(posId, self:snapshotBoard())
self:onLinkChange()
self:findSkillInfluenceGrids() self:findSkillInfluenceGrids()
self:onLinkChange()
end end
elseif eventType == ELIMINATION_TOUCH_EVENT.EXIT then elseif eventType == ELIMINATION_TOUCH_EVENT.EXIT then
@ -127,14 +142,23 @@ function BattleController:onTouchEvent(eventType, posId)
end end
DataManager.BattleData:clearGridSequence() DataManager.BattleData:clearGridSequence()
self:onLinkChange()
return return
end end
local cellList = {} local cellList = {}
local elementTypeMap = {}
for _, info in ipairs(sequence) do for _, info in ipairs(sequence) do
local entity = DataManager.BattleData:getGridEntity(info.posId) local entity = DataManager.BattleData:getGridEntity(info.posId)
table.insert(cellList, entity:getCell()) table.insert(cellList, entity:getCell())
if not entity:getSkillId() then
local elementType = entity:getElementType()
elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1
end
end end
DataManager.BattleData:addSkillEnergy(elementTypeMap)
self.battleUI:disableUITouch() self.battleUI:disableUITouch()
self.battleUI:eliminationAni(cellList, function() self.battleUI:eliminationAni(cellList, function()
self:onEliminationAniOver() self:onEliminationAniOver()
@ -216,10 +240,36 @@ function BattleController:fillBoard()
end end
self.battleUI:fallGrid(pathMap, function() self.battleUI:fallGrid(pathMap, function()
self:onFillBoardOver()
self.battleUI:enableUITouch() self.battleUI:enableUITouch()
end) end)
end end
function BattleController:onFillBoardOver()
local map = {}
for _, skillEntity in pairs(DataManager.BattleData:getSkillEntities()) do
if skillEntity:getEnergyEnough() then
map[skillEntity:getPosition()] = skillEntity:getSkillId()
end
end
Logger.logHighlight("------onFillBoardOver-------")
Logger.printTable(map)
for elementType, skillId in pairs(map) do
local list = DataManager.BattleData:getSameElementList(elementType, 1, true)
Logger.printTable(list)
for _, posId in ipairs(list) do
local entity = DataManager.BattleData:getGridEntity(posId)
if entity then
entity:setSkilId(skillId)
if entity:getElementType() ~= elementType then
entity:setElementType(elementType)
end
end
end
end
end
---- 从一个点直接遍历所有相关的路径 ---- 从一个点直接遍历所有相关的路径
function BattleController:fillThisPos(posId, columnCount) function BattleController:fillThisPos(posId, columnCount)
local entity = DataManager.BattleData:getGridEntity(posId) local entity = DataManager.BattleData:getGridEntity(posId)
@ -322,37 +372,9 @@ function BattleController:findSkillInfluenceGrids(isFinal)
local entity = DataManager.BattleData:getGridEntity(info.posId) local entity = DataManager.BattleData:getGridEntity(info.posId)
local skillId = entity:getSkillId() local skillId = entity:getSkillId()
if skillId then if skillId then
self:activeBoardSkill(info.posId, skillId, isFinal) local skillEntity = DataManager.BattleData:getSkillEntityByElement(entity:getElementType())
end if skillEntity then
end BATTLE_BOARD_SKILL_HANDLE.activeBoardSkill(info.posId, skillEntity, DataManager.BattleData:getGridEnties(), isFinal)
end
function BattleController:activeBoardSkill(posId, skillId, isFinal)
local skillCard = ConfigManager:getConfig("skill_hero")[skillId]
if not skillCard then
return
end
if isFinal then
if skillCard.method == 2 then
if skillCard.boardrange then
-- body
end
end
else
if skillCard.method == 1 then
if skillCard.boardrange then
local cludePosIdsMap = {}
for posId, entity in pairs(DataManager.BattleData:getGridEnties()) do
if entity:canLink() then
cludePosIdsMap[posId] = true
end
end
local ids = ModuleManager.BattleManager:getAroundPosIdsByList(posId, skillCard.boardrange, cludePosIdsMap)
for _, posId in ipairs(ids) do
local entity = DataManager.BattleData:getGridEntity(posId)
entity:setElementType(skillCard.skill_type_parameter)
end
end end
end end
end end

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0c2881479b6fcea41b5b168d0779f096
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,70 @@
local BattleConst = require "app/module/battle/battle_const"
local BattleBoardSkillHandle = {}
local SKILL_TYPE = BattleConst.SKILL_TYPE
local SKILL_METHOD_TYPE = BattleConst.SKILL_METHOD_TYPE
local function _takeElimination(posId, skillEntity, gridEntities)
local boardrange = skillEntity:getBoardRange()
if boardrange then
local cludePosIdsMap = {}
for posId, entity in pairs(gridEntities) do
cludePosIdsMap[posId] = true
end
local ids = ModuleManager.BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap)
cludePosIdsMap = {}
for _, posId in ipairs(ids) do
cludePosIdsMap[posId] = true
end
DataManager.BattleData:cacheSkillInfluenceGrids(cludePosIdsMap)
end
end
local function _takeChangeAround(posId, skillEntity, gridEntities)
local boardrange = skillEntity:getBoardRange()
if boardrange then
local cludePosIdsMap = {}
for posId, entity in pairs(gridEntities) do
if entity:canChangeInfo() then
cludePosIdsMap[posId] = true
end
end
local ids = ModuleManager.BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap)
for _, posId in ipairs(ids) do
local entity = gridEntities[posId]
if entity then
entity:setElementType(skillEntity:getSkillTypeParameter())
end
end
end
end
BattleBoardSkillHandle._activeBoardSkill = {
[SKILL_TYPE.ELIMINATION] = _takeElimination,
[SKILL_TYPE.CHANGE_AROUND] = _takeChangeAround,
}
function BattleBoardSkillHandle.activeBoardSkill(posId, skillEntity, gridEntities, isFinal)
if not skillEntity then
return
end
if isFinal then
if skillEntity:getMethond() == SKILL_METHOD_TYPE.ON_FINAL then
local func = BattleBoardSkillHandle._activeBoardSkill[skillEntity:getSkillType()]
if func then
func(posId, skillEntity, gridEntities)
end
end
else
if skillEntity:getMethond() == SKILL_METHOD_TYPE.ON_ENTER then
local func = BattleBoardSkillHandle._activeBoardSkill[skillEntity:getSkillType()]
if func then
func(posId, skillEntity, gridEntities)
end
end
end
end
return BattleBoardSkillHandle

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 14a09e5699837c548b5878119e718c87 guid: 08753749ebd71ea46a0a94518c022fa6
ScriptedImporter: ScriptedImporter:
internalIDToNameTable: [] internalIDToNameTable: []
externalObjects: {} externalObjects: {}

View File

@ -16,6 +16,7 @@ end
function BattleUI:_display() function BattleUI:_display()
local uiMap = self.root:genAllChildren() local uiMap = self.root:genAllChildren()
self:initGridCell() self:initGridCell()
self:initSkill()
end end
function BattleUI:_addListeners() function BattleUI:_addListeners()
@ -25,7 +26,52 @@ function BattleUI:_addListeners()
end) end)
end end
function BattleUI:initSkill()
if self.skillObjs then
return
end
self.skillObjs = {}
local uiMap = self.root:genAllChildren()
for elementType, skillEntity in pairs(DataManager.BattleData:getSkillEntities()) do
if not self.skillObjs[elementType] then
local prefix = "battle_ui.bg_2.skill_node_" .. elementType
self.skillObjs[elementType] = {
icon = uiMap[prefix],
mask = uiMap[prefix .. ".mask"],
}
self.skillObjs[elementType].imgComp = self.skillObjs[elementType].mask:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE)
self.skillObjs[elementType].icon:setSprite(GConst.ATLAS_PATH.ICON_SKILL, skillEntity:getBattleIcon())
self.skillObjs[elementType].mask:setSprite(GConst.ATLAS_PATH.ICON_SKILL, skillEntity:getBattleIcon())
end
end
end
function BattleUI:refreshSkill(elementMap)
if not self.skillObjs then
return
end
for elementType, skillEntity in pairs(DataManager.BattleData:getSkillEntities()) do
if not self.skillObjs[elementType] then
return
end
local add = 0
if elementMap and elementMap[elementType] then
add = elementMap[elementType]
end
local curEnergy = skillEntity:getEnergy() + add
local needEnergy = skillEntity:getNeedEnergy()
self.skillObjs[elementType].imgComp.fillAmount = (needEnergy - curEnergy) / needEnergy
end
end
function BattleUI:initGridCell() function BattleUI:initGridCell()
if self.root.gridCells then
self.gridCells = self.root.gridCells
self.gridInitOver = true
end
if self.gridCells and self.gridInitOver then if self.gridCells and self.gridInitOver then
self:onInitGridCellOver() self:onInitGridCellOver()
return return
@ -49,6 +95,7 @@ function BattleUI:initGridCell()
if self.cellLoadRemianCount <= 0 then if self.cellLoadRemianCount <= 0 then
self.gridInitOver = true self.gridInitOver = true
self:onInitGridCellOver() self:onInitGridCellOver()
self.root.gridCells = self.gridCells
end end
end) end)
end end
@ -112,6 +159,8 @@ function BattleUI:eliminationAni(cellList, callback)
callback() callback()
end, 1) end, 1)
end end
self:refreshSkill()
end end
function BattleUI:fallGrid(listInfo, callback) function BattleUI:fallGrid(listInfo, callback)

View File

@ -3,11 +3,15 @@ local GridCell = class("GridCell", BaseCell)
function GridCell:refresh(gridEntity, curElement) function GridCell:refresh(gridEntity, curElement)
local uiMap = self:getUIMap() local uiMap = self:getUIMap()
local elementType = gridEntity:getElementType() local elementType = gridEntity:getElementType()
local elementIcon = uiMap["grid_cell.touch_node.ani_node.middle_bg"]
local highLightIcon = uiMap["grid_cell.touch_node.ani_node.middle_bg.high_light_icon"]
if self.lastElementType ~= elementType then if self.lastElementType ~= elementType then
self.lastElementType = elementType self.lastElementType = elementType
local atlas, icon = ModuleManager.BattleManager:getElementIcon(elementType) local atlas, icon = ModuleManager.BattleManager:getElementIcon(elementType)
uiMap["grid_cell.touch_node.ani_node.middle_bg"]:setSprite(atlas, icon) elementIcon:setSprite(atlas, icon)
highLightIcon:setSprite(atlas, icon .. "_1")
end end
elementIcon:setVisible(true)
local showMask = false local showMask = false
if curElement and (curElement ~= elementType or not gridEntity:canLink()) then if curElement and (curElement ~= elementType or not gridEntity:canLink()) then
@ -24,6 +28,27 @@ function GridCell:refresh(gridEntity, curElement)
uiMap["grid_cell.touch_node.ani_node.up_bg"]:setSprite(atlas, icon) uiMap["grid_cell.touch_node.ani_node.up_bg"]:setSprite(atlas, icon)
end end
local skillIcon = uiMap["grid_cell.touch_node.ani_node.skill_icon"]
local skillHighLightIcon = uiMap["grid_cell.touch_node.ani_node.skill_icon.high_light_icon"]
local skillId = gridEntity:getSkillId()
if skillId then
elementIcon:setVisible(false)
skillIcon:setVisible(true)
if self.lastSkillId ~= skillId then
self.lastSkillId = skillId
local cfg = ModuleManager.BattleManager.SKILL_HERO_CFG[skillId]
if cfg then
skillIcon:setSprite(GConst.ATLAS_PATH.ICON_SKILL, tostring(cfg.battle_icon))
skillHighLightIcon:setSprite(GConst.ATLAS_PATH.ICON_SKILL, tostring(cfg.battle_icon) .. "_1")
end
end
else
skillIcon:setVisible(false)
end
self:showCircle(false)
self:showHighLight(false)
--- 测试代码 --- 测试代码
uiMap["grid_cell.touch_node.ani_node.count"]:setText(gridEntity:getAroundEliminationCount()) uiMap["grid_cell.touch_node.ani_node.count"]:setText(gridEntity:getAroundEliminationCount())
end end
@ -33,4 +58,17 @@ function GridCell:addTouchListener(func)
uiMap["grid_cell.touch_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_ELIMINATION_TOUCH_EVENT):AddTouchEventListener(func) uiMap["grid_cell.touch_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_ELIMINATION_TOUCH_EVENT):AddTouchEventListener(func)
end end
function GridCell:showCircle(show)
local uiMap = self:getUIMap()
uiMap["grid_cell.touch_node.ani_node.circle"]:setVisible(show)
end
function GridCell:showHighLight(show)
local uiMap = self:getUIMap()
local highLightIcon = uiMap["grid_cell.touch_node.ani_node.middle_bg.high_light_icon"]
local skillHighLightIcon = uiMap["grid_cell.touch_node.ani_node.skill_icon.high_light_icon"]
highLightIcon:setVisible(show)
skillHighLightIcon:setVisible(show)
end
return GridCell return GridCell

View File

@ -1,10 +1,11 @@
local BattleData = class("BattleData", BaseData) local BattleData = class("BattleData", BaseData)
local SKILL_HERO_CFG = ConfigManager:getConfig("skill_hero")
local BattleConst = GConst.BattleConst local BattleConst = GConst.BattleConst
local BATTLE_GRID_ENTITY = require "app/userdata/battle/battle_grid_entity" local BATTLE_GRID_ENTITY = require "app/userdata/battle/battle_grid_entity"
local BATTLE_CARD_SKILL_ENTITY = require "app/userdata/battle/skill/battle_card_skill_entity" local BATTLE_BOARD_SKILL_ENTITY = require "app/userdata/battle/skill/battle_borad_skill_entity"
function BattleData:init(board) function BattleData:init(board, skillIds)
self:clear() self:clear()
for i, info in ipairs(board) do for i, info in ipairs(board) do
@ -31,6 +32,15 @@ function BattleData:init(board)
self.elementTypeMap[data.elementType] = (self.elementTypeMap[data.elementType] or 0) + 1 self.elementTypeMap[data.elementType] = (self.elementTypeMap[data.elementType] or 0) + 1
end end
end end
--- todo
skillIds = {
10, 21, 30, 40, 50
}
for _, skillId in ipairs(skillIds) do
local cfg = SKILL_HERO_CFG[skillId]
self.skillMap[cfg.position] = BATTLE_BOARD_SKILL_ENTITY:create(skillId)
end
end end
function BattleData:clear() function BattleData:clear()
@ -38,6 +48,7 @@ function BattleData:clear()
self.gridEntities = {} self.gridEntities = {}
self.elementTypeMap = {} -- 同元素得格子数量 self.elementTypeMap = {} -- 同元素得格子数量
self.skillMap = {}
end end
function BattleData:getElementTypeMap() function BattleData:getElementTypeMap()
@ -80,16 +91,22 @@ function BattleData:removeGridSequence(posId)
end end
function BattleData:cacheSkillInfluenceGrids(grids) function BattleData:cacheSkillInfluenceGrids(grids)
self.skillInfluenceGrids = grids if not self.skillInfluenceGrids then
self.skillInfluenceGrids = {}
end
for posId, status in pairs(grids) do
self.skillInfluenceGrids[posId] = true
end
end end
function BattleData:getSkillInfluenceGrids() function BattleData:getSkillInfluenceGrids()
return self.skillInfluenceGrids return self.skillInfluenceGrids or {}
end end
function BattleData:clearGridSequence() function BattleData:clearGridSequence()
self.gridSequence = {} -- 格子队列 self.gridSequence = {} -- 格子队列
self.gridSequenceMap = {} -- 格子队列对应的map方面查找 self.gridSequenceMap = {} -- 格子队列对应的map方面查找
self.skillInfluenceGrids = {} -- 技能影响的格子
end end
function BattleData:getGridEnties() function BattleData:getGridEnties()
@ -134,6 +151,68 @@ function BattleData:setGridInfo(posId, gridInfo)
self.elementTypeMap[gridInfo.elementType] = (self.elementTypeMap[gridInfo.elementType] or 0) + 1 self.elementTypeMap[gridInfo.elementType] = (self.elementTypeMap[gridInfo.elementType] or 0) + 1
end end
end end
entity:setSkilId() -- 清除skillId
end
function BattleData:getSameElementList(elementType, count, useAlternate)
local result = {}
if not self.gridEntities then
return result
end
local sameElementList = {}
local alternateList = {}
for posId, entity in pairs(self.gridEntities) do
if entity:canChangeInfo() then
if entity:getElementType() == elementType then
table.insert(sameElementList, posId)
else
table.insert(alternateList, posId)
end
end
end
local addCount = 0
for i = 1, count do
if not sameElementList[i] then
break
end
table.insert(result, table.remove(sameElementList, math.random(1, #sameElementList)))
addCount = addCount + 1
end
if addCount < count and useAlternate then
for i = 1, count - addCount do
if not alternateList[1] then
break
end
table.insert(result, table.remove(alternateList, math.random(1, #alternateList)))
end
end
return result
end
function BattleData:getSkillEntities()
return self.skillMap
end
function BattleData:getSkillEntityByElement(elementType)
if not self.skillMap then
return
end
return self.skillMap[elementType]
end
function BattleData:addSkillEnergy(elementMap)
if not self.skillMap then
return
end
for elementType, entity in pairs(self.skillMap) do
entity:addEnergy(elementMap[elementType] or 0)
end
end end
return BattleData return BattleData

View File

@ -102,6 +102,9 @@ function BattleGridEntity:setIsIdle(isIdle)
end end
function BattleGridEntity:canLink() function BattleGridEntity:canLink()
if self:getIsIdle() then
return false
end
return not BattleConst.CANT_LINK_GRID_TYPE[self.gridType] return not BattleConst.CANT_LINK_GRID_TYPE[self.gridType]
end end
@ -139,4 +142,16 @@ function BattleGridEntity:getSkillId()
return self.skillId return self.skillId
end end
function BattleGridEntity:setSkilId(skillId)
self.skillId = skillId
self:setDirty()
end
function BattleGridEntity:canChangeInfo()
if self:canLink() and not self:getSkillId() then
return true
end
return false
end
return BattleGridEntity return BattleGridEntity

View File

@ -0,0 +1,114 @@
local BattleBoardSkillEnity = class("BattleBoardSkillEnity", BaseData)
function BattleBoardSkillEnity:ctor(skillId)
self:refreshSkillId(skillId)
self.curEnergy = 0
end
function BattleBoardSkillEnity:refreshSkillId(skillId)
self.skillId = skillId
self.config = ConfigManager:getConfig("skill_hero")[skillId]
end
function BattleBoardSkillEnity:getSkillId()
return self.skillId
end
function BattleBoardSkillEnity:getNeedEnergy()
if not self.config then
return 1
end
return self.config.energy
end
function BattleBoardSkillEnity:getPosition()
if not self.config then
return 1
end
return self.config.position
end
function BattleBoardSkillEnity:getMethond()
if not self.config then
return
end
return self.config.method
end
function BattleBoardSkillEnity:getSkillType()
if not self.config then
return
end
return self.config.skill_type
end
function BattleBoardSkillEnity:getSkillTypeParameter()
if not self.config then
return
end
return self.config.skill_type_parameter
end
function BattleBoardSkillEnity:getBoardRange()
if not self.config then
return
end
return self.config.boardrange
end
function BattleBoardSkillEnity:getEffect()
if not self.config then
return
end
return self.config.effect
end
function BattleBoardSkillEnity:getTartget()
if not self.config then
return
end
return self.config.obj
end
function BattleBoardSkillEnity:getIcon()
if not self.config then
return
end
return self.config.icon
end
function BattleBoardSkillEnity:getBattleIcon()
if not self.config then
return
end
return tostring(self.config.battle_icon)
end
function BattleBoardSkillEnity:getNameAct()
if not self.config then
return
end
return self.config.name_act
end
function BattleBoardSkillEnity:getEnergy()
return self.curEnergy
end
function BattleBoardSkillEnity:getEnergyEnough(onlyGetBool)
local enough = self.curEnergy >= self:getNeedEnergy()
if enough and not onlyGetBool then
self:clearEnergy()
end
return enough
end
function BattleBoardSkillEnity:addEnergy(count)
self.curEnergy = self.curEnergy + count
end
function BattleBoardSkillEnity:clearEnergy()
self.curEnergy = 0
end
return BattleBoardSkillEnity

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 02d214b08c9e8e249af651ea321569bd
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}

View File

@ -1,87 +0,0 @@
local BattleCardSkillEnity = class("BattleCardSkillEnity", BaseData)
function BattleCardSkillEnity:ctor(skillId)
self:refreshSkillId(skillId)
end
function BattleCardSkillEnity:refreshSkillId(skillId)
self.skillId = skillId
self.config = ConfigManager:getConfig("skill_hero")[skillId]
end
function BattleCardSkillEnity:getSkillId()
return self.skillId
end
function BattleCardSkillEnity:getMethond()
if not self.config then
return
end
return self.config.method
end
function BattleCardSkillEnity:getSkillType()
if not self.config then
return
end
return self.config.skill_type
end
function BattleCardSkillEnity:getSkillTypeParameter()
if not self.config then
return
end
return self.config.skill_type_parameter
end
function BattleCardSkillEnity:getBoardRange()
if not self.config then
return
end
return self.config.boardrange
end
function BattleCardSkillEnity:getEffect()
if not self.config then
return
end
return self.config.effect
end
function BattleCardSkillEnity:getTartget()
if not self.config then
return
end
return self.config.obj
end
function BattleCardSkillEnity:getTartget()
if not self.config then
return
end
return self.config.obj
end
function BattleCardSkillEnity:getIcon()
if not self.config then
return
end
return self.config.icon
end
function BattleCardSkillEnity:getBattleIcon()
if not self.config then
return
end
return self.config.battle_icon
end
function BattleCardSkillEnity:getNameAct()
if not self.config then
return
end
return self.config.name_act
end
return BattleCardSkillEnity