go_dreamfactory/modules/pvp/api_formation.go
2023-04-14 12:21:58 +08:00

46 lines
1.3 KiB
Go

package pvp
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/timewheel"
"go_dreamfactory/pb"
)
//参数校验
func (this *apiComp) FormationCheck(session comm.IUserSession, req *pb.PvpFormationReq) (code pb.ErrorCode) {
return
}
///设置战斗阵型
func (this *apiComp) Formation(session comm.IUserSession, req *pb.PvpFormationReq) (code pb.ErrorCode, data *pb.ErrorData) {
var (
battle *BattleItem
ok bool
)
if code = this.FormationCheck(session, req); code != pb.ErrorCode_Success {
return
}
this.module.lock.RLock()
battle, ok = this.module.battles[req.Battleid]
this.module.lock.RUnlock()
if ok && battle.State == pb.PvpState_ready {
battle.lock.Lock()
if session.GetUserId() == battle.Red.Uid {
battle.Redformation = req.Formation
} else {
battle.Blueformation = req.Formation
}
if battle.Redformation != nil && battle.Blueformation != nil { //都设置了战斗阵型
battle.State = pb.PvpState_battle
timewheel.Remove(battle.readytimer)
go this.module.startBattle(battle)
}
battle.lock.Unlock()
} else {
session.SendMsg(string(this.module.GetType()), "formation", &pb.PvpFormationResp{Issucc: false})
return
}
session.SendMsg(string(this.module.GetType()), "formation", &pb.PvpFormationResp{Issucc: true})
return
}