571 lines
15 KiB
Go
571 lines
15 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
|
|
caravan comm.ICaravan
|
|
dailytask comm.IDailytask
|
|
battle comm.IBattle
|
|
sys comm.ISys
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelwtask *ModelWTask
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &WTask{}
|
|
}
|
|
|
|
func (this *WTask) GetType() core.M_Modules {
|
|
return comm.ModuleWtask
|
|
}
|
|
|
|
func (this *WTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *WTask) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
|
|
return
|
|
}
|
|
this.battle = module.(comm.IBattle)
|
|
if module, err = this.service.GetModule(comm.ModuleSys); err != nil {
|
|
return
|
|
}
|
|
this.sys = module.(comm.ISys)
|
|
if module, err = this.service.GetModule(comm.ModuleCaravan); err != nil {
|
|
return
|
|
}
|
|
this.caravan = module.(comm.ICaravan)
|
|
if module, err = this.service.GetModule(comm.ModuleDailytask); err != nil {
|
|
return
|
|
}
|
|
this.dailytask = module.(comm.IDailytask)
|
|
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(session comm.IUserSession, condis []*pb.ConIProgress) {
|
|
this.Debug("收到子任务进度变化推送", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condis", Value: condis})
|
|
var (
|
|
wtask *pb.DBWTask
|
|
opencmdCondis map[int32][]*cfg.GameWorldTaskData
|
|
condisAll []int32
|
|
progress []*pb.ConIProgress
|
|
complete []int32
|
|
user *pb.DBUser
|
|
err error
|
|
errdata *pb.ErrorData
|
|
ok bool
|
|
)
|
|
//初步校验
|
|
opencmdCondis = this.configure.getopencmdTask()
|
|
for _, condi := range condis {
|
|
if _, ok = opencmdCondis[condi.Conid]; ok {
|
|
break
|
|
}
|
|
}
|
|
if !ok {
|
|
return
|
|
}
|
|
for k, _ := range opencmdCondis {
|
|
condisAll = append(condisAll, k)
|
|
}
|
|
if wtask, err = this.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
this.Error("读取玩家世界任务数据 失败", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
if _, progress, err = this.ModuleBuried.CheckCondition(session, condisAll...); err != nil {
|
|
this.Error("校验玩家子任务进度数据 失败", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
for _, v := range progress {
|
|
if v.State == pb.BuriedItemFinishState_buried_finish {
|
|
complete = append(complete, v.Conid)
|
|
}
|
|
}
|
|
if user, err = this.GetUserForSession(session); err != nil {
|
|
return
|
|
}
|
|
if errdata = this.inquireActivations(session, wtask, user.Lv, complete, true); errdata != nil {
|
|
this.Error("查询任务失败", log.Field{Key: "err", Value: errdata.String()})
|
|
}
|
|
}
|
|
|
|
// 获取商队任务
|
|
func (this *WTask) AcceptCaravanTask(session comm.IUserSession, groupId int32) (tid, groud int32, errdata *pb.ErrorData) {
|
|
var (
|
|
alltasks []*cfg.GameWorldTaskData
|
|
grouptask []*cfg.GameWorldTaskData = make([]*cfg.GameWorldTaskData, 0)
|
|
completeMap map[int32]struct{} = make(map[int32]struct{})
|
|
target *cfg.GameWorldTaskData
|
|
wtask *pb.DBWTask
|
|
err error
|
|
ok bool
|
|
)
|
|
alltasks = this.configure.getdesTask(5)
|
|
for _, v := range alltasks {
|
|
if v.Group == groupId {
|
|
grouptask = append(grouptask, v)
|
|
}
|
|
}
|
|
|
|
if len(grouptask) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("no found des:%d groud:%d tasks", 5, groupId),
|
|
}
|
|
return
|
|
}
|
|
|
|
if wtask, err = this.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for _, v := range wtask.Completes {
|
|
completeMap[v] = struct{}{}
|
|
}
|
|
|
|
for _, v := range grouptask {
|
|
if _, ok = completeMap[v.Key]; !ok { //找到一个为完成任务
|
|
target = v
|
|
break
|
|
}
|
|
}
|
|
|
|
if target == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("no found des:%d groud:%d nocomplete tasks", 5, groupId),
|
|
}
|
|
return
|
|
}
|
|
|
|
//有新任务接取
|
|
wtask.Activations = append(wtask.Activations, target.Key)
|
|
//有新任务接取
|
|
session.SendMsg(string(this.GetType()), "activationschange", &pb.WTaskActivationsChangePush{Activations: wtask.Activations})
|
|
if err = this.modelwtask.updateUserWTasks(session.GetUserId(), wtask); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
tid = target.Key
|
|
groud = target.Group
|
|
return
|
|
}
|
|
|
|
// 重置日常任务
|
|
func (this *WTask) ResetDailytaskTask(session comm.IUserSession, dailytaskid int32, groupId ...int32) (results map[int32][]int32, errdata *pb.ErrorData) {
|
|
var (
|
|
alltasks map[int32]*cfg.GameWorldTaskData = make(map[int32]*cfg.GameWorldTaskData)
|
|
groupTasks map[int32][]*cfg.GameWorldTaskData
|
|
tasks []*cfg.GameWorldTaskData
|
|
wtask *pb.DBWTask
|
|
activations []int32 = make([]int32, 0)
|
|
accepts []int32 = make([]int32, 0)
|
|
completes []int32 = make([]int32, 0)
|
|
condiIds []int32 = make([]int32, 0)
|
|
box map[int32]int32
|
|
err error
|
|
ok bool
|
|
boxchange bool
|
|
)
|
|
|
|
results = make(map[int32][]int32)
|
|
for _, v := range this.configure.getdesTask(1) {
|
|
alltasks[v.Key] = v
|
|
}
|
|
|
|
if wtask, err = this.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
//移除之前的日常任务
|
|
for _, v := range wtask.Activations {
|
|
if _, ok = alltasks[v]; !ok {
|
|
activations = append(activations, v)
|
|
}
|
|
}
|
|
for _, v := range wtask.Accepts {
|
|
if _, ok = alltasks[v]; !ok {
|
|
accepts = append(accepts, v)
|
|
}
|
|
}
|
|
for _, v := range wtask.Completes {
|
|
if _, ok = alltasks[v]; !ok {
|
|
completes = append(completes, v)
|
|
}
|
|
}
|
|
|
|
//添加新的日常任务
|
|
groupTasks = this.configure.getgroupTask()
|
|
for _, v := range groupId {
|
|
if tasks, ok = groupTasks[v]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.String(),
|
|
Message: fmt.Sprintf("no found group:%d", v),
|
|
}
|
|
return
|
|
}
|
|
for _, task := range tasks {
|
|
if task.Ontxe == 0 {
|
|
condiIds = append(condiIds, task.Completetask...)
|
|
activations = append(activations, task.Key)
|
|
if _, ok = results[v]; !ok {
|
|
results[v] = make([]int32, 0)
|
|
}
|
|
results[v] = append(results[v], task.Key)
|
|
if task.Trigger == 1 { //触发宝箱
|
|
if box, err = this.configure.getGameSearchitemAll(task.Key); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("getGameSearchitemAll uid:%s taskid:%v", session.GetUserId(), task.Key),
|
|
}
|
|
return
|
|
}
|
|
wtask.Boxs[task.Key] = &pb.DBWTaskBox{
|
|
Boxs: box,
|
|
}
|
|
boxchange = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
wtask.Activations = activations
|
|
wtask.Accepts = accepts
|
|
wtask.Completes = completes
|
|
wtask.Dailytaskgroup = dailytaskid
|
|
wtask.Exchange = make(map[int32]int32)
|
|
wtask.Events = make(map[int32]int32)
|
|
// if len(condiIds) > 0 {
|
|
// if err = this.ModuleBuried.ActiveCondition(session.GetUserId(), condiIds...); err != nil {
|
|
// errdata = &pb.ErrorData{
|
|
// Code: pb.ErrorCode_ExternalModule,
|
|
// Title: pb.ErrorCode_ExternalModule.ToString(),
|
|
// Message: fmt.Sprintf("ModuleBuried.ActiveCondition uid:%s condiIds:%v", session.GetUserId(), condiIds),
|
|
// }
|
|
// return
|
|
// }
|
|
// }
|
|
|
|
//有新任务接取
|
|
// this.pushtaskprogress(session, wtask, true)
|
|
//推送日常任务信息
|
|
session.SendMsg(string(this.GetType()), "dailytaskchange", &pb.WTaskDailytaskChangePush{Dailytaskgroup: wtask.Dailytaskgroup, Activations: wtask.Activations})
|
|
if boxchange {
|
|
session.SendMsg(string(this.GetType()), "boxchange", &pb.WTaskBoxChangePush{Boxs: wtask.Boxs})
|
|
}
|
|
if err = this.modelwtask.updateUserWTasks(session.GetUserId(), wtask); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 查询完成列表
|
|
func (this *WTask) InquireCompletes(uid string) []int32 {
|
|
var (
|
|
wtask *pb.DBWTask
|
|
completes []int32 = make([]int32, 0)
|
|
err error
|
|
)
|
|
if wtask, err = this.modelwtask.getUserWTasks(uid); err == nil {
|
|
completes = wtask.Completes
|
|
}
|
|
return completes
|
|
}
|
|
|
|
// 清除商队任务
|
|
func (this *WTask) ClearCaravanTask(session comm.IUserSession, task int32) {
|
|
var (
|
|
wtask *pb.DBWTask
|
|
err error
|
|
change bool
|
|
)
|
|
|
|
if wtask, err = this.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
for i, v := range wtask.Accepts {
|
|
if v == task {
|
|
wtask.Accepts = append(wtask.Accepts[0:i], wtask.Accepts[i+1:]...)
|
|
change = true
|
|
}
|
|
}
|
|
|
|
if change {
|
|
// this.pushtaskprogress(session, wtask, true)
|
|
if err = this.modelwtask.updateUserWTasks(session.GetUserId(), wtask); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// 跳世界任务
|
|
func (this *WTask) BingoJumpTask(session comm.IUserSession, taskId int32) (errdata *pb.ErrorData) {
|
|
var (
|
|
wtask *pb.DBWTask
|
|
accepts []int32 = make([]int32, 0)
|
|
acceptsMap map[int32]struct{} = make(map[int32]struct{})
|
|
complete []int32 = make([]int32, 0)
|
|
completeMap map[int32]struct{} = make(map[int32]struct{})
|
|
conf *cfg.GameWorldTaskData
|
|
update map[string]interface{} = make(map[string]interface{})
|
|
ok bool
|
|
err error
|
|
)
|
|
if conf, err = this.configure.gettaskconfconfigure(taskId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if wtask, err = this.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range wtask.Accepts {
|
|
acceptsMap[v] = struct{}{}
|
|
}
|
|
for _, v := range wtask.Completes {
|
|
completeMap[v] = struct{}{}
|
|
}
|
|
ok = false
|
|
for _, v := range wtask.Activations {
|
|
if taskId == v {
|
|
ok = true
|
|
}
|
|
}
|
|
|
|
if ok {
|
|
return
|
|
}
|
|
|
|
for {
|
|
if conf.Ontxe != 0 {
|
|
if _, ok = completeMap[conf.Ontxe]; !ok {
|
|
completeMap[conf.Ontxe] = struct{}{}
|
|
if _, ok = acceptsMap[conf.Ontxe]; ok {
|
|
delete(acceptsMap, conf.Ontxe)
|
|
}
|
|
}
|
|
if conf, err = this.configure.gettaskconfconfigure(conf.Ontxe); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
for k, _ := range acceptsMap {
|
|
accepts = append(accepts, k)
|
|
}
|
|
for k, _ := range completeMap {
|
|
complete = append(complete, k)
|
|
}
|
|
|
|
wtask.Activations = append(wtask.Activations, taskId)
|
|
wtask.Accepts = accepts
|
|
wtask.Completes = complete
|
|
update["activations"] = wtask.Activations
|
|
update["accepts"] = wtask.Accepts
|
|
update["completes"] = wtask.Completes
|
|
|
|
if err = this.modelwtask.Change(session.GetUserId(), update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.GetType()), "activationschange", &pb.WTaskActivationsChangePush{Activations: wtask.Activations})
|
|
return
|
|
}
|
|
|
|
// 完成任务
|
|
func (this *WTask) fishtask(session comm.IUserSession, wtask *pb.DBWTask, ispush bool) (errdata *pb.ErrorData) {
|
|
var (
|
|
opencmd []int32 = make([]int32, 0)
|
|
user *pb.DBUser
|
|
err error
|
|
)
|
|
if user, err = this.GetUserForSession(session); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
errdata = this.inquireActivations(session, wtask, user.Lv, opencmd, ispush)
|
|
return
|
|
}
|
|
|
|
// 校验组进度变化
|
|
func (this *WTask) checkgroupState(session comm.IUserSession, wtask *pb.DBWTask, group int32) {
|
|
var (
|
|
groupTask map[int32][]*cfg.GameWorldTaskData
|
|
completeMap map[int32]struct{} = make(map[int32]struct{})
|
|
des int32
|
|
ok bool
|
|
)
|
|
groupTask = this.configure.getgroupTask()
|
|
for _, v := range wtask.Completes {
|
|
completeMap[v] = struct{}{}
|
|
}
|
|
for _, v := range groupTask[group] {
|
|
if _, ok = completeMap[v.Key]; !ok {
|
|
return
|
|
}
|
|
des = v.Des
|
|
}
|
|
wtask.Groups[group] = 1
|
|
if des == 5 { //商队任务
|
|
this.caravan.TaskGroupComplete(session, group)
|
|
} else if des == 1 { //日常任务
|
|
this.dailytask.TaskGroupComplete(session, group)
|
|
}
|
|
}
|
|
|
|
// 查询可接取任务列表
|
|
func (this *WTask) inquireActivations(session comm.IUserSession, wtask *pb.DBWTask, lv int32, opencmd []int32, ispush bool) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameWorldTask
|
|
err error
|
|
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[int32]struct{} = make(map[int32]struct{})
|
|
condiIds []int32 = make([]int32, 0)
|
|
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]; !v.LockAdd && ok { //已在已接取任务列表中 LockAdd 0 表示只能接取一次 1 表示可以重复接取
|
|
continue
|
|
}
|
|
if _, ok = completeMap[v.Key]; ok { //已在完成列表中
|
|
continue
|
|
}
|
|
if lv < v.Lock || lv > v.Lockend { //等级不符合
|
|
continue
|
|
}
|
|
ok = true
|
|
for _, v1 := range v.Opencond {
|
|
if _, ok = opencmdMap[v1]; !ok { //功能未开启
|
|
break
|
|
}
|
|
}
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
if _, ok = completeMap[v.Ontxe]; v.Ontxe != 0 && !ok { //前置任务判断
|
|
continue
|
|
}
|
|
if v.Des == 5 || v.Des == 1 { //商队任务不主动触发 日常任务直接接取不进入可接取列表中
|
|
continue
|
|
}
|
|
wtask.Activations = append(wtask.Activations, v.Key)
|
|
changeActiva = true
|
|
if v.Des == 2 { //主线任务
|
|
wtask.Currchapter = v.Group
|
|
}
|
|
if _, ok = wtask.Groups[v.Group]; !ok {
|
|
wtask.Groups[v.Group] = 0
|
|
}
|
|
}
|
|
|
|
//有新任务接取
|
|
if ispush && changeActiva {
|
|
session.SendMsg(string(this.GetType()), "activationschange", &pb.WTaskActivationsChangePush{Activations: wtask.Activations})
|
|
}
|
|
|
|
if changeAccept {
|
|
if errdata = this.ModuleBuried.ActiveCondition(session, condiIds...); err != nil {
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|