战斗力

This commit is contained in:
puxuan 2025-09-09 19:24:42 +08:00
parent f18eb91d53
commit 96fe08e143
11 changed files with 307 additions and 2 deletions

View File

@ -90,6 +90,8 @@ local MODULE_PATHS = {
-- 天赋
TalentManager = "app/module/talent/talent_manager",
BagManager = "app/module/bag/bag_manager",
-- 战力/攻击力toast
PowerToastManager = "app/ui/common/power_toast_manager",
}
-- 这里的key对应func_open里的id

View File

@ -374,6 +374,7 @@ GConst.COLOR_CODE = {
GREEN = "#A3FF94",
RED = "#FF5050",
WHITE = "#FFFFFF",
LIGHT_GREEN = "#2FFF91",
}
GConst.UI_EFFECT_ORDER = {

View File

@ -2047,4 +2047,23 @@ function GFunc.showCommonBoxUI(id, showTips)
ModuleManager.CommonManager:showCommonBoxUI(id, showTips)
end
function GFunc.colorText(color, str)
local backStr = ""
backStr = string.format("<color=".. color.. ">%s</color>", str)
return backStr
end
--@region 战斗力
function GFunc.hidePowerToast()
ModuleManager.PowerToastManager:hideToast()
end
function GFunc.showPowerToast(before, after, posY)
if not before or not after then
return
end
ModuleManager.PowerToastManager:showToast(before, after, posY)
end
--@endregion
return GFunc

View File

@ -35,6 +35,7 @@ function HeroManager:upgradeHeroFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
DataManager.HeroData:setHeroLv(result.hero.id, result.hero.level)
DataManager.HeroData:setDirty()
DataManager.HeroData:calcPower()
AudioManager:playEffect(AudioManager.EFFECT_ID.HERO_UP)
end
@ -59,6 +60,7 @@ function HeroManager:heroStarReqFinish(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
DataManager.HeroData:onHeroStarUp(result.hero.id)
DataManager.HeroData:setDirty()
DataManager.HeroData:calcPower()
AudioManager:playEffect(AudioManager.EFFECT_ID.HERO_UP)
end

View File

@ -111,4 +111,15 @@ function MaincityManager:isActivSideBarModule(moduleKey)
return mainUI:isActivSideBarModule(moduleKey)
end
--@region 战斗力
function MaincityManager:checkShowPowerUI()
local curPower = DataManager.HeroData:getShowPower()
local lastPower = DataManager.HeroData:getLastPower()
if curPower ~= lastPower then
GFunc.hidePowerToast()
GFunc.showPowerToast(lastPower, curPower)
end
end
--@endregion
return MaincityManager

View File

@ -0,0 +1,129 @@
local PowerToastManager = class("PowerToastManager", BaseModule)
function PowerToastManager:ctor()
end
function PowerToastManager:clear()
self:clearSeq()
end
function PowerToastManager:hideToast()
self:showEffect(false)
UIManager:hidePowerToast()
end
function PowerToastManager:showToast(before, after, posY)
self.before = before
self.after = after
self.posY = posY or 243
self.power = self.before
self.diffVal = self.after - self.before
self:clearSeq()
self.isNew = true
UIManager:getPowerToast(function(prefabObject)
prefabObject:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS).enabled = true
local uiMap = prefabObject:genAllChildren()
self.bg = uiMap["power_change_toast.bg"]
self.powerTx = uiMap["power_change_toast.bg.power_tx"]
self.powerChange = uiMap["power_change_toast.bg.power_change_tx"]
-- self.powerSpine = uiMap["power_change_toast.bg.ui_spine_obj"]
-- self.effect1 = uiMap["power_change_toast.content.vfx_ui_zhanli_b01"]
-- self.effect2 = uiMap["power_change_toast.content.vfx_ui_zhanli_b03"]
self:showEffect(false)
self:showModuleUnlockAppearAnim()
-- self.powerSpine:playAnim("idle", false, true)
end)
end
-- 出现
function PowerToastManager:showModuleUnlockAppearAnim()
self.bg:setAnchoredPositionY(self.posY)
self.bg:setLocalScale(1, 1, 1)
-- if self.animEffect == nil then
-- self.animEffect = self.effect1:createBindTweenSequence()
-- self.animEffect:AppendInterval(0.3)
-- self.animEffect:AppendCallback(function()
-- self:showEffect(true)
-- end)
-- self.animEffect:AppendInterval(1)
-- self.animEffect:AppendCallback(function()
-- self:showEffect(false)
-- end)
-- else
-- self.animEffect:Restart()
-- end
if self.animAppear == nil then
self.animAppear = self.bg:createBindTweenSequence()
local tween = DOTweenManager:createDOTweenTo(
function()
return self.power
end,
function(value)
local str = GFunc.num2Str3(math.floor(value))
local str2 = GConst.EMPTY_STRING
local color = GConst.COLOR_CODE.LIGHT_GREEN
if self.diffVal > 0 then
str2 = "+" .. GFunc.num2Str3(self.diffVal)
else
str2 = "-" .. GFunc.num2Str3(math.abs(self.diffVal))
color = "#FF77D7"
end
self.powerTx:setText(str)
self.powerChange:setText(GFunc.colorText(color, str2))
end,
self.after, 1.5)
self.animAppear:Append(tween)
-- self.animAppear:Insert(1.45, self.bg:getTransform():DOScale(1.15, 0.2):SetLoops(2, CS.DG.Tweening.LoopType.Yoyo))
self.animAppear:SetAutoKill(true)
self.animAppear:OnComplete(function()
self.isNew = false
self:performWithDelayGlobal(function()
if self.isNew then
return
end
UIManager:hidePowerToast()
end, 0.5)
end)
else
self.animAppear:Restart()
end
end
function PowerToastManager:clearSeq()
if self.animEffect then
self.animEffect:Kill()
self.animEffect = nil
end
if self.animAppear then
self.animAppear:Kill()
self.animAppear = nil
end
end
function PowerToastManager:showEffect(show)
if self.effect1 then
self.effect1:setActive(false)
end
if self.effect2 then
self.effect2:setActive(false)
end
if not show then
return
end
if self.effect1 == nil or self.effect2 == nil then
return
end
self.effect1:setActive(true)
self.effect2:setActive(true)
self.effect1:play()
self.effect2:play()
self.effect1:setSortingOrder(28400, 0)
self.effect2:setSortingOrder(28400, 20)
end
return PowerToastManager

View File

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

View File

@ -244,6 +244,9 @@ function MainCityUI:_bind()
end
self:refreshBottomRp()
end)
self:bind(DataManager.HeroData, "isPowerDirty", function()
ModuleManager.MaincityManager:checkShowPowerUI()
end)
self:bind(DataManager.CollectionData, "isDirty", function()
self:refreshBottomRp()

View File

@ -737,9 +737,35 @@ function UIManager:hideRollToast(killSeq)
self.rollToast:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS).enabled = false
end
function UIManager:getPowerToast(callback)
if not self.powerToast then
UIPrefabManager:loadUIWidgetAsync("assets/prefabs/ui/common/power_change_toast.prefab", self.toastNode, function (_prefabObject)
if self.powerToast then
_prefabObject:destroy()
return
end
_prefabObject:initPrefabHelper()
self.powerToast = _prefabObject
callback(_prefabObject)
end)
else
callback(self.powerToast)
end
end
---- 回到登录界面时 killseq为true
function UIManager:hidePowerToast()
if not self.powerToast then
return
end
ModuleManager.PowerToastManager:clear()
self.powerToast:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS).enabled = false
end
function UIManager:hideToastAndMessageBox()
self:hideToast()
self:hideRollToast()
self:hidePowerToast()
end
function UIManager:getMainCanvasTransform()

View File

@ -8,6 +8,7 @@ function HeroData:ctor()
self.heroes = {}
self.data.activeCount = 0
self.data.isDirty = false
self.data.isPowerDirty = false
self.matchActiveHeroMap = {}
self.maxHeroLvOnInit = 0
@ -39,6 +40,8 @@ function HeroData:init(data)
self.matchActiveHeroMap[matchType][entity:getCfgId()] = true
end
end
self:calcPower()
end
-- 是否是合法的英雄
@ -338,4 +341,101 @@ function HeroData:calcAttr()
end
-- endregion
--@region 战斗力
function HeroData:getShowPower()
if self.curPower == nil then
self:calcPower()
end
return self.curPower
end
function HeroData:getLastPower()
return self.lastPower or 0
end
function HeroData:clearLastPower()
self.lastPower = nil
end
-- 计算战斗力
function HeroData:calcPower()
if self.lastPower then
self.lastPower = self.curPower
end
local attrPower = 0
local formation = DataManager.FormationData:getStageFormation()
for _, heroId in pairs(formation) do
local heroEntity = DataManager.HeroData:getHeroById(heroId)
if heroEntity then
attrPower = attrPower + heroEntity:getPower()
end
end
-- -- 天赋战力
-- local talentPower = DataManager.TalentData:getPower()
-- -- 英雄战力
-- local forcePower = DataManager.ForceData:getPower()
-- -- 英雄皮肤战力
-- local forceSkinPower = DataManager.ForceData:getSkinPower()
-- -- 英雄装备战力
-- local equipPower = DataManager.ForceEquipData:getPower()
-- -- 领主时装战力
-- local skinPower = DataManager.SkinData:getPower()
-- -- 宝物战力
-- local collectionPower = DataManager.CollectionData:getPower()
-- -- 防线战力
-- local defenseLinePower = DataManager.DefenseLineData:getPower()
-- -- 防线皮肤战力
-- local defenseLineSkinPower = DataManager.DefenseLineData:getSkinPower()
-- -- 宠物战力
-- local petPower = DataManager.PetData:getPower()
-- -- 魔法书战力
-- local magicBookPower = DataManager.MagicBookData:getPower()
-- -- 魔法阵战力
-- local magicCirclePower = DataManager.MagicCircleData:getPower()
self.curPower = 0
self.curPower = self.curPower + attrPower
-- self.curPower = self.curPower + talentPower
-- self.curPower = self.curPower + forcePower
-- self.curPower = self.curPower + forceSkinPower
-- self.curPower = self.curPower + equipPower
-- self.curPower = self.curPower + skinPower
-- self.curPower = self.curPower + collectionPower
-- self.curPower = self.curPower + defenseLinePower
-- self.curPower = self.curPower + defenseLineSkinPower
-- self.curPower = self.curPower + petPower
-- self.curPower = self.curPower + magicBookPower
-- self.curPower = self.curPower + magicCirclePower
-- if EDITOR_MODE and self:getIsSelf() then
-- Logger.logHighlight("PlayerEntity 总战力:" .. self.curPower)
-- Logger.logHighlight("PlayerEntity 属性战力:" .. attrPower)
-- Logger.logHighlight("PlayerEntity 天赋战力:" .. talentPower)
-- Logger.logHighlight("PlayerEntity 英雄战力:" .. forcePower)
-- Logger.logHighlight("PlayerEntity 英雄皮肤战力:" .. forceSkinPower)
-- Logger.logHighlight("PlayerEntity 英雄装备战力:" .. equipPower)
-- Logger.logHighlight("PlayerEntity 领主时装战力:" .. skinPower)
-- Logger.logHighlight("PlayerEntity 宝物战力:" .. collectionPower)
-- Logger.logHighlight("PlayerEntity 防线战力:" .. defenseLinePower)
-- Logger.logHighlight("PlayerEntity 防线皮肤战力:" .. defenseLineSkinPower)
-- Logger.logHighlight("PlayerEntity 宠物战力:" .. petPower)
-- Logger.logHighlight("PlayerEntity 魔法书战力:" .. magicBookPower)
-- Logger.logHighlight("PlayerEntity 魔法阵战力:" .. magicCirclePower)
-- end
if not self.lastPower then
self.lastPower = self.curPower
end
if self.lastPower ~= self.curPower then
self:setPowerDirty()
end
end
function HeroData:setPowerDirty()
self.data.isPowerDirty = not self.data.isPowerDirty
end
--@endregion
return HeroData

View File

@ -286,6 +286,7 @@ function HeroEntity:setLv(lv, onlyChangeLv)
self.data.lv = lv
self:_updateAllBaseAttr()
self:setDirty()
self:setAttrDirty()
if not onlyChangeLv then
ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP, lv)
@ -685,6 +686,7 @@ function HeroEntity:onHeroStarUp()
self.data.star = self.data.star + 1
self:setBaseAttrDirty()
self:setDirty()
self:setAttrDirty()
end
function HeroEntity:getMaxStar()
@ -725,7 +727,7 @@ function HeroEntity:setPowerDirty()
end
function HeroEntity:getPower()
if not self.curPower then
if not self.curPower or self.attrDirty then
self:getAllAttr()
end
return self.curPower
@ -757,7 +759,7 @@ function HeroEntity:_getAttrPower()
realValue = attrNum - 15000
end
power = power + math.floor(realValue * cfg.power / GConst.DEFAULT_FACTOR / GConst.DEFAULT_FACTOR + 0.0000001)
power = power + math.floor(realValue * cfg.power / GConst.DEFAULT_FACTOR + 0.0000001)
end
end