Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
163317542a
@ -252,18 +252,6 @@ type (
|
|||||||
}
|
}
|
||||||
//任务
|
//任务
|
||||||
ITask interface {
|
ITask interface {
|
||||||
//初始化 日常/周常/成就
|
|
||||||
InitTaskAll(uid string)
|
|
||||||
// 初始化指定的任务
|
|
||||||
InitTaskByTag(uid string, taskTag TaskTag)
|
|
||||||
//清空任务
|
|
||||||
ResetTask(uid string, taskTag TaskTag)
|
|
||||||
// 清理玩家任务数据
|
|
||||||
CleanData(uid string)
|
|
||||||
// 获取当前任务
|
|
||||||
GetTaskById(uid string, taskTag, taskId int32) *pb.TaskData
|
|
||||||
// 获取已完成的日任务列表
|
|
||||||
GetTaskDayFinished(uid string) []*pb.TaskData
|
|
||||||
///红点
|
///红点
|
||||||
IGetReddot
|
IGetReddot
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ func (this *apiComp) Complete(session comm.IUserSession, req *pb.StorylineComple
|
|||||||
conf *cfg.GameHeroupstoryChapterData
|
conf *cfg.GameHeroupstoryChapterData
|
||||||
award []*pb.UserAssets
|
award []*pb.UserAssets
|
||||||
ok bool
|
ok bool
|
||||||
|
iswin bool
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if errdata = this.CompleteCheck(session, req); errdata != nil {
|
if errdata = this.CompleteCheck(session, req); errdata != nil {
|
||||||
@ -35,6 +36,7 @@ func (this *apiComp) Complete(session comm.IUserSession, req *pb.StorylineComple
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if info, err = this.module.modeltask.getUserDTasks(session.GetUserId()); err != nil {
|
if info, err = this.module.modeltask.getUserDTasks(session.GetUserId()); err != nil {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_DBError,
|
Code: pb.ErrorCode_DBError,
|
||||||
@ -44,6 +46,15 @@ func (this *apiComp) Complete(session comm.IUserSession, req *pb.StorylineComple
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if 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, ok = info.Item[conf.Hero]; !ok {
|
if item, ok = info.Item[conf.Hero]; !ok {
|
||||||
info.Item[conf.Hero] = &pb.DBStorylineItem{
|
info.Item[conf.Hero] = &pb.DBStorylineItem{
|
||||||
Id: conf.Hero,
|
Id: conf.Hero,
|
||||||
@ -51,14 +62,22 @@ func (this *apiComp) Complete(session comm.IUserSession, req *pb.StorylineComple
|
|||||||
}
|
}
|
||||||
item = info.Item[conf.Hero]
|
item = info.Item[conf.Hero]
|
||||||
}
|
}
|
||||||
|
if conf.Leveltype == 1 { //剧情关卡
|
||||||
if item.Level[req.Level] != 0 {
|
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{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_ReqParameterError,
|
Code: pb.ErrorCode_ReqParameterError,
|
||||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||||
Message: fmt.Sprintf("%d received", req.Level),
|
Message: "battle no win!",
|
||||||
}
|
}
|
||||||
return
|
}
|
||||||
|
item.Level[req.Level] = 1
|
||||||
|
} else {
|
||||||
|
item.Level[req.Level] = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if errdata = this.module.DispenseRes(session, conf.Reward, true); errdata != nil {
|
if errdata = this.module.DispenseRes(session, conf.Reward, true); errdata != nil {
|
||||||
|
@ -24,6 +24,11 @@ func (this *apiComp) ActiveReceiveCheck(session comm.IUserSession, req *pb.TaskA
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActiveReceiveReq) (errdata *pb.ErrorData) {
|
func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActiveReceiveReq) (errdata *pb.ErrorData) {
|
||||||
|
var (
|
||||||
|
active *pb.DBActivity
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if errdata = this.ActiveReceiveCheck(session, req); errdata != nil {
|
if errdata = this.ActiveReceiveCheck(session, req); errdata != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -51,9 +56,16 @@ func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActive
|
|||||||
var flag bool
|
var flag bool
|
||||||
update := map[string]interface{}{}
|
update := map[string]interface{}{}
|
||||||
// 玩家的
|
// 玩家的
|
||||||
activeList := this.module.modelTaskActive.getActiveList(uid)
|
if active, err = this.module.modelTaskActive.getActiveList(uid); err != nil {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_DBError,
|
||||||
|
Title: pb.ErrorCode_DBError.ToString(),
|
||||||
|
Message: err.Error(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
// var activityData *pb.ActivityData
|
// var activityData *pb.ActivityData
|
||||||
for _, v := range activeList {
|
for _, v := range active.ActivityList {
|
||||||
if v.TaskId == req.Id {
|
if v.TaskId == req.Id {
|
||||||
if v.Received != 1 {
|
if v.Received != 1 {
|
||||||
conf := this.module.configure.getTaskActiveById(v.TaskId)
|
conf := this.module.configure.getTaskActiveById(v.TaskId)
|
||||||
@ -96,7 +108,7 @@ func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActive
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flag {
|
if flag {
|
||||||
update["activityList"] = activeList
|
update["activityList"] = active.ActivityList
|
||||||
|
|
||||||
if err := this.module.modelTaskActive.Change(session.GetUserId(), update); err != nil {
|
if err := this.module.modelTaskActive.Change(session.GetUserId(), update); err != nil {
|
||||||
this.module.Errorf("updateReceive err %v", err)
|
this.module.Errorf("updateReceive err %v", err)
|
||||||
|
@ -30,14 +30,19 @@ func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.TaskReceive
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq) (errdata *pb.ErrorData) {
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq) (errdata *pb.ErrorData) {
|
||||||
|
var (
|
||||||
|
userTask *pb.DBTask
|
||||||
|
taskDataList []*pb.TaskData
|
||||||
|
active *pb.DBActivity
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uid := session.GetUserId()
|
uid := session.GetUserId()
|
||||||
// 获取待领取的任务
|
// 获取待领取的任务
|
||||||
userTask := this.module.modelTask.getUserTask(uid, req.Id)
|
if userTask, err = this.module.modelTask.getUserTask(uid); err != nil {
|
||||||
|
|
||||||
if userTask == nil {
|
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_TaskNotFound,
|
Code: pb.ErrorCode_TaskNotFound,
|
||||||
Title: pb.ErrorCode_TaskNotFound.ToString(),
|
Title: pb.ErrorCode_TaskNotFound.ToString(),
|
||||||
@ -45,8 +50,6 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var taskDataList []*pb.TaskData
|
|
||||||
|
|
||||||
switch req.TaskTag {
|
switch req.TaskTag {
|
||||||
case int32(comm.TASK_DAILY):
|
case int32(comm.TASK_DAILY):
|
||||||
taskDataList = userTask.DayList
|
taskDataList = userTask.DayList
|
||||||
@ -115,10 +118,12 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
|
|||||||
// 周任务 自动领取奖励
|
// 周任务 自动领取奖励
|
||||||
if comm.TaskTag(req.TaskTag) == comm.TASK_WEEKLY {
|
if comm.TaskTag(req.TaskTag) == comm.TASK_WEEKLY {
|
||||||
TaskActive := make(map[string]interface{})
|
TaskActive := make(map[string]interface{})
|
||||||
activeList := this.module.modelTaskActive.getActiveList(uid)
|
if active, err = this.module.modelTaskActive.getActiveList(uid); err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
var rewards []*cfg.Gameatn
|
var rewards []*cfg.Gameatn
|
||||||
var maxTaskId int32
|
var maxTaskId int32
|
||||||
for _, v := range activeList {
|
for _, v := range active.ActivityList {
|
||||||
if v.Received != 1 {
|
if v.Received != 1 {
|
||||||
conf := this.module.configure.getTaskActiveById(v.TaskId)
|
conf := this.module.configure.getTaskActiveById(v.TaskId)
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
@ -141,7 +146,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(rewards) > 0 {
|
if len(rewards) > 0 {
|
||||||
TaskActive["activityList"] = activeList
|
TaskActive["activityList"] = active.ActivityList
|
||||||
|
|
||||||
if err := this.module.modelTaskActive.Change(session.GetUserId(), TaskActive); err != nil {
|
if err := this.module.modelTaskActive.Change(session.GetUserId(), TaskActive); err != nil {
|
||||||
this.module.Errorf("updateReceive err %v", err)
|
this.module.Errorf("updateReceive err %v", err)
|
||||||
|
@ -3,6 +3,7 @@ package task
|
|||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/mgo"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
@ -13,13 +14,13 @@ import (
|
|||||||
|
|
||||||
type ModelTaskActive struct {
|
type ModelTaskActive struct {
|
||||||
modules.MCompModel
|
modules.MCompModel
|
||||||
moduleTask *ModuleTask
|
module *ModuleTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ModelTaskActive) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *ModelTaskActive) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.TableName = comm.TableTaskActive
|
this.TableName = comm.TableTaskActive
|
||||||
err = this.MCompModel.Init(service, module, comp, options)
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
this.moduleTask = module.(*ModuleTask)
|
this.module = module.(*ModuleTask)
|
||||||
// 加索引
|
// 加索引
|
||||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||||
@ -28,55 +29,40 @@ func (this *ModelTaskActive) Init(service core.IService, module core.IModule, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化活跃度
|
// 初始化活跃度
|
||||||
func (this *ModelTaskActive) initActiveReward(uid string, taskTag comm.TaskTag) {
|
func (this *ModelTaskActive) initActiveReward(active *pb.DBActivity, taskTag comm.TaskTag) {
|
||||||
task := &pb.DBActivity{}
|
data := this.module.configure.getTaskActiveByTag(int32(taskTag))
|
||||||
if err := this.Get(uid, task); err != nil {
|
|
||||||
if err == mongo.ErrNoDocuments {
|
|
||||||
objId := primitive.NewObjectID().Hex()
|
|
||||||
task = &pb.DBActivity{
|
|
||||||
Uid: uid,
|
|
||||||
Id: objId,
|
|
||||||
}
|
|
||||||
this.moduleTask.modelTaskActive.Add(uid, task)
|
|
||||||
} else {
|
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data := this.moduleTask.configure.getTaskActiveByTag(int32(taskTag))
|
|
||||||
|
|
||||||
for _, conf := range data {
|
for _, conf := range data {
|
||||||
ta := &pb.ActivityData{
|
ta := &pb.ActivityData{
|
||||||
Tag: int32(taskTag),
|
Tag: int32(taskTag),
|
||||||
TaskId: conf.Key,
|
TaskId: conf.Key,
|
||||||
}
|
}
|
||||||
task.ActivityList = append(task.ActivityList, ta)
|
active.ActivityList = append(active.ActivityList, ta)
|
||||||
}
|
|
||||||
update := map[string]interface{}{
|
|
||||||
"activityList": task.ActivityList,
|
|
||||||
}
|
|
||||||
if err := this.moduleTask.modelTaskActive.Change(uid, update); err != nil {
|
|
||||||
this.moduleTask.Errorf("uid:%v tag:%v initActivity err %v", uid, err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ModelTaskActive) getActiveList(uid string) (list []*pb.ActivityData) {
|
func (this *ModelTaskActive) getActiveList(uid string) (active *pb.DBActivity, err error) {
|
||||||
task := &pb.DBActivity{}
|
active = &pb.DBActivity{}
|
||||||
if err := this.Get(uid, task); err != nil {
|
if err = this.Get(uid, active); err != nil && err != mgo.MongodbNil {
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
this.module.Errorf("getTaskList err %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err == mongo.ErrNoDocuments {
|
||||||
return task.ActivityList
|
objId := primitive.NewObjectID().Hex()
|
||||||
|
active = &pb.DBActivity{
|
||||||
|
Uid: uid,
|
||||||
|
Id: objId,
|
||||||
|
ActivityList: make([]*pb.ActivityData, 0),
|
||||||
|
}
|
||||||
|
err = this.Add(uid, active)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取玩家活跃度列表
|
// 获取玩家活跃度列表
|
||||||
func (this *ModelTaskActive) getActiveListByTag(uid string, taskTag comm.TaskTag) (list []*pb.ActivityData) {
|
func (this *ModelTaskActive) getActiveListByTag(uid string, taskTag comm.TaskTag) (list []*pb.ActivityData) {
|
||||||
task := &pb.DBActivity{}
|
task := &pb.DBActivity{}
|
||||||
if err := this.Get(uid, task); err != nil {
|
if err := this.Get(uid, task); err != nil {
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
this.module.Errorf("getTaskList err %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,29 +76,19 @@ func (this *ModelTaskActive) getActiveListByTag(uid string, taskTag comm.TaskTag
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查询完成的且未领取的任务 发现未领取返回true
|
// 查询完成的且未领取的任务 发现未领取返回true
|
||||||
func (this *ModelTaskActive) noReceiveTaskActive(uid string, taskTag comm.TaskTag) (bool, error) {
|
func (this *ModelTaskActive) noReceiveTaskActive(user *pb.DBUserExpand, activityList []*pb.ActivityData, taskTag comm.TaskTag) (bool, error) {
|
||||||
// 获取玩家活跃度
|
|
||||||
expand, err := this.moduleTask.ModuleUser.GetUserExpand(uid)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
task := &pb.DBActivity{}
|
|
||||||
if err := this.Get(uid, task); err != nil {
|
|
||||||
// this.moduleTask.Warnf("getTaskActivityList err %v", err)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range task.ActivityList {
|
for _, v := range activityList {
|
||||||
if v.Tag == int32(taskTag) && v.Received == 0 {
|
if v.Tag == int32(taskTag) && v.Received == 0 {
|
||||||
conf := this.moduleTask.configure.getTaskActiveById(v.TaskId)
|
conf := this.module.configure.getTaskActiveById(v.TaskId)
|
||||||
if conf != nil && expand != nil {
|
if conf != nil && user != nil {
|
||||||
switch taskTag {
|
switch taskTag {
|
||||||
case comm.TASK_DAILY:
|
case comm.TASK_DAILY:
|
||||||
if expand.Activeday >= conf.Active {
|
if user.Activeday >= conf.Active {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
case comm.TASK_WEEKLY:
|
case comm.TASK_WEEKLY:
|
||||||
if expand.Activeweek >= conf.Active {
|
if user.Activeweek >= conf.Active {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,27 +113,34 @@ func (this *ModelTaskActive) updateReceive(uid string, data map[string]interface
|
|||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return this.moduleTask.modelTaskActive.Change(uid, data)
|
return this.module.modelTaskActive.Change(uid, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空活跃度任务
|
// 清空活跃度任务
|
||||||
func (this *ModelTaskActive) clearTask(uid string, taskTag ...comm.TaskTag) {
|
func (this *ModelTaskActive) clearTask(uid string, taskTag ...comm.TaskTag) {
|
||||||
if len(taskTag) == 0 {
|
if len(taskTag) == 0 {
|
||||||
this.moduleTask.Errorf("least one param for taskTag")
|
this.module.Errorf("least one param for taskTag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := this.getActiveList(uid)
|
var (
|
||||||
for i := 0; i < len(data); i++ {
|
active *pb.DBActivity
|
||||||
if data[i].Tag == int32(taskTag[0]) {
|
err error
|
||||||
data = append(data[:i], data[i+1:]...)
|
)
|
||||||
|
if active, err = this.getActiveList(uid); err != nil {
|
||||||
|
this.module.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(active.ActivityList); i++ {
|
||||||
|
if active.ActivityList[i].Tag == int32(taskTag[0]) {
|
||||||
|
active.ActivityList = append(active.ActivityList[:i], active.ActivityList[i+1:]...)
|
||||||
i--
|
i--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update := map[string]interface{}{
|
update := map[string]interface{}{
|
||||||
"activityList": data,
|
"activityList": active.ActivityList,
|
||||||
}
|
}
|
||||||
if err := this.moduleTask.modelTaskActive.Change(uid, update); err != nil {
|
if err := this.module.modelTaskActive.Change(uid, update); err != nil {
|
||||||
this.moduleTask.Errorf("uid: %v err:%v", uid, err)
|
this.module.Errorf("uid: %v err:%v", uid, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
event_v2 "go_dreamfactory/lego/sys/event/v2"
|
event_v2 "go_dreamfactory/lego/sys/event/v2"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/lego/sys/mgo"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"sort"
|
"sort"
|
||||||
@ -18,14 +19,14 @@ import (
|
|||||||
|
|
||||||
type ModelTask struct {
|
type ModelTask struct {
|
||||||
modules.MCompModel
|
modules.MCompModel
|
||||||
moduleTask *ModuleTask
|
module *ModuleTask
|
||||||
EventApp *event_v2.App
|
EventApp *event_v2.App
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ModelTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *ModelTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.TableName = comm.TableTask
|
this.TableName = comm.TableTask
|
||||||
err = this.MCompModel.Init(service, module, comp, options)
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
this.moduleTask = module.(*ModuleTask)
|
this.module = module.(*ModuleTask)
|
||||||
this.EventApp = event_v2.NewApp()
|
this.EventApp = event_v2.NewApp()
|
||||||
// this.EventApp.Listen(comm.EventTaskChanged, this.doTaskHandle)
|
// this.EventApp.Listen(comm.EventTaskChanged, this.doTaskHandle)
|
||||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
@ -35,12 +36,7 @@ func (this *ModelTask) Init(service core.IService, module core.IModule, comp cor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查询完成的且未领取的任务 发现未领取返回true
|
// 查询完成的且未领取的任务 发现未领取返回true
|
||||||
func (this *ModelTask) noReceiveTask(uid string, taskTag comm.TaskTag) (bool, error) {
|
func (this *ModelTask) noReceiveTask(task *pb.DBTask, taskTag comm.TaskTag) (bool, error) {
|
||||||
task := &pb.DBTask{}
|
|
||||||
if err := this.Get(uid, task); err != nil {
|
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
if taskTag == comm.TASK_DAILY {
|
if taskTag == comm.TASK_DAILY {
|
||||||
for _, v := range task.DayList {
|
for _, v := range task.DayList {
|
||||||
if v.Received == 0 {
|
if v.Received == 0 {
|
||||||
@ -64,9 +60,9 @@ func (this *ModelTask) checkTaskStatus(uid string, list []*pb.TaskData) []*pb.Ta
|
|||||||
condIds = append(condIds, v.TypeId)
|
condIds = append(condIds, v.TypeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
conds, err := this.moduleTask.ModuleBuried.CheckCondition(uid, condIds...)
|
conds, err := this.module.ModuleBuried.CheckCondition(uid, condIds...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.moduleTask.Error(err.Error())
|
this.module.Error(err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +84,7 @@ func (this *ModelTask) checkTaskStatus(uid string, list []*pb.TaskData) []*pb.Ta
|
|||||||
func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DBTask {
|
func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DBTask {
|
||||||
task := &pb.DBTask{}
|
task := &pb.DBTask{}
|
||||||
if err := this.Get(uid, task); err != nil {
|
if err := this.Get(uid, task); err != nil {
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
this.module.Errorf("getTaskList err %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +116,8 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
|
|||||||
update["weekList"] = dataList
|
update["weekList"] = dataList
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := this.moduleTask.modelTask.Change(uid, update); err != nil {
|
if err := this.module.modelTask.Change(uid, update); err != nil {
|
||||||
this.moduleTask.Error("change err", log.Field{Key: "uid", Value: uid})
|
this.module.Error("change err", log.Field{Key: "uid", Value: uid})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前玩家成就任务
|
// 当前玩家成就任务
|
||||||
@ -136,7 +132,7 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
|
|||||||
|
|
||||||
// 判断上个成就任务领取了才显示最后一个任务
|
// 判断上个成就任务领取了才显示最后一个任务
|
||||||
isReceived := func(taskId int32) bool {
|
isReceived := func(taskId int32) bool {
|
||||||
if preCnf := this.moduleTask.configure.getPreTask(taskId); preCnf != nil {
|
if preCnf := this.module.configure.getPreTask(taskId); preCnf != nil {
|
||||||
if preTask := getCurTask(preCnf.Key); preTask != nil {
|
if preTask := getCurTask(preCnf.Key); preTask != nil {
|
||||||
if preTask.Received == 1 {
|
if preTask.Received == 1 {
|
||||||
return true
|
return true
|
||||||
@ -151,16 +147,16 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
|
|||||||
|
|
||||||
if taskTag == comm.TASK_ACHIEVE {
|
if taskTag == comm.TASK_ACHIEVE {
|
||||||
for _, v := range task.AchieveList {
|
for _, v := range task.AchieveList {
|
||||||
if curTask := this.moduleTask.configure.getTaskById(v.TaskId); curTask != nil {
|
if curTask := this.module.configure.getTaskById(v.TaskId); curTask != nil {
|
||||||
if v.Received == 0 {
|
if v.Received == 0 {
|
||||||
isFirst := this.moduleTask.configure.isFirstTask(curTask.Key)
|
isFirst := this.module.configure.isFirstTask(curTask.Key)
|
||||||
if curTask.IdAfter == 0 && isFirst { //未领取和没有下个连续任务的
|
if curTask.IdAfter == 0 && isFirst { //未领取和没有下个连续任务的
|
||||||
achieveList = append(achieveList, v)
|
achieveList = append(achieveList, v)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if isFirst && curTask.IdAfter != 0 { //连续任务的第一个任务
|
if isFirst && curTask.IdAfter != 0 { //连续任务的第一个任务
|
||||||
next := this.moduleTask.configure.getTaskById(curTask.IdAfter)
|
next := this.module.configure.getTaskById(curTask.IdAfter)
|
||||||
if next != nil && v.Received == 0 {
|
if next != nil && v.Received == 0 {
|
||||||
achieveList = append(achieveList, v)
|
achieveList = append(achieveList, v)
|
||||||
}
|
}
|
||||||
@ -176,7 +172,7 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
|
|||||||
achieveList = this.checkTaskStatus(uid, achieveList)
|
achieveList = this.checkTaskStatus(uid, achieveList)
|
||||||
|
|
||||||
update["achieveList"] = achieveList
|
update["achieveList"] = achieveList
|
||||||
if err := this.moduleTask.modelTask.Change(uid, update); err != nil {
|
if err := this.module.modelTask.Change(uid, update); err != nil {
|
||||||
log.Error("err", log.Field{Key: "uid", Value: uid})
|
log.Error("err", log.Field{Key: "uid", Value: uid})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +186,7 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
|
|||||||
func (this *ModelTask) getTaskById(uid string, taskTag comm.TaskTag, taskId int32) *pb.DBTask {
|
func (this *ModelTask) getTaskById(uid string, taskTag comm.TaskTag, taskId int32) *pb.DBTask {
|
||||||
task := &pb.DBTask{}
|
task := &pb.DBTask{}
|
||||||
if err := this.Get(uid, task); err != nil {
|
if err := this.Get(uid, task); err != nil {
|
||||||
this.moduleTask.Errorf("getTaskById err %v", err)
|
this.module.Errorf("getTaskById err %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,28 +216,13 @@ func (this *ModelTask) getTaskById(uid string, taskTag comm.TaskTag, taskId int3
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化任务
|
// 初始化任务
|
||||||
func (this *ModelTask) initTask(uid string, taskTag comm.TaskTag) error {
|
func (this *ModelTask) initTask(opencond map[string]int32, task *pb.DBTask, taskTag comm.TaskTag) error {
|
||||||
task := &pb.DBTask{}
|
data := this.module.configure.getTaskByTag(int32(taskTag))
|
||||||
if err := this.Get(uid, task); err != nil {
|
for _, cnf := range data {
|
||||||
if err == mongo.ErrNoDocuments {
|
if unlock, ok := opencond[cnf.Open]; !ok || unlock != 2 {
|
||||||
objId := primitive.NewObjectID().Hex()
|
continue
|
||||||
task = &pb.DBTask{
|
|
||||||
Uid: uid,
|
|
||||||
Id: objId,
|
|
||||||
}
|
|
||||||
if err := this.Add(uid, task); err != nil {
|
|
||||||
this.moduleTask.Errorf("initTask addlists err %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := this.moduleTask.configure.getTaskByTag(int32(taskTag))
|
|
||||||
update := map[string]interface{}{}
|
|
||||||
for _, cnf := range data {
|
|
||||||
t := &pb.TaskData{
|
t := &pb.TaskData{
|
||||||
Tag: cnf.IdTag,
|
Tag: cnf.IdTag,
|
||||||
TypeId: cnf.TypeId,
|
TypeId: cnf.TypeId,
|
||||||
@ -251,59 +232,39 @@ func (this *ModelTask) initTask(uid string, taskTag comm.TaskTag) error {
|
|||||||
}
|
}
|
||||||
if taskTag == comm.TASK_DAILY {
|
if taskTag == comm.TASK_DAILY {
|
||||||
task.DayList = append(task.DayList, t)
|
task.DayList = append(task.DayList, t)
|
||||||
update["dayList"] = task.DayList
|
|
||||||
} else if taskTag == comm.TASK_WEEKLY {
|
} else if taskTag == comm.TASK_WEEKLY {
|
||||||
task.WeekList = append(task.WeekList, t)
|
task.WeekList = append(task.WeekList, t)
|
||||||
update["weekList"] = task.WeekList
|
|
||||||
} else if taskTag == comm.TASK_ACHIEVE {
|
} else if taskTag == comm.TASK_ACHIEVE {
|
||||||
task.AchieveList = append(task.AchieveList, t)
|
task.AchieveList = append(task.AchieveList, t)
|
||||||
update["achieveList"] = task.AchieveList
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(update) > 0 {
|
|
||||||
if err := this.Change(uid, update); err != nil {
|
|
||||||
this.moduleTask.Errorf("initTask err %v", err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询用户任务
|
// 查询用户任务
|
||||||
func (this *ModelTask) getUserTask(uid string, taskId int32) *pb.DBTask {
|
func (this *ModelTask) getUserTask(uid string) (task *pb.DBTask, err error) {
|
||||||
task := &pb.DBTask{}
|
task = &pb.DBTask{}
|
||||||
if err := this.Get(uid, task); err != nil {
|
if err = this.Get(uid, task); err != nil && err != mgo.MongodbNil {
|
||||||
this.moduleTask.Errorf("getTaskList err %v", err)
|
return
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return task
|
if err == mongo.ErrNoDocuments {
|
||||||
|
objId := primitive.NewObjectID().Hex()
|
||||||
|
task = &pb.DBTask{
|
||||||
|
Uid: uid,
|
||||||
|
Id: objId,
|
||||||
|
}
|
||||||
|
if err = this.Add(uid, task); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取已完成的(日、周)任务
|
|
||||||
// func (this *ModelTask) getFinishTasks(uid string, taskTag comm.TaskTag) (list []*pb.TaskData) {
|
|
||||||
// task := this.getTaskListByTag(uid, taskTag)
|
|
||||||
// if taskTag == comm.TASK_DAILY {
|
|
||||||
// for _, v := range task.DayList {
|
|
||||||
// if v.Status == 1 {
|
|
||||||
// list = append(list, v)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else if taskTag == comm.TASK_WEEKLY {
|
|
||||||
// for _, v := range task.WeekList {
|
|
||||||
// if v.Status == 1 {
|
|
||||||
// list = append(list, v)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 获取待处理的(日、周)任务
|
// 获取待处理的(日、周)任务
|
||||||
func (this *ModelTask) getUnFinishTasks(uid string, taskId int32) (list []*pb.TaskData) {
|
func (this *ModelTask) getUnFinishTasks(uid string, taskId int32) (list []*pb.TaskData) {
|
||||||
task := &pb.DBTask{}
|
task := &pb.DBTask{}
|
||||||
if err := this.Get(uid, task); err != nil {
|
if err := this.Get(uid, task); err != nil {
|
||||||
this.moduleTask.Errorf("getTaskById err %v", err)
|
this.module.Errorf("getTaskById err %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,23 +291,12 @@ func (this *ModelTask) getUnFinishTasks(uid string, taskId int32) (list []*pb.Ta
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查任务状态 返回等待处理的任务
|
|
||||||
func (this *ModelTask) checkTask(uid string, taskId int32) (*pb.TaskData, bool) {
|
|
||||||
taskList := this.getUnFinishTasks(uid, taskId)
|
|
||||||
for _, v := range taskList {
|
|
||||||
if taskId == v.TaskId {
|
|
||||||
return v, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更改用户任务
|
// 更改用户任务
|
||||||
// Deprecated
|
// Deprecated
|
||||||
func (this *ModelTask) modifyUserTask(uid string, taskId int32, data map[string]interface{}) error {
|
func (this *ModelTask) modifyUserTask(uid string, taskId int32, data map[string]interface{}) error {
|
||||||
var task *pb.DBTask
|
var task *pb.DBTask
|
||||||
if err := this.GetList(uid, &task); err != nil {
|
if err := this.GetList(uid, &task); err != nil {
|
||||||
this.moduleTask.Errorf("getTaskById err %v", err)
|
this.module.Errorf("getTaskById err %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
@ -386,146 +336,15 @@ func (this *ModelTask) modifyUserTask(uid string, taskId int32, data map[string]
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空任务
|
|
||||||
// func (this *ModelTask) clearTask(uid string, taskTag ...comm.TaskTag) {
|
|
||||||
// if len(taskTag) == 0 {
|
|
||||||
// this.moduleTask.Error("TaskTag参数缺失",
|
|
||||||
// log.Field{Key: "uid", Value: uid},
|
|
||||||
// log.Field{Key: "params", Value: taskTag},
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// var task *pb.DBTask
|
|
||||||
// if err := this.GetList(uid, &task); err != nil {
|
|
||||||
// this.moduleTask.Errorf("getTaskById err %v", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if task == nil {
|
|
||||||
// this.moduleTask.Error("任务数据空",
|
|
||||||
// log.Field{Key: "uid", Value: uid},
|
|
||||||
// log.Field{Key: "taskTag", Value: taskTag},
|
|
||||||
// )
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// dr := this.moduleTask.ModuleRtask.GetCondiData(uid)
|
|
||||||
|
|
||||||
// update := map[string]interface{}{}
|
|
||||||
// if taskTag[0] == comm.TASK_DAILY {
|
|
||||||
// for _, v := range task.DayList {
|
|
||||||
// //删除任务条件数据
|
|
||||||
// if dr != nil && dr.Vals != nil {
|
|
||||||
// delete(dr.Vals, v.TypeId)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if err := this.moduleTask.ModuleRtask.ChangeCondi(uid, dr.Vals); err != nil {
|
|
||||||
// this.moduleTask.Error("更新任务条件数据", log.Field{Key: "uid", Value: uid})
|
|
||||||
// }
|
|
||||||
// update["dayList"] = make([]*pb.TaskData, 0)
|
|
||||||
// } else if taskTag[0] == comm.TASK_WEEKLY {
|
|
||||||
// for _, v := range task.WeekList {
|
|
||||||
// //删除任务条件数据
|
|
||||||
// if dr != nil && dr.Vals != nil {
|
|
||||||
// delete(dr.Vals, v.TypeId)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if err := this.moduleTask.ModuleRtask.ChangeCondi(uid, dr.Vals); err != nil {
|
|
||||||
// this.moduleTask.Error("更新任务条件数据", log.Field{Key: "uid", Value: uid})
|
|
||||||
// }
|
|
||||||
// update["weekList"] = make([]*pb.TaskData, 0)
|
|
||||||
// } else if taskTag[0] == comm.TASK_ACHIEVE {
|
|
||||||
// for _, v := range task.AchieveList {
|
|
||||||
// //删除任务条件数据
|
|
||||||
// if dr != nil && dr.Vals != nil {
|
|
||||||
// delete(dr.Vals, v.TypeId)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if err := this.moduleTask.ModuleRtask.ChangeCondi(uid, dr.Vals); err != nil {
|
|
||||||
// this.moduleTask.Error("更新任务条件数据", log.Field{Key: "uid", Value: uid})
|
|
||||||
// }
|
|
||||||
// update["weekList"] = make([]*pb.TaskData, 0)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if err := this.moduleTask.modelTask.Change(uid, update); err != nil {
|
|
||||||
// this.moduleTask.Error("清空任务数据", log.Field{Key: "uid", Value: uid})
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 任务处理
|
|
||||||
// func (this *ModelTask) doTaskHandle(event interface{}, next func(event interface{})) {
|
|
||||||
// tl := event.(*TaskListen)
|
|
||||||
|
|
||||||
// data, err := this.moduleTask.configure.getTasks(int32(tl.TaskType))
|
|
||||||
// if err != nil {
|
|
||||||
// this.moduleTask.Errorf("taskHandle err %v", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 获取玩家的任务条件数据
|
|
||||||
// dr := this.moduleTask.ModuleRtask.GetCondiData(tl.Uid)
|
|
||||||
// if dr == nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 遍历事件列表
|
|
||||||
// for _, conf := range data {
|
|
||||||
// // 从任务条件中查找
|
|
||||||
// ret, ok := dr.Vals[conf.TypeId]
|
|
||||||
// if !ok {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// task, ok := this.checkTask(tl.Uid, conf.Key)
|
|
||||||
// if !ok {
|
|
||||||
// this.moduleTask.Debug("任务已完成", log.Field{Key: "uid", Value: tl.Uid}, log.Field{Key: "任务ID", Value: conf.Key})
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var (
|
|
||||||
// progress int32
|
|
||||||
// update map[string]interface{}
|
|
||||||
// )
|
|
||||||
|
|
||||||
// if code := this.moduleTask.ModuleRtask.CheckCondi(tl.Uid, conf.TypeId); code == nil {
|
|
||||||
// // update data
|
|
||||||
// if ret != nil && len(ret.Data) > 0 {
|
|
||||||
// progress = ret.Data[0]
|
|
||||||
// }
|
|
||||||
// update = map[string]interface{}{
|
|
||||||
// "progress": progress,
|
|
||||||
// "status": 1,
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if ret != nil && len(ret.Data) > 0 {
|
|
||||||
// progress = ret.Data[0]
|
|
||||||
// }
|
|
||||||
// update = map[string]interface{}{
|
|
||||||
// "progress": progress,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if err = this.modifyUserTask(tl.Uid, task.TaskId, update); err != nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// this.moduleTask.Debug("更新任务",
|
|
||||||
// log.Field{Key: "uid", Value: tl.Uid}, log.Field{Key: "任务ID", Value: conf.Key},
|
|
||||||
// log.Field{Key: "事件ID", Value: conf.TypeId}, log.Field{Key: "progress", Value: update["progress"]},
|
|
||||||
// log.Field{Key: "status", Value: update["status"]},
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 更新活跃度
|
// 更新活跃度
|
||||||
func (this *ModelTask) updateActive(uid string, cfgId int32) error {
|
func (this *ModelTask) updateActive(uid string, cfgId int32) error {
|
||||||
// 更新活跃度
|
// 更新活跃度
|
||||||
de, err := this.moduleTask.ModuleUser.GetUserExpand(uid)
|
de, err := this.module.ModuleUser.GetUserExpand(uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := this.moduleTask.configure.getTaskById(cfgId)
|
conf := this.module.configure.getTaskById(cfgId)
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
return errors.New(fmt.Sprintf("%v config nil", cfgId))
|
return errors.New(fmt.Sprintf("%v config nil", cfgId))
|
||||||
}
|
}
|
||||||
@ -542,7 +361,7 @@ func (this *ModelTask) updateActive(uid string, cfgId int32) error {
|
|||||||
"activeweek": de.Activeweek,
|
"activeweek": de.Activeweek,
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.moduleTask.ModuleUser.ChangeUserExpand(uid, update)
|
return this.module.ModuleUser.ChangeUserExpand(uid, update)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskListen struct {
|
type TaskListen struct {
|
||||||
|
@ -51,30 +51,50 @@ func (this *ModuleTask) OnInstallComp() {
|
|||||||
// 模块启动接口
|
// 模块启动接口
|
||||||
func (this *ModuleTask) Start() (err error) {
|
func (this *ModuleTask) Start() (err error) {
|
||||||
err = this.ModuleBase.Start()
|
err = this.ModuleBase.Start()
|
||||||
|
event.RegisterGO(comm.EventUserLogin, this.EventUserLogin)
|
||||||
event.RegisterGO(comm.EventUserOffline, this.CleanTask)
|
event.RegisterGO(comm.EventUserOffline, this.CleanTask)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化日常、周常、成就
|
func (this *ModuleTask) EventUserLogin(session comm.IUserSession) {
|
||||||
func (this *ModuleTask) InitTaskAll(uid string) {
|
var (
|
||||||
this.modelTask.initTask(uid, comm.TASK_DAILY)
|
opencond map[string]int32
|
||||||
this.modelTask.initTask(uid, comm.TASK_WEEKLY)
|
errdata *pb.ErrorData
|
||||||
this.modelTask.initTask(uid, comm.TASK_ACHIEVE)
|
task *pb.DBTask
|
||||||
this.modelTaskActive.initActiveReward(uid, comm.TASK_DAILY)
|
active *pb.DBActivity
|
||||||
this.modelTaskActive.initActiveReward(uid, comm.TASK_WEEKLY)
|
err error
|
||||||
|
)
|
||||||
|
if opencond, errdata = this.ModuleSys.QueryOpenCondData(session.GetUserId()); errdata != nil {
|
||||||
|
this.Errorf("getTaskList err %v", errdata)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化指定的任务
|
if task, err = this.modelTask.getUserTask(session.GetUserId()); err != nil {
|
||||||
func (this *ModuleTask) InitTaskByTag(uid string, taskTag comm.TaskTag) {
|
this.Errorf("getTaskList err %v", err)
|
||||||
switch taskTag {
|
return
|
||||||
case comm.TASK_DAILY:
|
}
|
||||||
this.modelTask.initTask(uid, comm.TASK_DAILY)
|
this.modelTask.initTask(opencond, task, comm.TASK_DAILY)
|
||||||
this.modelTaskActive.initActiveReward(uid, comm.TASK_DAILY)
|
this.modelTask.initTask(opencond, task, comm.TASK_WEEKLY)
|
||||||
case comm.TASK_WEEKLY:
|
this.modelTask.initTask(opencond, task, comm.TASK_ACHIEVE)
|
||||||
this.modelTask.initTask(uid, comm.TASK_WEEKLY)
|
if err = this.modelTask.Change(session.GetUserId(), map[string]interface{}{
|
||||||
this.modelTaskActive.initActiveReward(uid, comm.TASK_WEEKLY)
|
"dayList": task.DayList,
|
||||||
case comm.TASK_ACHIEVE:
|
"weekList": task.WeekList,
|
||||||
this.modelTask.initTask(uid, comm.TASK_ACHIEVE)
|
"achieveList": task.AchieveList,
|
||||||
|
}); err != nil {
|
||||||
|
log.Error("err", log.Field{Key: "uid", Value: session.GetUserId()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if active, err = this.modelTaskActive.getActiveList(session.GetUserId()); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.modelTaskActive.initActiveReward(active, comm.TASK_DAILY)
|
||||||
|
this.modelTaskActive.initActiveReward(active, comm.TASK_WEEKLY)
|
||||||
|
if err = this.modelTaskActive.Change(session.GetUserId(), map[string]interface{}{
|
||||||
|
"activityList": active.ActivityList,
|
||||||
|
}); err != nil {
|
||||||
|
log.Error("err", log.Field{Key: "uid", Value: session.GetUserId()})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,61 +117,40 @@ func (this *ModuleTask) resetActive(uid string, taskTag comm.TaskTag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取玩家指定任务
|
|
||||||
func (this *ModuleTask) GetTaskById(uid string, taskTag, taskId int32) *pb.TaskData {
|
|
||||||
var task *pb.DBTask
|
|
||||||
if err := this.modelTask.GetList(uid, &task); err != nil {
|
|
||||||
log.Errorf("GetTaskById err %v", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if taskTag == int32(comm.TASK_DAILY) {
|
|
||||||
for _, v := range task.DayList {
|
|
||||||
if v.TaskId == taskId {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重置任务
|
|
||||||
func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) {
|
|
||||||
this.resetActive(uid, taskTag)
|
|
||||||
// this.modelTask.clearTask(uid, taskTag)
|
|
||||||
this.modelTaskActive.clearTask(uid, taskTag)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理任务数据
|
|
||||||
func (this *ModuleTask) CleanData(uid string) {
|
|
||||||
// this.modelTask.clearTask(uid)
|
|
||||||
this.modelTaskActive.clearTask(uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 任务处理器注册
|
|
||||||
type taskHandle func(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask
|
|
||||||
|
|
||||||
// 获取每日任务列表
|
|
||||||
// Deprecated
|
|
||||||
func (this *ModuleTask) GetTaskDayFinished(uid string) []*pb.TaskData {
|
|
||||||
return nil //this.modelTask.getFinishTasks(uid, comm.TASK_DAILY)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ModuleTask) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) {
|
func (this *ModuleTask) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) {
|
||||||
reddot = make(map[comm.ReddotType]*pb.ReddotItem)
|
reddot = make(map[comm.ReddotType]*pb.ReddotItem)
|
||||||
|
var (
|
||||||
|
task *pb.DBTask = &pb.DBTask{}
|
||||||
|
active *pb.DBActivity
|
||||||
|
userExpand *pb.DBUserExpand
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if task, err = this.modelTask.getUserTask(session.GetUserId()); err != nil {
|
||||||
|
this.Errorf("getTaskList err %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if active, err = this.modelTaskActive.getActiveList(session.GetUserId()); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 获取玩家活跃度
|
||||||
|
userExpand, err = this.ModuleUser.GetUserExpand(session.GetUserId())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range rid {
|
for _, v := range rid {
|
||||||
|
|
||||||
switch v {
|
switch v {
|
||||||
case comm.Reddot10101:
|
case comm.Reddot10101:
|
||||||
tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_DAILY)
|
tf, _ := this.modelTask.noReceiveTask(task, comm.TASK_DAILY)
|
||||||
reddot[comm.Reddot10101] = &pb.ReddotItem{
|
reddot[comm.Reddot10101] = &pb.ReddotItem{
|
||||||
Rid: int32(comm.Reddot10101),
|
Rid: int32(comm.Reddot10101),
|
||||||
Activated: tf,
|
Activated: tf,
|
||||||
Nextchanagetime: 0,
|
Nextchanagetime: 0,
|
||||||
}
|
}
|
||||||
case comm.Reddot10102:
|
case comm.Reddot10102:
|
||||||
tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_WEEKLY)
|
tf, _ := this.modelTask.noReceiveTask(task, comm.TASK_WEEKLY)
|
||||||
reddot[comm.Reddot10102] = &pb.ReddotItem{
|
reddot[comm.Reddot10102] = &pb.ReddotItem{
|
||||||
Rid: int32(comm.Reddot10102),
|
Rid: int32(comm.Reddot10102),
|
||||||
Activated: tf,
|
Activated: tf,
|
||||||
@ -159,21 +158,21 @@ func (this *ModuleTask) Reddot(session comm.IUserSession, rid ...comm.ReddotType
|
|||||||
}
|
}
|
||||||
|
|
||||||
case comm.Reddot10103:
|
case comm.Reddot10103:
|
||||||
tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_ACHIEVE)
|
tf, _ := this.modelTask.noReceiveTask(task, comm.TASK_ACHIEVE)
|
||||||
reddot[comm.Reddot10103] = &pb.ReddotItem{
|
reddot[comm.Reddot10103] = &pb.ReddotItem{
|
||||||
Rid: int32(comm.Reddot10103),
|
Rid: int32(comm.Reddot10103),
|
||||||
Activated: tf,
|
Activated: tf,
|
||||||
Nextchanagetime: 0,
|
Nextchanagetime: 0,
|
||||||
}
|
}
|
||||||
case comm.Reddot10201:
|
case comm.Reddot10201:
|
||||||
tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_DAILY)
|
tf, _ := this.modelTaskActive.noReceiveTaskActive(userExpand, active.ActivityList, comm.TASK_DAILY)
|
||||||
reddot[comm.Reddot10201] = &pb.ReddotItem{
|
reddot[comm.Reddot10201] = &pb.ReddotItem{
|
||||||
Rid: int32(comm.Reddot10201),
|
Rid: int32(comm.Reddot10201),
|
||||||
Activated: tf,
|
Activated: tf,
|
||||||
Nextchanagetime: 0,
|
Nextchanagetime: 0,
|
||||||
}
|
}
|
||||||
case comm.Reddot10301:
|
case comm.Reddot10301:
|
||||||
tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_WEEKLY)
|
tf, _ := this.modelTaskActive.noReceiveTaskActive(userExpand, active.ActivityList, comm.TASK_WEEKLY)
|
||||||
reddot[comm.Reddot10301] = &pb.ReddotItem{
|
reddot[comm.Reddot10301] = &pb.ReddotItem{
|
||||||
Rid: int32(comm.Reddot10301),
|
Rid: int32(comm.Reddot10301),
|
||||||
Activated: tf,
|
Activated: tf,
|
||||||
|
@ -48,10 +48,8 @@ func (this *apiComp) Initdata(session comm.IUserSession, req *pb.UserInitdataReq
|
|||||||
//验证码验证通过
|
//验证码验证通过
|
||||||
// TODO 检查该用户是否加入过工会
|
// TODO 检查该用户是否加入过工会
|
||||||
// 清除玩家数据
|
// 清除玩家数据
|
||||||
this.module.ModuleTask.CleanData(session.GetUserId()) //玩家任务
|
|
||||||
this.module.ModuleHero.CleanData(session.GetUserId()) //英雄数据
|
this.module.ModuleHero.CleanData(session.GetUserId()) //英雄数据
|
||||||
this.module.modelSetting.cleanData(session.GetUserId()) //用户设置
|
this.module.modelSetting.cleanData(session.GetUserId()) //用户设置
|
||||||
|
|
||||||
this.module.modelUser.delete(session.GetUserId()) //删除用户
|
this.module.modelUser.delete(session.GetUserId()) //删除用户
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,9 +66,6 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
|
|||||||
log.Errorf("User_CreateUser err %v", err)
|
log.Errorf("User_CreateUser err %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化任务
|
|
||||||
go this.module.ModuleTask.InitTaskAll(user.Uid)
|
|
||||||
isNewUser = true
|
isNewUser = true
|
||||||
} else {
|
} else {
|
||||||
// 玩家是否已在线
|
// 玩家是否已在线
|
||||||
|
@ -53,6 +53,7 @@ import (
|
|||||||
"go_dreamfactory/modules/smithy"
|
"go_dreamfactory/modules/smithy"
|
||||||
"go_dreamfactory/modules/sociaty"
|
"go_dreamfactory/modules/sociaty"
|
||||||
"go_dreamfactory/modules/stonehenge"
|
"go_dreamfactory/modules/stonehenge"
|
||||||
|
"go_dreamfactory/modules/storyline"
|
||||||
"go_dreamfactory/modules/sys"
|
"go_dreamfactory/modules/sys"
|
||||||
"go_dreamfactory/modules/task"
|
"go_dreamfactory/modules/task"
|
||||||
"go_dreamfactory/modules/tools"
|
"go_dreamfactory/modules/tools"
|
||||||
@ -119,7 +120,6 @@ func main() {
|
|||||||
pay.NewModule(),
|
pay.NewModule(),
|
||||||
privilege.NewModule(),
|
privilege.NewModule(),
|
||||||
growtask.NewModule(),
|
growtask.NewModule(),
|
||||||
// worldtask.NewModule(),
|
|
||||||
academy.NewModule(),
|
academy.NewModule(),
|
||||||
reddot.NewModule(),
|
reddot.NewModule(),
|
||||||
combat.NewModule(),
|
combat.NewModule(),
|
||||||
@ -149,6 +149,7 @@ func main() {
|
|||||||
herotask.NewModule(),
|
herotask.NewModule(),
|
||||||
shopcenter.NewModule(),
|
shopcenter.NewModule(),
|
||||||
addrecharge.NewModule(),
|
addrecharge.NewModule(),
|
||||||
|
storyline.NewModule(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user