105 lines
2.6 KiB
Go
105 lines
2.6 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelWorldtask struct {
|
|
modules.MCompModel
|
|
moduleWorldtask *Worldtask
|
|
service core.IService
|
|
}
|
|
|
|
func (this *ModelWorldtask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.TableName = comm.TableWorldtask
|
|
this.moduleWorldtask = module.(*Worldtask)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
// 获取玩家世界任务
|
|
func (this *ModelWorldtask) getWorldtask(uid string) (*pb.DBWorldtask, error) {
|
|
d := &pb.DBWorldtask{}
|
|
if err := this.Get(uid, d); err != nil {
|
|
if err != mongo.ErrNoDocuments {
|
|
log.Error("getWorldtask", log.Fields{"uid": uid})
|
|
return d, err
|
|
}
|
|
}
|
|
return d, nil
|
|
}
|
|
|
|
//判断前置任务是否完成
|
|
// true 已完成 false未完成
|
|
func (this *ModelWorldtask) IsPreFinished(userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) bool {
|
|
var (
|
|
lastTaskId int32
|
|
preTaskFinished bool
|
|
)
|
|
if curTaskConf.Ontxe == 0 {
|
|
preTaskFinished = true
|
|
} else {
|
|
lastTaskId = curTaskConf.Ontxe
|
|
}
|
|
|
|
for _, t := range userTask.TaskList {
|
|
if lastTaskId == t.TaskId && t.Status == 1 {
|
|
preTaskFinished = true
|
|
}
|
|
}
|
|
|
|
return preTaskFinished
|
|
}
|
|
|
|
// 判断任务是否已完成
|
|
func (this *ModelWorldtask) isFinished(taskId int32, list []*pb.Worldtask) bool {
|
|
for _, v := range list {
|
|
if v.TaskId == taskId {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 完成任务
|
|
func (this *ModelWorldtask) finishTask(groupId, taskId int32, task *pb.DBWorldtask) error {
|
|
if task == nil {
|
|
return errors.New("worldtask is nil")
|
|
}
|
|
update := map[string]interface{}{}
|
|
if task.LastTaskIds == nil {
|
|
task.LastTaskIds = make(map[int32]int32)
|
|
}
|
|
|
|
update["uid"] = task.Uid
|
|
task.TaskList = append(task.TaskList, &pb.Worldtask{
|
|
TaskId: taskId,
|
|
Status: 1, //完成
|
|
})
|
|
task.LastTaskIds[groupId] = taskId
|
|
|
|
update["taskList"] = task.TaskList
|
|
update["lastTaskIds"] = task.LastTaskIds
|
|
if err := this.Change(task.Uid, update); err != nil {
|
|
return err
|
|
}
|
|
|
|
if module, err := this.service.GetModule(comm.ModuleLinestory); err == nil {
|
|
if iLinestory, ok := module.(comm.ILinestory); ok {
|
|
if err := iLinestory.TaskFinishNotify(task.Uid, taskId, groupId); err != nil {
|
|
log.Error("世界任务完成通知支线剧情任务", log.Fields{"uid": task.Uid, "groupId": groupId, "taskId": taskId, "err": err.Error()})
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|