203 lines
5.3 KiB
Go
203 lines
5.3 KiB
Go
package storyline
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) CompleteCheck(session comm.IUserSession, req *pb.StorylineCompleteReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) Complete(session comm.IUserSession, req *pb.StorylineCompleteReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBStoryline
|
|
|
|
item *pb.DBStorylineItem
|
|
chapterconf *cfg.GameHeroupstoryChaptertxtData
|
|
cpconf *cfg.GameHeroupstoryChaptertxtData
|
|
conf *cfg.GameHeroupstoryChapterData
|
|
award []*pb.UserAssets
|
|
ftime int64
|
|
ok bool
|
|
iswin bool
|
|
isfish bool
|
|
err error
|
|
)
|
|
if errdata = this.CompleteCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameHeroupstoryChapter(req.Level); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.modeltask.getUserStoryline(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if item, ok = info.Item[conf.Hero]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("no activation hero:%d", conf.Hero),
|
|
}
|
|
return
|
|
}
|
|
//前置判断
|
|
if conf.Onlevel != 0 && item.Level[conf.Onlevel] == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("%d onlevel no Complete", req.Level),
|
|
}
|
|
return
|
|
}
|
|
|
|
//前置判断
|
|
if len(conf.Onlevelstory) == 2 && item.Level[conf.Onlevelstory[0]] == conf.Onlevelstory[1] {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("%d onlevel no Complete", req.Level),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf.Leveltype != 1 && item.Level[req.Level] != 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("%d received", req.Level),
|
|
}
|
|
return
|
|
}
|
|
|
|
if item.Level[req.Level] != 0 {
|
|
isfish = true
|
|
}
|
|
|
|
if chapterconf, err = this.module.configure.getGameHeroupstoryChaptertxt(conf.Chapter); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if chapterconf.Onchapter != 0 {
|
|
if cpconf, err = this.module.configure.getGameHeroupstoryChaptertxt(chapterconf.Onchapter); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if ftime, ok = item.Chapter[cpconf.ChapterID]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "chapter no fish!",
|
|
}
|
|
return
|
|
}
|
|
|
|
//是否到达解锁时间
|
|
if !configure.Now().After(time.Unix(ftime, 0).Add(time.Hour * time.Duration(chapterconf.Chaptertime))) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "chapter no can unlock",
|
|
}
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
if conf.Leveltype == 1 { //剧情关卡
|
|
item.Level[req.Level] = req.Story
|
|
} else if conf.Leveltype == 2 { //战斗管卡
|
|
if errdata, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil {
|
|
return
|
|
}
|
|
if !iswin {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "battle no win!",
|
|
}
|
|
return
|
|
}
|
|
item.Level[req.Level] = 1
|
|
} else if conf.Leveltype == 4 {
|
|
item.Level[req.Level] = 1
|
|
item.Chapter[conf.Chapter] = configure.Now().Unix()
|
|
} else if conf.Leveltype == 5 {
|
|
if req.Report != nil {
|
|
if errdata, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil {
|
|
return
|
|
}
|
|
if !iswin {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "battle no win!",
|
|
}
|
|
return
|
|
}
|
|
}
|
|
item.Level[req.Level] = 1
|
|
} else {
|
|
item.Level[req.Level] = 1
|
|
}
|
|
|
|
if !isfish {
|
|
if errdata = this.module.DispenseRes(session, conf.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
award = make([]*pb.UserAssets, 0)
|
|
for _, v := range conf.Reward {
|
|
award = append(award, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
}
|
|
|
|
this.module.modeltask.Change(session.GetUserId(), map[string]interface{}{
|
|
"item": info.Item,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "complete", &pb.StorylineCompleteResp{
|
|
Level: req.Level,
|
|
Story: req.Story,
|
|
Award: award,
|
|
Heroexp: map[string]int32{},
|
|
})
|
|
if len(award) > 0 {
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "StorylineCompleteReq", award)
|
|
})
|
|
}
|
|
return
|
|
}
|