133 lines
3.4 KiB
Go
133 lines
3.4 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.Field{Key: "uid", Value: 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 {
|
|
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]*pb.Worldtask)
|
|
}
|
|
|
|
taskConf := this.moduleWorldtask.worldtaskConf.GetDataMap()[taskId]
|
|
if taskConf == nil {
|
|
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
|
}
|
|
|
|
update["uid"] = task.Uid
|
|
wt := &pb.Worldtask{
|
|
TaskId: taskId,
|
|
TaskType: taskConf.Des,
|
|
}
|
|
task.TaskList = append(task.TaskList, wt)
|
|
task.LastTaskIds[groupId] = wt
|
|
|
|
update["taskList"] = task.TaskList
|
|
update["lastTaskIds"] = task.LastTaskIds
|
|
update["deliverNpc"] = 1
|
|
update["condiIds"] = []int32{}
|
|
update["npcStatus"] = 0
|
|
update["deliverNpc"] = 0
|
|
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.Debug("世界任务完成通知支线剧情任务",
|
|
log.Field{Key: "uid", Value: task.Uid},
|
|
log.Field{Key: "groupId", Value: groupId},
|
|
log.Field{Key: "taskId", Value: taskId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
if module, err := this.service.GetModule(comm.ModuleLibrary); err == nil {
|
|
if iLibrary, ok := module.(comm.ILibrary); ok {
|
|
if err := iLibrary.TaskFinishNotify(task.Uid, taskId, groupId); err != nil {
|
|
log.Debug("世界任务完成通知羁绊剧情任务",
|
|
log.Field{Key: "uid", Value: task.Uid},
|
|
log.Field{Key: "fetterId", Value: groupId},
|
|
log.Field{Key: "taskId", Value: taskId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|