Files
bl/logic/service/fight/input/ai.go
昔念 3af709f633 ```
feat(fight): AI战斗逻辑优化,修复技能使用判断逻辑

- 修改AI技能选择逻辑,从直接使用技能ID改为先存储技能实体再统一执行
- 修复usedskill变量类型从uint32改为*info.SkillEntity指针类型
- 优化技能使用流程,确保只有在找到可用技能时才执行UseSkill操作

fix(player): 调整玩家登录时的任务
2026-01-22 14:29:08 +08:00

96 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package input
import "blazing/logic/service/fight/info"
func (our *Input) GetAction() {
next := our.Exec(func(t Effect) bool {
return t.HookAction()
})
if !next {
return
}
// 获取己方当前宠物和对方当前宠物
selfPet := our.FightC.GetCurrPET(our.Player)
//没血就切换精灵
if selfPet.Info.Hp <= 0 {
for _, v := range our.AllPet {
if v.Info.Hp > 0 {
our.FightC.ChangePet(our.Player, v.Info.CatchTime)
return
}
}
// 如果没有可用宠物,则直接返回,不执行任何操作
return
}
//oppPet := opp.FightC.GetCurrPET(opp.Player)
skills := selfPet.Skills
// 空技能列表直接返回,避免错误
if len(skills) == 0 {
return
}
var usedskill *info.SkillEntity
for _, s := range skills {
if s == nil {
continue
}
if !s.CanUse() {
continue
}
// 计算技能对对方的伤害假设CalculatePower返回伤害值或需从技能中获取
s.DamageValue = our.CalculatePower(our.Opp, s)
// 判断是否能秒杀(伤害 >= 对方当前生命值)
if uint32(s.DamageValue.IntPart()) >= our.Opp.CurrentPet.Info.Hp { // 假设oppPet.HP为对方当前剩余生命值
usedskill = s
}
}
if usedskill == nil {
for _, s := range skills {
if s == nil {
continue
}
if !s.CanUse() {
continue
}
usedskill = s
}
}
if usedskill != nil {
our.FightC.UseSkill(our.Player, uint32(usedskill.ID))
} else {
our.FightC.UseSkill(our.Player, 0)
}
// // 若存在能秒杀的技能,优先使用(选伤害最高的,避免浪费高伤害技能)
// if len(killableSkills) > 0 {
// bestKillSkill := killableSkills[0].SkillEntity
// maxDamage := killableSkills[0].damage
// for _, ks := range killableSkills[1:] {
// if ks.damage.Cmp(maxDamage) > 0 { // 使用decimal的比较方法比较伤害值
// if ks.CanUse() {
// maxDamage = ks.damage
// bestKillSkill = ks.SkillEntity
// }
// }
// }
// our.FightC.UseSkill(our.Player, uint32(bestKillSkill.ID))
// return
// }
// if len(allSkills) <= 0 {
// our.FightC.UseSkill(our.Player, 0)
// return
// }
// 优化随机选择技能的逻辑,直接使用随机索引
// randomIdx := grand.Intn(len(allSkills))
// our.FightC.UseSkill(our.Player, uint32(allSkills[randomIdx].ID))
}