PGRData/Resources/Scripts/XEntity/XRpgTower/XRpgTowerCharacter.lua

431 lines
12 KiB
Lua
Raw Normal View History

2022-12-26 08:36:01 +00:00
--兵法蓝图角色模型类
local XRpgTowerCharacter = XClass(nil, "XRpgTowerCharacter")
local XRpgTowerTalent = require("XEntity/XRpgTower/XRpgTowerTalent")
local XRpgTowerItem = require("XEntity/XRpgTower/XRpgTowerItem")
--[[
*********
RCharaCfg
TalentIds ID列表
TalentPoints
Order
]]
--[[
================
================
]]
function XRpgTowerCharacter:Ctor(characterId, teamOrder)
self.RCharaCfg = XRpgTowerConfig.GetRCharacterCfgByCharacterIdAndLevel(characterId, 1)
self.RBaseCharaCfg = XRpgTowerConfig.GetRBaseCharaCfgByCharacterId(characterId)
self.RobotId = self.RCharaCfg.RobotId
self.Order = teamOrder
self.TalentIds = {}
end
--[[
================
(使)
@param XRpgCharacterData:
================
]]
function XRpgTowerCharacter:RefreshCharacterData(XRpgCharacterData)
self.RCharaCfg = XRpgTowerConfig.GetRCharacterCfgByCharacterIdAndLevel(XRpgCharacterData.CharacterId, XDataCenter.RpgTowerManager.GetCurrentLevel())
self.RBaseCharaCfg = XRpgTowerConfig.GetRBaseCharaCfgByCharacterId(XRpgCharacterData.CharacterId)
self.TalentPoint = XRpgTowerItem.New(XDataCenter.RpgTowerManager.GetTalentItemId())
self.RobotId = self.RCharaCfg.RobotId
self.TalentIds = self:InitTalentIds(XRpgCharacterData.TalentIds)
self.TalentPoint:SetNum(XRpgCharacterData.TalentPoints)
self:ResetInfo()
self:InitTalents()
end
function XRpgTowerCharacter:ResetInfo()
self:InitSkillInfo()
self:InitAbility()
end
--[[
================
================
]]
function XRpgTowerCharacter:InitSkillInfo()
self.RoleListSkill = nil
end
--[[
================
================
]]
function XRpgTowerCharacter:InitAbility()
self.Ability = nil
end
--[[
================
================
]]
function XRpgTowerCharacter:InitTalentIds(activeTalentIds)
local talentActiveDic = {}
for _, activeTalentId in pairs(activeTalentIds) do
talentActiveDic[activeTalentId] = true
end
return talentActiveDic
end
--[[
================
================
]]
function XRpgTowerCharacter:InitTalents()
local talents = XRpgTowerConfig.GetTalentCfgsByCharacterId(self:GetCharacterId())
self.Talents = {}
for layerId, talentLayer in pairs(talents) do
if not self.Talents[layerId] then self.Talents[layerId] = {} end
for index, talentCfg in pairs(talentLayer) do
table.insert(self.Talents[layerId], XRpgTowerTalent.New(talentCfg.TalentId, self.TalentIds[talentCfg.TalentId], self))
end
table.sort(self.Talents[layerId], function(rTalent1, rTalent2)
return rTalent1:GetId() < rTalent2:GetId()
end)
end
end
--[[
================
ID
================
]]
function XRpgTowerCharacter:GetCharacterId()
return self.RCharaCfg and self.RCharaCfg.CharacterId
end
--[[
================
ID
================
]]
function XRpgTowerCharacter:GetRobotId()
return self.RobotId
end
--[[
================
================
]]
function XRpgTowerCharacter:GetRobotCfg()
return XRobotManager.GetRobotTemplate(self:GetRobotId())
end
--[[
================
================
]]
function XRpgTowerCharacter:GetOrder()
return self.Order
end
--[[
================
================
]]
function XRpgTowerCharacter:GetDisplayAttrTypeData()
local attrData = {}
for i in pairs(self.RBaseCharaCfg.DisplayAttriName) do
local attr = {
Name = self.RBaseCharaCfg.DisplayAttriName[i],
Type = self.RBaseCharaCfg.DisplayAttriType[i]
}
table.insert(attrData, attr)
end
return attrData
end
--[[
================
================
]]
function XRpgTowerCharacter:GetAbility()
if self.Ability then return self.Ability end
--二期简化了技能树类型可以直接读取机器人表的ShowAbility
self.Ability = XRobotManager.GetRobotAbility(self:GetRobotId())
--[[
self.Ability = 0
--这里的角色属性已包含装备
local robotAttrib = self:GetCharaAttributes()
local attribAbility = XAttribManager.GetAttribAbility(robotAttrib)
--构建机器人技能数据
local skillData = XRobotManager.GetRobotSkillLevelDic(self.RobotId)
]]
if self.Talents then
for _, talentLayer in pairs(self.Talents) do
for index, talent in pairs(talentLayer) do
if talent:GetIsUnLock() then
self.Ability = self.Ability + talent:GetSpecialAbility()
--[[
local skillInfo = talent:GetSkillPlus()
if skillInfo then
for skillId, addLevel in pairs(skillInfo) do
skillData[skillId] = skillData[skillId] + addLevel
end
end
]]
end
end
end
end
--local skillAbility = XDataCenter.CharacterManager.GetSkillAbility(skillData)
--self.Ability = self.Ability + attribAbility + skillAbility
return self.Ability
end
--[[
================
================
]]
function XRpgTowerCharacter:GetCharaAttributes()
local extraAttribIds = {}
for _, talentLayer in pairs(self.Talents) do
for index, talent in pairs(talentLayer) do
if talent:GetIsUnLock() then
local attribId = talent:GetAttribPlus()
if attribId then
table.insert(extraAttribIds, attribId)
end
end
end
end
return XRobotManager.GetRobotAttribWithExtraAttrib(self.RobotId, extraAttribIds)
end
--[[
================
================
]]
function XRpgTowerCharacter:GetCharaTalentPlusAttr()
local extraAttr
for _, talentLayer in pairs(self.Talents) do
for index, talent in pairs(talentLayer) do
if talent:GetIsUnLock() then
local attribId = talent:GetAttribPlus()
if not extraAttr and attribId then
extraAttr = XTool.Clone(XAttribManager.GetAttribByAttribId(attribId))
elseif attribId then
XAttribManager.DoAddAttribsByAttrAndAddId(extraAttr, attribId)
end
end
end
end
return extraAttr
end
--[[
================
================
]]
function XRpgTowerCharacter:GetCharaName()
return XCharacterConfigs.GetCharacterName(self.RCharaCfg.CharacterId)
end
--[[
================
+
================
]]
function XRpgTowerCharacter:GetFullName()
return XCharacterConfigs.GetCharacterFullNameStr(self.RCharaCfg.CharacterId)
end
--[[
================
================
]]
function XRpgTowerCharacter:GetModelName()
return XCharacterConfigs.GetCharacterTradeName(self.RCharaCfg.CharacterId)
end
--[[
================
================
]]
function XRpgTowerCharacter:GetRoleListSkill()
if self.RoleListSkill then return self.RoleListSkill end
local skillData = XRobotManager.GetRobotSkillLevelDic(self:GetRobotId(), true)
self.RoleListSkill = {}
local removeNo = {
[22] = true,
[24] = true,
[25] = true,
[26] = true,
[27] = true
} -- 队长技SS,SSS,SSS+与终阶解放技能不展示
--增加角色天赋里面的技能增益
local plusSkillData = self:GetSkillPlusData()
for skillId, skillLevel in pairs(plusSkillData) do
skillData[skillId] = skillData[skillId] + skillLevel
end
--按SkillId排序
local tempList = {}
for skillId, skillLevel in pairs(skillData) do
local skillNo = skillId % 100
if not removeNo[skillNo] then
local skillInfo = XCharacterConfigs.GetSkillGradeDesConfig(skillId, skillLevel)
local tempData = { Order = skillId, Info = skillInfo}
table.insert(tempList, tempData)
end
end
table.sort(tempList, function(a,b) return a.Order < b.Order end)
for i = 1, #tempList do
table.insert(self.RoleListSkill, tempList[i].Info)
end
return self.RoleListSkill
end
--[[
================
================
]]
function XRpgTowerCharacter:GetSkillPlusData()
local plusSkillData = {}
if not self.Talents then return plusSkillData end
--统计每个激活天赋增加的技能
for _, talentLayer in pairs(self.Talents) do
for index, talent in pairs(talentLayer) do
if talent:GetIsUnLock() then
local skillInfo = talent:GetSkillPlus()
if skillInfo then
for skillId, addLevel in pairs(skillInfo) do
if not plusSkillData[skillId] then plusSkillData[skillId] = 0 end
plusSkillData[skillId] = plusSkillData[skillId] + addLevel
end
end
end
end
end
return plusSkillData
end
--[[
================
================
]]
function XRpgTowerCharacter:GetSmallHeadIcon()
local fashionId = XCharacterConfigs.GetCharacterTemplate(self.RCharaCfg.CharacterId).DefaultNpcFashtionId
return XDataCenter.FashionManager.GetFashionSmallHeadIcon(fashionId)
end
--[[
================
================
]]
function XRpgTowerCharacter:GetBigHeadIcon()
local fashionId = XCharacterConfigs.GetCharacterTemplate(self.RCharaCfg.CharacterId).DefaultNpcFashtionId
return XDataCenter.FashionManager.GetFashionBigHeadIcon(fashionId)
end
--[[
================
================
]]
function XRpgTowerCharacter:GetJobTypeIcon()
local jobType = XRobotManager.GetRobotJobType(self.RobotId)
return XCharacterConfigs.GetNpcTypeIcon(jobType)
end
--[[
================
================
]]
function XRpgTowerCharacter:GetIsMaxLevel()
return self.RCharaCfg and (self:GetLevel() >= XDataCenter.RpgTowerManager.GetMaxLevel())
end
--[[
================
================
]]
function XRpgTowerCharacter:GetTalentPoints()
return self.TalentPoint:GetNum()
end
--[[
================
================
]]
function XRpgTowerCharacter:GetTalents()
return self.Talents
end
--================
--根据等级获取角色的天赋对象列表
--================
function XRpgTowerCharacter:GetTalentsByLayer(layer)
return self.Talents[layer]
end
--[[
================
================
]]
function XRpgTowerCharacter:GetIsInTeam()
return XDataCenter.RpgTowerManager.GetCharacterIsInTeam(self:GetCharacterId())
end
--[[
================
================
]]
function XRpgTowerCharacter:GetElements()
local detailElementsList = XCharacterConfigs.GetCharDetailTemplate(self:GetCharacterId())
local elements = {}
if detailElementsList then
for i = 1, #detailElementsList.ObtainElementList do
local elementConfig = XCharacterConfigs.GetCharElement(detailElementsList.ObtainElementList[i])
elements[i] = elementConfig
end
end
return elements
end
--[[
================
@param rTalent:Id
================
]]
function XRpgTowerCharacter:TalentActive(rTalent, talentPoints)
self.TalentPoint:SetNum(talentPoints)
rTalent:UnLock()
self:ResetInfo()
end
--[[
================
@param talentPoints:
================
]]
function XRpgTowerCharacter:CharacterReset(talentPoints)
self.TalentPoint:SetNum(talentPoints)
for _, talentLayer in pairs(self.Talents) do
for index, talent in pairs(talentLayer) do
talent:Lock()
end
end
self:ResetInfo()
end
--[[
================
================
]]
function XRpgTowerCharacter:GetTalentItem()
return self.TalentPoint
end
--[[
================
================
]]
function XRpgTowerCharacter:CheckCanActiveTalent()
if not self.Talents then return false end
for _, talentLayer in pairs(self.Talents) do
for index, talent in pairs(talentLayer) do
if not talent:GetIsUnLock() and talent:GetCanUnLock() then return true end
end
end
return false
end
return XRpgTowerCharacter