57 lines
1.5 KiB
Go
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) StoveSkillLvCkeck(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.StoveSkillLvCkeck(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.configure.GetSmithyStoveConfigData(_smithy.StoveLv)
|
|
if curLvData == nil {
|
|
code = pb.ErrorCode_GourmetSkillMaxLv
|
|
return
|
|
}
|
|
nextLvData := this.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
|
|
}
|