任务红点

This commit is contained in:
wh_zcy 2022-11-11 15:07:34 +08:00
parent 1cec020d6c
commit 01cf37bd2b
8 changed files with 158 additions and 123 deletions

View File

@ -41,6 +41,8 @@ var (
viewRegister = map[string]MyCaseView{ viewRegister = map[string]MyCaseView{
// gm // gm
ff(comm.ModuleGM, "cmd"): &formview.BingoView{}, ff(comm.ModuleGM, "cmd"): &formview.BingoView{},
// reddot
ff(comm.ModuleReddot, "get"): &formview.ReddotView{},
//sys //sys
ff(comm.ModuleSys, "funclist"): &formview.SysFuncListView{}, ff(comm.ModuleSys, "funclist"): &formview.SysFuncListView{},
//user //user
@ -150,11 +152,13 @@ var (
string(comm.ModuleTroll), string(comm.ModuleTroll),
string(comm.ModuleGrowtask), string(comm.ModuleGrowtask),
string(comm.ModuleWorldtask), string(comm.ModuleWorldtask),
string(comm.ModuleReddot),
}, },
"gm": {ff(comm.ModuleGM, "cmd")}, "gm": {ff(comm.ModuleGM, "cmd")},
"sys": { "sys": {
ff(comm.ModuleSys, "funclist"), ff(comm.ModuleSys, "funclist"),
}, },
"reddot": {ff(comm.ModuleReddot, "get")},
"user": { "user": {
ff(comm.ModuleUser, user.UserSubTypeModifyAvatar), ff(comm.ModuleUser, user.UserSubTypeModifyAvatar),
ff(comm.ModuleUser, user.UserSubTypeModifyName), ff(comm.ModuleUser, user.UserSubTypeModifyName),
@ -273,6 +277,18 @@ var (
Rsp: &pb.GMCmdResp{}, Rsp: &pb.GMCmdResp{},
Enabled: true, Enabled: true,
}, },
"reddot": {
NavLabel: "红点",
MainType: string(comm.ModuleReddot),
Enabled: true,
},
ff(comm.ModuleReddot, "get"): {
Desc: "红点",
NavLabel: "红点",
MainType: string(comm.ModuleReddot),
SubType: "get",
Enabled: true,
},
"sys": { "sys": {
NavLabel: "系统", NavLabel: "系统",
MainType: string(comm.ModuleSys), MainType: string(comm.ModuleSys),

37
cmd/v2/ui/views/reddot.go Normal file
View File

@ -0,0 +1,37 @@
package formview
import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/pb"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
"github.com/spf13/cast"
)
type ReddotView struct {
BaseformView
}
func (this *ReddotView) CreateView(t *model.TestCase) fyne.CanvasObject {
reddotTypeEntry := widget.NewEntry()
this.form.AppendItem(widget.NewFormItem("红点类型", reddotTypeEntry))
this.form.OnSubmit = func() {
typesStr := strings.Split(reddotTypeEntry.Text, ",")
var rids []int32
for _, s := range typesStr {
rids = append(rids, cast.ToInt32(s))
}
if err := service.GetPttService().SendToClient(t.MainType, "get",
&pb.ReddotGetReq{
Rids: rids,
}); err != nil {
logrus.Error(err)
}
}
return this.form
}

View File

@ -137,6 +137,8 @@ type (
GetTaskById(uid string, taskId int32) *pb.DBTask GetTaskById(uid string, taskId int32) *pb.DBTask
// 获取已完成的任务列表 // 获取已完成的任务列表
GetTaskFinished(uid string, taskType TaskTag) []*pb.DBTask GetTaskFinished(uid string, taskType TaskTag) []*pb.DBTask
// 红点
Reddot(uid string, rid ...ReddotType) map[ReddotType]bool
} }
// 随机任务 // 随机任务

View File

@ -21,8 +21,23 @@ func (this *apiComp) Get(session comm.IUserSession, req *pb.ReddotGetReq) (code
if code = this.GetCheck(session, req); code != pb.ErrorCode_Success { if code = this.GetCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
for _, v := range req.Rids { for _, rid := range req.Rids {
reddot[v] = false // reddot[v] = false
switch rid {
case int32(comm.Reddot1):
for k, v := range this.module.ModuleTask.Reddot(session.GetUserId(), comm.Reddot1) {
reddot[int32(k)] = v
}
case int32(comm.Reddot2):
for k, v := range this.module.ModuleTask.Reddot(session.GetUserId(), comm.Reddot2) {
reddot[int32(k)] = v
}
case int32(comm.Reddot4):
for k, v := range this.module.ModuleTask.Reddot(session.GetUserId(), comm.Reddot2) {
reddot[int32(k)] = v
}
}
} }
// for k, v := range this.module.martialhall.Reddot(session.GetUserId(), comm.Reddot1) { // for k, v := range this.module.martialhall.Reddot(session.GetUserId(), comm.Reddot1) {
// reddot[int32(k)] = v // reddot[int32(k)] = v

View File

@ -53,6 +53,8 @@ func (this *ModelRtaskRecord) getRecord(uid string) *pb.DBRtaskRecord {
// 玩家登录时调用 // 玩家登录时调用
func (this *ModelRtaskRecord) initCondiData(uid string) error { func (this *ModelRtaskRecord) initCondiData(uid string) error {
dr := this.getRecord(uid) dr := this.getRecord(uid)
// 判断是否有记录
if dr.Vals == nil || len(dr.Vals) == 0 {
// 获取rdtask_condi配置表数据 // 获取rdtask_condi配置表数据
grc, err := this.moduleRtask.configure.getRtaskCondiCfg() grc, err := this.moduleRtask.configure.getRtaskCondiCfg()
if err != nil { if err != nil {
@ -62,8 +64,6 @@ func (this *ModelRtaskRecord) initCondiData(uid string) error {
return errors.New("配置空[rdtaskcondi] err") return errors.New("配置空[rdtaskcondi] err")
} }
// 判断是否有记录
if dr.Vals == nil || len(dr.Vals) == 0 {
record := &pb.DBRtaskRecord{Uid: uid} record := &pb.DBRtaskRecord{Uid: uid}
record.Id = primitive.NewObjectID().Hex() record.Id = primitive.NewObjectID().Hex()
record.Vals = make(map[int32]*pb.RtaskData) record.Vals = make(map[int32]*pb.RtaskData)

View File

@ -9,7 +9,6 @@ import (
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
) )
@ -30,21 +29,9 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond
} }
if record.Vals == nil { if record.Vals == nil {
data := &pb.RtaskData{ record.Vals = make(map[int32]*pb.RtaskData)
Rtype: cfg.Type,
Data: toMap(vals...),
Timestamp: configure.Now().Unix(),
} }
record.Vals = map[int32]*pb.RtaskData{
cfg.Id: data,
}
record.Id = primitive.NewObjectID().Hex()
record.Uid = uid
if err := this.Add(uid, record); err != nil {
return errors.Wrapf(err, "添加玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
}
} else {
if v, ok := record.Vals[cfg.Id]; ok { if v, ok := record.Vals[cfg.Id]; ok {
m := hasUpdateData(paramLen, v, vals...) m := hasUpdateData(paramLen, v, vals...)
if len(m) > 0 { if len(m) > 0 {
@ -66,7 +53,6 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond
} }
err = this.Change(uid, update) err = this.Change(uid, update)
} }
}
this.listenTask(uid, cfg.Id) this.listenTask(uid, cfg.Id)
return return
@ -74,10 +60,6 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond
// 累计更新 - 招募等 // 累计更新 - 招募等
func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) (err error) { func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) (err error) {
// t := configure.Now()
// defer func() {
// log.Debugf("add update耗时:%v", time.Since(t))
// }()
record := &pb.DBRtaskRecord{Uid: uid} record := &pb.DBRtaskRecord{Uid: uid}
err = this.Get(uid, record) err = this.Get(uid, record)
if err != nil { if err != nil {
@ -87,20 +69,8 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
} }
if record.Vals == nil { if record.Vals == nil {
record.Id = primitive.NewObjectID().Hex() record.Vals = make(map[int32]*pb.RtaskData)
data := &pb.RtaskData{
Data: toMap(vals...),
Rtype: cfg.Type,
Timestamp: configure.Now().Unix(),
} }
record.Vals = map[int32]*pb.RtaskData{
cfg.Id: data,
}
if err := this.Add(uid, record); err != nil {
return errors.Wrapf(err, "添加玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
}
} else {
//查找任务数据 //查找任务数据
if v, ok := record.Vals[cfg.Id]; ok { if v, ok := record.Vals[cfg.Id]; ok {
newCount := make([]int32, len(vals)) newCount := make([]int32, len(vals))
@ -124,7 +94,7 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
} }
err = this.Change(uid, update) err = this.Change(uid, update)
} }
}
this.listenTask(uid, cfg.Id) this.listenTask(uid, cfg.Id)
return return
} }

View File

@ -29,6 +29,21 @@ func (this *ModelTask) Init(service core.IService, module core.IModule, comp cor
return return
} }
// 查询完成的且未领取的任务 发现未领取返回true
func (this *ModelTask) noReceiveTask(uid string, taskTag comm.TaskTag) (bool, error) {
list := []*pb.DBTask{}
if err := this.GetList(uid, &list); err != nil {
this.moduleTask.Errorf("getTaskList err %v", err)
return false, err
}
for _, v := range list {
if v.Tag == int32(taskTag) && v.Status == 1 && v.Received == 0 {
return true, nil
}
}
return false, nil
}
//获取玩家任务列表 //获取玩家任务列表
func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) (newlist []*pb.DBTask) { func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) (newlist []*pb.DBTask) {
list := []*pb.DBTask{} list := []*pb.DBTask{}
@ -42,7 +57,6 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) (newli
return list[i].Sort < list[j].Sort return list[i].Sort < list[j].Sort
}) })
//
dr := this.moduleTask.ModuleRtask.GetCondiData(uid) dr := this.moduleTask.ModuleRtask.GetCondiData(uid)
if dr == nil { if dr == nil {
return return
@ -71,7 +85,7 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) (newli
return nil return nil
} }
// 判断上个任务领取了才显示最后一个任务 // 判断上个成就任务领取了才显示最后一个任务
isReceived := func(taskId int32) bool { isReceived := func(taskId int32) bool {
if preCnf := this.moduleTask.configure.getPreTask(taskId); preCnf != nil { if preCnf := this.moduleTask.configure.getPreTask(taskId); preCnf != nil {
if preTask := getCurTask(preCnf.Key); preTask != nil { if preTask := getCurTask(preCnf.Key); preTask != nil {

View File

@ -1,7 +1,6 @@
package task package task
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/event"
@ -128,25 +127,6 @@ func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) {
this.modelTaskActive.clearTask(uid, taskTag) this.modelTaskActive.clearTask(uid, taskTag)
} }
//任务处理
// func (this *ModuleTask) SendToTask(session comm.IUserSession, condiId int32, params ...int32) (code pb.ErrorCode) {
// tl := new(TaskListen)
// tl.Uid = session.GetUserId()
// tl.TaskType = comm.TaskType(condiId)
// this.modelTask.EventApp.Dispatch(comm.EventTaskChanged, tl)
// return
// }
//创建玩家攻略任务
func (this *ModuleTask) CreateTaskForStrategy(uid string, heroCfgId int32) {
//
ids := make(map[string]string)
ids, _ = this.modelTask.Redis.HGetAllToMapString(fmt.Sprintf("task:%v_%v", uid, comm.TASK_STRATEGY))
fmt.Println(ids)
//
}
// 清理任务数据 // 清理任务数据
func (this *ModuleTask) CleanData(uid string) { func (this *ModuleTask) CleanData(uid string) {
this.modelTask.clearTask(uid) this.modelTask.clearTask(uid)
@ -156,30 +136,31 @@ func (this *ModuleTask) CleanData(uid string) {
//任务处理器注册 //任务处理器注册
type taskHandle func(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask type taskHandle func(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask
// func (this *ModuleTask) register(taskType comm.TaskType, fn taskHandle) {
// if _, ok := this.taskHandleMap[int32(taskType)]; !ok {
// this.taskHandleMap[int32(taskType)] = fn
// }
// }
// 初始任务事件处理类
// func (this *ModuleTask) initTaskHandle() {
// if data, err := this.configure.getTaskList(); err == nil {
// for _, v := range data {
// switch v.TypeId {
// case int32(comm.TaskTypeUpEquip):
// this.register(comm.TaskTypeUpEquip, this.modelTask.UpEquip)
// case int32(comm.TaskTypeUpHeroStar):
// this.register(comm.TaskTypeUpHeroStar, this.modelTask.UpHeroStar)
// case int32(comm.TaskTypeUpHeroLevel):
// this.register(comm.TaskTypeUpHeroLevel, this.modelTask.UpHeroLevel)
// default:
// log.Warnf("%v task type not supported", v.TypeId)
// }
// }
// }
// }
func (this *ModuleTask) GetTaskFinished(uid string, taskTage comm.TaskTag) []*pb.DBTask { func (this *ModuleTask) GetTaskFinished(uid string, taskTage comm.TaskTag) []*pb.DBTask {
return this.modelTask.getFinishTasks(uid, taskTage) return this.modelTask.getFinishTasks(uid, taskTage)
} }
func (this *ModuleTask) Reddot(uid string, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) {
reddot = make(map[comm.ReddotType]bool)
for _, v := range rid {
switch v {
case comm.Reddot1:
if ok, _ := this.modelTask.noReceiveTask(uid, comm.TASK_DAILY); ok {
reddot[comm.Reddot1] = ok
break
}
case comm.Reddot2:
if ok, _ := this.modelTask.noReceiveTask(uid, comm.TASK_WEEKLY); ok {
reddot[comm.Reddot2] = ok
break
}
case comm.Reddot4:
if ok, _ := this.modelTask.noReceiveTask(uid, comm.TASK_ACHIEVE); ok {
reddot[comm.Reddot4] = ok
break
}
}
}
return
}