go_dreamfactory/modules/gourmet/module.go

82 lines
1.8 KiB
Go

/*
模块名:Gourmet
描述:美食家模块
开发:梅雄风
*/
package gourmet
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
)
type Gourmet struct {
modules.ModuleBase
api *apiComp
configure *configureComp
modelAtlas *modelAtlas
}
func NewModule() core.IModule {
return &Gourmet{}
}
func (this *Gourmet) GetType() core.M_Modules {
return comm.ModuleGourmet
}
func (this *Gourmet) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
return
}
func (this *Gourmet) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelAtlas = this.RegisterComp(new(modelAtlas)).(*modelAtlas)
}
//红点查询
func (this *Gourmet) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) {
reddot = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range rid {
switch v {
case comm.Reddot23101: // 铁匠铺手册台
reddot[comm.Reddot23101] = &pb.ReddotItem{
Rid: int32(comm.Reddot23101),
Activated: this.modelAtlas.checkReddot2301(session.GetUserId()),
}
break
}
}
return
}
// 获取做菜成功率 返回菜单的ID
func (this *Gourmet) GetSuccessRate(m map[string]int32, conf *cfg.GameBreakingbadData) (cid string) {
if conf == nil {
return
}
var (
rate int32
)
for _, v := range conf.Recipe {
if v1, ok := m[v.A]; ok {
rate += v.N * v1
}
}
if rand.Int31n(100) < rate {
return conf.Delicacies
} else {
cid = this.configure.GetNormalGourmetFood()
}
return
}