63 lines
1.8 KiB
Go
63 lines
1.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) RiseCheck(session comm.IUserSession, req *pb.SmithyRiseReq) (code pb.ErrorCode) {
|
|
if req.ItemId != "" && req.Count > 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
// 炉子升温
|
|
func (this *apiComp) Rise(session comm.IUserSession, req *pb.SmithyRiseReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
cost []*cfg.Gameatn // 消耗材料
|
|
)
|
|
|
|
code = this.RiseCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
stove, err := this.module.modelStove.getSmithyStoveList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
if conf := this.module.configure.GetSmithyStoveConf(stove.Lv); conf != nil {
|
|
if stove.Temperature >= conf.MaxTemperature { // 已经达到最大的温度值了
|
|
code = pb.ErrorCode_SmithyMaxTemperature
|
|
return
|
|
}
|
|
raise := this.module.configure.GetGlobalConf().RaiseTemperature
|
|
raise_temperatureNum := this.module.configure.GetGlobalConf().RaiseTemperatureNum
|
|
cost = append(cost, &cfg.Gameatn{
|
|
A: raise.A,
|
|
T: raise.T,
|
|
N: raise.N * req.Count,
|
|
})
|
|
|
|
if stove.Temperature+req.Count*raise_temperatureNum <= (conf.MaxTemperature - raise_temperatureNum) {
|
|
code = pb.ErrorCode_SmithyMaxTemperature
|
|
return
|
|
}
|
|
if code = this.module.ConsumeRes(session, cost, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
stove.Temperature += req.Count * raise_temperatureNum
|
|
update := make(map[string]interface{}, 0)
|
|
update["temperature"] = stove.Temperature
|
|
this.module.modelStove.updateSmithyStove(session.GetUserId(), update)
|
|
session.SendMsg(string(this.module.GetType()), "rise", &pb.SmithyRiseResp{Data: stove})
|
|
}
|
|
|
|
return
|
|
}
|