110 lines
3.5 KiB
Go
110 lines
3.5 KiB
Go
package wtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) BattleFinishCheck(session comm.IUserSession, req *pb.WTaskBattleFinishReq) (errdata *pb.ErrorData) {
|
|
if req.BattleConfId == 0 || req.Report == nil {
|
|
this.module.Error("世界任务战斗开始参数错误",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "params", Value: req.String()},
|
|
)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "BattleConfId is 0 or Report is null",
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.WTaskBattleFinishReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameWorldBattleData
|
|
prop []*cfg.Gameatn
|
|
atno []*pb.UserAtno
|
|
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
|
err error
|
|
isWin bool
|
|
)
|
|
if errdata = this.BattleFinishCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.getWorldtaskBattleById(req.BattleConfId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if isWin {
|
|
if conf.Carexe > 0 {
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
heros := make([]string, 0)
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if v.Oid != "" && !v.Ishelp { // 助战英雄不加经验
|
|
heros = append(heros, v.Oid)
|
|
}
|
|
}
|
|
if _, errdata = this.module.ModuleHero.AddHerosExp(session, heros, conf.Carexe); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
if conf.Reward > 0 {
|
|
user, err := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if prop = this.module.ModuleTools.GetGroupDataByLottery(conf.Reward, user.Vip, user.Lv); len(prop) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("掉落组未找到:%d", conf.Reward),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
prop = append(prop, conf.Playexp) //经验不返回前端展示
|
|
prop = append(prop, conf.Exreward...) //经验不返回前端展示
|
|
if errdata, atno = this.module.DispenseAtno(session, prop, true); errdata != nil {
|
|
this.module.Error("世界任务战斗玩家经验结算",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "playerExp", Value: conf.Playexp},
|
|
)
|
|
return
|
|
}
|
|
//触发任务
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype70, 1, req.BattleConfId))
|
|
} else {
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype227, 1, req.BattleConfId))
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "battlefinish", &pb.WTaskBattleFinishResp{BattleConfId: req.BattleConfId, Award: atno})
|
|
|
|
if len(tasks) > 0 {
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.ModuleBuried.TriggerBuried(session, tasks...)
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "WTaskBattleFinishReq", atno)
|
|
})
|
|
}
|
|
return
|
|
}
|