64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package pvp
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ActiveCancelCheck(session comm.IUserSession, req *pb.PvpActiveCancelReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
///设置战斗阵型
|
|
func (this *apiComp) ActiveCancel(session comm.IUserSession, req *pb.PvpActiveCancelReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
battle *BattleItem
|
|
ok bool
|
|
faiside int32
|
|
winside int32
|
|
)
|
|
if errdata = this.ActiveCancelCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
this.module.lock.RLock()
|
|
battle, ok = this.module.battles[req.Battleid]
|
|
this.module.lock.RUnlock()
|
|
if ok {
|
|
if battle.Red.Uid == session.GetUserId() {
|
|
faiside = 1
|
|
winside = 2
|
|
} else {
|
|
faiside = 2
|
|
winside = 1
|
|
}
|
|
if battle.State == pb.PvpState_battle {
|
|
this.module.battle.ConcedeBattle(&pb.BattleConcedeReq{
|
|
Battleid: req.Battleid,
|
|
Side: faiside,
|
|
})
|
|
} else {
|
|
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 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_BattleInCmdFailed,
|
|
Title: pb.ErrorCode_BattleInCmdFailed.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "activecancel", &pb.PvpActiveCancelResp{Issucc: true})
|
|
return
|
|
}
|