go_dreamfactory/modules/pvp/api_incmd.go

67 lines
1.7 KiB
Go

package pvp
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/timewheel"
"go_dreamfactory/pb"
"time"
"google.golang.org/protobuf/proto"
)
//参数校验
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 proto.Message) {
var (
battle *BattleItem
side int32
ok bool
)
if code = this.InCmdCheck(session, req); code != 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 code = this.module.battle.InCmdBattle(&pb.BattleInCmdReq{
Battleid: req.Battleid,
Side: side,
In: req.Cmd,
}); code != pb.ErrorCode_Success {
return
} else {
if battle.operatetimer != nil {
timewheel.Remove(battle.operatetimer)
}
}
} else {
code = pb.ErrorCode_BattleInCmdFailed
return
}
session.SendMsg(string(this.module.GetType()), "incmd", &pb.PvpInCmdResp{Battleid: req.Battleid, Cmd: req.Cmd})
return
}