feat(fight): 调整精灵切换逻辑与属性计算流程

移除 OnOwnerSwitchIn 和 OnOwnerSwitchOut 接口定义及调用逻辑,
简化精灵切换时的效果触发机制。

调整 PetInfo 属性计算方法中 Hp 与 MaxHp 的赋值顺序,
确保初始化时 Hp 值正确设置。
This commit is contained in:
2025-11-08 01:07:37 +08:00
parent 06cd6199b0
commit 28bef2cf98
4 changed files with 8 additions and 19 deletions

View File

@@ -34,8 +34,8 @@ type Effect interface {
//OnDefeat(opp *Input) bool // 精灵被击败时触发 //OnDefeat(opp *Input) bool // 精灵被击败时触发
OnSwitchIn(ctx Ctx) bool // 精灵出战 / 上场时触发 OnSwitchIn(ctx Ctx) bool // 精灵出战 / 上场时触发
OnSwitchOut(ctx Ctx) bool // 精灵下场时触发 OnSwitchOut(ctx Ctx) bool // 精灵下场时触发
OnOwnerSwitchIn(ctx Ctx) bool // 所属玩家精灵出战时触发 // OnOwnerSwitchIn(ctx Ctx) bool // 所属玩家精灵出战时触发
OnOwnerSwitchOut(ctx Ctx) bool // 所属玩家精灵下场时触发 // OnOwnerSwitchOut(ctx Ctx) bool // 所属玩家精灵下场时触发
Turn_End(ctx Ctx) //回合结束计算 Turn_End(ctx Ctx) //回合结束计算
PreBattleEnd(ctx Ctx) bool //战斗结束前 PreBattleEnd(ctx Ctx) bool //战斗结束前

View File

@@ -44,12 +44,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
} }
f.Switch = append(f.Switch, ret) f.Switch = append(f.Switch, ret)
f.GetInputByPlayer(c, false).InitAttackValue() //切换精灵消除能力提升 f.GetInputByPlayer(c, false).InitAttackValue() //切换精灵消除能力提升
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
t.OnOwnerSwitchOut(input.Ctx{})
return true
})
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool { f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
t.OnSwitchOut(input.Ctx{}) t.OnSwitchOut(input.Ctx{})
@@ -57,18 +52,14 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
return true return true
}) })
f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id) f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id)
f.GetInputByPlayer(c, false).Effects = make([]input.Effect, 0) //清除效果类
f.Broadcast(func(ff *input.Input) { //先给自身广播 f.Broadcast(func(ff *input.Input) { //先给自身广播
if ff.Player.GetInfo().UserID == c.GetInfo().UserID { if ff.Player.GetInfo().UserID == c.GetInfo().UserID {
ff.Player.SendChangePet(ret.Reason) ff.Player.SendChangePet(ret.Reason)
} }
}) })
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
t.OnOwnerSwitchIn(input.Ctx{})
return true
})
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool { f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
t.OnSwitchIn(input.Ctx{}) t.OnSwitchIn(input.Ctx{})

View File

@@ -282,7 +282,6 @@ func GenPetInfo(
// ---- 属性计算 ---- // ---- 属性计算 ----
p.CalculatePetPane() p.CalculatePetPane()
p.Hp = p.MaxHp
p.Update(true) p.Update(true)

View File

@@ -34,12 +34,13 @@ func (p *PetInfo) CalculatePetPane() {
naxml := xmlres.NatureRootMap[int(p.Nature)] naxml := xmlres.NatureRootMap[int(p.Nature)]
petxml := xmlres.PetMAP[int(p.ID)] petxml := xmlres.PetMAP[int(p.ID)]
// 计算各项属性 // 计算各项属性
hp := p.calculatePetHPPanelSize( p.MaxHp = p.calculatePetHPPanelSize(
uint32(petxml.HP), uint32(petxml.HP),
p.Dv, p.Dv,
p.Level, p.Level,
p.Ev[0], p.Ev[0],
) )
p.Hp = p.MaxHp
// * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5) // * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5)
p.Prop[0] = p.calculatePetPanelSize( p.Prop[0] = p.calculatePetPanelSize(
uint32(petxml.Atk), uint32(petxml.Atk),
@@ -81,6 +82,4 @@ func (p *PetInfo) CalculatePetPane() {
naxml.SpeedCorrect, naxml.SpeedCorrect,
) )
// 设置计算结果
p.MaxHp = hp
} }