Files
Main/Assets/GameAssets/Resources/Lua/Logic/PlayerSkill/PlayerSkillCell.lua
2025-01-25 04:38:09 +08:00

118 lines
3.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
--作者: yangqf
--日期: 2021-03-26
--文件: PlayerSkillCell.lua
--模块: PlayerSkillCell
--描述: 玩家技能格子
------------------------------------------------
local L_PlayerSkill = require "Logic.PlayerSkill.PlayerSkill"
local PlayerSkillCell = {
--配置ID
CfgID = 0,
--当前配置
Cfg = nil,
--当前技能索引
CurIndex = 0,
--索引倒计时倒计时结束后索引归0
IndexTimer = 0,
--技能列表
SkillList = nil,
--技能数量
SkillCount = 0,
--刷新回调
RereshCallBack = nil,
}
function PlayerSkillCell:New(cfg, useSkills)
local _m = Utils.DeepCopy(self)
_m.CfgID = cfg.Id
_m.Cfg = cfg
_m.CurIndex = 1
if cfg.Id == 1007000 then
local dad = 0
end
_m.SkillList = List:New()
if useSkills ~= nil then
for i = 1, #useSkills do
local _skillCfg = DataConfig.DataSkill[useSkills[i]]
if _skillCfg ~= nil then
_m.SkillList:Add(L_PlayerSkill:New(_skillCfg, true))
end
end
else
local _skillIds = Utils.SplitNumber(cfg.SkillId, '_')
for i = 1, #_skillIds do
local _skillCfg = DataConfig.DataSkill[_skillIds[i]]
if _skillCfg ~= nil then
_m.SkillList:Add(L_PlayerSkill:New(_skillCfg, true))
end
end
end
_m.SkillCount = #_m.SkillList
return _m
end
--当前技能
function PlayerSkillCell:GetCurSkill()
if self.CurIndex < 1 or self.CurIndex > self.SkillCount then
CurIndex = 1
end
if self.CurIndex <= self.SkillCount then
return self.SkillList[self.CurIndex]
end
return nil
end
--更新CD
function PlayerSkillCell:Update(dt)
if self.SkillCount > 0 then
if self.IndexTimer > 0 then
self.IndexTimer = self.IndexTimer - dt
if self.IndexTimer <= 0 then
self.CurIndex = 1
self.IndexTimer = 0
if self.RereshCallBack ~= nil then
self.RereshCallBack()
end
end
end
end
for i = 1, self.SkillCount do
self.SkillList[i]:Update(dt)
end
end
--填充技能列表
function PlayerSkillCell:FillSkillList(skillList)
for i = 1, self.SkillCount do
skillList:Add(self.SkillList[i])
end
end
--使用技能回调
function PlayerSkillCell:OnUseSkill(skillId)
local _selfSkill = false
for i = 1, self.SkillCount do
if self.SkillList[i].CfgID == skillId then
_selfSkill = true
break
end
end
if _selfSkill then
self.CurIndex = self.CurIndex + 1
if self.CurIndex > self.SkillCount then
self.CurIndex = 1
self.IndexTimer = 0
else
self.IndexTimer = 2
end
if self.RereshCallBack ~= nil then
self.RereshCallBack()
end
end
end
return PlayerSkillCell