70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
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) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
///设置战斗阵型
|
|
func (this *apiComp) InCmd(session comm.IUserSession, req *pb.PvpInCmdReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
battle *BattleItem
|
|
side int32
|
|
ok bool
|
|
)
|
|
|
|
if errdata = this.InCmdCheck(session, req); errdata != nil {
|
|
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 errdata = this.module.battle.InCmdBattle(&pb.BattleInCmdReq{
|
|
Battleid: req.Battleid,
|
|
Side: side,
|
|
In: req.Cmd,
|
|
}); errdata != nil {
|
|
return
|
|
} else {
|
|
if battle.operatetimer != nil {
|
|
timewheel.Remove(battle.operatetimer)
|
|
}
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_BattleInCmdFailed,
|
|
Title: pb.ErrorCode_BattleInCmdFailed.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "incmd", &pb.PvpInCmdResp{Battleid: req.Battleid, Cmd: req.Cmd})
|
|
return
|
|
}
|