- 在多个战斗控制器方法中添加 defer 调用,确保战斗操作正确延迟执行 - 修改 ChangePet 方法返回值类型,增强接口一致性 - 修复战斗准备阶段逻辑,重构战斗开始信息构建过程 - 移除冗余广播调用,调整 PVE 战斗初始化流程 - 更新 README 中的 pprof 命令地址并完善项目介绍部分 fix(effect): 修复效果叠加逻辑与ID解析问题 - 效果叠加时默认增加一层,而非直接相加参数 - 修正 EffectIDCombiner 类型、CatchTime 的掩码偏移计算错误 - 添加重复效果日志输出,便于调试追踪 feat(boss): 完善BOSS特性实现逻辑 - 修正 NewSel17 特性
161 lines
5.4 KiB
Go
161 lines
5.4 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"sync/atomic"
|
|
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/logic/service/player"
|
|
"blazing/logic/service/space"
|
|
)
|
|
|
|
// public static const ARENA_SET_OWENR:uint = 2417;
|
|
// 如果星际擂台上无人,站到星际擂台的包
|
|
// 前端到后端无数据内容 空包
|
|
// 后端到前端无数据内容 空包
|
|
// 都需要通过2419包广播更新擂台状态
|
|
func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
if !c.CanFight() {
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
|
}
|
|
c.Fightinfo.Mode = 0 //取消队列匹配
|
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 0, 1) {
|
|
|
|
c.GetSpace().Owner.Set(c)
|
|
c.GetSpace().Broadcast(c, 2419, c.GetSpace().Owner)
|
|
c.SendPackCmd(2419, c.GetSpace().Owner)
|
|
return
|
|
}
|
|
|
|
return nil, errorcode.ErrorCodes.ErrChampionExists
|
|
}
|
|
|
|
// public static const ARENA_FIGHT_OWENR:uint = 2418;
|
|
// 挑战擂台的包
|
|
// 前端到后端无数据内容 空包
|
|
// 后端到前端无数据内容 空包
|
|
// 还是后端主动发送2503的包给双方前端后 等待前端加载完毕 主动发送2404包通知后端开始战斗
|
|
// 并不会通知对方是否接受挑战。只要有人挑战就直接进入对战
|
|
func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
if !c.CanFight() {
|
|
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
|
}
|
|
|
|
if c.Info.UserID == c.GetSpace().Owner.UserID {
|
|
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
|
}
|
|
|
|
if c.GetSpace().Owner.ARENA_Player == nil {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError200007
|
|
}
|
|
|
|
if !c.GetSpace().Owner.ARENA_Player.CanFight() {
|
|
c.GetSpace().Owner.Set(c)
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
return
|
|
}
|
|
//原子操作,修改擂台状态
|
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 1, 2) {
|
|
//成功发起擂台挑战后才修改我放状态
|
|
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
|
c.Fightinfo.Status = info.BattleMode.FIGHT_ARENA
|
|
|
|
_, err = fight.NewFight(c, c.GetSpace().Owner.ARENA_Player, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
|
|
|
if foi.Reason != 0 && foi.WinnerId == c.GetInfo().UserID { //异常退出
|
|
|
|
c.GetSpace().Owner.Reset()
|
|
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
|
|
}
|
|
|
|
if foi.Reason == 0 { //异常退出
|
|
|
|
if foi.WinnerId == c.GetInfo().UserID {
|
|
c.Info.MaxArenaWins += 1
|
|
} else {
|
|
c.GetSpace().Owner.ARENA_Player.GetInfo().MaxArenaWins += 1
|
|
}
|
|
|
|
}
|
|
//todo 擂主输了,那就直接让他放弃擂台
|
|
|
|
}) ///开始对战,房主方以及被邀请方
|
|
|
|
if err <= 0 { //发起战斗成功
|
|
atomic.StoreUint32(&c.GetSpace().Owner.ChallengerID, c.GetInfo().UserID) //传回的指针赋值给ID
|
|
//c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
//c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
} else {
|
|
|
|
atomic.StoreUint32(&c.GetSpace().Owner.Flag, 1)
|
|
|
|
}
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
return
|
|
}
|
|
return nil, errorcode.ErrorCodes.ErrChampionExists
|
|
|
|
}
|
|
|
|
// 获取星际擂台信息的包 进入空间站地图前端会发送请求包 或者 有人站到星际擂台上后 广播回包
|
|
// 前端到后端无数据内容
|
|
// 后端到前端
|
|
func (h Controller) ARENA_GET_INFO(data *fight.ARENA_GET_INFO, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
|
|
|
|
result = &c.GetSpace().Owner
|
|
return
|
|
}
|
|
|
|
// public static const ARENA_UPFIGHT:uint = 2420;
|
|
// 放弃擂台挑战的包
|
|
// 前端到后端无数据内容
|
|
// 后端到前端无数据内容
|
|
// 都需要通过2419包广播更新擂台状态
|
|
func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
//原子操作,修改擂台状态
|
|
if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID { //说明已经有人了
|
|
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
|
|
}
|
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.UserID, c.GetInfo().UserID, 0) {
|
|
|
|
c.GetSpace().Owner.Reset()
|
|
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
return nil, -1
|
|
}
|
|
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
|
|
|
|
}
|
|
|
|
// public static const ARENA_OWENR_ACCE:uint = 2422;
|
|
// 此包为擂台战对战结束后 胜方前端会发送给后端 具体作用为通知后端发送2419包更新擂台信息。
|
|
// 前端到后端无数据内容
|
|
// 后端到前端无数据内容
|
|
// public static const ARENA_OWENR_OUT:uint = 2423;
|
|
// 此包不清楚具体怎么触发 但已知此包为后端主动发送。不清楚什么情况下回用到
|
|
func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
s := c.GetSpace()
|
|
|
|
if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID && c.GetInfo().UserID != atomic.LoadUint32(&c.GetSpace().Owner.ChallengerID) { //说明已经有人了
|
|
return nil, -1
|
|
}
|
|
s.Owner.Set(c)
|
|
|
|
atomic.StoreUint32(&s.Owner.Flag, 1)
|
|
|
|
s.Broadcast(c, 2419, &s.Owner)
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
|
|
return nil, -1
|
|
}
|