120 lines
3.1 KiB
Go
120 lines
3.1 KiB
Go
package linestory
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelLinestory struct {
|
|
modules.MCompModel
|
|
moduleLinestory *ModuleLinestory
|
|
service core.IService
|
|
}
|
|
|
|
func (this *ModelLinestory) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableLinestory
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleLinestory = module.(*ModuleLinestory)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *ModelLinestory) getLinestory(uid string) *pb.DBLinestory {
|
|
ls := &pb.DBLinestory{
|
|
Uid: uid,
|
|
}
|
|
if err := this.Get(uid, ls); err != nil {
|
|
if err == mongo.ErrNoDocuments {
|
|
ls.Id = primitive.NewObjectID().Hex()
|
|
|
|
if err := this.Add(uid, ls); err != nil {
|
|
log.Errorf("save linestory err:%v", err)
|
|
return ls
|
|
}
|
|
return ls
|
|
} else {
|
|
log.Errorf("getLinestory err:%v", err)
|
|
return ls
|
|
}
|
|
}
|
|
return ls
|
|
}
|
|
|
|
// 获取章节节点信息
|
|
func (this *ModelLinestory) getChapters(uid string) map[int32]*pb.TaskChapter {
|
|
ls := this.getLinestory(uid)
|
|
return ls.TaskChapter
|
|
}
|
|
|
|
// 校验前置任务是否完成
|
|
// true完成 false未完成
|
|
func (this *ModelLinestory) isPreFinished(finishTasks []int32, taskId int32) bool {
|
|
// maintaskConf, ok := this.moduleLinestory.confMaintask.GetDataMap()[taskId]
|
|
// if !ok {
|
|
// return false
|
|
// }
|
|
// if maintaskConf.SubTask == 0 {
|
|
// return true
|
|
// }
|
|
|
|
// if _, ok := utils.Findx(finishTasks, maintaskConf.SubTask); ok {
|
|
// return true
|
|
// }
|
|
|
|
return false
|
|
}
|
|
|
|
// 获取玩家支线剧情-主线任务
|
|
func (this *ModelLinestory) getMaintasks(uid string, groupId int32) (list []*pb.TaskMain) {
|
|
// 调用世界任务接口groupId & taskId
|
|
if module, err := this.service.GetModule(comm.ModuleWorldtask); err == nil {
|
|
if iwt, ok := module.(comm.IWorldtask); ok {
|
|
// 获取玩家世界任务
|
|
wt := iwt.GetMyWorldtask(uid)
|
|
this.moduleLinestory.Debug("获取玩家世界任务",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "groupId", Value: groupId},
|
|
log.Field{Key: "worldtask", Value: wt},
|
|
)
|
|
if wt != nil {
|
|
mainTasks := this.moduleLinestory.configure.getMainTaskCfgByGroup(groupId)
|
|
for _, conf := range mainTasks {
|
|
// 遍历已完成的世界任务
|
|
for _, task := range wt.TaskList {
|
|
if conf.Id == task {
|
|
list = append(list, &pb.TaskMain{
|
|
TaskId: conf.Id,
|
|
Status: 1,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 章节奖励领取
|
|
func (this *ModelLinestory) receive(uid string, groupId int32) (err error) {
|
|
ls := this.getLinestory(uid)
|
|
if v, ok := ls.TaskChapter[groupId]; ok {
|
|
if v.Receive == 1 {
|
|
v.Receive = 2
|
|
update := map[string]interface{}{
|
|
"taskChapter": ls.TaskChapter,
|
|
}
|
|
return this.Change(uid, update)
|
|
} else {
|
|
return comm.NewCustomError(pb.ErrorCode_LinestoryNoReceive)
|
|
}
|
|
}
|
|
return comm.NewCustomError(pb.ErrorCode_LinestoryChapterNoOpen)
|
|
}
|