58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"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 !atomic.CompareAndSwapUint32(&c.Fightinfo.Status, 0, 1) { //邀请前提是自己没在战斗
|
|
return nil, errorcode.ErrorCodes.ErrInBattle
|
|
|
|
}
|
|
c.Fightinfo.PlayerID = data.UserID
|
|
c.Fightinfo.Mode = data.Mode
|
|
err = c.AgreeBattle(data.UserID, data.Flag, func(p common.PlayerI) bool {
|
|
|
|
_, err = fight.NewFight(p, c, func(foi *info.FightOverInfo) {
|
|
|
|
})
|
|
return err <= 0
|
|
})
|
|
return
|
|
}
|
|
|
|
// 邀请其他人进行战斗
|
|
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
|
|
}
|