100 lines
2.5 KiB
Go
100 lines
2.5 KiB
Go
package gourmet
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) CreateFoodCheck(session comm.IUserSession, req *pb.GourmetCreateFoodReq) (errdata *pb.ErrorData) {
|
|
if req.Cid == "" || len(req.Material) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///获取美食城基本信息
|
|
func (this *apiComp) CreateFood(session comm.IUserSession, req *pb.GourmetCreateFoodReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
res []*cfg.Gameatn
|
|
curFood string // 做出来的食物ID
|
|
bFirst bool // 是否首次获得
|
|
)
|
|
errdata = this.CreateFoodCheck(session, req)
|
|
if errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
conf, err := this.configure.GetGrormetCookBookConf(req.Cid)
|
|
if err != nil { // 配置校验
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for k, v := range req.Material {
|
|
if v == 0 { // 过滤
|
|
continue
|
|
}
|
|
res = append(res, &cfg.Gameatn{
|
|
A: "item",
|
|
T: k,
|
|
N: v,
|
|
})
|
|
}
|
|
if len(res) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// 构建消耗
|
|
if errdata = this.module.CheckRes(session, res); errdata != nil {
|
|
return
|
|
}
|
|
|
|
curFood = this.module.GetSuccessRate(req.Material, conf)
|
|
if curFood == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("curfood:%s", curFood),
|
|
}
|
|
return
|
|
}
|
|
if errdata = this.module.ConsumeRes(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
atn := &cfg.Gameatn{
|
|
A: "item",
|
|
T: curFood,
|
|
N: 1,
|
|
}
|
|
this.module.DispenseRes(session, []*cfg.Gameatn{atn}, true)
|
|
|
|
rst, _ := this.module.modelAtlas.getGourmetAtlasList(session.GetUserId()) // 校验是否首次获得
|
|
if _, ok := rst.Atlas[curFood]; !ok {
|
|
bFirst = true
|
|
rst.Atlas[curFood] = -1
|
|
if err := this.module.modelAtlas.Change(session.GetUserId(), map[string]interface{}{
|
|
"atlas": rst.Atlas,
|
|
}); err != nil {
|
|
this.module.Errorf("change modelAtlas failed: %v", err)
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "createfood", &pb.GourmetCreateFoodResp{
|
|
Cid: curFood,
|
|
FirstGet: bFirst,
|
|
})
|
|
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype150, 1))
|
|
return
|
|
}
|