92 lines
2.3 KiB
Go
92 lines
2.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)
|
|
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(uid string, condId int32) error {
|
|
//下一个任务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 != "" {
|
|
for _, id := range userTask.LastTaskIds {
|
|
taskConf, err := this.configure.getWorldtaskById(id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if taskConf != nil {
|
|
if taskConf.AutoAccept == 1 { //自动截取,返回下一个任务
|
|
nextTaskId = taskConf.IdAfter
|
|
if nextTaskId == 0 {
|
|
this.Debug("已经是最后一个任务了")
|
|
return nil
|
|
}
|
|
nexttaskConf, err := this.configure.getWorldtaskById(nextTaskId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// 判断玩家等级要求
|
|
if user.Lv < nexttaskConf.Lock {
|
|
return fmt.Errorf("等级不满足 uid:%v 要求lv:%v", uid, nexttaskConf.Lock)
|
|
}
|
|
//推送
|
|
if err := this.SendMsgToUser(string(this.GetType()), "nexttask", &pb.WorldtaskNexttaskPush{
|
|
NextTaskId: nextTaskId,
|
|
}, uid); err != nil {
|
|
log.Errorf("任务条件达成推送失败 err:%v", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|