Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
0f5ee04eee
@ -1,42 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/base"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
WorldtaskSubtypeMine = "mine"
|
||||
WorldtaskSubtypeAccept = "accept"
|
||||
WorldtaskSubtypeFinish = "finish"
|
||||
WorldtaskNexttaskPush = "nexttask"
|
||||
WorldtaskBattleStart = "battlestart"
|
||||
WorldtaskBattleFinish = "battlefinish"
|
||||
WorldtaskComplete = "completecondi"
|
||||
WorldtaskChapterReward = "chapterreward"
|
||||
)
|
||||
|
||||
type apiComp struct {
|
||||
modules.MCompGate
|
||||
service base.IRPCXService
|
||||
module *Worldtask
|
||||
}
|
||||
|
||||
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
_ = this.MCompGate.Init(service, module, comp, options)
|
||||
this.service = service.(base.IRPCXService)
|
||||
this.module = module.(*Worldtask)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) sendMsg(session comm.IUserSession, subType string, rsp proto.Message) {
|
||||
if err := session.SendMsg(string(this.module.GetType()), subType, rsp); err != nil {
|
||||
this.module.Error("Worldtask sendMsg err", log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
// 任务接取
|
||||
func (a *apiComp) AcceptCheck(session comm.IUserSession, req *pb.WorldtaskAcceptReq) (errdata *pb.ErrorData) {
|
||||
if req.TaskId <= 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq) (errdata *pb.ErrorData) {
|
||||
if errdata = a.AcceptCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uid := session.GetUserId()
|
||||
user := a.module.ModuleUser.GetUser(uid)
|
||||
if user == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_UserSessionNobeing,
|
||||
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
|
||||
Datastring: uid,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
rsp := &pb.WorldtaskAcceptResp{}
|
||||
myWorldtask, err := a.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Datastring: uid,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 当前任务配置
|
||||
curTaskConf, err := a.module.configure.getWorldtaskById(req.TaskId)
|
||||
if err != nil || curTaskConf == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 判断玩家等级要求
|
||||
if user.Lv < curTaskConf.Lock {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskLvNotEnough,
|
||||
Title: pb.ErrorCode_WorldtaskLvNotEnough.ToString(),
|
||||
Message: fmt.Sprintf("实际等级:%d 期望等级:%d", user.Lv, curTaskConf.Lock),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 前置任务ID 只有世界任务才校验前置
|
||||
if !a.module.modelWorldtask.IsPreFinished(myWorldtask, curTaskConf) {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskLastUnFinished,
|
||||
Title: pb.ErrorCode_WorldtaskLastUnFinished.ToString(),
|
||||
Message: fmt.Sprintf("%v前置任务%v未完成", curTaskConf.Key, curTaskConf.Ontxe),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if myWorldtask.CurrentTasks == nil {
|
||||
myWorldtask.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
}
|
||||
|
||||
if tasks, ok := myWorldtask.CurrentTasks[curTaskConf.Group]; ok {
|
||||
for _, task := range tasks.TaskMap {
|
||||
if req.TaskId == task.TaskId {
|
||||
if task.NpcStatus == 1 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskNoAccept,
|
||||
Title: pb.ErrorCode_WorldtaskNoAccept.ToString(),
|
||||
Message: fmt.Sprintf("不能重复接取 taskId:%v", req.TaskId),
|
||||
}
|
||||
return
|
||||
} else {
|
||||
task.NpcStatus = 1
|
||||
for _, cid := range curTaskConf.Completetask {
|
||||
task.Conds = append(task.Conds, &pb.ConIProgress{
|
||||
Conid: cid,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tasks = &pb.Worldtasks{
|
||||
TaskMap: make(map[int32]*pb.Worldtask),
|
||||
}
|
||||
task := &pb.Worldtask{
|
||||
TaskId: req.TaskId,
|
||||
TaskType: curTaskConf.Des,
|
||||
NpcStatus: 1, //接取
|
||||
}
|
||||
|
||||
for _, cid := range curTaskConf.Completetask {
|
||||
task.Conds = append(task.Conds, &pb.ConIProgress{
|
||||
Conid: cid,
|
||||
})
|
||||
}
|
||||
|
||||
tasks.TaskMap[req.TaskId] = task
|
||||
myWorldtask.CurrentTasks[curTaskConf.Group] = tasks
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
"currentTasks": myWorldtask.CurrentTasks,
|
||||
}
|
||||
|
||||
if err := a.module.modelWorldtask.Change(uid, update); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
a.module.ModuleBuried.ActiveCondition(uid, curTaskConf.Completetask...)
|
||||
|
||||
//判断是否要结束任务
|
||||
if ((len(curTaskConf.Completetask) >= 1 && curTaskConf.Completetask[0] == 0) || len(curTaskConf.Completetask) == 0) &&
|
||||
curTaskConf.DeliverNpc == 0 {
|
||||
a.sendMsg(session, WorldtaskSubtypeAccept, rsp)
|
||||
//结束任务
|
||||
a.module.modelWorldtask.taskFinish(session, req.TaskId, myWorldtask, curTaskConf)
|
||||
a.module.modelWorldtask.taskFinishPush(session, myWorldtask, curTaskConf)
|
||||
} else if curTaskConf.DeliverNpc == 0 && len(curTaskConf.Completetask) > 0 {
|
||||
var flag bool
|
||||
conds, err := a.module.ModuleBuried.CheckCondition(uid, curTaskConf.Completetask...)
|
||||
if err == nil {
|
||||
flag = true
|
||||
for _, cond := range conds {
|
||||
rsp.Conds = append(rsp.Conds, cond)
|
||||
if cond.State != pb.BuriedItemFinishState_buried_finish {
|
||||
flag = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if flag {
|
||||
a.sendMsg(session, WorldtaskSubtypeAccept, rsp)
|
||||
a.module.modelWorldtask.taskFinish(session, req.TaskId, myWorldtask, curTaskConf)
|
||||
a.module.modelWorldtask.taskFinishPush(session, myWorldtask, curTaskConf)
|
||||
return
|
||||
}
|
||||
a.sendMsg(session, WorldtaskSubtypeAccept, rsp)
|
||||
} else {
|
||||
// 已完成的任务条件
|
||||
conds, err := a.module.ModuleBuried.CheckCondition(uid, curTaskConf.Completetask...)
|
||||
if err == nil {
|
||||
// var unfinishCondIds []int32
|
||||
for _, cond := range conds {
|
||||
// if cond.State == pb.BuriedItemFinishState_buried_finish {
|
||||
rsp.Conds = append(rsp.Conds, cond)
|
||||
// }
|
||||
// else if cond.State == pb.BuriedItemFinishState_buried_unfinish {
|
||||
// unfinishCondIds = append(unfinishCondIds, cond.Conid)
|
||||
// }
|
||||
}
|
||||
// a.module.ModuleBuried.ActiveCondition(uid, unfinishCondIds...)
|
||||
}
|
||||
a.sendMsg(session, WorldtaskSubtypeAccept, rsp)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
)
|
||||
|
||||
// 战斗结束的请求
|
||||
func (this *apiComp) BattlefinishCheck(session comm.IUserSession, req *pb.WorldtaskBattleFinishReq) (errdata *pb.ErrorData) {
|
||||
if req.BattleConfId <= 0 || req.TaskId <= 0 || req.Report == nil {
|
||||
this.module.Error("世界任务战斗结束参数错误",
|
||||
log.Field{Key: "uid", Value: session.GetUserId()},
|
||||
log.Field{Key: "params", Value: req.String()},
|
||||
)
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBattleFinishReq) (errdata *pb.ErrorData) {
|
||||
if errdata = this.BattlefinishCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
battleConf, err := this.module.configure.getWorldtaskBattleCfg()
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
uid := session.GetUserId()
|
||||
taskConf, err := this.module.configure.getWorldtaskById(req.TaskId)
|
||||
if err != nil || taskConf == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 当前玩家世界任务
|
||||
userTask, err := this.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
rsp := &pb.WorldtaskBattleFinishResp{}
|
||||
|
||||
if len(taskConf.Completetask) == 0 {
|
||||
if err := this.module.modelWorldtask.finishTask(req.TaskId, userTask); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
this.sendMsg(session, WorldtaskBattleFinish, rsp)
|
||||
return
|
||||
}
|
||||
|
||||
battleModule, err := this.module.service.GetModule(comm.ModuleBattle)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_SystemError,
|
||||
Title: pb.ErrorCode_SystemError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if ibattle, ok := battleModule.(comm.IBattle); ok {
|
||||
var isWin bool
|
||||
if errdata, isWin = ibattle.CheckBattleReport(session, req.Report); errdata == nil {
|
||||
if isWin {
|
||||
if battleConf, ok := battleConf.GetDataMap()[req.BattleConfId]; ok {
|
||||
|
||||
if battleConf.Carexe > 0 {
|
||||
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
||||
for _, v := range req.Report.Info.Redflist[0].Team {
|
||||
if !v.Ishelp { // 助战英雄不加经验
|
||||
this.module.ModuleHero.AddHeroExp(session, v.Oid, battleConf.Carexe)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if errdata = this.module.DispenseRes(session, []*cfg.Gameatn{battleConf.Playexp}, true); errdata != nil {
|
||||
this.module.Error("世界任务战斗玩家经验结算",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "playerExp", Value: battleConf.Playexp},
|
||||
)
|
||||
return
|
||||
} else {
|
||||
//触发任务
|
||||
go this.module.ModuleBuried.TriggerBuried(session.Clone(), comm.GetBuriedParam(comm.Rtype70, 1, req.BattleConfId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ExternalModule,
|
||||
Title: pb.ErrorCode_ExternalModule.ToString(),
|
||||
Message: "战报校验错误",
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//判断是否配置了通知module
|
||||
if len(taskConf.Module) == 0 {
|
||||
|
||||
// 发奖
|
||||
// if errdata = this.module.DispenseRes(session, taskConf.Reword, true); errdata != nil {
|
||||
// this.module.Error("资源发放",
|
||||
// log.Field{Key: "uid", Value: uid},
|
||||
// log.Field{Key: "taskId", Value: req.TaskId},
|
||||
// log.Field{Key: "reword", Value: taskConf.Reword},
|
||||
// log.Field{Key: "errdata", Value: errdata},
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
} else {
|
||||
for _, m := range taskConf.Module {
|
||||
i, err := this.service.GetModule(core.M_Modules(m))
|
||||
if err != nil {
|
||||
this.module.Error("GetModule err", log.Field{Key: "err", Value: err.Error()})
|
||||
continue
|
||||
}
|
||||
if ic, ok := i.(comm.ITaskComplete); ok {
|
||||
ic.TaskComplete(session, req.TaskId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.sendMsg(session, WorldtaskBattleFinish, rsp)
|
||||
return
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
// 战斗开始
|
||||
func (this *apiComp) BattlestartCheck(session comm.IUserSession, req *pb.WorldtaskBattleStartReq) (errdata *pb.ErrorData) {
|
||||
if req.BattleConfId == 0 || req.Battle == nil {
|
||||
this.module.Error("世界任务战斗开始参数错误",
|
||||
log.Field{Key: "uid", Value: session.GetUserId()},
|
||||
log.Field{Key: "params", Value: req.String()},
|
||||
)
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) Battlestart(session comm.IUserSession, req *pb.WorldtaskBattleStartReq) (errdata *pb.ErrorData) {
|
||||
if errdata = this.BattlestartCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
resp := &pb.WorldtaskBattleStartResp{}
|
||||
|
||||
battleConf, err := this.module.configure.getWorldtaskBattleById(req.BattleConfId)
|
||||
if err != nil || battleConf == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: fmt.Sprintf("战斗配置未找到 %v", req.BattleConfId),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
iBattle, err := this.module.service.GetModule(comm.ModuleBattle)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_SystemError,
|
||||
Title: pb.ErrorCode_SystemError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if b, y := iBattle.(comm.IBattle); y {
|
||||
var (
|
||||
record *pb.DBBattleRecord
|
||||
)
|
||||
errdata, record = b.CreateEveBattle(session, &pb.BattleEVEReq{
|
||||
Rulesid: battleConf.BattleReadyID,
|
||||
Ptype: pb.PlayType_rtask,
|
||||
Format: req.Battle,
|
||||
Buleformat: battleConf.FormatList,
|
||||
})
|
||||
|
||||
if errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if record != nil {
|
||||
resp = &pb.WorldtaskBattleStartResp{
|
||||
Info: &pb.BattleInfo{
|
||||
Id: record.Id,
|
||||
Rulesid: battleConf.BattleReadyID,
|
||||
Btype: record.Btype,
|
||||
Ptype: record.Ptype,
|
||||
RedCompId: record.RedCompId,
|
||||
Redflist: record.Redflist,
|
||||
BlueCompId: record.BlueCompId,
|
||||
Buleflist: record.Buleflist,
|
||||
Tasks: record.Tasks,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskBattleCreate,
|
||||
Title: pb.ErrorCode_WorldtaskBattleCreate.ToString(),
|
||||
Message: "战斗记录是空",
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
this.sendMsg(session, WorldtaskBattleStart, resp)
|
||||
}
|
||||
return
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *apiComp) ChapterrewardCheck(session comm.IUserSession, req *pb.WorldtaskChapterrewardReq) (errdata *pb.ErrorData) {
|
||||
if req.GroupId <= 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) Chapterreward(session comm.IUserSession, req *pb.WorldtaskChapterrewardReq) (errdata *pb.ErrorData) {
|
||||
if errdata = this.ChapterrewardCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uid := session.GetUserId()
|
||||
rsp := &pb.WorldtaskChapterrewardResp{}
|
||||
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if stats, ok := myWorldtask.Chapters[req.GroupId]; !ok {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskChapterUnFinished,
|
||||
Title: pb.ErrorCode_WorldtaskChapterUnFinished.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
} else {
|
||||
if stats == 2 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskChapterReceived,
|
||||
Title: pb.ErrorCode_WorldtaskChapterReceived.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
gwa, err := this.module.configure.getWorldAllCfg()
|
||||
if err != nil || gwa == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
rewardCnf := gwa.GetDataMap()[req.GroupId]
|
||||
if rewardCnf == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: fmt.Sprintf("未找到组%v配置", req.GroupId),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
this.module.DispenseRes(session, rewardCnf.Reword, true)
|
||||
|
||||
this.sendMsg(session, WorldtaskChapterReward, rsp)
|
||||
|
||||
return
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
// 任务完成条件
|
||||
func (this *apiComp) CompleteCondiCheck(session comm.IUserSession, req *pb.WorldtaskCompleteCondiReq) (errdata *pb.ErrorData) {
|
||||
if req.TaskId <= 0 || req.CondiId <= 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskCompleteCondiReq) (errdata *pb.ErrorData) {
|
||||
if errdata = this.CompleteCondiCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rsp := &pb.WorldtaskCompleteCondiResp{}
|
||||
uid := session.GetUserId()
|
||||
|
||||
// 当前任务配置
|
||||
curTaskConf, err := this.module.configure.getWorldtaskById(req.TaskId)
|
||||
if err != nil || curTaskConf == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
if (len(curTaskConf.Completetask) >= 1 && curTaskConf.Completetask[0] == 0) ||
|
||||
len(curTaskConf.Completetask) == 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskNoProcess,
|
||||
Title: pb.ErrorCode_WorldtaskNoProcess.ToString(),
|
||||
Message: "无完成条件",
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
myWorldtask.Uid = uid
|
||||
|
||||
// 校验任务条件
|
||||
conds, err := this.module.ModuleBuried.FinishConditionAndCheck(uid, []int32{req.CondiId}, curTaskConf.Completetask...)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ExternalModule,
|
||||
Title: pb.ErrorCode_ExternalModule.ToString(),
|
||||
Message: comm.NewExternalModuleErr("buried", "CheckCondition", uid, req.CondiId).Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 设置当前任务的完成条件
|
||||
for _, tasks := range myWorldtask.CurrentTasks {
|
||||
if task, ok := tasks.TaskMap[req.TaskId]; ok {
|
||||
for _, cond := range conds {
|
||||
for _, exist_cond := range task.Conds {
|
||||
if cond.Conid == exist_cond.Conid {
|
||||
continue
|
||||
}
|
||||
task.Conds = append(task.Conds, cond)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
"currentTasks": myWorldtask.CurrentTasks,
|
||||
}
|
||||
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
this.sendMsg(session, WorldtaskComplete, rsp)
|
||||
|
||||
//结束任务
|
||||
if curTaskConf.DeliverNpc == 0 {
|
||||
this.module.modelWorldtask.taskFinish(session, req.TaskId, myWorldtask, curTaskConf)
|
||||
this.module.modelWorldtask.taskFinishPush(session, myWorldtask, curTaskConf)
|
||||
}
|
||||
return
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
// 世界任务完成
|
||||
func (this *apiComp) FinishCheck(session comm.IUserSession, req *pb.WorldtaskFinishReq) (errdata *pb.ErrorData) {
|
||||
if req.TaskId == 0 {
|
||||
this.module.Error("世界任务完成参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishReq) (errdata *pb.ErrorData) {
|
||||
if errdata = this.FinishCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
uid := session.GetUserId()
|
||||
|
||||
rsp := &pb.WorldtaskFinishResp{}
|
||||
|
||||
// 获取用户信息
|
||||
user := this.module.ModuleUser.GetUser(uid)
|
||||
if user == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_UserSessionNobeing,
|
||||
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
|
||||
Datastring: uid,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 当前任务配置
|
||||
curTaskConf, err := this.module.configure.getWorldtaskById(req.TaskId)
|
||||
if err != nil || curTaskConf == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if curTaskConf.DeliverNpc == 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskNoProcess,
|
||||
Title: pb.ErrorCode_WorldtaskNoProcess.ToString(),
|
||||
Message: "配置DeliverNpc字段是0",
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 判断玩家等级要求
|
||||
if user.Lv < curTaskConf.Lock {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskLvNotEnough,
|
||||
Title: pb.ErrorCode_WorldtaskLvNotEnough.ToString(),
|
||||
Message: fmt.Sprintf("实际等级:%d 期望等级:%d", user.Lv, curTaskConf.Lock),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 当前玩家世界任务
|
||||
userTask, err := this.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
if userTask.Uid == "" {
|
||||
userTask.Uid = uid
|
||||
}
|
||||
|
||||
// 前置任务ID 只有世界任务才校验前置 (完成任务无需校验前置任务)
|
||||
// if !this.module.modelWorldtask.IsPreFinished(userTask, curTaskConf) {
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_WorldtaskLastUnFinished,
|
||||
// Title: pb.ErrorCode_WorldtaskLastUnFinished.ToString(),
|
||||
// Message: fmt.Sprintf("任务[%v]的前置任务 [%v] 未完成", curTaskConf.Key, curTaskConf.Ontxe),
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
//判断任务是否已完成
|
||||
for _, v := range userTask.TaskList {
|
||||
if v == req.TaskId {
|
||||
this.module.Debug("任务已完成,返回下一个",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "taskId", Value: req.TaskId},
|
||||
)
|
||||
this.sendMsg(session, WorldtaskSubtypeFinish, rsp)
|
||||
this.module.modelWorldtask.taskFinishPush(session, userTask, curTaskConf)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
conds, err := this.module.ModuleBuried.CheckCondition(uid, curTaskConf.Completetask...)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ExternalModule,
|
||||
Title: pb.ErrorCode_ExternalModule.ToString(),
|
||||
Message: comm.NewExternalModuleErr("Buried", "CheckCondition", uid, curTaskConf.Completetask).Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, cond := range conds {
|
||||
if cond.State == pb.BuriedItemFinishState_buried_unfinish {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_RtaskCondiNoReach,
|
||||
Title: pb.ErrorCode_RtaskCondiNoReach.ToString(),
|
||||
Message: fmt.Sprintf("世界任务[%v] 条件[%v]未达成", req.TaskId, cond.Conid),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, cond := range conds {
|
||||
if cond.State == pb.BuriedItemFinishState_buried_unfinish {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_RtaskCondiNoReach,
|
||||
Title: pb.ErrorCode_RtaskCondiNoReach.ToString(),
|
||||
Message: fmt.Sprintf("世界任务[%v]条件[%v]未达标,类型:%v 实际:%v 期望:%v", req.TaskId, cond.Conid, cond.Btype, cond.Value, cond.Target),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 完成任务
|
||||
if err := this.module.modelWorldtask.finishTask(req.TaskId, userTask); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_WorldtaskFinish,
|
||||
Title: pb.ErrorCode_WorldtaskFinish.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
// 发奖
|
||||
if errdata = this.module.DispenseRes(session, curTaskConf.Reword, true); errdata != nil {
|
||||
this.module.Error("资源发放",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "taskId", Value: req.TaskId},
|
||||
log.Field{Key: "reword", Value: curTaskConf.Reword},
|
||||
log.Field{Key: "errdata", Value: errdata},
|
||||
)
|
||||
}
|
||||
|
||||
//判断是否配置了通知module
|
||||
for _, m := range curTaskConf.Module {
|
||||
i, err := this.service.GetModule(core.M_Modules(m))
|
||||
if err != nil {
|
||||
this.module.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if ic, ok := i.(comm.ITaskComplete); ok {
|
||||
ic.TaskComplete(session, req.TaskId)
|
||||
}
|
||||
}
|
||||
this.sendMsg(session, WorldtaskSubtypeFinish, rsp)
|
||||
this.module.modelWorldtask.taskFinishPush(session, userTask, curTaskConf)
|
||||
return
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dailyDes int32 = 1
|
||||
weekDes int32 = 4
|
||||
)
|
||||
|
||||
// 我的世界任务
|
||||
func (this *apiComp) MineCheck(session comm.IUserSession, req *pb.WorldtaskMineReq) (errdata *pb.ErrorData) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) (errdata *pb.ErrorData) {
|
||||
uid := session.GetUserId()
|
||||
|
||||
user := this.module.ModuleUser.GetUser(uid)
|
||||
if user == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_UserNofound,
|
||||
Title: pb.ErrorCode_UserNofound.ToString(),
|
||||
Message: "战斗记录是空",
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
this.module.Error("获取玩家世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if myWorldtask.CurrentTasks == nil {
|
||||
myWorldtask.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
}
|
||||
|
||||
//查询当前所有任务组下的完成条件数据
|
||||
var condIds []int32
|
||||
// condMap := make(map[int32][]int32)
|
||||
for _, v := range myWorldtask.CurrentTasks {
|
||||
for _, t := range v.TaskMap {
|
||||
cfg, err := this.module.configure.getWorldtaskById(t.TaskId)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
if (len(cfg.Completetask) >= 1 && cfg.Completetask[0] > 0) &&
|
||||
len(cfg.Completetask) > 0 {
|
||||
condIds = append(condIds, cfg.Completetask...)
|
||||
// condMap[k] = cfg.Completetask
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
condIds = utils.RemoveDuplicate(condIds)
|
||||
// this.module.modelWorldtask.updateRandomTask(uid, myWorldtask)
|
||||
|
||||
// 查询任务的条件进度
|
||||
conds, err := this.module.ModuleBuried.CheckCondition(uid, condIds...)
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ExternalModule,
|
||||
Title: pb.ErrorCode_ExternalModule.ToString(),
|
||||
Message: comm.NewExternalModuleErr("buried", "CheckCondition", condIds).Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// for k, v := range condMap {
|
||||
for _, mw := range myWorldtask.CurrentTasks {
|
||||
for _, task := range mw.TaskMap {
|
||||
task.Conds = make([]*pb.ConIProgress, 0)
|
||||
_cfg, _ := this.module.configure.getWorldtaskById(task.TaskId)
|
||||
for _, cond := range conds {
|
||||
if _, ok := utils.Findx(_cfg.Completetask, cond.Conid); ok {
|
||||
task.Conds = append(task.Conds, cond)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
rsp := &pb.WorldtaskMineResp{
|
||||
Task: myWorldtask,
|
||||
}
|
||||
|
||||
this.sendMsg(session, WorldtaskSubtypeMine, rsp)
|
||||
return
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *apiComp) TriggerCheck(session comm.IUserSession, req *pb.WorldtaskTriggerReq) (errdata *pb.ErrorData) {
|
||||
if len(req.Params) < 1 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) Trigger(session comm.IUserSession, req *pb.WorldtaskTriggerReq) (errdata *pb.ErrorData) {
|
||||
if errdata = this.TriggerCheck(session, req); errdata != nil {
|
||||
return
|
||||
}
|
||||
rsp := &pb.WorldtaskTriggerResp{Flag: true, RtaskType: req.RtaskType}
|
||||
// 校验
|
||||
if req.CondiId != 0 {
|
||||
condIds, err := this.module.ModuleBuried.CheckCondition(session.GetUserId(), req.CondiId)
|
||||
if err == nil && len(condIds) > 0 {
|
||||
rsp.Flag = true
|
||||
}
|
||||
// 触发
|
||||
} else if req.RtaskType != 0 && len(req.Params) > 0 {
|
||||
conds := []int32{}
|
||||
switch len(req.Params) {
|
||||
case 2:
|
||||
conds = make([]int32, 1)
|
||||
conds[0] = req.Params[1]
|
||||
case 3:
|
||||
conds = make([]int32, 2)
|
||||
conds[0] = req.Params[1]
|
||||
conds[1] = req.Params[2]
|
||||
case 4:
|
||||
conds = make([]int32, 3)
|
||||
conds[0] = req.Params[1]
|
||||
conds[1] = req.Params[2]
|
||||
conds[2] = req.Params[3]
|
||||
case 5:
|
||||
conds = make([]int32, 4)
|
||||
conds[0] = req.Params[1]
|
||||
conds[1] = req.Params[2]
|
||||
conds[2] = req.Params[3]
|
||||
conds[3] = req.Params[4]
|
||||
}
|
||||
this.module.ModuleBuried.TriggerBuried(session.Clone(), comm.GetBuriedParam(comm.TaskType(req.RtaskType), req.Params[0], conds...))
|
||||
|
||||
rsp.Flag = true
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), "trigger", rsp)
|
||||
return
|
||||
}
|
@ -1,229 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
gameWorldTask = "game_worldtask.json"
|
||||
gameWorldtaskBattle = "game_worldbattle.json"
|
||||
gameWorldAll = "game_worldall.json"
|
||||
gameburiedCond = "game_buriedcondi.json"
|
||||
gamerdtasknpc = "game_rdtasknpc.json"
|
||||
)
|
||||
|
||||
type configureComp struct {
|
||||
modules.MCompConfigure
|
||||
module *Worldtask
|
||||
lock sync.RWMutex
|
||||
worldtaskConf map[int32]*cfg.GameWorldTaskData //key 条件ID
|
||||
}
|
||||
|
||||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.MCompConfigure.Init(service, module, comp, options)
|
||||
this.module = module.(*Worldtask)
|
||||
err = this.LoadMultiConfigure(map[string]interface{}{
|
||||
gameWorldTask: cfg.NewGameWorldTask,
|
||||
gameWorldtaskBattle: cfg.NewGameWorldBattle,
|
||||
gameWorldAll: cfg.NewGameWorldAll,
|
||||
gameburiedCond: cfg.NewGameBuriedCondi,
|
||||
gamerdtasknpc: cfg.NewGameRdtaskNpc,
|
||||
})
|
||||
this.worldtaskConf = make(map[int32]*cfg.GameWorldTaskData)
|
||||
configure.RegisterConfigure(gameWorldTask, cfg.NewGameBuriedCondi, this.updateconfigure)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) Start() (err error) {
|
||||
err = this.MCompConfigure.Start()
|
||||
this.checkWorldtaskConf()
|
||||
conf, err := this.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
this.worldtaskConf = conf.GetDataMap()
|
||||
return
|
||||
}
|
||||
|
||||
// 配置文件校验
|
||||
func (this *configureComp) checkWorldtaskConf() (err error) {
|
||||
worldtaskConf, err := this.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buriedCondConf, err := this.getBuriedCondCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, data := range worldtaskConf.GetDataList() {
|
||||
// 检查 lock
|
||||
if data.Lock < 1 {
|
||||
this.module.Errorf("taskId:%v lock:%v可能存在问题", data.Key, data.Lock)
|
||||
}
|
||||
//检查group
|
||||
if data.Group <= 0 {
|
||||
this.module.Errorf("taskId:%v group:%v可能存在问题", data.Key, data.Group)
|
||||
}
|
||||
//检查des
|
||||
if data.Des < 1 || data.Des > 5 {
|
||||
// errs = append(errs, fmt.Sprintf("taskId:%v des:%v可能存在问题", data.Key, data.Des))
|
||||
this.module.Errorf("taskId:%v des:%v可能存在问题", data.Key, data.Des)
|
||||
}
|
||||
// 检查completetask 是否有效
|
||||
for _, condId := range data.Completetask {
|
||||
if condId > 0 {
|
||||
if _, ok := buriedCondConf.GetDataMap()[condId]; !ok {
|
||||
this.module.Errorf("taskId:%v completetask:%v可能是无效的ID", data.Key, condId)
|
||||
// errs = append(errs, fmt.Sprintf("taskId:%v completetask:%v可能是无效的ID", data.Key, condId))
|
||||
}
|
||||
}
|
||||
}
|
||||
//检查NPC
|
||||
if data.Npc > 0 {
|
||||
if _, err := this.getNPCById(data.Npc); err != nil {
|
||||
this.module.Errorf("npcId:%v 可能无效,检查world_task表字段Npc值是否存在于buried/rdtasknpc", data.Npc)
|
||||
// errs = append(errs, fmt.Sprintf("npcId:%v 可能无效,检查world_task表字段Npc值是否存在于buried/rdtasknpc", data.Npc))
|
||||
}
|
||||
}
|
||||
if data.DeliverNpc > 0 {
|
||||
if _, err := this.getNPCById(data.Npc); err != nil {
|
||||
this.module.Errorf("npcId:%v 可能无效,检查world_task表字段deliver_npc值是否存在于buried/rdtasknpc", data.Npc)
|
||||
// errs = append(errs, fmt.Sprintf("npcId:%v 可能无效,检查world_task表字段deliver_npc值是否存在于buried/rdtasknpc", data.Npc))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, data := range buriedCondConf.GetDataList() {
|
||||
if data.NPC > 0 {
|
||||
if _, err := this.getNPCById(data.NPC); err != nil {
|
||||
this.module.Errorf("npcId:%v 可能无效,检查buried_condi表字段NPC值是否存在于buried/rdtasknpc", data.NPC)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) getWorldtaskCfg() (data *cfg.GameWorldTask, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = this.GetConfigure(gameWorldTask); err != nil {
|
||||
return
|
||||
} else {
|
||||
if data, ok = v.(*cfg.GameWorldTask); !ok {
|
||||
err = fmt.Errorf("%T is *cfg.GameWorldTask", v)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) updateconfigure() {
|
||||
gwt, err := this.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
this.lock.Lock()
|
||||
this.worldtaskConf = gwt.GetDataMap()
|
||||
this.lock.Unlock()
|
||||
}
|
||||
|
||||
func (this *configureComp) getWorldAllCfg() (data *cfg.GameWorldAll, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = this.GetConfigure(gameWorldAll); err != nil {
|
||||
return
|
||||
} else {
|
||||
if data, ok = v.(*cfg.GameWorldAll); !ok {
|
||||
err = fmt.Errorf("%T is *cfg.GameWorldAll", v)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) getWorldtaskById(taskId int32) (*cfg.GameWorldTaskData, error) {
|
||||
gwt, err := this.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if data, ok := gwt.GetDataMap()[taskId]; ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, comm.NewNotFoundConfErr(moduleName_cn, gameWorldTask, taskId)
|
||||
}
|
||||
|
||||
func (this *configureComp) getNPCById(npcId int32) (npc *cfg.GameRdtaskNpcData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
)
|
||||
if v, err = this.GetConfigure(gamerdtasknpc); err != nil {
|
||||
return
|
||||
} else {
|
||||
data, ok := v.(*cfg.GameRdtaskNpc)
|
||||
if !ok {
|
||||
err = fmt.Errorf("%T is *cfg.GameRdtaskNpc", v)
|
||||
return
|
||||
}
|
||||
if npc, ok = data.GetDataMap()[npcId]; ok {
|
||||
return
|
||||
}
|
||||
err = comm.NewNotFoundConfErr(moduleName_cn, gamerdtasknpc, npc)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) getWorldtaskBattleCfg() (data *cfg.GameWorldBattle, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = this.GetConfigure(gameWorldtaskBattle); err != nil {
|
||||
return
|
||||
} else {
|
||||
if data, ok = v.(*cfg.GameWorldBattle); !ok {
|
||||
err = fmt.Errorf("%T is *cfg.GameWorldBattle", v)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) getWorldtaskBattleById(confId int32) (*cfg.GameWorldBattleData, error) {
|
||||
gwt, err := this.getWorldtaskBattleCfg()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if data, ok := gwt.GetDataMap()[confId]; ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf("GameWorldBattleData config id:%v not found", confId)
|
||||
}
|
||||
|
||||
func (this *configureComp) getBuriedCondCfg() (data *cfg.GameBuriedCondi, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = this.GetConfigure(gameburiedCond); err != nil {
|
||||
return
|
||||
} else {
|
||||
if data, ok = v.(*cfg.GameBuriedCondi); !ok {
|
||||
err = fmt.Errorf("%T is *cfg.GameWorldAll", v)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
@ -1,402 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
)
|
||||
|
||||
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
|
||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||
})
|
||||
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 _, v := range userTask.TaskList {
|
||||
if lastTaskId == v {
|
||||
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(taskId int32, task *pb.DBWorldtask) error {
|
||||
if task == nil {
|
||||
return errors.New("worldtask is nil")
|
||||
}
|
||||
|
||||
worldtaskConf, err := this.moduleWorldtask.configure.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
this.moduleWorldtask.Errorln(err.Error())
|
||||
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
||||
}
|
||||
|
||||
update := map[string]interface{}{}
|
||||
|
||||
taskConf := worldtaskConf.GetDataMap()[taskId]
|
||||
if taskConf == nil {
|
||||
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
||||
}
|
||||
|
||||
update["uid"] = task.Uid
|
||||
// wt := &pb.Worldtask{
|
||||
// TaskId: taskId,
|
||||
// TaskType: taskConf.Des,
|
||||
// }
|
||||
|
||||
for _, tId := range task.TaskList {
|
||||
if tId == taskId {
|
||||
return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed)
|
||||
}
|
||||
}
|
||||
|
||||
task.TaskList = append(task.TaskList, taskId)
|
||||
|
||||
if task.CurrentTasks == nil {
|
||||
task.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
}
|
||||
|
||||
//有下个任务
|
||||
// if taskConf.IdAfter != 0 {
|
||||
// wt.NpcStatus = 0
|
||||
// wt.DeliverNpc = 0
|
||||
// task.CurrentTasks[groupId] = wt
|
||||
// update[""] = task.CurrentTasks
|
||||
// }
|
||||
|
||||
update["taskList"] = task.TaskList
|
||||
|
||||
if err := this.Change(task.Uid, update); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 查找后续任务
|
||||
func (this *ModelWorldtask) findNextTasks(parentTaskId int32) (taskIds []int32) {
|
||||
gwt, err := this.moduleWorldtask.configure.getWorldtaskCfg()
|
||||
if err != nil || gwt == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range gwt.GetDataList() {
|
||||
if v.Ontxe == parentTaskId {
|
||||
taskIds = append(taskIds, v.Key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 更新当前任务的完成条件
|
||||
func (this *ModelWorldtask) updateCurrentTaskCond(uid string, userLv int32, userTask *pb.DBWorldtask, currentTaskId, nextTaskId int32) *pb.DBWorldtask {
|
||||
nextTaskConf, err := this.moduleWorldtask.configure.getWorldtaskById(nextTaskId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if nextTaskConf == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if userLv < nextTaskConf.Lock {
|
||||
return nil
|
||||
}
|
||||
|
||||
if nextTaskConf.Des == 1 || nextTaskConf.Des == 4 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if userTask.CurrentTasks == nil {
|
||||
userTask.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
}
|
||||
|
||||
update := make(map[string]interface{})
|
||||
nwt, ok := userTask.CurrentTasks[nextTaskConf.Group]
|
||||
if ok {
|
||||
// 删除
|
||||
delete(nwt.TaskMap, currentTaskId)
|
||||
}
|
||||
|
||||
if nwt == nil {
|
||||
nwt = &pb.Worldtasks{
|
||||
TaskMap: make(map[int32]*pb.Worldtask),
|
||||
}
|
||||
userTask.CurrentTasks[nextTaskConf.Group] = nwt
|
||||
}
|
||||
|
||||
nwt.TaskMap[nextTaskId] = &pb.Worldtask{
|
||||
TaskId: nextTaskId,
|
||||
TaskType: nextTaskConf.Des,
|
||||
}
|
||||
|
||||
update["currentTasks"] = userTask.CurrentTasks
|
||||
|
||||
if len(update) > 0 {
|
||||
if err := this.Change(uid, update); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return userTask
|
||||
}
|
||||
|
||||
// 任务完成推送
|
||||
func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) {
|
||||
// this.updateRandomTask(session.GetUserId(), userTask)
|
||||
u := this.moduleWorldtask.ModuleUser.GetUser(session.GetUserId())
|
||||
if u == nil {
|
||||
return
|
||||
}
|
||||
|
||||
nextTaskIds := this.findNextTasks(curTaskConf.Key)
|
||||
this.moduleWorldtask.Debug("nextTaskIds", log.Field{Key: "nextTaskIds", Value: nextTaskIds})
|
||||
|
||||
nextTask := make(map[int32]*pb.Worldtasks)
|
||||
if len(nextTaskIds) > 0 {
|
||||
for _, next := range nextTaskIds {
|
||||
ut := this.updateCurrentTaskCond(session.GetUserId(), u.Lv, userTask, curTaskConf.Key, next)
|
||||
if ut != nil {
|
||||
for k, v := range ut.CurrentTasks {
|
||||
nextTask[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if curTaskConf.Des == 5 {
|
||||
nwt, ok := userTask.CurrentTasks[curTaskConf.Group]
|
||||
if ok {
|
||||
// 删除
|
||||
delete(nwt.TaskMap, curTaskConf.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if nextTaskIds == nil {
|
||||
nextTask[curTaskConf.Group] = &pb.Worldtasks{} //表示没有下一个任务
|
||||
}
|
||||
|
||||
if curTaskConf.IdAfter == 0 {
|
||||
// 章节完成
|
||||
if _, ok := userTask.Chapters[curTaskConf.Group]; !ok {
|
||||
delete(userTask.CurrentTasks, curTaskConf.Group)
|
||||
delete(nextTask, curTaskConf.Group)
|
||||
if userTask.Chapters == nil {
|
||||
userTask.Chapters = make(map[int32]int32)
|
||||
}
|
||||
userTask.Chapters[curTaskConf.Group] = 1 //已解锁待领取
|
||||
|
||||
}
|
||||
}
|
||||
update := map[string]interface{}{
|
||||
"chapters": userTask.Chapters,
|
||||
"currentTasks": userTask.CurrentTasks,
|
||||
}
|
||||
this.Change(session.GetUserId(), update)
|
||||
// 任务完成推送
|
||||
session.SendMsg(string(this.moduleWorldtask.GetType()), WorldtaskNexttaskPush, &pb.WorldtaskNexttaskPush{
|
||||
NextTask: nextTask,
|
||||
FinishedTaskIds: []int32{curTaskConf.Key},
|
||||
})
|
||||
}
|
||||
|
||||
// 任务完成
|
||||
func (this *ModelWorldtask) taskFinish(session comm.IUserSession, taskId int32, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) {
|
||||
if err := this.finishTask(taskId, userTask); err != nil {
|
||||
this.moduleWorldtask.Error("完成任务失败",
|
||||
log.Field{Key: "uid", Value: session.GetUserId()},
|
||||
log.Field{Key: "taskId", Value: taskId},
|
||||
log.Field{Key: "err", Value: err.Error()},
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
this.moduleWorldtask.DispenseRes(session, curTaskConf.Reword, true)
|
||||
//判断是否配置了通知module
|
||||
for _, m := range curTaskConf.Module {
|
||||
i, err := this.service.GetModule(core.M_Modules(m))
|
||||
if err != nil {
|
||||
this.moduleWorldtask.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if ic, ok := i.(comm.ITaskComplete); ok {
|
||||
ic.TaskComplete(session, taskId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ModelWorldtask) filterTask(userLv, des int32, wt *pb.DBWorldtask) (taskIds []int32) {
|
||||
if des != 1 && des != 4 {
|
||||
return
|
||||
}
|
||||
gwt, err := this.moduleWorldtask.configure.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range gwt.GetDataList() {
|
||||
// 主角等级
|
||||
if v.Des == des && userLv >= v.Lock && userLv <= v.Lockend {
|
||||
if v.Ontxe != 0 {
|
||||
//寻找前置
|
||||
if _, ok := utils.Findx(wt.TaskList, v.Ontxe); ok {
|
||||
taskIds = append(taskIds, v.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 随机日常、周常任务
|
||||
func (this *ModelWorldtask) randomTask(userLv, des int32, wt *pb.DBWorldtask) (taskIds []int32) {
|
||||
var num int32
|
||||
if des == 1 {
|
||||
num = this.moduleWorldtask.ModuleTools.GetGlobalConf().DailyNum
|
||||
} else if des == 4 {
|
||||
num = this.moduleWorldtask.ModuleTools.GetGlobalConf().WeekNum
|
||||
}
|
||||
|
||||
tIds := this.filterTask(userLv, des, wt)
|
||||
if len(tIds) < int(num) {
|
||||
num = int32(len(tIds))
|
||||
}
|
||||
idx := utils.RandomNumbers(0, len(tIds), int(num))
|
||||
|
||||
for i := 0; i < len(idx); i++ {
|
||||
taskIds = append(taskIds, tIds[i])
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelWorldtask) updateRandomTask(uid string, myWorldtask *pb.DBWorldtask) {
|
||||
user := this.moduleWorldtask.ModuleUser.GetUser(uid)
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
|
||||
now := configure.Now().Unix()
|
||||
update := make(map[string]interface{})
|
||||
// 日常
|
||||
if now-myWorldtask.DaliyRefreshTime >= 3600*24 {
|
||||
dailyIds := this.randomTask(user.Lv, dailyDes, myWorldtask)
|
||||
if len(dailyIds) > 0 {
|
||||
for _, v := range dailyIds {
|
||||
gwtd, err := this.moduleWorldtask.configure.getWorldtaskById(v)
|
||||
if err != nil || gwtd == nil {
|
||||
continue
|
||||
}
|
||||
if task, ok := myWorldtask.CurrentTasks[gwtd.Group]; ok {
|
||||
task.TaskMap[v] = &pb.Worldtask{
|
||||
TaskId: v,
|
||||
TaskType: gwtd.Des,
|
||||
}
|
||||
} else {
|
||||
taskMap := make(map[int32]*pb.Worldtask)
|
||||
taskMap[v] = &pb.Worldtask{
|
||||
TaskId: v,
|
||||
TaskType: gwtd.Des,
|
||||
}
|
||||
myWorldtask.CurrentTasks[gwtd.Group] = &pb.Worldtasks{
|
||||
TaskMap: taskMap,
|
||||
}
|
||||
}
|
||||
}
|
||||
update["daliyRefreshTime"] = configure.Now().Unix()
|
||||
}
|
||||
}
|
||||
//周常
|
||||
if now-myWorldtask.WeekRefreshTime >= 3600*24*7 {
|
||||
weekIds := this.randomTask(user.Lv, weekDes, myWorldtask)
|
||||
if len(weekIds) > 0 {
|
||||
for _, v := range weekIds {
|
||||
gwtd, err := this.moduleWorldtask.configure.getWorldtaskById(v)
|
||||
if err != nil || gwtd == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if task, ok := myWorldtask.CurrentTasks[gwtd.Group]; ok {
|
||||
task.TaskMap[v] = &pb.Worldtask{
|
||||
TaskId: v,
|
||||
TaskType: gwtd.Des,
|
||||
}
|
||||
} else {
|
||||
taskMap := make(map[int32]*pb.Worldtask)
|
||||
taskMap[v] = &pb.Worldtask{
|
||||
TaskId: v,
|
||||
TaskType: gwtd.Des,
|
||||
}
|
||||
myWorldtask.CurrentTasks[gwtd.Group] = &pb.Worldtasks{
|
||||
TaskMap: taskMap,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update["weekRefreshTime"] = configure.Now().Unix()
|
||||
}
|
||||
}
|
||||
|
||||
update["currentTasks"] = myWorldtask.CurrentTasks
|
||||
|
||||
if err := this.Change(uid, update); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
@ -1,499 +0,0 @@
|
||||
package worldtask
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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)
|
||||
|
||||
var moduleName_cn = "世界任务"
|
||||
|
||||
type Worldtask struct {
|
||||
modules.ModuleBase
|
||||
api *apiComp
|
||||
service base.IRPCXService
|
||||
configure *configureComp
|
||||
modelWorldtask *ModelWorldtask
|
||||
}
|
||||
|
||||
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()
|
||||
// event.Register(comm.EventBuriedComplete, this.TCondFinishNotify)
|
||||
return
|
||||
}
|
||||
|
||||
// 功能开启
|
||||
func (this *Worldtask) OpenCmdNotice(uid string, keys ...string) {
|
||||
|
||||
}
|
||||
|
||||
var errs []string
|
||||
|
||||
// 完成条件通知
|
||||
func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
|
||||
this.Debug("世界任务完成条件通知", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condIds", Value: conds})
|
||||
|
||||
session, ok := this.GetUserSession(uid)
|
||||
if !ok {
|
||||
this.Errorln("获取session失败")
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if ok {
|
||||
session.Push()
|
||||
}
|
||||
this.PutUserSession(session)
|
||||
}()
|
||||
// 玩家世界任务
|
||||
userTask, err := this.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
this.Error("获取玩家世界任务", log.Field{Key: "uid", Value: uid})
|
||||
return
|
||||
}
|
||||
|
||||
worldtaskConf, err := this.configure.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
this.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tasks := map[int32][]int32{}
|
||||
taskgroup := map[int32]int32{}
|
||||
allconds := []int32{}
|
||||
// for _, cfg := range worldtaskConf.GetDataList() {
|
||||
for _, group := range userTask.CurrentTasks {
|
||||
for _, v := range group.TaskMap {
|
||||
tconfig := worldtaskConf.GetDataMap()[v.TaskId]
|
||||
for _, condId := range tconfig.Completetask {
|
||||
for _, cond := range conds {
|
||||
if condId == cond.Conid { //&& cond.State == pb.BuriedItemFinishState_buried_finish {
|
||||
tasks[tconfig.Key] = tconfig.Completetask
|
||||
taskgroup[tconfig.Key] = tconfig.Group
|
||||
allconds = append(allconds, tconfig.Completetask...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
if len(allconds) == 0 {
|
||||
// this.Debug("未匹配到完成的条件")
|
||||
return
|
||||
}
|
||||
|
||||
allconds = utils.RemoveDuplicate(allconds)
|
||||
allpass := make(map[int32]*pb.ConIProgress)
|
||||
if len(allconds) != len(conds) {
|
||||
if conds, err = this.ModuleBuried.CheckCondition(uid, allconds...); err != nil {
|
||||
log.Errorf("调用接口错误:%s", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range conds {
|
||||
allpass[v.Conid] = v
|
||||
|
||||
}
|
||||
fishtask := []int32{}
|
||||
var currentTasks []*pb.CurrentTask = make([]*pb.CurrentTask, 0, len(tasks))
|
||||
for k, onds := range tasks {
|
||||
ok := true
|
||||
ctask := &pb.CurrentTask{
|
||||
GroupId: taskgroup[k],
|
||||
TaskId: k,
|
||||
Conds: make([]*pb.ConIProgress, 0),
|
||||
}
|
||||
|
||||
for _, v := range onds {
|
||||
ctask.Conds = append(ctask.Conds, allpass[v])
|
||||
if allpass[v].State != pb.BuriedItemFinishState_buried_finish {
|
||||
ok = false
|
||||
}
|
||||
}
|
||||
currentTasks = append(currentTasks, ctask)
|
||||
if ok {
|
||||
fishtask = append(fishtask, k)
|
||||
}
|
||||
|
||||
}
|
||||
session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{
|
||||
Tasks: currentTasks,
|
||||
})
|
||||
if len(fishtask) > 0 {
|
||||
for _, v := range fishtask {
|
||||
curTaskConf, _ := this.configure.getWorldtaskById(v)
|
||||
if curTaskConf.DeliverNpc == 0 {
|
||||
this.modelWorldtask.taskFinish(session, v, userTask, curTaskConf)
|
||||
this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
"currentTasks": userTask.CurrentTasks,
|
||||
}
|
||||
this.modelWorldtask.Change(uid, update)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取我的世界任务
|
||||
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
|
||||
}
|
||||
} else if mytask.Uid == "" {
|
||||
update := map[string]interface{}{
|
||||
"uid": uid,
|
||||
}
|
||||
if err := this.modelWorldtask.Change(uid, update); 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)
|
||||
}
|
||||
|
||||
worldtaskConf, err := this.configure.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
this.Errorln(err.Error())
|
||||
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
||||
}
|
||||
|
||||
taskConf := 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 worldtaskConf.GetDataList() {
|
||||
if v.Group == groupId && v.Key <= taskId && v.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.CurrentTasks == nil {
|
||||
mytask.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
}
|
||||
|
||||
if len(nextTaskIds) >= 1 {
|
||||
if t, ok := mytask.CurrentTasks[groupId]; ok {
|
||||
t.TaskMap[nextTaskIds[0]] = &pb.Worldtask{
|
||||
TaskId: nextTaskIds[0],
|
||||
TaskType: 2, //设置主线类型
|
||||
}
|
||||
}
|
||||
update["currentTasks"] = mytask.CurrentTasks
|
||||
}
|
||||
|
||||
if err := this.modelWorldtask.Change(uid, update); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rsp := &pb.WorldtaskFinishIdsPush{}
|
||||
|
||||
return session.SendMsg(string(this.GetType()), "finishids", rsp)
|
||||
}
|
||||
|
||||
// 通过任务ID bingo
|
||||
func (this *Worldtask) JumpTaskByTaskId(session comm.IUserSession, taskId int32) error {
|
||||
uid := session.GetUserId()
|
||||
//查询当前世界任务数据
|
||||
mytask, err := this.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 如果是空 或Uid是空 初始一条基础数据
|
||||
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
|
||||
}
|
||||
} else if mytask.Uid == "" {
|
||||
update := map[string]interface{}{
|
||||
"uid": uid,
|
||||
}
|
||||
if err := this.modelWorldtask.Change(uid, update); err != nil {
|
||||
this.Error("更新世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err})
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//重置taskList
|
||||
mytask.TaskList = []int32{}
|
||||
|
||||
worldtaskConf, err := this.configure.getWorldtaskCfg()
|
||||
if err != nil {
|
||||
this.Errorln(err.Error())
|
||||
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
||||
}
|
||||
|
||||
// 获取当前bingo的任务配置
|
||||
taskConf := worldtaskConf.GetDataMap()[taskId]
|
||||
if taskConf == nil {
|
||||
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
|
||||
}
|
||||
|
||||
// 返回所有前置任务
|
||||
mytask.TaskList = this.recursionTasks(worldtaskConf, taskId)
|
||||
|
||||
update := map[string]interface{}{
|
||||
"taskList": mytask.TaskList,
|
||||
}
|
||||
|
||||
mytask.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
|
||||
tasks := &pb.Worldtasks{
|
||||
TaskMap: make(map[int32]*pb.Worldtask),
|
||||
}
|
||||
|
||||
tasks.TaskMap[taskId] = &pb.Worldtask{
|
||||
TaskId: taskId,
|
||||
TaskType: taskConf.Des,
|
||||
}
|
||||
|
||||
mytask.CurrentTasks[taskConf.Group] = tasks
|
||||
update["currentTasks"] = mytask.CurrentTasks
|
||||
|
||||
if err := this.modelWorldtask.Change(uid, update); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rsp := &pb.WorldtaskFinishIdsPush{}
|
||||
|
||||
return session.SendMsg(string(this.GetType()), "finishids", rsp)
|
||||
}
|
||||
|
||||
// 返回任务ID
|
||||
func (this *Worldtask) AcceptCaravanTask(session comm.IUserSession, groupId int32) (task *pb.Worldtask, errdata *pb.ErrorData) {
|
||||
// uid := session.GetUserId()
|
||||
// var (
|
||||
// curTaskConf *cfg.GameWorldTaskData
|
||||
// isfinsh bool
|
||||
// )
|
||||
// mytask, err := this.modelWorldtask.getWorldtask(uid)
|
||||
// if err != nil {
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_DBError,
|
||||
// Title: pb.ErrorCode_DBError.String(),
|
||||
// Message: "no found task data",
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
if gwt, err := this.configure.getWorldtaskCfg(); err == nil {
|
||||
for _, v := range gwt.GetDataList() {
|
||||
if v.Group == groupId && v.Des == 5 {
|
||||
// if _, ok := utils.Findx(mytask.TaskList, v.Key); !ok {
|
||||
task = &pb.Worldtask{
|
||||
TaskId: v.Key,
|
||||
TaskType: v.Des,
|
||||
NpcStatus: 1,
|
||||
}
|
||||
// curTaskConf = v
|
||||
break
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if task == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.String(),
|
||||
Message: fmt.Sprintf("no fond groupId:%d", groupId),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// if mytask.CurrentTasks == nil {
|
||||
// mytask.CurrentTasks = make(map[int32]*pb.Worldtasks)
|
||||
// }
|
||||
|
||||
// if _, ok1 := mytask.CurrentTasks[curTaskConf.Group]; !ok1 {
|
||||
// mytask.CurrentTasks[curTaskConf.Group] = &pb.Worldtasks{
|
||||
// TaskMap: make(map[int32]*pb.Worldtask),
|
||||
// }
|
||||
|
||||
// }
|
||||
// mytask.CurrentTasks[curTaskConf.Group].TaskMap[task.TaskId] = &pb.Worldtask{
|
||||
// TaskId: task.TaskId,
|
||||
// TaskType: curTaskConf.Des,
|
||||
// NpcStatus: 1,
|
||||
// }
|
||||
// if err = this.ModuleBuried.ActiveCondition(uid, curTaskConf.Completetask...); err != nil {
|
||||
// log.Errorf("调用接口错误:%s", err.Error())
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_ExternalModule,
|
||||
// Title: pb.ErrorCode_ExternalModule.String(),
|
||||
// Message: fmt.Sprintf("ModuleBuried.ActiveCondition err:%s", err.Error()),
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// if task.Conds, err = this.ModuleBuried.CheckCondition(uid, curTaskConf.Completetask...); err != nil {
|
||||
// log.Errorf("调用接口错误:%s", err.Error())
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_ExternalModule,
|
||||
// Title: pb.ErrorCode_ExternalModule.String(),
|
||||
// Message: fmt.Sprintf("ModuleBuried.CheckCondition err:%s", err.Error()),
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// isfinsh = true
|
||||
// for _, v := range task.Conds {
|
||||
// if v.State != pb.BuriedItemFinishState_buried_finish {
|
||||
// isfinsh = false
|
||||
// }
|
||||
// }
|
||||
// if isfinsh && curTaskConf.DeliverNpc != 0 {
|
||||
// isfinsh = false
|
||||
// }
|
||||
// //判断是否要结束任务
|
||||
// if ((len(curTaskConf.Completetask) >= 1 && curTaskConf.Completetask[0] == 0) ||
|
||||
// len(curTaskConf.Completetask) == 0) && curTaskConf.DeliverNpc == 0 {
|
||||
// isfinsh = true
|
||||
// }
|
||||
|
||||
// update := map[string]interface{}{
|
||||
// "currentTasks": mytask.CurrentTasks,
|
||||
// }
|
||||
// if err := this.modelWorldtask.Change(uid, update); err != nil {
|
||||
// }
|
||||
// if isfinsh { //结束任务
|
||||
// this.modelWorldtask.taskFinish(session, task.TaskId, mytask, curTaskConf)
|
||||
// this.modelWorldtask.taskFinishPush(session, mytask, curTaskConf)
|
||||
// }
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Worldtask) UpdateTaskStatus(uid string, taskId int32) {
|
||||
myWorldtask, err := this.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
this.Error("获取玩家世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
curTaskConf, err := this.configure.getWorldtaskById(taskId)
|
||||
if err != nil || curTaskConf == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if curTaskConf.Des != 5 {
|
||||
return
|
||||
}
|
||||
|
||||
var wt *pb.Worldtask
|
||||
if curTaskConf.Ontxe != 0 {
|
||||
//pre task
|
||||
wt = &pb.Worldtask{
|
||||
TaskId: curTaskConf.Ontxe,
|
||||
TaskType: curTaskConf.Des,
|
||||
NpcStatus: 1,
|
||||
}
|
||||
} else {
|
||||
wt = &pb.Worldtask{
|
||||
TaskId: taskId,
|
||||
TaskType: curTaskConf.Des,
|
||||
NpcStatus: 1,
|
||||
}
|
||||
}
|
||||
|
||||
if tasks, ok := myWorldtask.CurrentTasks[curTaskConf.Group]; ok {
|
||||
tasks.TaskMap[taskId] = wt
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
"currentTasks": myWorldtask.CurrentTasks,
|
||||
}
|
||||
|
||||
if err := this.modelWorldtask.Change(uid, update); err != nil {
|
||||
this.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Worldtask) recursionTasks(worldtaskConf *cfg.GameWorldTask, taskId int32) (taskIds []int32) {
|
||||
if taskConf, ok := worldtaskConf.GetDataMap()[taskId]; ok {
|
||||
preId := taskConf.Ontxe
|
||||
for preId > 0 {
|
||||
if tc, ok := worldtaskConf.GetDataMap()[preId]; ok {
|
||||
taskIds = append(taskIds, preId)
|
||||
preId = tc.Ontxe
|
||||
}
|
||||
}
|
||||
}
|
||||
return taskIds
|
||||
}
|
Loading…
Reference in New Issue
Block a user