package pvp import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/pb" "time" ) //参数校验 func (this *apiComp) InCmdCheck(session comm.IUserSession, req *pb.PvpInCmdReq) (code pb.ErrorCode) { return } ///设置战斗阵型 func (this *apiComp) InCmd(session comm.IUserSession, req *pb.PvpInCmdReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( battle *BattleItem side int32 ok bool cd pb.ErrorCode ) defer func() { session.SendMsg(string(this.module.GetType()), "incmd", &pb.PvpInCmdResp{Code: cd, Battleid: req.Battleid, Cmd: req.Cmd}) }() if cd = this.InCmdCheck(session, req); cd != pb.ErrorCode_Success { return } this.module.lock.RLock() battle, ok = this.module.battles[req.Battleid] this.module.lock.RUnlock() if ok { if session.GetUserId() == battle.Red.Uid { side = 1 } else { side = 2 } //不该自己出手 if battle.curroperate.Side != side { session.SendMsg(string(this.module.GetType()), "incmd", &pb.PvpInCmdResp{Code: pb.ErrorCode_BattleInCmdFailed, Battleid: req.Battleid, Cmd: req.Cmd}) return } //请求倒计时开始 if req.Cmd.Cmdtype == "ComEmitCountdown" { battle.operatetimer = timewheel.Add(time.Second*30, this.module.operateTimeOut, battle.Id) session.SendMsg(string(this.module.GetType()), "incmd", &pb.PvpInCmdResp{Battleid: req.Battleid, Cmd: req.Cmd}) return } //技能释放指令 if cd = this.module.battle.InCmdBattle(&pb.BattleInCmdReq{ Battleid: req.Battleid, Side: side, In: req.Cmd, }); cd != pb.ErrorCode_Success { return } else { if battle.operatetimer != nil { timewheel.Remove(battle.operatetimer) } } } else { cd = pb.ErrorCode_BattleInCmdFailed return } return }