go_dreamfactory/modules/smithy/api_forgeequip.go
2023-02-16 15:37:59 +08:00

95 lines
2.8 KiB
Go

package smithy
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ForgeEquipCheck(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (code pb.ErrorCode) {
if req.ReelId == 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
// 打造装备
func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (code pb.ErrorCode, data proto.Message) {
var (
stove *pb.DBStove
err error
update map[string]interface{}
costRes []*cfg.Gameatn
)
update = make(map[string]interface{})
code = this.ForgeEquipCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
stove, err = this.module.modelStove.getSmithyStoveList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
reelcfg := this.module.configure.GetSmithyReelConfigData(req.ReelId)
if reelcfg == nil {
code = pb.ErrorCode_ReqParameterError // 没有找到该类型的图纸信息
return
}
// 校验图纸是否激活
if _, ok := stove.Data[req.ReelId]; !ok { // 是不是首次打造
if !this.module.configure.CheckSmithyFirstReelConfigData(reelcfg.Type, req.ReelId) { // 没有激活图纸
code = pb.ErrorCode_SmithyNoReel
return
}
stove.Data[req.ReelId] = &pb.Mastery{
Lv: 1,
Value: 0,
}
//update["data"] = stove.Data
}
stove.Data[req.ReelId].Value += 1
// 是否是精益打造
if req.Quality > 0 {
costRes = append(costRes, reelcfg.Quality)
}
costRes = append(costRes, reelcfg.Consume...)
if code = this.module.CheckRes(session, costRes); code != pb.ErrorCode_Success {
return
}
// 检查炉温 是否够
if stove.Temperature < reelcfg.Temperature {
code = pb.ErrorCode_SmithyNoTemperature // 炉温不够 直接返回
return
}
// 检查是否提升了熟练度等级
nextProficiency := this.module.configure.GetSmithyProficileData(req.ReelId, stove.Data[req.ReelId].Lv+1)
if nextProficiency != nil && nextProficiency.Proficiency >= stove.Data[req.ReelId].Value { // 提升熟练度
stove.Data[req.ReelId].Lv += 1
stove.Data[req.ReelId].Value = 0
// 校验是否解锁了新的图纸
if nextProficiency.Type == comm.SmithyReelType3 {
stove.Data[nextProficiency.Value1] = &pb.Mastery{
Lv: 1,
Value: 0,
}
}
}
if code = this.module.ConsumeRes(session, costRes, true); code != pb.ErrorCode_Success {
return
}
stove.Temperature -= reelcfg.Temperature // 消耗温度
update["data"] = stove.Data
update["temperature"] = stove.Temperature
this.module.modelStove.updateSmithyStove(session.GetUserId(), update)
session.SendMsg(string(this.module.GetType()), "forgeequip", &pb.SmithyForgeEquipResp{Data: stove})
return
}