46 lines
1.2 KiB
Go
46 lines
1.2 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) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
///设置战斗阵型
|
|
func (this *apiComp) Formation(session comm.IUserSession, req *pb.PvpFormationReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
battle *BattleItem
|
|
ok bool
|
|
)
|
|
if errdata = this.FormationCheck(session, req); errdata != nil {
|
|
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
|
|
}
|