93 lines
2.2 KiB
Go
93 lines
2.2 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
var (
|
|
dailyDes int32 = 1
|
|
weekDes int32 = 4
|
|
)
|
|
|
|
// 我的世界任务
|
|
func (this *apiComp) MineCheck(session comm.IUserSession, req *pb.WorldtaskMineReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) (code pb.ErrorCode, data proto.Message) {
|
|
uid := session.GetUserId()
|
|
|
|
user := this.module.ModuleUser.GetUser(uid)
|
|
if user == nil {
|
|
code = pb.ErrorCode_UserNofound
|
|
return
|
|
}
|
|
|
|
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
|
|
if err != nil {
|
|
this.module.Error("获取玩家世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
if myWorldtask.CurrentTask == nil {
|
|
myWorldtask.CurrentTask = make(map[int32]*pb.Worldtask)
|
|
}
|
|
|
|
now := configure.Now().Unix()
|
|
update := make(map[string]interface{})
|
|
|
|
// 日常
|
|
if now-myWorldtask.DaliyRefreshTime >= 3600*24 {
|
|
dailyIds := this.module.randomTask(user.Lv, dailyDes, myWorldtask)
|
|
for _, v := range dailyIds {
|
|
gwtd, err := this.module.configure.getWorldtaskById(v)
|
|
if err != nil || gwtd == nil {
|
|
continue
|
|
}
|
|
myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{
|
|
TaskId: v,
|
|
TaskType: gwtd.Des,
|
|
}
|
|
}
|
|
update["daliyRefreshTime"] = configure.Now().Unix()
|
|
}
|
|
|
|
//周常
|
|
if now-myWorldtask.WeekRefreshTime >= 3600*24*7 {
|
|
weekIds := this.module.randomTask(user.Lv, weekDes, myWorldtask)
|
|
for _, v := range weekIds {
|
|
gwtd, err := this.module.configure.getWorldtaskById(v)
|
|
if err != nil || gwtd == nil {
|
|
continue
|
|
}
|
|
myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{
|
|
TaskId: v,
|
|
TaskType: gwtd.Des,
|
|
}
|
|
}
|
|
update["weekRefreshTime"] = configure.Now().Unix()
|
|
}
|
|
|
|
update["currentTask"] = myWorldtask.CurrentTask
|
|
|
|
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
rsp := &pb.WorldtaskMineResp{
|
|
Task: myWorldtask,
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.module.GetType()), WorldtaskSubtypeMine, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
return
|
|
}
|