Files
bl/logic/service/fight/input/input.go

193 lines
5.3 KiB
Go
Raw Normal View History

package input
import (
2025-09-30 18:32:15 +08:00
"blazing/common/data/xmlres"
2025-11-11 05:54:24 +00:00
"blazing/logic/service/common"
2025-09-30 18:32:15 +08:00
"blazing/logic/service/fight/action"
"blazing/logic/service/fight/info"
"github.com/jinzhu/copier"
2025-09-28 08:13:42 +00:00
"github.com/shopspring/decimal"
)
type Input struct {
CanChange bool //是否可以死亡切换CanChange
CurrentPet *info.BattlePetEntity //当前精灵
AllPet []*info.BattlePetEntity
Player common.PlayerI
2025-11-11 05:54:24 +00:00
Opp *Input
Finished bool //是否加载完成
*info.AttackValue
FightC common.FightI
// info.BattleActionI
Effects []Effect //effects 实际上全局就是effect无限回合 //effects容器 技能的
EffectCache []Effect //这里是命中前执行的容器,也就是命中前执行的所有逻辑相关,理论上一个effect被激活,就应该同时将其他的effect取消激活
Effect_Lost []Effect
//CanUseSkill bool
//Effect_Lost []Effect
//NewEffects []Effect
DamageZone struct {
2025-09-29 02:40:35 +08:00
Damage decimal.Decimal //伤害
BeforeADD decimal.Decimal //攻击伤害
BeforeMul decimal.Decimal
BeforeFloor decimal.Decimal
BeforeDiv decimal.Decimal
BeforeSUB decimal.Decimal
BeforeLock decimal.Decimal //锁伤 先锁受击方,再锁攻击方 受击方免疫也是这么锁 免疫等于锁0
BeforeLocked decimal.Decimal
//BeforePost decimal.Decimal
2025-09-28 08:13:42 +00:00
//OldAttack int //攻击伤害被挡前伤害记录
} //伤害容器
2025-09-30 18:32:15 +08:00
//First bool //是否先手
}
func NewInput(c common.FightI, p common.PlayerI) *Input {
ret := &Input{FightC: c, Player: p}
ret.Effects = make([]Effect, 0)
// t := Geteffect(EffectType.Damage, 0)
// t.Effect.SetArgs(ret)
// ret.AddEffect(t) //添加默认基类,实现继承
p.SetFightC(c) //给玩家设置战斗容器
return ret
}
2025-11-11 05:54:24 +00:00
func (our *Input) GetPetInfo() *info.BattlePetEntity {
return our.CurrentPet
}
func (our *Input) SetOPP(t *Input) {
2025-11-11 05:54:24 +00:00
our.Opp = t
2025-11-10 08:25:40 +00:00
}
2025-11-11 05:54:24 +00:00
func (our *Input) GenSataus() {
``` refactor(socket): 移除未使用的网络相关导入和注释掉的 RST 攻击检测逻辑 移除了 `ServerEvent.go` 中未使用的 `net` 和 `strings` 包导入。同时, 将原有的 RST 攻击检测及防护逻辑代码注释掉,便于后续重新设计或彻底删除。 fix(logic): 调整 fight pool 初始化与释放策略 将 `fight/action.go` 中的 `Fightpool` 类型从 `*ants.MultiPool` 改为 `*ants.Pool`,并调整其初始化方式为 `NewPool(-1)` 以适应动态扩容。 此外,在 `main.go` 中将 `ReleaseTimeout` 参数由 100 调整为 0, 确保立即清理超时任务。 feat(fight): 优化战斗输入状态重置逻辑 在 `fight/action.go` 的 `ReadyFight` 方法中提前设置 `GetInputByPlayer(c, false).Finished = true`,避免重复赋值。 同时更新了状态睡眠效果的处理流程,并简化了输入模块的状态缓存机制, 移除了冗余的 `Initeffectcache` 函数调用及相关逻辑。 perf(fight): 动态计算玩家动作等待时间 在 `loop.go` 的 `collectPlayerActions` 方法中, 将固定超时时间替换为基于 `waittime` 的动态等待时间计算公式, 提高响应灵活性。同时修复通道关闭判断条件以增强稳定性。 refactor(fight): 更新技能效果解析和状态持续逻辑 修改 `input.go` 中 `GenSataus` 方法以正确初始化状态数组; 在 `Turn.go` 中重构 `Turn_End` 方法内的执行逻辑, 确保仅在我方后手时增加回合数,提升战斗流程准确性。 chore(service): 删除废弃文件 SocketHandler_Tomee.go 完全移除已弃用的 `SocketHandler_Tomee.go` 文件及其全部内容, 减少项目冗余代码。 ```
2025-11-13 05:05:05 +08:00
our.Status = [20]int8{}
2025-11-10 08:25:40 +00:00
for i := 0; i < 20; i++ { //堆叠状态剩余回合
2025-11-11 05:54:24 +00:00
t := our.GetEffect(EffectType.Status, i)
2025-11-10 08:25:40 +00:00
if t != nil && t.Alive() { //状态都是叠层类的
2025-11-10 08:25:40 +00:00
2025-11-11 05:54:24 +00:00
our.Status[i] = int8(t.Duration())
2025-11-10 08:25:40 +00:00
}
}
}
2025-11-11 05:54:24 +00:00
func (our *Input) GenInfo() {
2025-11-10 08:25:40 +00:00
2025-11-11 05:54:24 +00:00
our.RemainHp = int32(our.CurrentPet.Info.Hp)
our.SkillList = our.CurrentPet.Info.SkillList
2025-11-10 08:25:40 +00:00
// f.Second.SkillList = f.Second.CurrentPet.Info.SkillList
// f.Second.RemainHp = int32(f.Second.CurrentPet.Info.Hp)
// ret.FAttack = *f.First.AttackValue
// ret.SAttack = *f.Second.AttackValue
}
2025-11-11 05:54:24 +00:00
func (our *Input) ResetAttackValue() {
our.AttackValue.SkillID = 0
our.AttackValue.IsCritical = 0
our.AttackValue.GainHp = 0
our.AttackValue.LostHp = 0
our.DamageZone.Damage = decimal.NewFromInt(0)
//our.CanUseSkill = true
}
// 这个每回合都会调用
2025-11-11 05:54:24 +00:00
func (our *Input) InitAttackValue() {
our.AttackValue = info.NewAttackValue(our.Player.GetInfo().UserID)
}
2025-11-11 05:54:24 +00:00
func (our *Input) GetPet(id uint32) (ii *info.BattlePetEntity, Reason info.ChangePetInfo) {
for _, v := range our.AllPet {
if v.Info.CatchTime == uint32(id) {
copier.Copy(&Reason, &v.Info)
2025-11-11 05:54:24 +00:00
Reason.UserId = our.Player.GetInfo().UserID
ii = v
}
}
return
}
// GetStatusBonus 获取最高的状态倍率
// 遍历状态数组返回存在的状态中最高的倍率无状态则返回1.0
2025-11-11 05:54:24 +00:00
func (our *Input) GetStatusBonus() float64 {
// 异常状态倍率映射表(状态索引 -> 倍率)
var statusBonuses = map[info.EnumPetStatus]float64{
info.PetStatus.Paralysis: 1.5,
info.PetStatus.Poisoned: 1.5,
info.PetStatus.Sleep: 2.0,
// /info.BattleStatus.Frozen: 2.0,
}
maxBonus := 1.0 // 默认无状态倍率
for statusIdx := 0; statusIdx < 20; statusIdx++ {
t := Geteffect(EffectType.Status, statusIdx)
// 检查状态是否存在数组中值为1表示存在该状态
if t != nil && t.Stack() > 0 {
if bonus, exists := statusBonuses[info.EnumPetStatus(statusIdx)]; exists && bonus > maxBonus {
maxBonus = bonus
}
}
}
return maxBonus
}
2025-09-30 18:32:15 +08:00
// 解析并 施加effect
func (our *Input) Parseskill(skill *action.SelectSkillAction) {
if skill == nil {
return
}
our.EffectCache = make([]Effect, 0) //先把上一回合数据清空,但是应该把本身延续类效果集成过来
our.Effect_Lost = make([]Effect, 0)
``` refactor(socket): 移除未使用的网络相关导入和注释掉的 RST 攻击检测逻辑 移除了 `ServerEvent.go` 中未使用的 `net` 和 `strings` 包导入。同时, 将原有的 RST 攻击检测及防护逻辑代码注释掉,便于后续重新设计或彻底删除。 fix(logic): 调整 fight pool 初始化与释放策略 将 `fight/action.go` 中的 `Fightpool` 类型从 `*ants.MultiPool` 改为 `*ants.Pool`,并调整其初始化方式为 `NewPool(-1)` 以适应动态扩容。 此外,在 `main.go` 中将 `ReleaseTimeout` 参数由 100 调整为 0, 确保立即清理超时任务。 feat(fight): 优化战斗输入状态重置逻辑 在 `fight/action.go` 的 `ReadyFight` 方法中提前设置 `GetInputByPlayer(c, false).Finished = true`,避免重复赋值。 同时更新了状态睡眠效果的处理流程,并简化了输入模块的状态缓存机制, 移除了冗余的 `Initeffectcache` 函数调用及相关逻辑。 perf(fight): 动态计算玩家动作等待时间 在 `loop.go` 的 `collectPlayerActions` 方法中, 将固定超时时间替换为基于 `waittime` 的动态等待时间计算公式, 提高响应灵活性。同时修复通道关闭判断条件以增强稳定性。 refactor(fight): 更新技能效果解析和状态持续逻辑 修改 `input.go` 中 `GenSataus` 方法以正确初始化状态数组; 在 `Turn.go` 中重构 `Turn_End` 方法内的执行逻辑, 确保仅在我方后手时增加回合数,提升战斗流程准确性。 chore(service): 删除废弃文件 SocketHandler_Tomee.go 完全移除已弃用的 `SocketHandler_Tomee.go` 文件及其全部内容, 减少项目冗余代码。 ```
2025-11-13 05:05:05 +08:00
// our.Initeffectcache() //这里说明是延续的效果,每次复制出来一个新的就好了
//i.NewEffects = make([]Effect, 0) //这里说明是新增的效果
temparg := skill.SideEffectArgS
2025-09-30 18:32:15 +08:00
for _, v := range skill.SideEffectS {
2025-09-30 18:32:15 +08:00
t := Geteffect(EffectType.Skill, v)
args := xmlres.EffectArgs[v]
//这里是给双方添加buff
if t != nil {
2025-11-11 05:54:24 +00:00
t.SetArgs(our, temparg[:args]...) //设置入参,施加方永远是我方
2025-09-30 18:32:15 +08:00
// if t.Owner() { //如果取反,说明是给对方添加的回合效果
// //实际上,owner永远为反,说明是对方给我添加的
// t.SetArgs(i, temparg[:args]...) //设置入参,施加方永远是我方
// //给双方添加
// defender.AddEffect(t)
// } else {
//t.SetArgs(i, temparg[:args]...) //设置入参
loste := our.AddEffect(our, t)
if loste != nil {
our.Effect_Lost = append(our.Effect_Lost, loste)
}
// }
//这里是临时缓存buff,后面确认命中后修改HIT状态
// t.Alive() //先让效果保持存活
2025-11-11 05:54:24 +00:00
our.EffectCache = append(our.EffectCache, t)
// i.NewEffects = append(i.NewEffects, t)
2025-09-30 18:32:15 +08:00
}
temparg = temparg[args:]
}
}