go_dreamfactory/modules/moonfantasy/module.go
2022-10-12 12:34:23 +08:00

84 lines
2.1 KiB
Go

package moonfantasy
import (
"crypto/rand"
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/big"
)
/*
模块名:月子秘境
描述:随机世界副本
开发:李伟
*/
func NewModule() core.IModule {
m := new(Moonfantasy)
return m
}
type Moonfantasy struct {
modules.ModuleBase
service base.IRPCXService
chat comm.IChat
battle comm.IBattle
api_comp *apiComp
configure *configureComp
modelDream *modelDreamComp
modelUserMF *modelUserMF
}
//模块名
func (this *Moonfantasy) GetType() core.M_Modules {
return comm.ModuleMoonfantasy
}
//模块初始化接口 注册用户创建角色事件
func (this *Moonfantasy) 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 *Moonfantasy) Start() (err error) {
err = this.ModuleBase.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleChat); err != nil {
return
}
this.chat = module.(comm.IChat)
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
return
}
this.battle = module.(comm.IBattle)
return
}
//装备组件
func (this *Moonfantasy) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelDream = this.RegisterComp(new(modelDreamComp)).(*modelDreamComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelUserMF = this.RegisterComp(new(modelUserMF)).(*modelUserMF)
}
//触发月之秘境
func (this *Moonfantasy) Trigger(session comm.IUserSession, source *pb.BattleReport) {
var (
triggerData *cfg.GameDreamlandTriggerData
err error
)
if triggerData, err = this.configure.GettriggerData(int32(source.Info.Ptype)); err == nil && triggerData.Open {
n, _ := rand.Int(rand.Reader, big.NewInt(1000))
if int32(n.Int64()) < triggerData.DreamlandPro {
this.modelDream.trigger(session, source)
}
}
}