This commit is contained in:
liwei1dao 2023-05-29 21:21:22 +08:00
commit c753d2fc90
4 changed files with 62 additions and 66 deletions

View File

@ -3,52 +3,46 @@ package rtask
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"strings"
"github.com/spf13/cast"
) )
func (this *apiComp) RtestCheck(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode) { func (this *apiComp) RtestCheck(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode) {
if len(req.Params) < 1 {
code = pb.ErrorCode_ReqParameterError
}
return return
} }
func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode, data *pb.ErrorData) { func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode, data *pb.ErrorData) {
if code = this.RtestCheck(session, req); code != pb.ErrorCode_Success {
return
}
rsp := &pb.RtaskTestResp{Flag: true, RtaskType: req.RtaskType} rsp := &pb.RtaskTestResp{Flag: true, RtaskType: req.RtaskType}
// 校验
if req.CondiId != 0 { if req.CondiId != 0 {
if code = this.module.CheckCondi(session.GetUserId(), req.CondiId); code != pb.ErrorCode_Success { condIds, err := this.module.ModuleBuried.CheckCondition(session.GetUserId(), req.CondiId)
if err == nil && len(condIds) > 0 {
rsp.Flag = false rsp.Flag = false
} }
} else if req.GroupId != 0 { // 触发
// 获取当前玩家 } else if req.RtaskType != 0 && len(req.Params) > 0 {
rtask := this.module.modelRtask.GetRtask(session.GetUserId()) conds := []int32{}
if rtask == nil { switch len(req.Params) {
code = pb.ErrorCode_RtaskNoRtask case 2:
return conds[0] = req.Params[1]
case 3:
conds[0] = req.Params[1]
conds[1] = req.Params[2]
case 4:
conds[0] = req.Params[1]
conds[1] = req.Params[2]
conds[2] = req.Params[3]
case 5:
conds[0] = req.Params[1]
conds[1] = req.Params[2]
conds[2] = req.Params[3]
conds[3] = req.Params[4]
} }
this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.TaskType(req.RtaskType), req.Params[0], conds...))
rtaskIds := make([]int32, 0)
ids := strings.Split(req.RtaskIds, ",")
for _, id := range ids {
rtaskIds = append(rtaskIds, cast.ToInt32(id))
}
if v, ok := rtask.FrtaskIds[req.GroupId]; ok {
v.RtaskIds = rtaskIds
} else {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
rtask.FrtaskIds[req.GroupId] = &pb.FrtaskIds{RtaskIds: rtaskIds}
}
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
this.module.modelRtask.Change(rtask.Uid, update)
} else {
// this.module.ModuleBuried.TriggerBuried(session.GetUserId(), &comm.BuriedParam{
// TT: comm.TaskType(req.RtaskType),
// Params: req.Params,
// })
rsp.Flag = true rsp.Flag = true
} }

View File

@ -13,12 +13,13 @@ func (this *apiComp) SendCheck(session comm.IUserSession, req *pb.TaskSendReq) (
} }
func (this *apiComp) Send(session comm.IUserSession, req *pb.TaskSendReq) (code pb.ErrorCode, data *pb.ErrorData) { func (this *apiComp) Send(session comm.IUserSession, req *pb.TaskSendReq) (code pb.ErrorCode, data *pb.ErrorData) {
if imodule, err := this.service.GetModule(comm.ModuleRtask); err == nil { // if imodule, err := this.service.GetModule(comm.ModuleRtask); err == nil {
if itask, ok := imodule.(comm.IRtask); ok { // if itask, ok := imodule.(comm.IRtask); ok {
itask.TriggerTask(session.GetUserId(), comm.GetTaskParam(comm.TaskType(req.TaskType), req.Params...)) // itask.TriggerTask(session.GetUserId(), comm.GetTaskParam(comm.TaskType(req.TaskType), req.Params...))
} // }
} // }
// this.module.ModuleBuried.TriggerBuried(session.GetUserId(),comm.GetBuriedParam(comm.TaskType(req.TaskType)))
rsp := &pb.TaskSendResp{ rsp := &pb.TaskSendResp{
IsSucc: true, IsSucc: true,
} }

View File

@ -27,7 +27,7 @@ func (this *ModelTaskActive) Init(service core.IService, module core.IModule, co
return return
} }
//初始化活跃度 // 初始化活跃度
func (this *ModelTaskActive) initActiveReward(uid string, taskTag comm.TaskTag) { func (this *ModelTaskActive) initActiveReward(uid string, taskTag comm.TaskTag) {
task := &pb.DBActivity{} task := &pb.DBActivity{}
if err := this.Get(uid, task); err != nil { if err := this.Get(uid, task); err != nil {
@ -72,7 +72,7 @@ func (this *ModelTaskActive) getActiveList(uid string) (list []*pb.ActivityData)
return task.ActivityList return task.ActivityList
} }
//获取玩家活跃度列表 // 获取玩家活跃度列表
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 {
@ -98,7 +98,7 @@ func (this *ModelTaskActive) noReceiveTaskActive(uid string, taskTag comm.TaskTa
} }
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("getTaskActivityList err %v", err) // this.moduleTask.Warnf("getTaskActivityList err %v", err)
return false, err return false, err
} }
@ -122,7 +122,7 @@ func (this *ModelTaskActive) noReceiveTaskActive(uid string, taskTag comm.TaskTa
return false, nil return false, nil
} }
//获取玩家活跃记录 id 唯一ID // 获取玩家活跃记录 id 唯一ID
func (this *ModelTaskActive) getUserActive(uid string, taskId int32, taskTag comm.TaskTag) *pb.ActivityData { func (this *ModelTaskActive) getUserActive(uid string, taskId int32, taskTag comm.TaskTag) *pb.ActivityData {
record := this.getActiveListByTag(uid, taskTag) record := this.getActiveListByTag(uid, taskTag)
for _, v := range record { for _, v := range record {
@ -140,7 +140,7 @@ func (this *ModelTaskActive) updateReceive(uid string, data map[string]interface
return this.moduleTask.modelTaskActive.Change(uid, data) return this.moduleTask.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.moduleTask.Errorf("least one param for taskTag")

View File

@ -81,31 +81,32 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa
} else { } else {
//触发任务 //触发任务
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype70, 1, req.BattleConfId)) go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype70, 1, req.BattleConfId))
if userTask.CurrentTask == nil {
userTask.CurrentTask = make(map[int32]*pb.Worldtask)
}
if _, ok := utils.Findx(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId); !ok {
userTask.CurrentTask[req.GroupId].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId)
}
update := map[string]interface{}{
"currentTask": userTask.CurrentTask,
}
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
code = pb.ErrorCode_DBError
return
}
//推送
// session.SendMsg(string(this.module.GetType()), "completecondis", &pb.WorldtaskCompletecondisPush{
// GroupId: req.GroupId,
// TaskId: req.TaskId,
// CondiIds: userTask.CurrentTask[req.GroupId].CondiIds,
// })
} }
} }
} }
if userTask.CurrentTask == nil {
userTask.CurrentTask = make(map[int32]*pb.Worldtask)
}
if _, ok := utils.Findx(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId); !ok {
userTask.CurrentTask[req.GroupId].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId)
}
update := map[string]interface{}{
"currentTask": userTask.CurrentTask,
}
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
code = pb.ErrorCode_DBError
return
}
//推送
session.SendMsg(string(this.module.GetType()), "completecondis", &pb.WorldtaskCompletecondisPush{
GroupId: req.GroupId,
TaskId: req.TaskId,
CondiIds: userTask.CurrentTask[req.GroupId].CondiIds,
})
} else { } else {
rsp.Code = code rsp.Code = code
this.sendMsg(session, WorldtaskBattleFinish, rsp) this.sendMsg(session, WorldtaskBattleFinish, rsp)