refactor(fight): 重构战斗系统效果处理逻辑
- 移除 Effect0 基类效果 - 调整 Input 结构,删除未使用的属性 - 优化 Effect 接口,增加 GetMaxStack 方法 - 重构效果初始化逻辑,支持不同类型效果的初始化 - 优化效果的添加和移除操作 - 调整宠物效果信息结构,合并参数
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user