127 lines
3.3 KiB
Go
127 lines
3.3 KiB
Go
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"
|
|
)
|
|
|
|
var _ comm.IWorldtask = (*Worldtask)(nil)
|
|
|
|
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) TaskcondNotify(session comm.IUserSession, condId int32) error {
|
|
uid := session.GetUserId()
|
|
//下一个任务ID
|
|
var nextTaskId int32
|
|
// 获取用户信息
|
|
user := this.ModuleUser.GetUser(uid)
|
|
if user == nil {
|
|
return fmt.Errorf("玩家uid:%v not found", uid)
|
|
}
|
|
|
|
// 玩家世界任务
|
|
userTask, err := this.modelWorldtask.getWorldtask(uid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if userTask.Uid != "" {
|
|
//查找任务ID根据condId 可能会找出不同的任务
|
|
// 遍历配置表
|
|
conf, err := this.configure.getWorldtaskCfg()
|
|
if err != nil || conf == nil {
|
|
return err
|
|
}
|
|
|
|
finishedTaskIds := make(map[int32]int32) //达成的任务条件
|
|
for _, c := range conf.GetDataList() {
|
|
if c.Completetask == condId && c.Completetask != 0 {
|
|
finishedTaskIds[c.Group] = c.Key
|
|
}
|
|
}
|
|
|
|
for k, id := range finishedTaskIds {
|
|
taskConf, err := this.configure.getWorldtaskById(id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if taskConf != nil {
|
|
if !this.modelWorldtask.IsPreFinished(userTask, taskConf) {
|
|
return nil
|
|
}
|
|
if taskConf.AutoAccept == 1 { //自动截取,返回下一个任务
|
|
nextTaskId = taskConf.IdAfter
|
|
|
|
// 判断玩家等级要求
|
|
if user.Lv < taskConf.Lock {
|
|
return fmt.Errorf("等级不满足 uid:%v 要求lv:%v", uid, taskConf.Lock)
|
|
}
|
|
|
|
//完成任务
|
|
if err := this.modelWorldtask.finishTask(k, id, userTask); err != nil {
|
|
this.Errorf("世界任务完成失败 err:%v", err)
|
|
return err
|
|
}
|
|
|
|
//发奖
|
|
if code := this.DispenseRes(session, taskConf.Reword, true); code != pb.ErrorCode_Success {
|
|
this.Errorf("资源发放失败 err:%v", err)
|
|
}
|
|
|
|
if nextTaskId != 0 {
|
|
if err := session.SendMsg(string(this.GetType()), "nexttask", &pb.WorldtaskNexttaskPush{
|
|
NextTaskId: nextTaskId,
|
|
}); err != nil {
|
|
log.Errorf("任务条件达成推送失败 err:%v", err)
|
|
}
|
|
} else {
|
|
this.Debugf("已经是最后一个任务了 taskId:%v", taskConf.Key)
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// bingo世界任务跳跃 支持回退
|
|
func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, rtaskId int32) error {
|
|
// d, err := this.modelWorldtask.getWorldtask(session.GetUserId())
|
|
return nil
|
|
}
|