英雄升级

This commit is contained in:
meixiongfeng 2022-06-27 19:12:46 +08:00
parent 7814e10fe7
commit 726dcccf88
9 changed files with 164 additions and 25 deletions

View File

@ -88,6 +88,10 @@ const (
LogHandleType_Delete LogHandleType = "delete"
)
const (
HeroStarLvRatio int32 = 10 // 卡牌等级上限系数(星级*10
)
//Api Check 错误返回结构
type ErrorCode struct {
Code pb.ErrorCode

View File

@ -10,8 +10,72 @@ import (
func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.Hero_StrengthenUplv_Req) (result map[string]interface{}, code comm.ErrorCode) {
if req.HeroObjID == "" {
code.Code = pb.ErrorCode_ReqParameterError
return
}
_hero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.HeroObjID) // 校验升级的对象是否存在
if err != 0 {
code.Code = pb.ErrorCode_HeroNoExist
return
}
_expHero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在
if err != 0 {
code.Code = pb.ErrorCode_HeroNoExist
return
}
if req.Amount <= 0 { // 消耗数量校验
code.Code = pb.ErrorCode_HeroNoExist
return
}
curLv := _hero.Lv
curExp := _hero.Exp // 当前英雄的经验
var costGold int32 // 当前需要消耗金币的数量
var addExp int32 // 需要增加的经验
// 查询 本次消耗会获得多少经验
expConf, err1 := this.module.configure_comp.GetHeroExpConByHeroid(_expHero.HeroID)
if err1 != nil {
addExp = expConf.Heroexp * req.Amount
}
if _expHero.Count <= req.Amount { // 消耗经验卡片数量不足
code.Code = pb.ErrorCode_HeroNoEnough
return
}
// 校验当前能不能升级
if _hero.Lv >= _hero.Star*comm.HeroStarLvRatio { // 达到最大等级
code.Code = pb.ErrorCode_HeroMaxLv
return
}
if _data, err1 := this.module.configure_comp.GetHeroLevelUpByLv(curLv); err1 == nil {
costGold += _data.Gold[0].N
curExp += addExp // 先把经验加上
// 当前升级需要消耗的经验
for { // 死循环判断一键升级
if _data.Heroexp[0].N <= curExp { // 升级操作
curExp = _data.Heroexp[0].N
if curExp >= 0 { // 大于下一级经验
curLv += 1 // 经验够了 那么等级+1
if _data, err1 := this.module.configure_comp.GetHeroLevelUpByLv(curLv); err1 == nil {
if _data.Heroexp[0].N > curExp { // 经验不足则 直接返回
break
}
costGold += _data.Gold[0].N
} else {
break
}
}
} else {
break
}
}
}
// 校验金币消耗
result = map[string]interface{}{
"costGold": costGold,
"curExp": curExp,
"curLv": curLv,
}
//this.module.model_hero.moduleHero.GetHeroInfoByObjID()
return
}

View File

@ -31,13 +31,6 @@ func (this *Configure_Comp) Init(service core.IService, module core.IModule, com
this.LoadConfigure(game_heroStarup, cfg.NewGame_heroStarup)
this.LoadConfigure(game_heroLevelup, cfg.NewGame_heroLevelup)
this.LoadConfigure(game_heroExp, cfg.NewGame_heroExp)
// this.GetHeroConfigure()
// this.GetHeroStargrowCon()
// this.GetHeroLevelgrowCon()
// this.GetHeroStarupCon()
// this.GetHeroLevelUpCon()
// this.GetHeroExpCon()
return
}
@ -125,6 +118,23 @@ func (this *Configure_Comp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup
return
}
// 获取英雄升级相关配置数据
func (this *Configure_Comp) GetHeroLevelUpByLv(lv int32) (data *cfg.Game_heroLevelupData, err error) {
if v, err1 := this.GetConfigure(game_heroLevelup); err1 == nil {
if configure, ok := v.(*cfg.Game_heroLevelup); !ok {
err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v)
return
} else {
data = configure.Get(lv)
}
} else {
err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v)
}
return
}
func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err error) {
var (
v interface{}
@ -140,3 +150,21 @@ func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err er
}
return
}
func (this *Configure_Comp) GetHeroExpConByHeroid(hid int32) (data *cfg.Game_heroExpData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_heroExp); err == nil {
if configure, ok := v.(*cfg.Game_heroExp); !ok {
err = fmt.Errorf("%T no is *cfg.Game_heroExp", v)
return
} else {
data = configure.Get(hid)
}
} else {
err = fmt.Errorf("%T no is *cfg.Game_heroExp", v)
}
return
}

View File

@ -50,6 +50,11 @@ func (this *Hero) GetHero(heroId int32) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
}
func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
}
//佩戴装备
func (this *Hero) InstallEquip(heroId, equipId string) pb.ErrorCode {
return pb.ErrorCode_Success

View File

@ -62,7 +62,9 @@ const (
ErrorCode_PackGridNumUpper ErrorCode = 1202 //背包格子数量已达上限
ErrorCode_PackGirdAmountUpper ErrorCode = 1203 //背包格子容量已达上限
// hero
ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在
ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在
ErrorCode_HeroNoEnough ErrorCode = 1301 //英雄数量不足
ErrorCode_HeroMaxLv ErrorCode = 1302 //英雄达到最大等级
//equipment
ErrorCode_EquipmentOnFoundEquipment ErrorCode = 1400 // 未找到武器
ErrorCode_EquipmentLvlimitReached ErrorCode = 1401 // 武器等级已达上限
@ -107,6 +109,8 @@ var (
1202: "PackGridNumUpper",
1203: "PackGirdAmountUpper",
1300: "HeroNoExist",
1301: "HeroNoEnough",
1302: "HeroMaxLv",
1400: "EquipmentOnFoundEquipment",
1401: "EquipmentLvlimitReached",
}
@ -147,6 +151,8 @@ var (
"PackGridNumUpper": 1202,
"PackGirdAmountUpper": 1203,
"HeroNoExist": 1300,
"HeroNoEnough": 1301,
"HeroMaxLv": 1302,
"EquipmentOnFoundEquipment": 1400,
"EquipmentLvlimitReached": 1401,
}
@ -183,7 +189,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0xab, 0x06, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x6f, 0x2a, 0xce, 0x06, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
@ -230,11 +236,14 @@ var file_errorcode_proto_rawDesc = []byte{
0x65, 0x72, 0x10, 0xb2, 0x09, 0x12, 0x18, 0x0a, 0x13, 0x50, 0x61, 0x63, 0x6b, 0x47, 0x69, 0x72,
0x64, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x70, 0x65, 0x72, 0x10, 0xb3, 0x09, 0x12,
0x10, 0x0a, 0x0b, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x78, 0x69, 0x73, 0x74, 0x10, 0x94,
0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4f, 0x6e,
0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x10, 0xf8,
0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4c, 0x76,
0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xf9, 0x0a, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x0a, 0x12, 0x11, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x6e, 0x6f, 0x75, 0x67,
0x68, 0x10, 0x95, 0x0a, 0x12, 0x0e, 0x0a, 0x09, 0x48, 0x65, 0x72, 0x6f, 0x4d, 0x61, 0x78, 0x4c,
0x76, 0x10, 0x96, 0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e,
0x74, 0x4f, 0x6e, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e,
0x74, 0x10, 0xf8, 0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e,
0x74, 0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10,
0xf9, 0x0a, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
}
var (

View File

@ -81,9 +81,9 @@ type Hero_StrengthenUplv_Req struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
HeroObjID string `protobuf:"bytes,1,opt,name=heroObjID,proto3" json:"heroObjID"` // 英雄对象ID
ExpCardID []string `protobuf:"bytes,2,rep,name=expCardID,proto3" json:"expCardID"` // 经验卡对象ID
Amount int32 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount"` // 消耗经验卡数量
HeroObjID string `protobuf:"bytes,1,opt,name=heroObjID,proto3" json:"heroObjID"` // 英雄对象ID
ExpCardID string `protobuf:"bytes,2,opt,name=expCardID,proto3" json:"expCardID"` // 经验卡对象ID
Amount int32 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount"` // 消耗经验卡数量
}
func (x *Hero_StrengthenUplv_Req) Reset() {
@ -125,11 +125,11 @@ func (x *Hero_StrengthenUplv_Req) GetHeroObjID() string {
return ""
}
func (x *Hero_StrengthenUplv_Req) GetExpCardID() []string {
func (x *Hero_StrengthenUplv_Req) GetExpCardID() string {
if x != nil {
return x.ExpCardID
}
return nil
return ""
}
func (x *Hero_StrengthenUplv_Req) GetAmount() int32 {
@ -908,7 +908,7 @@ var file_hero_hero_msg_proto_rawDesc = []byte{
0x72, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x65, 0x6e, 0x55, 0x70, 0x6c, 0x76, 0x5f, 0x52, 0x65, 0x71,
0x12, 0x1c, 0x0a, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x4f, 0x62, 0x6a, 0x49, 0x44, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x4f, 0x62, 0x6a, 0x49, 0x44, 0x12, 0x1c,
0x0a, 0x09, 0x65, 0x78, 0x70, 0x43, 0x61, 0x72, 0x64, 0x49, 0x44, 0x18, 0x02, 0x20, 0x03, 0x28,
0x0a, 0x09, 0x65, 0x78, 0x70, 0x43, 0x61, 0x72, 0x64, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x09, 0x65, 0x78, 0x70, 0x43, 0x61, 0x72, 0x64, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06,
0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x6d,
0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3c, 0x0a, 0x18, 0x48, 0x65, 0x72, 0x6f, 0x5f, 0x53, 0x74, 0x72,

View File

@ -46,7 +46,8 @@ enum ErrorCode {
// hero
HeroNoExist = 1300; //
HeroNoEnough = 1301; //
HeroMaxLv = 1302; //
//equipment
EquipmentOnFoundEquipment = 1400; //
EquipmentLvlimitReached = 1401; //

View File

@ -14,7 +14,7 @@ message ItemData{
//
message Hero_StrengthenUplv_Req {
string heroObjID = 1; // ID
repeated string expCardID = 2; // ID
string expCardID = 2; // ID
int32 amount = 3; //
}

View File

@ -12,7 +12,8 @@ import "errors"
type Game_heroLevelupData struct {
Level int32
Heroexp int32
Heroexp []*Game_atn
Gold []*Game_atn
Hp float32
Atk float32
Def float32
@ -25,7 +26,34 @@ func (Game_heroLevelupData) GetTypeId() int {
func NewGame_heroLevelupData(_buf map[string]interface{}) (_v *Game_heroLevelupData, err error) {
_v = &Game_heroLevelupData{}
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["level"].(float64); !_ok_ { err = errors.New("level error"); return }; _v.Level = int32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["heroexp"].(float64); !_ok_ { err = errors.New("heroexp error"); return }; _v.Heroexp = int32(_tempNum_) }
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["heroexp"].([]interface{}); !_ok_ { err = errors.New("heroexp error"); return }
_v.Heroexp = make([]*Game_atn, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ *Game_atn
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = NewGame_atn(_x_); err != nil { return } }
_v.Heroexp = append(_v.Heroexp, _list_v_)
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["gold"].([]interface{}); !_ok_ { err = errors.New("gold error"); return }
_v.Gold = make([]*Game_atn, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ *Game_atn
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = NewGame_atn(_x_); err != nil { return } }
_v.Gold = append(_v.Gold, _list_v_)
}
}
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["hp"].(float64); !_ok_ { err = errors.New("hp error"); return }; _v.Hp = float32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["atk"].(float64); !_ok_ { err = errors.New("atk error"); return }; _v.Atk = float32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["def"].(float64); !_ok_ { err = errors.New("def error"); return }; _v.Def = float32(_tempNum_) }