213 lines
5.6 KiB
Go
213 lines
5.6 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
var _ comm.IWorldtask = (*Worldtask)(nil)
|
|
|
|
type Worldtask struct {
|
|
modules.ModuleBase
|
|
api *apiComp
|
|
service base.IRPCXService
|
|
configure *configureComp
|
|
modelWorldtask *ModelWorldtask
|
|
worldtaskConf *cfg.GameWorldTask
|
|
worldBattleConf *cfg.GameWorldBattle
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Worldtask{}
|
|
}
|
|
func (this *Worldtask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service.(base.IRPCXService)
|
|
return
|
|
}
|
|
|
|
func (this *Worldtask) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelWorldtask = this.RegisterComp(new(ModelWorldtask)).(*ModelWorldtask)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
func (this *Worldtask) GetType() core.M_Modules {
|
|
return comm.ModuleWorldtask
|
|
}
|
|
|
|
func (this *Worldtask) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
if this.worldtaskConf, err = this.configure.getWorldtaskCfg(); err != nil {
|
|
return err
|
|
}
|
|
if this.worldBattleConf, err = this.configure.getWorldtaskBattleCfg(); err != nil {
|
|
return err
|
|
}
|
|
return
|
|
}
|
|
|
|
// 任务条件达成通知
|
|
func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId int32) error {
|
|
uid := session.GetUserId()
|
|
// 玩家世界任务
|
|
userTask, err := this.modelWorldtask.getWorldtask(uid)
|
|
if err != nil {
|
|
this.Error("获取玩家世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId})
|
|
return err
|
|
}
|
|
|
|
var groupId, taskId int32
|
|
// 检索condId是否是世界任务的完成条件
|
|
finishedTaskIds := make(map[int32]int32) //达成的任务条件
|
|
for _, c := range this.worldtaskConf.GetDataList() {
|
|
for _, v := range c.Completetask {
|
|
if v == condId {
|
|
//校验任务是否是当前任务
|
|
if task, ok := userTask.CurrentTask[c.Group]; ok {
|
|
if task.NpcStatus == 1 && c.Key == task.TaskId {
|
|
finishedTaskIds[c.Group] = c.Key
|
|
groupId = c.Group
|
|
taskId = c.Key
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(finishedTaskIds) == 0 {
|
|
return nil
|
|
}
|
|
|
|
if userTask.CurrentTask == nil {
|
|
userTask.CurrentTask = make(map[int32]*pb.Worldtask)
|
|
}
|
|
|
|
wt, ok := userTask.CurrentTask[groupId]
|
|
if !ok {
|
|
wt = &pb.Worldtask{}
|
|
}
|
|
|
|
if _, ok := utils.Findx(wt.CondiIds, condId); !ok {
|
|
wt.CondiIds = append(wt.CondiIds, condId)
|
|
}
|
|
|
|
userTask.CurrentTask[groupId] = wt
|
|
|
|
this.Debug("当前任务更新", log.Field{Key: "currentTask", Value: userTask.CurrentTask})
|
|
update := map[string]interface{}{
|
|
"currentTask": userTask.CurrentTask,
|
|
}
|
|
this.modelWorldtask.Change(uid, update)
|
|
|
|
session.SendMsg(string(this.GetType()), "completecondis", &pb.WorldtaskCompletecondisPush{
|
|
GroupId: groupId,
|
|
TaskId: taskId,
|
|
CondiIds: wt.CondiIds,
|
|
})
|
|
this.Debug("推送完成条件",
|
|
log.Field{Key: "condiIds", Value: wt.CondiIds},
|
|
log.Field{Key: "taskId", Value: taskId})
|
|
|
|
// 当前任务配置
|
|
curTaskConf, err := this.configure.getWorldtaskById(taskId)
|
|
if err != nil || curTaskConf == nil {
|
|
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
|
}
|
|
|
|
//结束任务
|
|
if curTaskConf.DeliverNpc == 0 {
|
|
this.modelWorldtask.taskFinish(session, groupId, taskId, userTask, curTaskConf)
|
|
this.modelWorldtask.taskFinishPush(session, groupId, userTask, curTaskConf)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 获取我的世界任务
|
|
func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask {
|
|
wt, err := this.modelWorldtask.getWorldtask(uid)
|
|
if err != nil {
|
|
log.Errorln(err.Error())
|
|
return nil
|
|
}
|
|
return wt
|
|
}
|
|
|
|
// bingo世界任务跳跃 支持回退
|
|
func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId int32) error {
|
|
uid := session.GetUserId()
|
|
|
|
mytask, err := this.modelWorldtask.getWorldtask(uid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if mytask == nil {
|
|
mytask = &pb.DBWorldtask{}
|
|
mytask.Uid = uid
|
|
if err := this.modelWorldtask.Add(uid, mytask); err != nil {
|
|
this.Error("添加世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err})
|
|
return err
|
|
}
|
|
}
|
|
|
|
if _, ok := utils.Findx(mytask.TaskList, taskId); ok {
|
|
this.Error("GM 任务已完成", log.Field{Key: "taskId", Value: taskId})
|
|
return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed)
|
|
}
|
|
|
|
taskConf := this.worldtaskConf.GetDataMap()[taskId]
|
|
if taskConf == nil {
|
|
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
|
}
|
|
|
|
//重置taskList
|
|
mytask.TaskList = []int32{}
|
|
|
|
//遍历
|
|
if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 {
|
|
for _, v := range this.worldtaskConf.GetDataList() {
|
|
if v.Group == groupId && v.Key <= taskId && v.Des == 2 { //只做主线的des=2
|
|
mytask.TaskList = append(mytask.TaskList, v.Key)
|
|
}
|
|
}
|
|
} else {
|
|
mytask.TaskList = append(mytask.TaskList, taskId)
|
|
}
|
|
|
|
update := map[string]interface{}{
|
|
"taskList": mytask.TaskList,
|
|
}
|
|
|
|
//当前任务
|
|
nextTaskIds := this.modelWorldtask.findNextTasks(taskId)
|
|
|
|
if mytask.CurrentTask == nil {
|
|
mytask.CurrentTask = make(map[int32]*pb.Worldtask)
|
|
}
|
|
|
|
if len(nextTaskIds) == 1 {
|
|
mytask.CurrentTask[groupId] = &pb.Worldtask{
|
|
TaskId: nextTaskIds[0],
|
|
TaskType: 2, //设置主线类型
|
|
}
|
|
update["currentTask"] = mytask.CurrentTask
|
|
}
|
|
|
|
if err := this.modelWorldtask.Change(uid, update); err != nil {
|
|
return err
|
|
}
|
|
|
|
rsp := &pb.WorldtaskFinishIdsPush{}
|
|
|
|
return session.SendMsg(string(this.GetType()), "finishids", rsp)
|
|
}
|