From 72e6b8c7064163d08e4b5251e658de018177577f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Tue, 16 Sep 2025 22:51:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fight):=20=E9=87=8D=E6=9E=84=E6=88=98?= =?UTF-8?q?=E6=96=97=E7=B3=BB=E7=BB=9F=E6=95=88=E6=9E=9C=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 Effect0 基类效果 - 调整 Input 结构,删除未使用的属性 - 优化 Effect 接口,增加 GetMaxStack 方法 - 重构效果初始化逻辑,支持不同类型效果的初始化 - 优化效果的添加和移除操作 - 调整宠物效果信息结构,合并参数 --- logic/service/fight/effect/effect.prop.go | 24 +++++++++++++ .../effect/{base.go => effect_damage.go} | 0 logic/service/fight/effect/effect_status.go | 1 + logic/service/fight/info/BattlePetEntity.go | 4 +-- logic/service/fight/input/input.go | 9 ++--- logic/service/fight/input/nodemanger.go | 35 +++++++++++++------ logic/service/fight/node/node.go | 6 ++-- logic/service/player/player.go | 7 ++-- modules/blazing/model/pet.go | 10 +++--- 9 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 logic/service/fight/effect/effect.prop.go rename logic/service/fight/effect/{base.go => effect_damage.go} (100%) create mode 100644 logic/service/fight/effect/effect_status.go diff --git a/logic/service/fight/effect/effect.prop.go b/logic/service/fight/effect/effect.prop.go new file mode 100644 index 000000000..ff2a5b556 --- /dev/null +++ b/logic/service/fight/effect/effect.prop.go @@ -0,0 +1,24 @@ +package effect + +import ( + "blazing/logic/service/fight/input" + "blazing/logic/service/fight/node" +) + +type Prop struct { + node.EffectNode +} + +func init() { + + prop := &Prop{ + EffectNode: node.EffectNode{ + MaxStack: 6, + }, + } + + for i := 1; i < 7; i++ { + input.InitPropEffect(i, prop) + + } +} diff --git a/logic/service/fight/effect/base.go b/logic/service/fight/effect/effect_damage.go similarity index 100% rename from logic/service/fight/effect/base.go rename to logic/service/fight/effect/effect_damage.go diff --git a/logic/service/fight/effect/effect_status.go b/logic/service/fight/effect/effect_status.go new file mode 100644 index 000000000..f2b52b16b --- /dev/null +++ b/logic/service/fight/effect/effect_status.go @@ -0,0 +1 @@ +package effect diff --git a/logic/service/fight/info/BattlePetEntity.go b/logic/service/fight/info/BattlePetEntity.go index 5b20867f7..b6accbd1d 100644 --- a/logic/service/fight/info/BattlePetEntity.go +++ b/logic/service/fight/info/BattlePetEntity.go @@ -111,9 +111,9 @@ type BattlePetEntity struct { statusConditions sync.Map // key: StatusCondition, value: int (剩余回合) Skills [4]*SkillEntity // 技能槽(最多4个技能) - Status StatusDict //精灵的状态 + //Status StatusDict //精灵的状态 //能力提升属性 - Prop PropDict + //Prop PropDict NotAlive bool `struc:"skip"` DamageZone map[EnumCategory]map[EnumsZoneType]map[EnumsZoneType][]float64 // 三维map 伤害类型-》增还是减-》加还是乘-》值 } diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index 335c2ebcd..6dfe691b7 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -18,12 +18,9 @@ type Input struct { *info.AttackValue FightC common.FightI // info.BattleActionI - Effects []Effect //effects 实际上全局就是effect无限回合 //effects容器 技能的 - // Prop NodeManager //属性容器 - // Status NodeManager //状态容器 - //NewSeIdx NodeManager //全局容器 - Damage decimal.Decimal //造成伤害 - First bool //是否先手 + Effects []Effect //effects 实际上全局就是effect无限回合 //effects容器 技能的 + Damage decimal.Decimal //造成伤害 + First bool //是否先手 } func NewInput(c common.FightI, p common.PlayerI) *Input { diff --git a/logic/service/fight/input/nodemanger.go b/logic/service/fight/input/nodemanger.go index bf9f31f37..00519ac3e 100644 --- a/logic/service/fight/input/nodemanger.go +++ b/logic/service/fight/input/nodemanger.go @@ -69,7 +69,7 @@ type Effect interface { GetArgSize() int Alive() bool Stack(int) int - MaxStack() int + GetMaxStack() int NotALive() GetOwner() bool // 技能属主,比如寄生和镇魂歌,属主是对方) //GetSkill() *BattleSkillEntity //获得技能ctx @@ -81,6 +81,14 @@ func InitSkillEffect(id int, t Effect) { NodeM[id+1000000] = t } +func InitPropEffect(id int, t Effect) { + + NodeM[id+2000000] = t +} +func InitStatusEffect(id int, t Effect) { + + NodeM[id+3000000] = t +} func getTypeName(v interface{}) string { // 获取类型信息 t := reflect.TypeOf(v) @@ -123,13 +131,16 @@ func (c *Input) AddEffect(e Effect) { // 删除 func (c *Input) RemoveEffect(e Effect) { - //*var remain []Effect - for _, eff := range c.Effects { - if eff.ID() == e.ID() { - eff.NotALive() + + slice := c.Effects + for i := 0; i < len(slice); { + if slice[i].ID() == e.ID() { + slice = append(slice[:i], slice[i+1:]...) + } else { + i++ } } - //c.Effects = remain + c.Effects = slice } // ForEachEffectBool 遍历所有 Effect,执行“无参数、返回 bool”的方法 @@ -154,12 +165,14 @@ func (c *Input) Exec(fn func(Effect) bool) bool { // 消除回合类效果 efftype 输入是消对方的还是自己的,false是自己,true是对方 func (c *Input) CancelTurn(efftype bool) { - //var remain []Effect - for _, eff := range c.Effects { - if eff.Duration(0) > 0 { //false是自身,true是对方,反转后为真就是自己的 - eff.NotALive() + slice := c.Effects + for i := 0; i < len(slice); { + if slice[i].Duration(0) > 0 { //false是自身,true是对方,反转后为真就是自己的 + slice = append(slice[:i], slice[i+1:]...) + } else { + i++ } } - //c.Effects = remain + c.Effects = slice } diff --git a/logic/service/fight/node/node.go b/logic/service/fight/node/node.go index 7a46551f1..eb62e21cb 100644 --- a/logic/service/fight/node/node.go +++ b/logic/service/fight/node/node.go @@ -16,7 +16,7 @@ type EffectNode struct { Input *input.Input stacks int // 当前层数 ArgSize int - maxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果 ,异常和能力的叠层 + MaxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果 ,异常和能力的叠层 SideEffectArgs []int // 附加效果参数 Owner bool //是否作用自身 Success bool // 是否执行成功 成功XXX,失败XXX @@ -59,9 +59,9 @@ func (this *EffectNode) Stack(t int) int { return this.stacks } -func (this *EffectNode) MaxStack() int { +func (this *EffectNode) GetMaxStack() int { - return this.maxStack + return this.MaxStack } func (this *EffectNode) Duration(t int) int { diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 925c39a07..a479ba8f0 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -67,7 +67,7 @@ func (c *Conn) SendPack(bytes []byte) error { _, err := c.MainConn.Write(bytes) if err != nil { - logging.Error(err) + glog.Debug(context.Background(), err) } } @@ -224,8 +224,9 @@ func LeaveMap(c common.PlayerI) { t := NewTomeeHeader(2002, c.ID()) space.GetSpace(c.MapID()).Range(func(playerID uint32, player common.PlayerI) bool { - - player.SendPack(t.Pack(&space.LeaveMapOutboundInfo{UserID: c.ID()})) + if playerID != c.ID() { + player.SendPack(t.Pack(&space.LeaveMapOutboundInfo{UserID: c.ID()})) + } return true }) diff --git a/modules/blazing/model/pet.go b/modules/blazing/model/pet.go index 2c6258e1e..ecbb83877 100644 --- a/modules/blazing/model/pet.go +++ b/modules/blazing/model/pet.go @@ -92,8 +92,8 @@ func GenPetInfo(id int, dv, natureId, abilityTypeEnum, shinyid, level []int) *Pe }) naxml := xmlres.NatureRootMap[int(p.Nature)] petxml := xmlres.PetMAP[int(id)] - p.EffectInfo[0].Args1 = byte(petxml.Type) //默认本族加成 - p.EffectInfo[0].Args2 = 5 //默认等级1 + + p.EffectInfo[0].Args = []int{petxml.Type, 5} //默认等级1 tttt := make([]uint32, 0) for _, v := range petxml.LearnableMoves.Moves { if p.Level >= uint32(v.LearningLv) { @@ -286,9 +286,9 @@ type PetEffectInfo struct { Status byte `struc:"byte" json:"status"` //特性为1,能量珠为2 LeftCount byte `struc:"byte" json:"left_count"` //剩余次数 EID uint16 `struc:"uint16" json:"effect_id"` //特效ID - Args1 byte `struc:"byte" json:"reserve1"` //参数1 - Args2 byte `struc:"byte" json:"reserve3"` //参数2 - Args []int `struc:"skip" json:"Args"` //自定义参数装载 + ArgsLen uint32 `struc:"sizeof=Args"` + + Args []int ` json:"Args"` //自定义参数装载 }