refactor(fight): 重构战斗状态效果系统

- 重命名BaseStatus.Switch方法为SwitchOut以提高语义清晰度
- 修改ParasiticSeed结构体继承关系,从BaseStatus改为EffectNode
- 添加Status字段用于存储状态类型枚举
- 修复战斗循环中血量计算逻辑,使用Min替代Max确保血量不超过上限
- 完善PetSwitch逻辑,确保我方单位下场时状态正确失效

fix(fight): 修复战斗播报和切换逻辑

- 在战斗回合信息中添加技能
This commit is contained in:
2025-12-26 03:51:24 +08:00
parent 143e02de77
commit fd4c494530
10 changed files with 99 additions and 75 deletions

View File

@@ -18,7 +18,7 @@ type BaseStatus struct {
}
// 重写切换事件:我方单位切换时清除状态
func (e *BaseStatus) Switch(in *input.Input, _ info.AttackValue, _ *info.BattlePetEntity) bool {
func (e *BaseStatus) SwitchOut(in *input.Input) bool {
// 我方单位下场时,状态失效
if in == e.Ctx().Our {
e.Alive(false)
@@ -94,7 +94,8 @@ func (e *Burned) Skill_Hit() bool {
// 寄生种子状态:扣血同时给对方回血
type ParasiticSeed struct {
BaseStatus
node.EffectNode
Status info.EnumPetStatus // 状态类型枚举
}
// 技能命中前触发寄生效果

View File

@@ -249,6 +249,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
}
fmt.Println(i,
"技能名称:", attacker.CurrentPet.Info.Name,
"玩家技能伤害:", attacker.SumDamage,
"自身剩余血量:", attacker.CurrentPet.Info.Hp,
"对手剩余血量:", defender.CurrentPet.Info.Hp,
@@ -291,7 +292,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
defender.CurrentPet.NotAlive = true
f.Broadcast(func(ff *input.Input) {
defender.Exec(func(t input.Effect) bool {
ff.Exec(func(t input.Effect) bool {
t.SwitchOut(defender)

View File

@@ -64,7 +64,7 @@ func (f *FightC) battleLoop() {
}
ff.Player.GetInfo().PetList[j].Hp = utils.Max(ff.Player.GetInfo().PetList[j].MaxHp, ff.AllPet[i].Info.Hp)
ff.Player.GetInfo().PetList[j].Hp = utils.Min(ff.Player.GetInfo().PetList[j].MaxHp, ff.AllPet[i].Info.Hp)
ff.Player.GetInfo().PetList[j].SkillList = ff.AllPet[i].Info.SkillList
}

View File

@@ -17,5 +17,9 @@ func (e *EffectNode) SwitchOut(in *input.Input) bool {
///我放下场
e.Alive(false)
}
if in == e.Ctx().Our {
e.Alive(false)
}
return true
}

View File

@@ -5,18 +5,18 @@ import (
"blazing/modules/config/service"
)
type MeleeController struct {
type CdkController struct {
*cool.Controller
}
func init() {
var task_info_controller = &MeleeController{
&cool.Controller{
Prefix: "/admin/monster/melee",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewMELEEService(),
},
}
// 注册路由
cool.RegisterController(task_info_controller)
cool.RegisterController(&CdkController{
&cool.Controller{
Prefix: "/admin/game/cdk",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewCdkService(),
},
})
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"blazing/cool"
"blazing/modules/config/service"
)
type ItemController struct {
*cool.Controller
}
func init() {
// 注册路由
cool.RegisterController(&ItemController{
&cool.Controller{
Prefix: "/admin/game/item",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewItemService(),
},
})
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"blazing/cool"
"blazing/modules/config/service"
)
type ColorController struct {
*cool.Controller
}
func init() {
// 注册路由
cool.RegisterController(&ColorController{
&cool.Controller{
Prefix: "/admin/game/shiny",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewShinyService(),
},
})
}

View File

@@ -1,10 +1,7 @@
package model
import (
"blazing/common/data"
"blazing/cool"
"errors"
"fmt"
)
// 表名常量定义:炫彩皮肤表
@@ -31,16 +28,6 @@ type ColorfulSkin struct {
Remark string `gorm:"size:512;default:'';comment:'炫彩皮肤备注'" json:"remark" description:"备注信息"`
}
// ColorfulSkinEX 炫彩皮肤扩展模型(用于前端/业务层展示,非数据库存储字段)
type ColorfulSkinEX struct {
ColorfulSkin // 嵌入核心炫彩皮肤模型
ColorS data.GlowFilter `json:"color" description:"光环名称(前端展示用,关联光环配置表查询)"`
BindElfNames []string `json:"bind_elf_names" description:"绑定精灵名称列表"`
IsEnabledDesc string `json:"is_enabled_desc" description:"启用状态描述"`
IsUniversalDesc string `json:"is_universal_desc" description:"通用状态描述"`
}
// -------------------------- 核心配套方法(仅更名适配,逻辑不变)--------------------------
func (*ColorfulSkin) TableName() string {
return TableNameColorfulSkin
@@ -65,55 +52,6 @@ func NewColorfulSkin() *ColorfulSkin {
}
}
// -------------------------- 业务操作方法(逻辑不变,仅调整提示信息标识)--------------------------
// AddBindElfId 为炫彩皮肤添加单个绑定精灵ID避免重复添加
func (c *ColorfulSkin) AddBindElfId(elfId uint32) error {
if elfId == 0 {
return errors.New("绑定精灵ID不能为空不能为0")
}
// 检查是否已绑定,避免重复
for _, id := range c.BindElfIds {
if id == elfId {
return fmt.Errorf("精灵ID%d已绑定当前炫彩皮肤配置无需重复添加", elfId)
}
}
c.BindElfIds = append(c.BindElfIds, elfId)
return nil
}
// RemoveBindElfId 从炫彩皮肤移除单个绑定精灵ID
func (c *ColorfulSkin) RemoveBindElfId(elfId uint32) error {
if elfId == 0 {
return errors.New("绑定精灵ID不能为空不能为0")
}
for i, id := range c.BindElfIds {
if id == elfId {
c.BindElfIds = append(c.BindElfIds[:i], c.BindElfIds[i+1:]...)
return nil
}
}
return fmt.Errorf("当前炫彩皮肤配置未绑定精灵ID%d无法移除", elfId)
}
// AddRefreshCount 增加刷新次数支持批量累加默认累加1
func (c *ColorfulSkin) AddRefreshCount(addNum uint32) error {
if addNum <= 0 {
return errors.New("增加的刷新次数必须大于0")
}
c.RefreshCount += addNum
return nil
}
// AddUsageCount 增加使用次数支持批量累加默认累加1
func (c *ColorfulSkin) AddUsageCount(addNum uint32) error {
if addNum <= 0 {
return errors.New("增加的使用次数必须大于0")
}
c.UsageCount += addNum
return nil
}
// -------------------------- 表结构自动同步 --------------------------
func init() {
cool.CreateTable(&ColorfulSkin{})

View File

@@ -0,0 +1,18 @@
package service
import (
"blazing/cool"
"blazing/modules/config/model"
)
type CdkService struct {
*cool.Service
}
func NewCdkService() *CdkService {
return &CdkService{
&cool.Service{
Model: model.NewCDKConfig(),
},
}
}

View File

@@ -0,0 +1,18 @@
package service
import (
"blazing/cool"
"blazing/modules/config/model"
)
type ShinyService struct {
*cool.Service
}
func NewShinyService() *ShinyService {
return &ShinyService{
&cool.Service{
Model: model.NewColorfulSkin(),
},
}
}