go_dreamfactory/modules/smithy/api_stoveskilllv.go
2022-08-30 17:14:35 +08:00

57 lines
1.5 KiB
Go

package smithy
import (
"crypto/rand"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"math/big"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) StoveSkillLvCheck(session comm.IUserSession, req *pb.SmithyStoveSkillLvReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) StoveSkillLv(session comm.IUserSession, req *pb.SmithyStoveSkillLvReq) (code pb.ErrorCode, dat proto.Message) {
code = this.StoveSkillLvCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
_smithy, err := this.module.modelSmithy.getSmithyList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
curLvData := this.module.configure.GetSmithyStoveConfigData(_smithy.StoveLv)
if curLvData == nil {
code = pb.ErrorCode_GourmetSkillMaxLv
return
}
nextLvData := this.module.configure.GetSmithyStoveConfigData(_smithy.StoveLv + 1)
if nextLvData == nil {
code = pb.ErrorCode_GourmetSkillMaxLv
return
}
// 升级
code = this.module.ConsumeRes(session, curLvData.Starupneed, true) // 消耗检测
if code != pb.ErrorCode_Success {
return
}
// 概率升级
n, _ := rand.Int(rand.Reader, big.NewInt(100))
if n.Int64() < int64(curLvData.Probability) { // 可以升级
// 技能升级成功
_smithy.StoveLv += 1
this.module.modelSmithy.CalculationStoveSkillLv(session.GetUserId(), _smithy, _smithy.StoveLv)
}
session.SendMsg(string(this.module.GetType()), SmithyDeskSkillLvResp, &pb.SmithyDeskSkillLvResp{Data: _smithy})
return
}