refactor(fight/effect): 重构伤害处理逻辑,统一使用DamageZone管理伤害值并优化Effect接口,移除过时方法
This commit is contained in:
@@ -10,9 +10,73 @@ import (
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func (u *Input) Death() {
|
||||
func (u *Input) BeforeSkill(opp *Input, skill *info.SkillEntity) {
|
||||
skill.AttackTimeC(int(u.GetProp(5, true))) //计算命中
|
||||
skill.Crit = 0
|
||||
if skill.Category() == info.Category.STATUS { //属性技能不用算暴击
|
||||
return
|
||||
}
|
||||
CritRate := utils.Max(skill.CritRate, 1)
|
||||
|
||||
u.CurrentPet.Info.Hp = 0
|
||||
//CritAtkFirst: 先出手时必定致命一击; 默认: 0
|
||||
if skill.CritAtkFirst != 0 && u.First {
|
||||
CritRate = 16
|
||||
}
|
||||
//CritAtkSecond: 后出手时必定致命一击; 默认: 0
|
||||
if skill.CritAtkSecond != 0 && !u.First {
|
||||
CritRate = 16
|
||||
}
|
||||
// CritSelfHalfHp: 自身体力低于一半时必定致命一击; 默认: 0
|
||||
if skill.CritSelfHalfHp != 0 && (u.CurrentPet.HP < int(u.CurrentPet.Info.MaxHp)/2) {
|
||||
CritRate = 16
|
||||
}
|
||||
// CritFoeHalfHp: 对方体力低于一半时必定致命一击; 默认: 0
|
||||
if skill.CritSelfHalfHp != 0 && (opp.CurrentPet.HP < int(opp.CurrentPet.Info.MaxHp)/2) {
|
||||
CritRate = 16
|
||||
}
|
||||
|
||||
//todo 暴击伤害
|
||||
if t, _, _ := u.Player.Roll(625*CritRate, 10000); t {
|
||||
skill.Crit = 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 伤害落实
|
||||
func (u *Input) Damage(attacker *Input, id int) {
|
||||
attacker.Exec(func(t Effect) bool {
|
||||
|
||||
t.BeforeAttack(u, attacker.GetDamage(0)) //红伤落实前,我方增伤
|
||||
|
||||
return true
|
||||
})
|
||||
attacker.Exec(func(t Effect) bool {
|
||||
|
||||
t.Attack(u, attacker.GetEffect(EffectType.Damage, id)) //红伤落实前,我方增伤
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
u.Exec(func(t Effect) bool {
|
||||
|
||||
t.BeforeAttacked(attacker, attacker.GetEffect(EffectType.Damage, id)) //红伤落实,内部有befer
|
||||
|
||||
return true
|
||||
})
|
||||
u.Exec(func(t Effect) bool {
|
||||
|
||||
t.Attacked(attacker, attacker.GetEffect(EffectType.Damage, id)) //红伤落实,内部有befer
|
||||
|
||||
return true
|
||||
})
|
||||
if uint32(attacker.GetEffect(EffectType.Damage, id).Effect.Stack()) > u.CurrentPet.Info.Hp {
|
||||
//这里其实是受到致死伤害
|
||||
//然后先触发死亡效果,消除所有buff
|
||||
//然后触发回神效果
|
||||
u.CurrentPet.Info.Hp = 0
|
||||
} else {
|
||||
u.CurrentPet.Info.Hp = u.CurrentPet.Info.Hp - u.AttackValue.LostHp
|
||||
}
|
||||
|
||||
//todo 待实现死亡effet
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ type Effect interface {
|
||||
PreSkill(opp *Input, skill *info.SkillEntity) //对技能修改,比如变威力
|
||||
BeforeSkill(opp *Input, skill *info.SkillEntity) // 技能命中前触发
|
||||
OnSkill(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断
|
||||
AfterSkill(opp *Input, skill *info.SkillEntity) // 技能命中后触发
|
||||
|
||||
// OnSkillPP() bool //技能PP减少节点
|
||||
AfterProp(t *Input)
|
||||
@@ -22,10 +21,10 @@ type Effect interface {
|
||||
BeferAttr(t *info.BattlePetEntity) //在获取属性后,比如视为对方属性
|
||||
SetArgs(input *Input, param ...int)
|
||||
|
||||
AddZone(opp *Input, skill *EffectID) //加区
|
||||
MulZone(opp *Input, skill *EffectID) //乘区
|
||||
BeforeAttacked(opp *Input, skill *info.SkillEntity) // 受击前触发
|
||||
Attacked(opp *Input, skill *info.SkillEntity) // 受击触发
|
||||
BeforeAttack(opp *Input, id int) // 攻击前触发 ,这时候就是+区间
|
||||
Attack(opp *Input, id int) // 攻击触发
|
||||
BeforeAttacked(opp *Input, id int) //受击前触发 这时候就是百分比减伤区间
|
||||
Attacked(opp *Input, id int) // 受击触发 这时候就是点数减伤
|
||||
|
||||
// Shield() bool // 护盾值变化时触发
|
||||
// PostDamage() bool // 伤害结算后触发(血量扣除后)
|
||||
|
||||
@@ -20,18 +20,19 @@ type Input struct {
|
||||
*info.AttackValue
|
||||
FightC common.FightI
|
||||
// info.BattleActionI
|
||||
Effects *utils.OrderedMap[int, Effect] //effects 实际上全局就是effect无限回合 //effects容器 技能的
|
||||
//Damage decimal.Decimal //造成伤害
|
||||
First bool //是否先手
|
||||
Effects *utils.OrderedMap[int, Effect] //effects 实际上全局就是effect无限回合 //effects容器 技能的
|
||||
DamageZone map[info.EnumCategory]int //伤害容器
|
||||
First bool //是否先手
|
||||
}
|
||||
|
||||
func NewInput(c common.FightI, p common.PlayerI) *Input {
|
||||
ret := &Input{FightC: c, Player: p}
|
||||
ret.Effects = utils.NewOrderedMap[int, Effect]()
|
||||
t := Geteffect(EffectType.Damage, 0)
|
||||
t.Effect.SetArgs(ret)
|
||||
ret.AddEffect(t) //添加默认基类,实现继承
|
||||
p.SetFightC(c) //给玩家设置战斗容器
|
||||
ret.DamageZone = make(map[info.EnumCategory]int)
|
||||
// t := Geteffect(EffectType.Damage, 0)
|
||||
// t.Effect.SetArgs(ret)
|
||||
// ret.AddEffect(t) //添加默认基类,实现继承
|
||||
p.SetFightC(c) //给玩家设置战斗容器
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ var EffectType = enum.New[struct {
|
||||
Skill EnumEffectType `enum:"1000000"` //技能
|
||||
//Prop EnumEffectType `enum:"2000000"` //属性
|
||||
Status EnumEffectType `enum:"3000000"` //状态
|
||||
Damage EnumEffectType `enum:"4000000"` //伤害
|
||||
|
||||
|
||||
}]()
|
||||
var NodeM = make(map[int]Effect, 0)
|
||||
@@ -67,11 +67,28 @@ func (c *Input) GetProp(id int, istue bool) int {
|
||||
return realValue
|
||||
|
||||
}
|
||||
func (c *Input) GetDamage(etype info.EnumCategory) int {
|
||||
rer, ok := c.DamageZone[etype]
|
||||
|
||||
func (c *Input) GetEffect(etype EnumEffectType, id int) Effect {
|
||||
rer, _ := c.Effects.Load(id + int(etype))
|
||||
if ok {
|
||||
|
||||
return rer
|
||||
return rer
|
||||
//todo 获取后GetEffect
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (c *Input) GetEffect(etype EnumEffectType, id int) *EffectID {
|
||||
rer, ok := c.Effects.Load(id + int(etype))
|
||||
|
||||
if ok {
|
||||
|
||||
return &EffectID{
|
||||
ID: id + int(etype),
|
||||
Effect: rer,
|
||||
}
|
||||
//todo 获取后GetEffect
|
||||
}
|
||||
return &EffectID{}
|
||||
}
|
||||
func (c *Input) StatEffect_Exist(id int) bool {
|
||||
rer, ok := c.Effects.Load(id + int(EffectType.Status))
|
||||
|
||||
Reference in New Issue
Block a user