53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package pvp
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ActiveCancelCheck(session comm.IUserSession, req *pb.PvpActiveCancelReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
///设置战斗阵型
|
|
func (this *apiComp) ActiveCancel(session comm.IUserSession, req *pb.PvpActiveCancelReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
battle *BattleItem
|
|
ok bool
|
|
winside int32
|
|
)
|
|
if code = this.ActiveCancelCheck(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 battle.Red.Uid == session.GetUserId() {
|
|
winside = 2
|
|
} else {
|
|
winside = 1
|
|
}
|
|
this.module.PvpFinishPush(&pb.BattleFinishPush{
|
|
Battleid: req.Battleid,
|
|
WinSide: winside,
|
|
})
|
|
if err := this.module.SendMsgToSession(string(comm.ModulePvp), "cancel", &pb.PvpCancelPush{
|
|
ServicePath: fmt.Sprintf("%s/%s", this.service.GetType(), this.service.GetId()),
|
|
Battleid: battle.Id,
|
|
}, battle.RedSession, battle.BlueSession); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
} else {
|
|
code = pb.ErrorCode_BattleInCmdFailed
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "activecancel", &pb.PvpActiveCancelResp{Issucc: true})
|
|
return
|
|
}
|