Files
bl/logic/controller/fight_pvp_withplayer.go
昔念 4751594ee8 ```
feat: 更新战斗系统模型结构和Redis消息处理

- 引入gredis依赖用于Redis消息处理
- 将战斗相关的枚举和结构体从info包迁移到model包
- 更新战斗结束原因、攻击值等类型的引用路径
- 添加新的zset工具包到工作区
- 修改Redis消息处理逻辑以正确解析gredis.Message类型
- 在战斗控制器中统一使用model包下的类型定义
2026-03-04 22:47:21 +08:00

110 lines
2.8 KiB
Go

package controller
import (
"blazing/common/socket/errorcode"
"blazing/modules/player/model"
"sync/atomic"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
"blazing/logic/service/player"
)
// 接收战斗或者取消战斗的包
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.GetSpace().Owner.UserID == c.Info.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.GetSpace().Owner.UserID == data.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if !atomic.CompareAndSwapUint32(&c.Fightinfo.Mode, 0, data.Mode) { //邀请前提是自己没在战斗
return nil, errorcode.ErrorCodes.ErrInBattle
}
r := c.CanFight()
if c.CanFight() != 0 {
return nil, r
}
//c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
resp := &info.S2C_NOTE_HANDLE_FIGHT_INVITE{
UserID: c.Info.UserID,
Nick: c.Info.Nick,
}
for _, v := range c.HavePVPinfo {
if v.GetInfo().UserID == data.UserID && v.Getfightinfo().Mode == data.Mode {
resp.Result = data.Flag
if resp.Result == 0 {
v.SendPackCmd(2502, &resp)
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
return
}
// 检查邀请者的邀请是否有效(对方已取消邀请)
if v.Getfightinfo().Status == 0 {
resp.Result = 4 // 邀请已取消
v.SendPackCmd(2502, &resp)
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
return
}
_, err = fight.NewFight(v, c, func(foi model.FightOverInfo) {
//println("好友对战测试", foi.Reason)
})
if err <= 0 { //成功发起对战
c.HavePVPinfo = make([]common.PlayerI, 0)
return
} else {
resp.Result = 3
v.SendPackCmd(2502, &resp)
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
return
}
}
}
atomic.StoreUint32(&c.Fightinfo.Status, 0)
return
}
// 邀请其他人进行战斗
func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.GetSpace().Owner.UserID == c.Info.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.GetSpace().Owner.ChallengerID == c.Info.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.GetSpace().Owner.UserID == data.UserID {
return nil, errorcode.ErrorCodes.ErrSystemError
}
// c.Fightinfo.PlayerID = data.UserID
c.Fightinfo.Mode = data.Mode
c.Fightinfo.Status = 1
// c.Fightinfo.Type = 0
v, ok := c.GetSpace().User.Load(data.UserID)
if ok {
v.InvitePlayer(c)
}
return nil, 0
}
// 取消队列
func (h Controller) OnPlayerCanceledOtherInviteFight(data *fight.InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
atomic.StoreUint32(&c.Fightinfo.Mode, 0) //设置状态为0
return
}