204 lines
4.6 KiB
Go
204 lines
4.6 KiB
Go
package rtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
|
|
"github.com/spf13/cast"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelRtask struct {
|
|
modules.MCompModel
|
|
moduleRtask *ModuleRtask
|
|
service core.IService
|
|
}
|
|
|
|
func (this *ModelRtask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableRtask
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleRtask = module.(*ModuleRtask)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
//查询用户随机任务
|
|
func (this *ModelRtask) GetRtask(uid string) *pb.DBRtask {
|
|
rtask := &pb.DBRtask{Uid: uid}
|
|
err := this.Get(uid, rtask)
|
|
if err != nil {
|
|
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
|
|
_id := primitive.NewObjectID().Hex()
|
|
rtask.Id = _id
|
|
if err := this.Add(uid, rtask); err != nil {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
return rtask
|
|
}
|
|
|
|
// 做任务之前的校验
|
|
func (this *ModelRtask) checkHandle(uid string, frtaskIds []int32, conf *cfg.GameRdtaskData) (code pb.ErrorCode, ok bool) {
|
|
//判断前置任务状态
|
|
if conf.PreTid != 0 {
|
|
if _, ok := utils.Findx(frtaskIds, conf.PreTid); !ok {
|
|
code = pb.ErrorCode_RtaskPreNoFinish
|
|
return code, false
|
|
}
|
|
}
|
|
|
|
//验证限定条件
|
|
for _, v := range conf.Condition {
|
|
if ok = this.checkCondi(uid, v); !ok {
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 确定选项前的校验
|
|
func (this *ModelRtask) checkCondi(uid string, condiId int32) (ok bool) {
|
|
if condiId == 0 {
|
|
return true
|
|
}
|
|
//验证限定条件
|
|
if condi, ok := this.moduleRtask.rtaskHandleMap[condiId]; ok {
|
|
if ok = condi.fn(uid, condi.cfg); !ok {
|
|
log.Infof("uid: %v do rtask %v condition not reach", uid, condiId)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 英雄指定
|
|
func (this *ModelRtask) HeroTarget(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool) {
|
|
heroModule, err := this.service.GetModule(comm.ModuleHero)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
h := heroModule.(comm.IHero)
|
|
for _, v := range h.GetHeroList(uid) {
|
|
if cast.ToString(cfg.Data1) == v.HeroID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 指定英雄的等级
|
|
func (this *ModelRtask) HeroLvTarget(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool) {
|
|
heroModule, err := this.service.GetModule(comm.ModuleHero)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
h := heroModule.(comm.IHero)
|
|
var hero *pb.DBHero
|
|
for _, v := range h.GetHeroList(uid) {
|
|
if cast.ToString(cfg.Data1) == v.HeroID {
|
|
hero = v
|
|
}
|
|
}
|
|
if hero != nil {
|
|
return cast.ToString(cfg.Data1) == hero.HeroID && cfg.Data1 == hero.Lv
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// 指定英雄的指定装备的数量
|
|
func (this *ModelRtask) EquipNum(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool) {
|
|
heroModule, err := this.service.GetModule(comm.ModuleHero)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
h := heroModule.(comm.IHero)
|
|
var hero *pb.DBHero
|
|
for _, v := range h.GetHeroList(uid) {
|
|
if cast.ToString(cfg.Data1) == v.HeroID {
|
|
hero = v
|
|
}
|
|
}
|
|
|
|
var count int32
|
|
if hero != nil {
|
|
// 验证装备
|
|
_, ok := utils.Findx(hero.EquipID, cast.ToString(cfg.Data2))
|
|
// 验证数量
|
|
for _, v := range hero.EquipID {
|
|
if v != "0" {
|
|
count++
|
|
}
|
|
}
|
|
return cast.ToString(cfg.Data1) == hero.HeroID &&
|
|
ok && cfg.Data3 == count
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// 剧情ID
|
|
func (this *ModelRtask) PoltId(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool) {
|
|
mlModule, err := this.service.GetModule(comm.ModuleMainline)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
ml := mlModule.(comm.IMainline)
|
|
jqId := ml.GetUsermainLineData(uid)
|
|
return cfg.Data1 == jqId
|
|
}
|
|
|
|
// 每日任务
|
|
func (this *ModelRtask) TaskDay(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool) {
|
|
taskModule, err := this.service.GetModule(comm.ModuleTask)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
itask := taskModule.(comm.ITask)
|
|
|
|
if task := itask.GetTaskById(uid, cfg.Data1); task == nil {
|
|
return false
|
|
} else {
|
|
//任务完成
|
|
if task.Status == 1 {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// 指定英雄的星级
|
|
func (this *ModelRtask) HeroStarTarget(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool) {
|
|
heroModule, err := this.service.GetModule(comm.ModuleHero)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
h := heroModule.(comm.IHero)
|
|
|
|
var hero *pb.DBHero
|
|
for _, v := range h.GetHeroList(uid) {
|
|
if cast.ToString(cfg.Data1) == v.HeroID {
|
|
hero = v
|
|
}
|
|
}
|
|
|
|
if hero != nil {
|
|
return cast.ToString(cfg.Data1) == hero.HeroID && cfg.Data2 == hero.Star
|
|
}
|
|
|
|
return false
|
|
}
|