任务完成推送

This commit is contained in:
zhaocy 2022-07-21 09:41:29 +08:00
parent 21e6225520
commit 49ae24219c
9 changed files with 152 additions and 33 deletions

View File

@ -92,7 +92,7 @@ var (
},
},
rsp: &pb.HeroStrengthenUpStarResp{},
// enabled: true,
enabled: true,
}
tcs = append(tcs, tc)
@ -119,7 +119,7 @@ var (
HeroObjID: heroId,
},
rsp: &pb.HeroAwakenResp{},
enabled: true,
// enabled: true,
}
tcs = append(tcs, tc3)
}

View File

@ -46,7 +46,7 @@ type (
UpdateEquipment(session IUserSession, hero *pb.DBHero, equip []*pb.DB_Equipment) (code pb.ErrorCode)
//获取玩家英雄列表
GetHeroList(uid string) []*pb.DBHero
//
//清理玩家英雄数据
CleanData(uid string)
}
@ -85,8 +85,8 @@ type (
//清空任务
ResetTask(uid string, taskTag TaskTag)
//任务通知
SendToTask(uid string, taskType TaskType, param *pb.TaskParam) (code pb.ErrorCode)
// 清理玩家数据
SendToTask(session IUserSession, taskType TaskType, param *pb.TaskParam) (code pb.ErrorCode)
// 清理玩家任务数据
CleanData(uid string)
}
)

View File

@ -158,7 +158,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
"isOverlying": false,
}
// 触发星级任务
this.module.ModuleTask.SendToTask(session.GetUserId(), comm.TaskTypeGetHero, &pb.TaskParam{First: _hero.Star})
this.module.ModuleTask.SendToTask(session, comm.TaskTypeGetHero, &pb.TaskParam{First: _hero.Star})
// 保存数据
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), _hero.Id, _heroMap)
if err1 != nil {

View File

@ -415,6 +415,45 @@ func (this *ModelHero) PushHeroProperty(session comm.IUserSession, heroId string
return //session.SendMsg("hero", "property", &pb.HeroPropertyPush{Property: m})
}
// 英雄升星
func (this *ModelHero) HeroStarUp(session comm.IUserSession, hero *pb.DBHero) (code pb.ErrorCode) {
_heroMap := map[string]interface{}{
"star": hero.Star + 1,
"isOverlying": false,
}
// 触发星级任务
this.moduleHero.ModuleTask.SendToTask(session, comm.TaskTypeGetHero, &pb.TaskParam{First: hero.Star + 1})
// 保存数据
err1 := this.modifyHeroData(session.GetUserId(), hero.Id, _heroMap)
if err1 != nil {
code = pb.ErrorCode_DBError
this.moduleHero.Errorf("update hero skill failed:%v", err1)
}
// 计算属性
data := make(map[string]int32, 0)
newConfig := this.moduleHero.configure.GetHeroStar(hero.Star - 1)
if newConfig == nil {
code = pb.ErrorCode_ConfigurationException
return
}
data[comm.Hp] = int32(math.Floor((1.0 + float64(newConfig.StarupHp)) * float64(hero.Property[comm.Hp]) / 100))
data[comm.Atk] = int32(math.Floor((1.0 + float64(newConfig.StarupAtk)) * float64(hero.Property[comm.Atk]) / 100))
data[comm.Def] = int32(math.Floor((1.0 + float64(newConfig.StarupDef)) * float64(hero.Property[comm.Def]) / 100))
data[comm.Speed] = int32(math.Floor((1.0 + float64(newConfig.StarupSpeed)) * float64(hero.Property[comm.Speed]) / 100))
this.mergeMainProperty(session.GetUserId(), hero.Id, data)
err1 = this.PushHeroProperty(session, hero.Id) // 推送属性变化
if err1 != nil {
code = pb.ErrorCode_Unknown
this.moduleHero.Errorf("PushHeroProperty err!")
}
return
}
func (this *ModelHero) cleanData(uid string) {
userList := this.moduleHero.GetHeroList(uid)
for _, v := range userList {

View File

@ -6,11 +6,12 @@ import (
)
const (
TaskSubTypeList = "list" //任务列表
TaskSubTypeReceive = "receive" //领取
TaskSubTypeActiveList = "activelist" //活跃度列表
TaskSubTypeActiveReceive = "activereceive" //活跃度领取
TaskSubTypeStrategy = "strategy" //卡牌攻略
TaskSubTypeList = "list" //任务列表
TaskSubTypeReceive = "receive" //领取
TaskSubTypeActiveList = "activelist" //活跃度列表
TaskSubTypeActiveReceive = "activereceive" //活跃度领取
TaskSubTypeStrategy = "strategy" //卡牌攻略
TaskSubTypeFinishedPush = "taskfinishedpush" //推送
)
type apiComp struct {

View File

@ -116,12 +116,12 @@ func (this *ModelTask) modifyUserTask(uid string, taskTag comm.TaskTag, taskId s
}
//任务处理
func (this *ModelTask) taskHandle(uid string, taskType comm.TaskType, taskParam *pb.TaskParam) error {
func (this *ModelTask) taskHandle(uid string, taskType comm.TaskType, taskParam *pb.TaskParam) (*pb.DBTask, error) {
//查询当前用户未完成的任务列表
data, err := this.moduleTask.configure.getTasks(int32(taskType))
if err != nil {
log.Errorf("taskHandle err %v", err)
return err
return nil, err
}
for _, conf := range data {
@ -131,34 +131,40 @@ func (this *ModelTask) taskHandle(uid string, taskType comm.TaskType, taskParam
}
//检查进度,执行处理器
if v, ok := this.checkTaskProgress(uid, conf); ok {
if err := this.finishHandle(v, comm.TaskTag(conf.IdTag), conf); err != nil {
return err
if tt, err := this.finishHandle(v, comm.TaskTag(conf.IdTag), conf); err != nil {
return nil, err
} else {
return tt, nil
}
}
}
return nil
return nil, nil
}
//任务完成处理
func (this *ModelTask) finishHandle(userTask *pb.DBTask, taskTag comm.TaskTag, config *cfg.Game_taskRoundData) error {
if userTask.Progress-1 < 0 {
return fmt.Errorf("uid %s task[%s] was finished", userTask.Uid, userTask.Id)
func (this *ModelTask) finishHandle(userTask *pb.DBTask, taskTag comm.TaskTag, config *cfg.Game_taskRoundData) (*pb.DBTask, error) {
progress := userTask.Progress - 1
if progress < 0 {
return nil, fmt.Errorf("uid %s task[%s] was finished", userTask.Uid, userTask.Id)
}
//修改玩家任务状态和进度
update := map[string]interface{}{
"progress": userTask.Progress - 1,
"progress": progress,
}
if userTask.Progress-1 == 0 {
if progress == 0 {
update["status"] = 1
}
if err := this.modifyUserTask(userTask.Uid, taskTag, userTask.Id, update); err != nil {
log.Errorf("err %v", err)
return err
return nil, err
}
return nil
userTask.Progress = progress
userTask.Status = 1
return nil, nil
}
//清空任务

View File

@ -78,9 +78,13 @@ func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) {
}
//任务处理
func (this *ModuleTask) SendToTask(uid string, taskType comm.TaskType, taskPram *pb.TaskParam) (code pb.ErrorCode) {
if err := this.modelTask.taskHandle(uid, taskType, taskPram); err != nil {
func (this *ModuleTask) SendToTask(session comm.IUserSession, taskType comm.TaskType, taskPram *pb.TaskParam) (code pb.ErrorCode) {
if task, err := this.modelTask.taskHandle(session.GetUserId(), taskType, taskPram); err != nil {
code = pb.ErrorCode_TaskHandle
} else {
if err := session.SendMsg(string(comm.ModuleTask), TaskSubTypeFinishedPush, &pb.TaskFinishedPush{TaskId: task.TaskId}); err != nil {
this.modelTask.moduleTask.Errorf("SendToTask sendmsg err:%v", err)
}
}
return
}

View File

@ -44,3 +44,8 @@ message TaskDoStrategyReq {
message TaskDoStrategyResp {
repeated int32 taskIds = 1; //ID
}
//
message TaskFinishedPush {
int32 taskId = 1;
}

View File

@ -527,6 +527,54 @@ func (x *TaskDoStrategyResp) GetTaskIds() []int32 {
return nil
}
//任务完成推送
type TaskFinishedPush struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
TaskId int32 `protobuf:"varint,1,opt,name=taskId,proto3" json:"taskId"`
}
func (x *TaskFinishedPush) Reset() {
*x = TaskFinishedPush{}
if protoimpl.UnsafeEnabled {
mi := &file_task_task_msg_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *TaskFinishedPush) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TaskFinishedPush) ProtoMessage() {}
func (x *TaskFinishedPush) ProtoReflect() protoreflect.Message {
mi := &file_task_task_msg_proto_msgTypes[10]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use TaskFinishedPush.ProtoReflect.Descriptor instead.
func (*TaskFinishedPush) Descriptor() ([]byte, []int) {
return file_task_task_msg_proto_rawDescGZIP(), []int{10}
}
func (x *TaskFinishedPush) GetTaskId() int32 {
if x != nil {
return x.TaskId
}
return 0
}
var File_task_task_msg_proto protoreflect.FileDescriptor
var file_task_task_msg_proto_rawDesc = []byte{
@ -566,8 +614,11 @@ var file_task_task_msg_proto_rawDesc = []byte{
0x01, 0x28, 0x05, 0x52, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x43, 0x66, 0x67, 0x49, 0x64, 0x22, 0x2e,
0x0a, 0x12, 0x54, 0x61, 0x73, 0x6b, 0x44, 0x6f, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79,
0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x18,
0x01, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06,
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x01, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x22, 0x2a,
0x0a, 0x10, 0x54, 0x61, 0x73, 0x6b, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x50, 0x75,
0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -582,7 +633,7 @@ func file_task_task_msg_proto_rawDescGZIP() []byte {
return file_task_task_msg_proto_rawDescData
}
var file_task_task_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_task_task_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_task_task_msg_proto_goTypes = []interface{}{
(*TaskReceiveReq)(nil), // 0: TaskReceiveReq
(*TaskReceiveResp)(nil), // 1: TaskReceiveResp
@ -594,12 +645,13 @@ var file_task_task_msg_proto_goTypes = []interface{}{
(*TaskActiveReceiveResp)(nil), // 7: TaskActiveReceiveResp
(*TaskDoStrategyReq)(nil), // 8: TaskDoStrategyReq
(*TaskDoStrategyResp)(nil), // 9: TaskDoStrategyResp
(*DBTask)(nil), // 10: DBTask
(*DBTaskActive)(nil), // 11: DBTaskActive
(*TaskFinishedPush)(nil), // 10: TaskFinishedPush
(*DBTask)(nil), // 11: DBTask
(*DBTaskActive)(nil), // 12: DBTaskActive
}
var file_task_task_msg_proto_depIdxs = []int32{
10, // 0: TaskListResp.list:type_name -> DBTask
11, // 1: TaskActiveListResp.list:type_name -> DBTaskActive
11, // 0: TaskListResp.list:type_name -> DBTask
12, // 1: TaskActiveListResp.list:type_name -> DBTaskActive
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
@ -734,6 +786,18 @@ func file_task_task_msg_proto_init() {
return nil
}
}
file_task_task_msg_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*TaskFinishedPush); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -741,7 +805,7 @@ func file_task_task_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_task_task_msg_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,
NumMessages: 11,
NumExtensions: 0,
NumServices: 0,
},