fix(fight): 修复技能命中和伤害计算逻辑错误
- 修正 `Effect7` 中敌我双方血量判断逻辑,确保技能命中率和伤害值正确计算 - 调整 `FightC` 中技能攻击流程,统一使用 `Exec` 替代 `ExecCace` 执行效果 - 移除重复的 `AddEffects` 方法,简化效果添加逻辑 - 注释暂未使用的逻辑,避免无效调用影响战斗流程 - 增加战斗超时保护机制,防止协程泄漏 - 优化玩家离线保存逻辑
This commit is contained in:
@@ -25,7 +25,7 @@ type Effect7 struct {
|
||||
}
|
||||
|
||||
func (e *Effect7) Skill_Hit_Pre() bool {
|
||||
if e.Ctx().Our.CurrentPet.Info.Hp <= e.Input.CurrentPet.Info.Hp {
|
||||
if e.Ctx().Opp.CurrentPet.Info.Hp <= e.Ctx().Our.CurrentPet.Info.Hp {
|
||||
e.Ctx().SkillEntity.Accuracy = 0
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (e *Effect7) Damage_Floor() bool {
|
||||
}
|
||||
fmt.Println("Effect7_old", e.Ctx().DamageZone.Damage.IntPart())
|
||||
if e.Ctx().DamageZone.Type == info.DamageType.Red {
|
||||
e.Ctx().DamageZone.Damage = decimal.NewFromInt(int64(e.Ctx().Our.CurrentPet.Info.Hp - e.Ctx().Opp.CurrentPet.Info.Hp))
|
||||
e.Ctx().DamageZone.Damage = decimal.NewFromInt(int64(e.Ctx().Opp.CurrentPet.Info.Hp - e.Ctx().Our.CurrentPet.Info.Hp))
|
||||
|
||||
}
|
||||
fmt.Println("Effect7_new", e.Ctx().DamageZone.Damage.IntPart())
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *info.SkillEntity) {
|
||||
//oldpet := f.copypet(attacker.CurrentPet)
|
||||
|
||||
a.AttackTimeC(attacker.GetProp(5, true)) //计算命中
|
||||
defender.ExecCace(func(t input.Effect) bool { //计算闪避 ,然后修改对方命中),同时相当于计算属性无效这种
|
||||
a.AttackTimeC(attacker.GetProp(5, true)) //计算命中
|
||||
defender.Exec(func(t input.Effect) bool { //计算闪避 ,然后修改对方命中),同时相当于计算属性无效这种
|
||||
|
||||
t.Ctx().SkillEntity = a
|
||||
t.Skill_Hit_ex()
|
||||
@@ -27,14 +27,14 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *info.Ski
|
||||
})
|
||||
|
||||
attacker.AttackValue.AttackTime = a.AttackTime //是否命中赋值
|
||||
attacker.ExecCace(func(t input.Effect) bool { //计算命中 miss改命中
|
||||
attacker.Exec(func(t input.Effect) bool { //计算命中 miss改命中
|
||||
//计算视为效果
|
||||
t.Ctx().SkillEntity = a
|
||||
t.Calculate_Pre() //相当于先调整基础命中,不光调整命中,这里还能调整技能属性,暴击率
|
||||
|
||||
return true
|
||||
})
|
||||
attacker.ExecCace(func(t input.Effect) bool {
|
||||
attacker.Exec(func(t input.Effect) bool {
|
||||
//计算变威力
|
||||
t.Ctx().SkillEntity = a
|
||||
t.Skill_Hit() //相当于先调整基础命中,不光调整命中,这里还能调整技能属性,暴击率
|
||||
@@ -69,7 +69,7 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *info.Ski
|
||||
}
|
||||
|
||||
}
|
||||
attacker.AddEffects(attacker.EffectCache...) //命中再添加效果
|
||||
// attacker.AddEffects(attacker.EffectCache...) //命中再添加效果
|
||||
for _, e := range attacker.EffectCache {
|
||||
//这里实现应该参考本地技能是否命中,然后
|
||||
e.Hit(a.AttackTime != 0) //我方效果命中
|
||||
@@ -146,7 +146,7 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
//是否miss都应该施加解析effect
|
||||
f.First.Parseskill(f.Second, fattack) //解析到临时数据
|
||||
|
||||
f.First.ExecCace(func(t input.Effect) bool { //回合开始前
|
||||
f.First.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Compare_Pre(fattack, sattack) //先结算技能的优先级
|
||||
@@ -157,7 +157,7 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
if sattack != nil {
|
||||
f.Second.Parseskill(f.Second, sattack) //解析到临时数据
|
||||
|
||||
f.Second.ExecCace(func(t input.Effect) bool { //回合开始前
|
||||
f.Second.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Compare_Pre(fattack, sattack) //先结算技能的优先级
|
||||
@@ -182,13 +182,13 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
}
|
||||
}
|
||||
var attacker, defender *input.Input
|
||||
f.First.ExecCace(func(t input.Effect) bool { //回合开始前
|
||||
f.First.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Turn_Start()
|
||||
return true
|
||||
})
|
||||
f.Second.ExecCace(func(t input.Effect) bool { //回合开始前
|
||||
f.Second.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Turn_Start()
|
||||
@@ -209,12 +209,12 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
}
|
||||
|
||||
currentskill = oldskill
|
||||
attacker.Initeffectcache()
|
||||
//attacker.Initeffectcache()
|
||||
// fmt.Println("开始攻击威力", oldskill.Power)
|
||||
if oldskill != nil {
|
||||
fmt.Println("开始攻击威力", oldskill.Power)
|
||||
}
|
||||
canuseskill := attacker.ExecCace(func(t input.Effect) bool { //这个是能否使用技能
|
||||
canuseskill := attacker.Exec(func(t input.Effect) bool { //这个是能否使用技能
|
||||
//结算状态
|
||||
//然后这里还可以处理自爆类
|
||||
t.Ctx().SkillEntity = currentskill
|
||||
@@ -242,6 +242,13 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
skill.PP--
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
//根本没释放技能,这些效果全部失效
|
||||
for _, e := range attacker.EffectCache {
|
||||
e.Alive()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//技能使用后
|
||||
|
||||
@@ -124,16 +124,7 @@ func equalInts(a, b []int) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (our *Input) AddEffects(e ...Effect) {
|
||||
|
||||
for _, v := range e {
|
||||
|
||||
// v.Alive()
|
||||
our.AddEffect(v)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
func (our *Input) AddEffect(e Effect) {
|
||||
e.Alive(true) //添加后默认激活
|
||||
//todo 免疫
|
||||
@@ -198,22 +189,6 @@ func (our *Input) Exec(fn func(Effect) bool) bool {
|
||||
|
||||
return result
|
||||
}
|
||||
func (our *Input) ExecCace(fn func(Effect) bool) bool {
|
||||
result := true
|
||||
|
||||
for _, value := range our.EffectCache {
|
||||
if value.Alive() {
|
||||
value.Ctx().Our = our
|
||||
value.Ctx().Opp = our.Opp
|
||||
value.Ctx().DamageZone = &info.DamageZone{}
|
||||
if !fn(value) { //存在false,但是仍然要向下执行
|
||||
result = false //如果是false,说明存在阻止向下执行的effect,比如免疫能力提升效果
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// 消除回合类效果 efftype 输入是消对方的还是自己的,false是自己,true是对方
|
||||
func (our *Input) CancelTurn() {
|
||||
|
||||
@@ -180,10 +180,10 @@ func (our *Input) Parseskill(defender *Input, skill *action.SelectSkillAction) {
|
||||
// defender.AddEffect(t)
|
||||
// } else {
|
||||
//t.SetArgs(i, temparg[:args]...) //设置入参
|
||||
//i.AddEffect(t)
|
||||
our.AddEffect(t)
|
||||
// }
|
||||
//这里是临时缓存buff,后面确认命中后修改HIT状态
|
||||
t.Alive() //先让效果保持存活
|
||||
// t.Alive() //先让效果保持存活
|
||||
our.EffectCache = append(our.EffectCache, t)
|
||||
// i.NewEffects = append(i.NewEffects, t)
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ func (f *FightC) battleLoop() {
|
||||
close(f.actionChan)
|
||||
fmt.Println("战斗循环结束")
|
||||
close(f.over)
|
||||
|
||||
}
|
||||
|
||||
// 收集玩家动作(含超时判定)
|
||||
@@ -91,6 +92,7 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat
|
||||
if pid != 0 && (f.Info.Status == info.BattleStatus.FIGHT_WITH_BOSS ||
|
||||
f.Info.Status == info.BattleStatus.FIGHT_WITH_NPC) {
|
||||
f.GetInputByAction(paction, true).GetAction(f.Our)
|
||||
//panic("AI自动技能")
|
||||
}
|
||||
|
||||
actions[pid] = paction
|
||||
|
||||
@@ -333,7 +333,13 @@ func (p *Player) Save() {
|
||||
p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
|
||||
}()
|
||||
//<-ov
|
||||
<-p.FightC.GetOverChan() //等待结束
|
||||
select {
|
||||
case <-p.FightC.GetOverChan(): //等待结束
|
||||
case <-time.After(time.Second * 5): //等待5秒
|
||||
cool.Loger.Error(context.TODO(), "战斗崩溃", p.Info.UserID)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
p.Info.TimeToday = p.Info.TimeToday + uint32(time.Now().Unix()) - uint32(p.Onlinetime) //保存电池时间
|
||||
|
||||
Reference in New Issue
Block a user