This commit is contained in:
meixiongfeng 2023-10-16 15:35:00 +08:00
commit 1c7edc3687
6 changed files with 215 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package entertainment
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
type apiComp struct {
modules.MCompGate
service core.IService
module *Entertainment
chat comm.IChat
}
//组件初始化接口
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Entertainment)
this.service = service
return
}
func (this *apiComp) Start() (err error) {
err = this.MCompGate.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleChat); err != nil {
return
}
this.chat = module.(comm.IChat)
return
}

View File

@ -0,0 +1,27 @@
package entertainment
import (
"go_dreamfactory/modules"
"go_dreamfactory/lego/core"
)
const (
dragon_trainlv = "game_trainlv.json"
dragon_play = "game_dragonplay.json"
game_buzkashimount = "game_buzkashimount.json"
game_dragonlvitem = "game_dragonlvitem.json"
)
// /配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Entertainment
}
// 组件初始化接口
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.(*Entertainment)
return
}

View File

@ -0,0 +1,61 @@
package entertainment
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"go_dreamfactory/pb"
"sync"
"google.golang.org/protobuf/proto"
)
/*
游戏管理组件
*/
type gameMgrComp struct {
cbase.ModuleCompBase
module *Entertainment
lock sync.RWMutex
rooms map[string]*Room
}
func (this *gameMgrComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.ModuleCompBase.Init(service, module, comp, options)
this.module = module.(*Entertainment)
this.rooms = make(map[string]*Room)
return
}
func (this *gameMgrComp) CreateRoom(room *Room) {
this.lock.Lock()
this.rooms[room.Id] = room
this.lock.Unlock()
}
func (this *gameMgrComp) CloseRoom(id string) {
this.lock.Lock()
delete(this.rooms, id)
this.lock.Unlock()
}
func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, req proto.Message) (errdata *pb.ErrorData) {
var (
room *Room
ok bool
)
this.lock.RLock()
room, ok = this.rooms[rid]
this.lock.RUnlock()
if ok {
errdata = room.ReceiveMessage(session, req)
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.String(),
Message: fmt.Sprintf("on found room:%s", rid),
}
}
return
}

View File

@ -0,0 +1,26 @@
package entertainment
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelComp struct {
modules.MCompModel
module *Entertainment
}
func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableDragon
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Entertainment)
// 通过uid创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}

View File

@ -0,0 +1,51 @@
package entertainment
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
func NewModule() core.IModule {
m := new(Entertainment)
return m
}
type Entertainment struct {
modules.ModuleBase
service core.IService
api *apiComp
configure *configureComp
model *modelComp
gameMgr *gameMgrComp
}
// 模块名
func (this *Entertainment) GetType() core.M_Modules {
return comm.ModuleDragon
}
// 模块初始化接口 注册用户创建角色事件
func (this *Entertainment) 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 *Entertainment) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.model = this.RegisterComp(new(modelComp)).(*modelComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.gameMgr = this.RegisterComp(new(gameMgrComp)).(*gameMgrComp)
}
func (this *Entertainment) Start() (err error) {
if err = this.ModuleBase.Start(); err != nil {
return
}
return
}

View File

@ -0,0 +1,18 @@
package entertainment
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
//游戏房间
type Room struct {
Id string
}
func (this *Room) ReceiveMessage(session comm.IUserSession, req proto.Message) (errdata *pb.ErrorData) {
return
}