go_dreamfactory/modules/items/api_potionsynthesis.go
2023-04-01 17:24:33 +08:00

72 lines
1.7 KiB
Go

package items
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) PotionSynthesisCheck(session comm.IUserSession, req *pb.ItemsPotionSynthesisReq) (code pb.ErrorCode) {
return
}
//魔药合成
func (this *apiComp) PotionSynthesis(session comm.IUserSession, req *pb.ItemsPotionSynthesisReq) (code pb.ErrorCode, data proto.Message) {
var (
configure *cfg.GamePotionsData
need []*cfg.Gameatn
give []*cfg.Gameatn
err error
)
if configure, err = this.module.configure.GetMaterialConfigure(req.Id); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
need = make([]*cfg.Gameatn, len(configure.Material))
for i, v := range configure.Material {
need[i] = &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N * req.Num,
}
}
if code = this.module.ConsumeRes(session, configure.Material, true); code != pb.ErrorCode_Success {
return
}
give = make([]*cfg.Gameatn, 0)
if req.Succnum <= configure.NormalScore {
for _, v := range configure.LowYield {
give = append(give, &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N * req.Num,
})
}
} else if req.Succnum < configure.HighScore {
for _, v := range configure.StandardYield {
give = append(give, &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N * req.Num,
})
}
} else {
for _, v := range configure.HighYield {
give = append(give, &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N * req.Num,
})
}
}
if code = this.module.DispenseRes(session, give, true); code != pb.ErrorCode_Success {
return
}
session.SendMsg(string(this.module.GetType()), "potionsynthesis", &pb.ItemsPotionSynthesisResp{Succ: true, Id: req.Id, Num: req.Num})
return
}