119 lines
2.5 KiB
Go
119 lines
2.5 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) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
|
|
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 map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
|
|
var (
|
|
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot23101}
|
|
ok bool
|
|
)
|
|
items = make(map[comm.ReddotType]*pb.ReddotItem)
|
|
for _, v := range selfrid {
|
|
if _, ok = rid[v]; ok {
|
|
break
|
|
}
|
|
}
|
|
|
|
if !ok {
|
|
return
|
|
}
|
|
for _, v := range selfrid {
|
|
if _, ok = rid[v]; ok {
|
|
switch v {
|
|
case comm.Reddot23101: // 铁匠铺手册台
|
|
items[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.S]; ok {
|
|
rate += v.D * v1
|
|
}
|
|
}
|
|
|
|
if rand.Int31n(100) < rate {
|
|
return conf.Delicacies
|
|
} else {
|
|
cid = this.configure.GetNormalGourmetFood()
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Gourmet) GMCreateAltas(uid string) {
|
|
_gourmet, err := this.modelAtlas.getGourmetAtlasList(uid)
|
|
if err != nil {
|
|
return
|
|
}
|
|
sz, err := this.configure.GMGetAllCookBookConf()
|
|
if err != nil { // 配置校验
|
|
return
|
|
}
|
|
_gourmet.Atlas = make(map[string]int32)
|
|
for _, v := range sz {
|
|
_gourmet.Atlas[v] = 1
|
|
}
|
|
if err := this.modelAtlas.Change(uid, map[string]interface{}{
|
|
"atlas": _gourmet.Atlas,
|
|
}); err != nil {
|
|
this.Errorf("change modelAtlas failed: %v", err)
|
|
}
|
|
}
|