Files
bl/logic/controller/fight_pvp_withplayer.go
2025-11-18 23:41:31 +00:00

57 lines
1.7 KiB
Go

package controller
import (
"blazing/common/socket/errorcode"
"sync/atomic"
"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.CanFight() {
// return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
// }
if !atomic.CompareAndSwapUint32(&c.Fightinfo.Status, 0, 1) { //邀请前提是自己没在战斗
return nil, errorcode.ErrorCodes.ErrInBattle
}
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok {
fight.NewFight(p1, c, func(foi *info.FightOverInfo) {
}) ///开始对战,房主方以及被邀请方
}
return nil, -1
}
// 邀请其他人进行战斗
func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
//进入邀请,以及确认对战模式
if !atomic.CompareAndSwapUint32(&c.Fightinfo.PlayerID, 0, data.UserID) { //邀请前提是自己没邀请别人
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
}
c.Fightinfo.Mode = data.Mode
c.InvitePlayerToBattle()
return nil, 0
}
// 取消队列
func (h Controller) OnPlayerCanceledOtherInviteFight(data *fight.InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if atomic.LoadUint32(&c.Fightinfo.Status) != 0 { //如果没有战斗状态,则不做任何处理
atomic.StoreUint32(&c.Fightinfo.Status, 0) //设置状态为0
}
//否则报错
return nil, errorcode.ErrorCodes.ErrCannotCancelBattle
}