198 lines
5.5 KiB
Go
198 lines
5.5 KiB
Go
package wtask
|
|
|
|
import (
|
|
"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
|
|
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)
|
|
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)
|
|
finishtasks []int32 = make([]int32, 0)
|
|
award []*pb.UserAssets = make([]*pb.UserAssets, 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.Accepttask {
|
|
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)),
|
|
}
|
|
ok = true
|
|
for i, v := range v.Completetask {
|
|
task.Conlds[i] = condisMap[v]
|
|
if task.Conlds[i].State != pb.BuriedItemFinishState_buried_unfinish {
|
|
ok = false
|
|
}
|
|
}
|
|
detailstasks = append(detailstasks, task)
|
|
if ok && v.DeliverNpc == 0 { //自动完成
|
|
finishtasks = append(finishtasks, k)
|
|
this.DispenseRes(session, v.Reword, true) //发送奖励
|
|
for _, v := range v.Reword {
|
|
award = append(award, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
session, _ = this.GetUserSession(uid)
|
|
defer func() {
|
|
session.Push()
|
|
this.PutUserSession(session)
|
|
}()
|
|
//发送进度变化消息
|
|
session.SendMsg(string(this.GetType()), "accepttaskchange", &pb.WTaskAccepttaskChangePush{Accepttask: detailstasks})
|
|
|
|
if len(finishtasks) > 0 {
|
|
//发送任务完成推送
|
|
session.SendMsg(string(this.GetType()), "autofinsh", &pb.WTaskAutoFinshPush{Completes: finishtasks, Award: award})
|
|
utask.Completes = append(utask.Completes, finishtasks...)
|
|
this.inquireActivations(session, utask, 1, []string{})
|
|
}
|
|
}
|
|
|
|
// 查询可接取任务列表
|
|
func (this *WTask) inquireActivations(session comm.IUserSession, wtask *pb.DBWTask, lv int32, opencmd []string) (err error) {
|
|
var (
|
|
conf *cfg.GameWorldTask
|
|
completeMap map[int32]struct{} = make(map[int32]struct{})
|
|
opencmdMap map[string]struct{} = make(map[string]struct{})
|
|
ok bool
|
|
change bool
|
|
)
|
|
if conf, err = this.configure.getWorldtaskCfg(); err != nil {
|
|
return
|
|
}
|
|
|
|
for _, v := range wtask.Completes {
|
|
completeMap[v] = struct{}{}
|
|
}
|
|
for _, v := range opencmd {
|
|
opencmdMap[v] = struct{}{}
|
|
}
|
|
for _, v := range conf.GetDataList() {
|
|
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
|
|
}
|
|
wtask.Activations = append(wtask.Activations, v.Key)
|
|
change = true
|
|
}
|
|
|
|
if change {
|
|
session.SendMsg(string(this.GetType()), "autofinsh", &pb.WTaskActivationsPush{Activations: wtask.Activations})
|
|
}
|
|
return
|
|
}
|