go_dreamfactory/modules/rtask/api_tasktest.go
2023-03-10 16:50:09 +08:00

65 lines
1.6 KiB
Go

package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cast"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) RtestCheck(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode, data proto.Message) {
rsp := &pb.RtaskTestResp{Flag: true}
if req.CondiId != 0 {
if err, ok := this.moduleRtask.modelRtask.checkCondi(session.GetUserId(), req.CondiId); !ok {
rsp.Flag = false
log.Errorf("%v", errors.WithMessage(err, session.GetUserId()))
}
} else if req.GroupId != 0 {
// 获取当前玩家
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
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.moduleRtask.modelRtask.Change(rtask.Uid, update)
} else {
this.moduleRtask.TriggerTask(session.GetUserId(), &comm.TaskParam{
TT: comm.TaskType(req.RtaskType),
Params: req.Params,
})
rsp.Flag = true
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), "rtest", rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}