refactor(fight/effect): 重构伤害处理逻辑,统一使用DamageZone管理伤害值并优化Effect接口,移除过时方法
This commit is contained in:
@@ -18,7 +18,7 @@ func init() {
|
||||
|
||||
}
|
||||
func (e *Effect1) AfterSkill(opp *input.Input, skill *info.SkillEntity) {
|
||||
t := e.Input.GetEffect(input.EffectType.Damage, 0).Stack()
|
||||
e.Input.CurrentPet.Info.Hp += uint32(t / 2)
|
||||
|
||||
e.Input.CurrentPet.Info.Hp += uint32(e.Input.GetDamage(0) / 2)
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package effect
|
||||
|
||||
import (
|
||||
"blazing/common/utils"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/fight/node"
|
||||
)
|
||||
@@ -23,7 +22,7 @@ type Effect8 struct {
|
||||
}
|
||||
|
||||
// 伤害落实前触发,限制最大伤害
|
||||
func (e *Effect8) BeforeAttacked(opp *input.Input, skill *info.SkillEntity) {
|
||||
func (e *Effect8) Attack(opp *input.Input, eff *input.EffectID) {
|
||||
|
||||
// //在这里修改伤害
|
||||
// if opp.GetEffect(input.EffectType.Damage, 0).MaxStack() != 0 { //限制最大伤害
|
||||
@@ -31,8 +30,8 @@ func (e *Effect8) BeforeAttacked(opp *input.Input, skill *info.SkillEntity) {
|
||||
// }
|
||||
|
||||
opp.Pet(e.Input, func() { //我方取敌方属性
|
||||
dg := utils.Min(e.Input.GetEffect(input.EffectType.Damage, 0).Stack(), int(opp.CurrentPet.Info.Hp)-1)
|
||||
e.Input.GetEffect(input.EffectType.Damage, 0).Stack(dg)
|
||||
|
||||
e.Input.DamageZone[0] = utils.Min(e.Input.GetDamage(0), int(opp.CurrentPet.Info.Hp)-1)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
package effect
|
||||
|
||||
import (
|
||||
"blazing/common/utils"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/fight/node"
|
||||
)
|
||||
|
||||
// 施加一个基类effect
|
||||
type Effect0 struct {
|
||||
node.EffectNode
|
||||
}
|
||||
|
||||
func (e *Effect0) OnSwitchOut() bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *Effect0) OnOwnerSwitchIn() bool {
|
||||
|
||||
return true
|
||||
}
|
||||
func (e *Effect0) TurnEnd(opp *input.Input) {
|
||||
e.Input.AttackValue.RemainHp = int32(e.Input.CurrentPet.Info.Hp)
|
||||
|
||||
}
|
||||
|
||||
// 使用技能时
|
||||
func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) {
|
||||
e.Input.Skill(skill, func() { //变威力作用
|
||||
|
||||
e.Stack(int(e.Input.CalculatePower(opp, skill).IntPart()))
|
||||
})
|
||||
|
||||
e.Input.Exec(func(t input.Effect) bool { //计算暴击率加成
|
||||
|
||||
e.Input.AttackValue.IsCritical = skill.Crit
|
||||
return e.Input.AttackValue.IsCritical == 0
|
||||
})
|
||||
e.Input.Exec(func(t input.Effect) bool { //加伤
|
||||
|
||||
t.AddZone(e.Input, &input.EffectID{
|
||||
ID: 1,
|
||||
Effect: e,
|
||||
})
|
||||
return true
|
||||
})
|
||||
e.Input.Exec(func(t input.Effect) bool { //乘伤
|
||||
|
||||
t.MulZone(e.Input, &input.EffectID{
|
||||
ID: 1,
|
||||
Effect: e,
|
||||
})
|
||||
return true
|
||||
})
|
||||
if e.Input.AttackValue.IsCritical == 1 {
|
||||
|
||||
e.Stack(e.Stack() * 2)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
func (e *Effect0) BeforeSkill(opp *input.Input, skill *info.SkillEntity) {
|
||||
skill.AttackTimeC(int(opp.GetProp(5, true))) //计算命中
|
||||
skill.Crit = 0
|
||||
if skill.Category() == info.Category.STATUS { //属性技能不用算暴击
|
||||
return
|
||||
}
|
||||
CritRate := utils.Max(skill.CritRate, 1)
|
||||
|
||||
//CritAtkFirst: 先出手时必定致命一击; 默认: 0
|
||||
if skill.CritAtkFirst != 0 && e.Input.First {
|
||||
CritRate = 16
|
||||
}
|
||||
//CritAtkSecond: 后出手时必定致命一击; 默认: 0
|
||||
if skill.CritAtkSecond != 0 && !e.Input.First {
|
||||
CritRate = 16
|
||||
}
|
||||
// CritSelfHalfHp: 自身体力低于一半时必定致命一击; 默认: 0
|
||||
if skill.CritSelfHalfHp != 0 && (e.Input.CurrentPet.HP < int(e.Input.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, _, _ := e.Input.Player.Roll(625*CritRate, 10000); t {
|
||||
skill.Crit = 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 受击触发
|
||||
func (e *Effect0) Attacked(opp *input.Input, skill *info.SkillEntity) {
|
||||
|
||||
e.Input.Exec(func(t input.Effect) bool { //加伤
|
||||
|
||||
t.AddZone(opp, &input.EffectID{
|
||||
ID: 1,
|
||||
Effect: e,
|
||||
})
|
||||
return true
|
||||
})
|
||||
e.Input.Exec(func(t input.Effect) bool { //乘伤
|
||||
|
||||
t.MulZone(opp, &input.EffectID{
|
||||
ID: 1,
|
||||
Effect: e,
|
||||
})
|
||||
return true
|
||||
})
|
||||
|
||||
|
||||
opp.AttackValue.LostHp = uint32(opp.GetEffect(input.EffectType.Damage, 0).Stack())
|
||||
if uint32(opp.AttackValue.LostHp) > e.Input.CurrentPet.Info.Hp {
|
||||
//这里其实是受到致死伤害
|
||||
//然后先触发死亡效果,消除所有buff
|
||||
//然后触发回神效果
|
||||
e.Input.CurrentPet.Info.Hp = 0
|
||||
} else {
|
||||
e.Input.CurrentPet.Info.Hp = e.Input.CurrentPet.Info.Hp - opp.AttackValue.LostHp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
input.InitEffect(input.EffectType.Damage, 0, &Effect0{})
|
||||
|
||||
}
|
||||
@@ -12,25 +12,52 @@ type EffectStatus struct {
|
||||
Status info.EnumBattleStatus
|
||||
}
|
||||
|
||||
type EffectStatusNotSkill struct {
|
||||
type StatusNotSkill struct {
|
||||
EffectStatus
|
||||
}
|
||||
|
||||
func (e *EffectStatusNotSkill) CanSkill(opp *input.Input) bool {
|
||||
func (e *StatusNotSkill) CanSkill(opp *input.Input) bool {
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
// 扣血类
|
||||
type DrainHP struct {
|
||||
EffectStatus
|
||||
}
|
||||
|
||||
func (e *DrainHP) OnTurnStart(opp *input.Input) {
|
||||
e.Input.Pet(e.Input, func() { //我方取我方
|
||||
e.Input.CurrentPet.Info.Hp = -e.Input.CurrentPet.Info.MaxHp / 8
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 被寄生种子 扣血类
|
||||
type StatusDrainedHP struct {
|
||||
DrainHP
|
||||
}
|
||||
|
||||
func (e *StatusDrainedHP) OnTurnStart(opp *input.Input) {
|
||||
e.DrainHP.OnTurnStart(opp)
|
||||
opp.Pet(e.Input, func() { //我方取我方
|
||||
opp.CurrentPet.Info.Hp = -e.Input.CurrentPet.Info.MaxHp / 8
|
||||
})
|
||||
|
||||
}
|
||||
func init() {
|
||||
//麻痹,疲惫,害怕,石化,都是无法行动
|
||||
|
||||
tt := func(t info.EnumBattleStatus, f *EffectStatusNotSkill) {
|
||||
tt := func(t info.EnumBattleStatus, f *StatusNotSkill) {
|
||||
|
||||
f.Status = t
|
||||
input.InitEffect(input.EffectType.Status, int(t), f)
|
||||
}
|
||||
tt(info.PetStatus.Paralysis, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Tired, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Sleep, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Petrified, &EffectStatusNotSkill{})
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.DrainHP), &EffectStatus{}) //寄生种子
|
||||
|
||||
tt(info.PetStatus.Paralysis, &StatusNotSkill{})
|
||||
tt(info.PetStatus.Tired, &StatusNotSkill{})
|
||||
tt(info.PetStatus.Sleep, &StatusNotSkill{})
|
||||
tt(info.PetStatus.Petrified, &StatusNotSkill{})
|
||||
|
||||
}
|
||||
|
||||
@@ -434,11 +434,25 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *SelectSk
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
attacker.BeforeSkill(defender, a.Skill)
|
||||
attacker.AttackValue.AttackTime = a.Skill.AttackTime
|
||||
f.parseskill(attacker, defender, a) //是否miss都应该施加解析effect
|
||||
|
||||
if attacker.AttackValue.AttackTime > 0 { //如果命中
|
||||
|
||||
attacker.Skill(a.Skill, func() { //变威力作用
|
||||
attacker.DamageZone[0] = int(attacker.CalculatePower(defender, a.Skill).IntPart())
|
||||
|
||||
})
|
||||
|
||||
attacker.AttackValue.IsCritical = a.Skill.Crit
|
||||
|
||||
if attacker.AttackValue.IsCritical == 1 {
|
||||
|
||||
attacker.DamageZone[0] *= 2
|
||||
|
||||
}
|
||||
|
||||
attacker.Exec(func(t input.Effect) bool {
|
||||
t.Hit(true) //我方效果命中
|
||||
|
||||
@@ -455,26 +469,10 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *SelectSk
|
||||
})
|
||||
// 扣减防御方血量
|
||||
|
||||
} //todo 处理未命中效果
|
||||
attacker.Exec(func(t input.Effect) bool {
|
||||
}
|
||||
|
||||
t.BeforeAttacked(attacker, a.Skill) //红伤落实前
|
||||
|
||||
return true
|
||||
})
|
||||
defender.Exec(func(t input.Effect) bool {
|
||||
|
||||
t.Attacked(attacker, a.Skill) //红伤落实
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
attacker.Exec(func(t input.Effect) bool {
|
||||
|
||||
t.AfterSkill(defender, a.Skill) //技能使用完毕后结算
|
||||
|
||||
return true
|
||||
})
|
||||
defender.Damage(attacker, 0)
|
||||
attacker.AttackValue.LostHp = uint32(attacker.GetEffect(input.EffectType.Damage, 0).Effect.Stack()) //红伤落实
|
||||
}
|
||||
|
||||
//回合有先手方和后手方,同时有攻击方和被攻击方
|
||||
@@ -528,7 +526,7 @@ func (f *FightC) enterturn(fattack, sattack BattleActionI) {
|
||||
skill.Skill.Info.PP-- //减少PP
|
||||
}
|
||||
fmt.Println(i,
|
||||
"玩家技能伤害:", attacker.GetEffect(input.EffectType.Damage, 0).Stack(),
|
||||
"玩家技能伤害:", attacker.GetEffect(input.EffectType.Damage, 0).Effect.Stack(),
|
||||
"自身剩余血量:", attacker.CurrentPet.Info.Hp,
|
||||
"对手剩余血量:", defender.CurrentPet.Info.Hp,
|
||||
)
|
||||
@@ -569,6 +567,8 @@ func (f *FightC) enterturn(fattack, sattack BattleActionI) {
|
||||
t.TurnEnd(f.First) //返回本身结算,如果false,说明不能使用技能了
|
||||
return true
|
||||
})
|
||||
f.First.AttackValue.RemainHp = int32(f.First.CurrentPet.Info.Hp)
|
||||
f.Second.AttackValue.RemainHp = int32(f.Second.CurrentPet.Info.Hp)
|
||||
ret := info.AttackValueS{
|
||||
FAttack: *f.First.AttackValue,
|
||||
SAttack: *f.Second.AttackValue,
|
||||
@@ -577,12 +577,12 @@ func (f *FightC) enterturn(fattack, sattack BattleActionI) {
|
||||
for i := 0; i < 20; i++ { //堆叠状态剩余回合
|
||||
|
||||
t := f.First.GetEffect(input.EffectType.Status, i)
|
||||
if t != nil {
|
||||
ret.FAttack.Status[i] = int8(t.Duration())
|
||||
if t.ID != 0 {
|
||||
ret.FAttack.Status[i] = int8(t.Effect.Duration())
|
||||
}
|
||||
t = f.Second.GetEffect(input.EffectType.Status, i)
|
||||
if t != nil {
|
||||
ret.FAttack.Status[i] = int8(t.Duration())
|
||||
if t.ID != 0 {
|
||||
ret.FAttack.Status[i] = int8(t.Effect.Duration())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
)
|
||||
|
||||
// 加算区
|
||||
func (e *EffectNode) AddZone(opp *input.Input, skill *input.EffectID) {
|
||||
|
||||
}
|
||||
|
||||
// 乘算区
|
||||
func (e *EffectNode) MulZone(opp *input.Input, skill *input.EffectID) {
|
||||
|
||||
// 受击触发
|
||||
func (this *EffectNode) Attack(opp *input.Input, eff *input.EffectID) {
|
||||
}
|
||||
|
||||
// 受击触发
|
||||
func (this *EffectNode) Attacked(opp *input.Input, skill *info.SkillEntity) {
|
||||
func (this *EffectNode) BeforeAttack(opp *input.Input, eff *input.EffectID) {
|
||||
}
|
||||
|
||||
// 受击触发
|
||||
func (this *EffectNode) BeforeAttacked(opp *input.Input, skill *info.SkillEntity) {
|
||||
func (this *EffectNode) Attacked(opp *input.Input, eff *input.EffectID) {
|
||||
}
|
||||
|
||||
// 受击触发
|
||||
func (this *EffectNode) BeforeAttacked(opp *input.Input, eff *input.EffectID) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user