From c8e2cc53d60df67c042e85fe099858f2717916aa Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Wed, 8 Jun 2022 11:25:25 +0800 Subject: [PATCH] fix: 英雄升级,经验书批量操作 --- cmd/gameserver/action/HeroAction.go | 58 +++++++++++++++++++++++++++++++++------------------------- pb/game.pb.go | 26 ++++++++------------------ protos | 2 +- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/cmd/gameserver/action/HeroAction.go b/cmd/gameserver/action/HeroAction.go index 590c17d..70b1d95 100644 --- a/cmd/gameserver/action/HeroAction.go +++ b/cmd/gameserver/action/HeroAction.go @@ -4,12 +4,14 @@ import ( "fmt" "github.com/golang/protobuf/proto" "go.mongodb.org/mongo-driver/bson" + "pro2d/common" "pro2d/common/components" "pro2d/common/db/mongoproxy" "pro2d/common/logger" "pro2d/csvdata" "pro2d/models" "pro2d/pb" + "strconv" ) /* @@ -49,35 +51,41 @@ func HeroUpLevelRpc(role *models.RoleModel, msg components.IMessage) (int32, int logger.Error("loginRpc err: %v", err) return 1, nil } - if req.Count <= 0 { - req.Count = 1 - } + items := common.StringToMapNum(req.Items) + var hero *models.HeroModel + for id, count := range items { + itemId, err := strconv.Atoi(id) + if err != nil { + continue + } - item := csvdata.Get().TbItemData.Get(req.ItemId) - if item == nil { - return 2, nil - } - if item.Type != 2003 { - return 3, nil - } + item := csvdata.Get().TbItemData.Get(int32(itemId)) + if item == nil { + return 2, nil + } + if item.Type != 2003 { + return 3, nil + } - itemExp := csvdata.Get().TbExpItemData.Get(item.ID) - if itemExp == nil { - return 4, nil - } + itemExp := csvdata.Get().TbExpItemData.Get(item.ID) + if itemExp == nil { + return 4, nil + } - hero, ok := role.Heros[req.HeroId] - if !ok { - return 5, nil - } + h := role.Heros[req.HeroId] + if h == nil { + return 5, nil + } + + if !role.CostItem(fmt.Sprintf("%d", item.ID), count) { + return 6, nil + } - if !role.CostItem(fmt.Sprintf("%d", item.ID), req.Count) { - return 6, nil + hero = h.(*models.HeroModel) + level, exp := hero.UpLevel(itemExp.Exp) + h.SetProperty("level", level) + h.SetProperty("exp", exp) } - h := hero.(*models.HeroModel) - level, exp := h.UpLevel(itemExp.Exp) - h.SetProperty("level", level) - h.SetProperty("exp", exp) - return 0, h.Hero + return 0, hero.Hero } diff --git a/pb/game.pb.go b/pb/game.pb.go index 2d7241c..e5d93d9 100644 --- a/pb/game.pb.go +++ b/pb/game.pb.go @@ -972,8 +972,7 @@ type HeroUpLevelReq struct { unknownFields protoimpl.UnknownFields HeroId string `protobuf:"bytes,1,opt,name=heroId,proto3" json:"heroId,omitempty"` - ItemId int32 `protobuf:"varint,2,opt,name=itemId,proto3" json:"itemId,omitempty"` - Count int32 `protobuf:"varint,3,opt,name=count,proto3" json:"count,omitempty"` + Items string `protobuf:"bytes,2,opt,name=items,proto3" json:"items,omitempty"` // [itemId1=count1, itemId2=count2] } func (x *HeroUpLevelReq) Reset() { @@ -1015,18 +1014,11 @@ func (x *HeroUpLevelReq) GetHeroId() string { return "" } -func (x *HeroUpLevelReq) GetItemId() int32 { +func (x *HeroUpLevelReq) GetItems() string { if x != nil { - return x.ItemId - } - return 0 -} - -func (x *HeroUpLevelReq) GetCount() int32 { - if x != nil { - return x.Count + return x.Items } - return 0 + return "" } var File_game_proto protoreflect.FileDescriptor @@ -1111,14 +1103,12 @@ var file_game_proto_rawDesc = []byte{ 0x22, 0x3a, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x27, 0x0a, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x45, 0x71, 0x75, 0x69, - 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x22, 0x56, 0x0a, 0x0e, + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x22, 0x3e, 0x0a, 0x0e, 0x48, 0x65, 0x72, 0x6f, 0x55, 0x70, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x14, - 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x42, 0x0a, 0x5a, 0x08, + 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/protos b/protos index 753495c..cfb6f56 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit 753495c6eff899239365191a19507c564f161d37 +Subproject commit cfb6f56c89fb705384c4dd1984782815010f1557 -- libgit2 0.21.2