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

41 lines
1.1 KiB
Go
Raw Normal View History

package player
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight/info"
"sync/atomic"
)
// JoinFight 加入战斗队列
func (p *Player) JoinFight(handler func(p common.PlayerI) bool) errorcode.ErrorCode {
//加入队列前就开始判断一次
if !p.CanFight() {
return errorcode.ErrorCodes.ErrNoEligiblePokemon
}
if p.GetSpace().Owner.UserID == p.Info.UserID {
return errorcode.ErrorCodes.ErrSystemError
}
p.GetSpace().User.Range(func(key uint32, opponent common.PlayerI) bool {
if opponent.GetInfo().UserID != p.Info.UserID {
//确认是乱斗模式
if opponent.Getfightinfo() == p.Getfightinfo() && p.CanFight() {
success := handler(opponent)
if success {
atomic.StoreUint32(&opponent.(*Player).Fightinfo.Mode, 0)
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
}
return success //如果发起成功就停止,否则继续遍历队列
}
}
return false
})
return 0
}
// SendLoadPercent 发送加载进度
func (p *Player) SendLoadPercent(loadInfo info.LoadPercentOutboundInfo) {
p.SendPack(common.NewTomeeHeader(2441, p.Info.UserID).Pack(&loadInfo))
}