82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package dispatch
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 公告板信息
|
|
|
|
func (a *apiComp) NoticeCheck(session comm.IUserSession, req *pb.DispatchNoticeReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
func (a *apiComp) Notice(session comm.IUserSession, req *pb.DispatchNoticeReq) (code pb.ErrorCode, data proto.Message) {
|
|
d := a.module.modelDispatch.getDBDispatch(session.GetUserId())
|
|
if d == nil {
|
|
code = pb.ErrorCode_DataNotFound
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
rsp := &pb.DispatchNoticeResp{}
|
|
|
|
if len(d.Nb.Tasks) == 0 {
|
|
tasks, err := a.module.modelDispatch.taskRandom(uid, d)
|
|
if err != nil {
|
|
|
|
return
|
|
}
|
|
if len(tasks) == 0 {
|
|
return
|
|
}
|
|
|
|
freeCount := a.module.configure.GetGlobalConf().DispatchFreecheck
|
|
nb := &pb.Noticeboard{
|
|
Lv: 1, //公告初始升级
|
|
FreeCount: freeCount,
|
|
Tasks: tasks,
|
|
UpdateTime: configure.Now().Unix(),
|
|
}
|
|
|
|
update := map[string]interface{}{
|
|
"nb": nb,
|
|
}
|
|
if err := a.module.modelDispatch.Change(uid, update); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
d.Nb = nb
|
|
} else {
|
|
//恢复门票
|
|
one := utils.DiffDays(d.Nb.UpdateTime, configure.Now().Unix())
|
|
if one >= 1 {
|
|
itemId := a.module.configure.GetGlobalConf().DispatchNumtools.T
|
|
left := a.module.ModuleItems.QueryItemAmount(uid, itemId)
|
|
limit := a.module.configure.GetGlobalConf().DispatchNumoftimes
|
|
if int32(left) < limit {
|
|
add := limit - int32(left)
|
|
atn := &cfg.Gameatn{A: "item", T: itemId, N: add}
|
|
a.module.DispenseRes(session, []*cfg.Gameatn{atn}, true)
|
|
}
|
|
}
|
|
//周任务重置
|
|
n := utils.DiffDays(d.Nb.UpdateTime, configure.Now().Unix())
|
|
day := a.module.configure.GetGlobalConf().DispatchWeektaskcheck
|
|
if int32(n) >= day {
|
|
d.Nb.WeekCount = 0
|
|
d.Nb.WeekReceived = []int32{}
|
|
d.Nb.UpdateTime = configure.Now().Unix()
|
|
}
|
|
a.module.modelDispatch.updateNotice(session.GetUserId(), d)
|
|
}
|
|
|
|
rsp.Dispatch = d.Nb
|
|
session.SendMsg(string(a.module.GetType()), "notice", rsp)
|
|
return
|
|
}
|