代码优化

This commit is contained in:
meixiongfeng 2023-02-22 17:26:06 +08:00
parent 8d8d2e3c3d
commit 8a507cda02
6 changed files with 57 additions and 90 deletions

View File

@ -548,13 +548,17 @@
50,
50
],
"raise_temperature": [
110001,
50
],
"exemption_TemperatureCos": [
110002,
50
]
"raise_temperature": {
"a": "item",
"t": "1110001",
"n": 1
},
"raise_temperatureNum": 50,
"exemption_TemperatureCos": {
"a": "item",
"t": "110002",
"n": 1
},
"exemption_TemperatureCosNum": 50
}
]

View File

@ -5,7 +5,6 @@ import (
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"strconv"
"google.golang.org/protobuf/proto"
)
@ -86,20 +85,18 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq
// 是否是熔岩打造
if req.Lava > 0 {
// 预计消耗温度
exemption := this.module.configure.GetGlobalConf().ExemptionTemperatureCos
if len(exemption) != 2 {
code = pb.ErrorCode_ConfigNoFound
return
}
if reelcfg.TemperatureCos > req.Lava*exemption[1] {
exemption := this.module.configure.GetGlobalConf().ExemptionTemperatureCos // "item,1110001,1
raise_temperatureNum := this.module.configure.GetGlobalConf().ExemptionTemperatureCosNum
raise_temperatureNum = req.Lava * exemption.N
if reelcfg.TemperatureCos > raise_temperatureNum {
code = pb.ErrorCode_SmithyLackLava // 缺少熔岩
return
}
// 检查消耗
lavaCost := &cfg.Gameatn{
A: "item",
T: strconv.Itoa(int(exemption[0])),
N: req.Lava,
A: exemption.A,
T: exemption.T,
N: exemption.N * req.Lava,
}
if code = this.module.CheckRes(session, []*cfg.Gameatn{lavaCost}); code != pb.ErrorCode_Success {
return
@ -157,8 +154,10 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq
sz := make([]int32, 4) // 最高 4个品质
// 获得极品权重
sz[3] = this.module.modelStove.StoveToolsQualityProbability(stove)
if equip, code1 := this.module.ModuleEquipment.GetForgeEquip(session, req.SuiteId, req.Position, customLv, sz); code1 != pb.ErrorCode_Success {
if equip, code1 := this.module.ModuleEquipment.GetForgeEquip(session, req.SuiteId, req.Position, customLv, sz); code1 == pb.ErrorCode_Success {
rsp.Equip = append(rsp.Equip, equip)
} else {
code = code1
return
}
} else {

View File

@ -4,7 +4,6 @@ import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"strconv"
"google.golang.org/protobuf/proto"
)
@ -32,40 +31,32 @@ func (this *apiComp) Rise(session comm.IUserSession, req *pb.SmithyRiseReq) (cod
code = pb.ErrorCode_DBError
return
}
conf := this.module.configure.GetSmithyStoveConf(stove.Lv)
if conf != nil {
cost = append(cost, &cfg.Gameatn{
A: "item",
T: req.ItemId,
N: req.Count,
})
raise := this.module.configure.GetGlobalConf().RaiseTemperature
if len(raise) != 2 {
code = pb.ErrorCode_ConfigNoFound // 配置有误 直接返回
return //
}
if req.ItemId != strconv.Itoa(int(raise[0])) {
code = pb.ErrorCode_ReqParameterError
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[0] >= conf.MaxTemperature-raise[0] {
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[0]
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})
}
session.SendMsg(string(this.module.GetType()), "rise", &pb.SmithyRiseResp{Data: stove})
code = pb.ErrorCode_ConfigNoFound
return
}

View File

@ -65,6 +65,7 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual
if scoreConf == nil {
return false
}
update := make(map[string]interface{}, 0)
if v, ok := list.Atlas[id]; ok { // 找到相同的
if v.Activate { // 已经激活的
if len(v.Data) > 1 {
@ -74,9 +75,6 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual
v.Data[1].Quality = quality
v.Data[1].Score = scoreConf.Score
v.Data[1].Time = configure.Now().Unix()
update := make(map[string]interface{}, 0)
update["tujian"] = list.Atlas
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
}
}
} else { // 没有激活的
@ -87,9 +85,6 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual
v.Data[0].Quality = quality
v.Data[0].Score = scoreConf.Score
v.Data[0].Time = configure.Now().Unix()
update := make(map[string]interface{}, 0)
update["tujian"] = list.Atlas
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
}
} else {
v.Data = make([]*pb.ForgeData, 0)
@ -101,12 +96,8 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual
Time: configure.Now().Unix(),
}
v.Data = append(v.Data, newData)
update := make(map[string]interface{}, 0)
update["tujian"] = list.Atlas
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
}
}
return true
} else {
sz := &pb.ForgeList{}
newData := &pb.ForgeData{
@ -119,10 +110,9 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual
sz.Data = append(sz.Data, newData)
sz.Activate = false // 第一次获得 默认是非激活状态
list.Atlas[id] = sz
update := make(map[string]interface{}, 0)
update["tujian"] = list.Atlas
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
}
update["atlas"] = list.Atlas
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
}
return true
}
@ -135,11 +125,16 @@ func (this *modelAtlas) CheckActivateAtlasCollect(uid string, id string) {
if _, ok := list.Collect[id]; !ok {
list.Collect[id] = &pb.CollectData{
Id: id,
Score: atlasConf.AtlasScore,
Time: configure.Now().Unix(),
}
list.Score += atlasConf.AtlasScore
update := make(map[string]interface{}, 0)
update["collect"] = list.Collect
update["score"] = list.Score
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
}
}
}
}

View File

@ -414,9 +414,9 @@ type CollectData struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id"`
Score int32 `protobuf:"varint,2,opt,name=score,proto3" json:"score"`
Time int64 `protobuf:"varint,3,opt,name=time,proto3" json:"time"` // 获得时间
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id"` // 收集图鉴id
Score int32 `protobuf:"varint,2,opt,name=score,proto3" json:"score"`
Time int64 `protobuf:"varint,3,opt,name=time,proto3" json:"time"` // 获得时间
}
func (x *CollectData) Reset() {
@ -451,11 +451,11 @@ func (*CollectData) Descriptor() ([]byte, []int) {
return file_smithy_smithy_db_proto_rawDescGZIP(), []int{5}
}
func (x *CollectData) GetId() int32 {
func (x *CollectData) GetId() string {
if x != nil {
return x.Id
}
return 0
return ""
}
func (x *CollectData) GetScore() int32 {
@ -1006,7 +1006,7 @@ var file_smithy_smithy_db_proto_rawDesc = []byte{
0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x47, 0x0a, 0x0b, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63,
0x74, 0x44, 0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02,
0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74,
0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x22,
0x47, 0x0a, 0x09, 0x46, 0x6f, 0x72, 0x67, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x04,

View File

@ -176,8 +176,10 @@ type GameGlobalData struct {
Moonshopmoney []int32
Generaltp *Gameatn
SmithyPurchaseType []int32
RaiseTemperature []int32
ExemptionTemperatureCos []int32
RaiseTemperature *Gameatn
RaiseTemperatureNum int32
ExemptionTemperatureCos *Gameatn
ExemptionTemperatureCosNum int32
}
const TypeId_GameGlobalData = 477542761
@ -755,34 +757,10 @@ func (_v *GameGlobalData)Deserialize(_buf map[string]interface{}) (err error) {
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["raise_temperature"].([]interface{}); !_ok_ { err = errors.New("raise_temperature error"); return }
_v.RaiseTemperature = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.RaiseTemperature = append(_v.RaiseTemperature, _list_v_)
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["exemption_TemperatureCos"].([]interface{}); !_ok_ { err = errors.New("exemption_TemperatureCos error"); return }
_v.ExemptionTemperatureCos = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.ExemptionTemperatureCos = append(_v.ExemptionTemperatureCos, _list_v_)
}
}
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _buf["raise_temperature"].(map[string]interface{}); !_ok_ { err = errors.New("raise_temperature error"); return }; if _v.RaiseTemperature, err = DeserializeGameatn(_x_); err != nil { return } }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["raise_temperatureNum"].(float64); !_ok_ { err = errors.New("raise_temperatureNum error"); return }; _v.RaiseTemperatureNum = int32(_tempNum_) }
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _buf["exemption_TemperatureCos"].(map[string]interface{}); !_ok_ { err = errors.New("exemption_TemperatureCos error"); return }; if _v.ExemptionTemperatureCos, err = DeserializeGameatn(_x_); err != nil { return } }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["exemption_TemperatureCosNum"].(float64); !_ok_ { err = errors.New("exemption_TemperatureCosNum error"); return }; _v.ExemptionTemperatureCosNum = int32(_tempNum_) }
return
}