86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package rtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) BattleFinishCheck(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode) {
|
|
if req.RtaskId == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.BattleFinishCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
//校验战斗结果
|
|
iBattle, err := this.moduleRtask.modelRtask.service.GetModule(comm.ModuleBattle)
|
|
if err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
var isWin bool
|
|
if b, y := iBattle.(comm.IBattle); y {
|
|
if code, isWin = b.CheckBattleReport(session, req.Report); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
if isWin {
|
|
// 获取玩家的任务
|
|
rtask := &pb.DBRtask{}
|
|
if err := this.moduleRtask.modelRtask.Get(session.GetUserId(), rtask); err != nil {
|
|
return
|
|
}
|
|
|
|
// 获取当前任务配置
|
|
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
|
|
if conf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
log.Errorf("rdtask %v no found", req.RtaskId)
|
|
return
|
|
}
|
|
|
|
var (
|
|
frtaskArr *pb.FrtaskIds //完成的任务
|
|
ok bool
|
|
)
|
|
|
|
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
|
|
frtaskArr = &pb.FrtaskIds{}
|
|
}
|
|
|
|
// 更新完成的任务
|
|
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId)
|
|
if rtask.FrtaskIds == nil {
|
|
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
|
|
}
|
|
rtask.FrtaskIds[conf.Group] = frtaskArr
|
|
update := map[string]interface{}{
|
|
"frtaskIds": rtask.FrtaskIds,
|
|
}
|
|
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleFinish,
|
|
&pb.RtaskBattleFinishResp{
|
|
RtaskId: req.RtaskId,
|
|
IsWin: isWin,
|
|
}); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
|
|
return
|
|
}
|