314 lines
8.7 KiB
Go
314 lines
8.7 KiB
Go
package wtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
const modulename = "世界任务"
|
|
|
|
type WTask struct {
|
|
modules.ModuleBase
|
|
service core.IService
|
|
modelBattle comm.IBattle
|
|
modelSys comm.ISys
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelwtask *ModelWTask
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &WTask{}
|
|
}
|
|
|
|
func (this *WTask) GetType() core.M_Modules {
|
|
return comm.ModuleWorldtask
|
|
}
|
|
|
|
func (this *WTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *WTask) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
|
|
return
|
|
}
|
|
this.modelBattle = module.(comm.IBattle)
|
|
if module, err = this.service.GetModule(comm.ModuleSys); err != nil {
|
|
return
|
|
}
|
|
this.modelSys = module.(comm.ISys)
|
|
return
|
|
}
|
|
|
|
func (this *WTask) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelwtask = this.RegisterComp(new(ModelWTask)).(*ModelWTask)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
|
|
}
|
|
|
|
// 埋点通知
|
|
func (this *WTask) BuriedsNotify(uid string, condis []*pb.ConIProgress) {
|
|
var (
|
|
session comm.IUserSession
|
|
condisMap map[int32]*pb.ConIProgress = make(map[int32]*pb.ConIProgress)
|
|
utask *pb.DBWTask
|
|
accepttaskMap map[int32]struct{} = make(map[int32]struct{})
|
|
condlTask map[int32][]*cfg.GameWorldTaskData
|
|
temptasks []*cfg.GameWorldTaskData
|
|
changetasks map[int32]*cfg.GameWorldTaskData = make(map[int32]*cfg.GameWorldTaskData)
|
|
checkcondlsMap map[int32]struct{} = make(map[int32]struct{})
|
|
checkcondls []int32 = make([]int32, 0)
|
|
detailstasks []*pb.DBWTaskItem = make([]*pb.DBWTaskItem, 0)
|
|
ok bool
|
|
needcheck bool //是否需要校验
|
|
|
|
err error
|
|
)
|
|
if utask, err = this.modelwtask.getUserWTasks(uid); err != nil {
|
|
this.Error("读取玩家世界任务数据 失败", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
condlTask = this.configure.getcondlTask()
|
|
|
|
for _, v := range condis {
|
|
condisMap[v.Conid] = v
|
|
}
|
|
|
|
for _, v := range utask.Accepts {
|
|
accepttaskMap[v] = struct{}{}
|
|
}
|
|
|
|
for _, v := range condis {
|
|
if temptasks, ok = condlTask[v.Conid]; ok {
|
|
for _, task := range temptasks {
|
|
if _, ok = accepttaskMap[task.Key]; ok { //任务列表进度有变化
|
|
if _, ok = changetasks[task.Key]; ok {
|
|
changetasks[task.Key] = task
|
|
for _, cid := range task.Completetask {
|
|
if _, ok = checkcondlsMap[cid]; !ok {
|
|
checkcondlsMap[cid] = struct{}{}
|
|
checkcondls = append(checkcondls, cid)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(changetasks) == 0 { //没有任务变化
|
|
return
|
|
}
|
|
for k, _ := range checkcondlsMap {
|
|
if _, ok = condisMap[k]; !ok {
|
|
needcheck = true
|
|
}
|
|
}
|
|
if needcheck { //校验有变化的任务 的完成条件
|
|
if condis, err = this.ModuleBuried.CheckCondition(uid, checkcondls...); err != nil {
|
|
this.Error("校验玩家子任务进度数据 失败", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
for _, v := range condis {
|
|
condisMap[v.Conid] = v
|
|
}
|
|
}
|
|
|
|
//推送进度变化消息
|
|
for k, v := range changetasks {
|
|
task := &pb.DBWTaskItem{
|
|
Tid: k,
|
|
Conlds: make([]*pb.ConIProgress, len(v.Completetask)),
|
|
}
|
|
for i, v := range v.Completetask {
|
|
task.Conlds[i] = condisMap[v]
|
|
}
|
|
detailstasks = append(detailstasks, task)
|
|
}
|
|
|
|
session, _ = this.GetUserSession(uid)
|
|
defer func() {
|
|
session.Push()
|
|
this.PutUserSession(session)
|
|
}()
|
|
//发送进度变化消息
|
|
session.SendMsg(string(this.GetType()), "accepttaskchange", &pb.WTaskAcceptChangePush{Accepts: detailstasks})
|
|
}
|
|
|
|
// 校验任务进度
|
|
func (this *WTask) pushtaskprogress(session comm.IUserSession, wtask *pb.DBWTask) (errdata *pb.ErrorData) {
|
|
var (
|
|
tasks []*pb.DBWTaskItem = make([]*pb.DBWTaskItem, 0)
|
|
checkcondlsMap map[int32]struct{} = make(map[int32]struct{})
|
|
checkcondls []int32 = make([]int32, 0)
|
|
conf *cfg.GameWorldTaskData
|
|
condis []*pb.ConIProgress = make([]*pb.ConIProgress, 0)
|
|
condisMap map[int32]*pb.ConIProgress = make(map[int32]*pb.ConIProgress)
|
|
err error
|
|
ok bool
|
|
)
|
|
if len(wtask.Accepts) == 0 {
|
|
return
|
|
}
|
|
|
|
for _, v := range wtask.Accepts {
|
|
if conf, err = this.configure.gettaskconfconfigure(v); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range conf.Completetask {
|
|
if _, ok = checkcondlsMap[v]; !ok {
|
|
checkcondlsMap[v] = struct{}{}
|
|
checkcondls = append(checkcondls, v)
|
|
}
|
|
}
|
|
}
|
|
if len(checkcondls) > 0 {
|
|
if condis, err = this.ModuleBuried.CheckCondition(session.GetUserId(), checkcondls...); err != nil {
|
|
this.Error("校验玩家子任务进度数据 失败", log.Field{Key: "err", Value: err.Error()})
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ExternalModule,
|
|
Title: pb.ErrorCode_ExternalModule.ToString(),
|
|
Message: fmt.Sprintf("ModuleBuried.CheckCondition Error:%s", err.Error()),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range condis {
|
|
condisMap[v.Conid] = v
|
|
}
|
|
}
|
|
|
|
for _, v := range wtask.Accepts {
|
|
if conf, err = this.configure.gettaskconfconfigure(v); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
task := &pb.DBWTaskItem{
|
|
Tid: v,
|
|
Conlds: make([]*pb.ConIProgress, len(conf.Completetask)),
|
|
}
|
|
ok = true
|
|
for i, v := range conf.Completetask {
|
|
task.Conlds[i] = condisMap[v]
|
|
}
|
|
tasks = append(tasks, task)
|
|
}
|
|
session.SendMsg(string(this.GetType()), "acceptchange", &pb.WTaskAcceptChangePush{Accepts: tasks})
|
|
return
|
|
}
|
|
|
|
// 完成任务
|
|
func (this *WTask) fishtask(session comm.IUserSession, wtask *pb.DBWTask) {
|
|
var (
|
|
opencmdMap map[string]int32
|
|
opencmd []string
|
|
user *pb.DBUser
|
|
errdata *pb.ErrorData
|
|
)
|
|
|
|
if opencmdMap, errdata = this.modelSys.QueryOpenCondData(session.GetUserId()); errdata != nil {
|
|
this.Error("查询用户功能是否开启表 失败!", log.Field{Key: "key", Value: errdata})
|
|
return
|
|
}
|
|
opencmd = make([]string, 0)
|
|
for k, v := range opencmdMap {
|
|
if v == 2 {
|
|
opencmd = append(opencmd, k)
|
|
}
|
|
}
|
|
if user = this.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
|
this.Error("获取用户信息失败!", log.Field{Key: "uid", Value: session.GetUserId()})
|
|
return
|
|
}
|
|
this.inquireActivations(session, wtask, user.Lv, opencmd)
|
|
}
|
|
|
|
// 查询可接取任务列表
|
|
func (this *WTask) inquireActivations(session comm.IUserSession, wtask *pb.DBWTask, lv int32, opencmd []string) (err error) {
|
|
var (
|
|
conf *cfg.GameWorldTask
|
|
activatMap map[int32]struct{} = make(map[int32]struct{})
|
|
acceptsMap map[int32]struct{} = make(map[int32]struct{})
|
|
completeMap map[int32]struct{} = make(map[int32]struct{})
|
|
opencmdMap map[string]struct{} = make(map[string]struct{})
|
|
ok bool
|
|
changeActiva bool
|
|
changeAccept bool
|
|
)
|
|
if conf, err = this.configure.getWorldtaskCfg(); err != nil {
|
|
return
|
|
}
|
|
for _, v := range wtask.Activations {
|
|
activatMap[v] = struct{}{}
|
|
}
|
|
for _, v := range wtask.Accepts {
|
|
acceptsMap[v] = struct{}{}
|
|
}
|
|
for _, v := range wtask.Completes {
|
|
completeMap[v] = struct{}{}
|
|
}
|
|
for _, v := range opencmd {
|
|
opencmdMap[v] = struct{}{}
|
|
}
|
|
for _, v := range conf.GetDataList() {
|
|
if _, ok = activatMap[v.Key]; ok { //已在可接取列表中
|
|
continue
|
|
}
|
|
if _, ok = acceptsMap[v.Key]; ok { //已在已接取任务列表中
|
|
continue
|
|
}
|
|
if _, ok = completeMap[v.Key]; ok { //已在完成列表中
|
|
continue
|
|
}
|
|
if lv < v.Lock || lv > v.Lockend { //等级不符合
|
|
continue
|
|
}
|
|
if _, ok = opencmdMap[v.Opencond]; v.Opencond != "" && !ok { //功能未开启
|
|
continue
|
|
}
|
|
if _, ok = completeMap[v.Ontxe]; v.Ontxe != 0 && !ok { //前置任务判断
|
|
continue
|
|
}
|
|
if v.Des == 5 { //商队任务不主动触发
|
|
continue
|
|
}
|
|
if v.AutoAccept == 0 {
|
|
wtask.Activations = append(wtask.Activations, v.Key)
|
|
changeActiva = true
|
|
} else if v.AutoAccept == 1 { //自动接取任务
|
|
wtask.Accepts = append(wtask.Accepts, v.Key)
|
|
changeAccept = true
|
|
}
|
|
|
|
}
|
|
|
|
//有新任务接取
|
|
if changeActiva {
|
|
session.SendMsg(string(this.GetType()), "activations", &pb.WTaskActivationsChangePush{Activations: wtask.Activations})
|
|
}
|
|
|
|
if changeAccept {
|
|
this.pushtaskprogress(session, wtask)
|
|
}
|
|
return
|
|
}
|