This commit is contained in:
meixiongfeng 2023-07-11 20:50:32 +08:00
commit 7424b5c57b
7 changed files with 156 additions and 2 deletions

View File

@ -90,7 +90,7 @@ const (
ModuleGuidance core.M_Modules = "guidance" //引导
ModuleWtask core.M_Modules = "wtask" //世界任务
ModulePasson core.M_Modules = "passon" //传功房
ModuleWarorder core.M_Modules = "warorder" //战令
)
// 数据表名定义处

20
modules/warorder/api.go Normal file
View File

@ -0,0 +1,20 @@
package warorder
import (
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
type apiComp struct {
modules.MCompGate
service base.IRPCXService
module *Warorder
}
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.(*Warorder)
return
}

View File

@ -0,0 +1,22 @@
package warorder
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"sync"
)
const ()
type configureComp struct {
modules.MCompConfigure
module *Warorder
lock sync.RWMutex
}
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.(*Warorder)
return
}

View File

@ -0,0 +1,66 @@
package warorder
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelWarorder struct {
modules.MCompModel
module *Warorder
}
func (this *modelWarorder) 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.TableWtask
this.module = module.(*Warorder)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 获取用户全部的埋点数据
func (this *modelWarorder) getUserWTasks(uid string) (results *pb.DBWTask, err error) {
results = &pb.DBWTask{}
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
if err == mgo.MongodbNil {
err = nil
results = &pb.DBWTask{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Currchapter: 0,
Activations: make([]int32, 0),
Accepts: make([]int32, 0),
Completes: make([]int32, 0),
Groups: make(map[int32]int32),
}
err = this.Add(uid, results)
}
return
}
func (this *modelWarorder) updateUserWTasks(uid string, data *pb.DBWTask) (err error) {
if err = this.Change(uid, map[string]interface{}{
"currchapter": data.Currchapter,
"activations": data.Activations,
"accepts": data.Accepts,
"completes": data.Completes,
"groups": data.Groups,
}); err != nil {
this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()})
return
}
return
}

View File

@ -0,0 +1,44 @@
package warorder
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
const modulename = "战令"
type Warorder struct {
modules.ModuleBase
service core.IService
api *apiComp
configure *configureComp
modelWarorder *modelWarorder
}
func NewModule() core.IModule {
return &Warorder{}
}
func (this *Warorder) GetType() core.M_Modules {
return comm.ModuleWarorder
}
func (this *Warorder) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
return
}
func (this *Warorder) Start() (err error) {
err = this.ModuleBase.Start()
return
}
func (this *Warorder) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelWarorder = this.RegisterComp(new(modelWarorder)).(*modelWarorder)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}

View File

@ -238,7 +238,7 @@ func (this *WTask) AcceptCaravanTask(session comm.IUserSession, groupId int32) (
//有新任务接取
wtask.Activations = append(wtask.Activations, target.Key)
//有新任务接取
session.SendMsg(string(this.GetType()), "activations", &pb.WTaskActivationsChangePush{Activations: wtask.Activations})
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,

View File

@ -49,6 +49,7 @@ import (
"go_dreamfactory/modules/tools"
"go_dreamfactory/modules/user"
"go_dreamfactory/modules/viking"
"go_dreamfactory/modules/warorder"
"go_dreamfactory/modules/worldtask"
"go_dreamfactory/modules/wtask"
"go_dreamfactory/services"
@ -130,6 +131,7 @@ func main() {
guidance.NewModule(),
wtask.NewModule(),
passon.NewModule(),
warorder.NewModule(),
)
}