105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package dispatch
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 刷新
|
|
func (this *apiComp) RefreshCheck(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBDispatch
|
|
need []*cfg.Gameatn
|
|
)
|
|
info = this.module.modelDispatch.getDBDispatch(session.GetUserId())
|
|
if info == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DataNotFound,
|
|
Title: pb.ErrorCode_DataNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info.Nb != nil {
|
|
if info.Nb.FreeCount > 0 {
|
|
//更新刷新次数
|
|
if err := this.module.modelDispatch.updateFreeCount(session.GetUserId(), info.Nb); err != nil {
|
|
var customer = new(comm.CustomError)
|
|
var code pb.ErrorCode
|
|
if errors.As(err, &customer) {
|
|
code = customer.Code
|
|
errdata = &pb.ErrorData{
|
|
Code: code,
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
refreshCount := this.module.ModuleTools.GetGlobalConf().DispatchRefreshtimes
|
|
if info.Nb.RefreshCount >= refreshCount {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DispatchRefreshMax,
|
|
Title: pb.ErrorCode_DispatchRefreshMax.ToString(),
|
|
}
|
|
return
|
|
}
|
|
need = make([]*cfg.Gameatn, 0)
|
|
money := this.module.ModuleTools.GetGlobalConf().DispatchCheckmoney
|
|
|
|
need = append(need, &cfg.Gameatn{
|
|
A: money.A,
|
|
T: money.T,
|
|
N: money.N * (info.Nb.RefreshCount + 1),
|
|
})
|
|
//消耗金币
|
|
|
|
if errdata = this.module.ConsumeRes(session, need, true); errdata != nil {
|
|
return
|
|
}
|
|
if err := this.module.modelDispatch.updateRefreshCount(session.GetUserId(), info.Nb); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
//刷新公告(随机新的任务 包括未领取和正在进行的任务)
|
|
tasks, err := this.module.modelDispatch.taskRandom(session.GetUserId(), info)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
//更新公告任务
|
|
if err := this.module.modelDispatch.updateTasks(session.GetUserId(), info.Nb, tasks); err != nil {
|
|
this.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()})
|
|
return
|
|
}
|
|
|
|
rsp := &pb.DispatchRefreshResp{
|
|
FreeCount: info.Nb.FreeCount,
|
|
RefreshCount: info.Nb.RefreshCount,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "refresh", rsp)
|
|
return
|
|
}
|