Commit c8e2cc53d60df67c042e85fe099858f2717916aa

Authored by zhangqijia
1 parent 24283e5d

fix: 英雄升级,经验书批量操作

cmd/gameserver/action/HeroAction.go
... ... @@ -4,12 +4,14 @@ import (
4 4 "fmt"
5 5 "github.com/golang/protobuf/proto"
6 6 "go.mongodb.org/mongo-driver/bson"
  7 + "pro2d/common"
7 8 "pro2d/common/components"
8 9 "pro2d/common/db/mongoproxy"
9 10 "pro2d/common/logger"
10 11 "pro2d/csvdata"
11 12 "pro2d/models"
12 13 "pro2d/pb"
  14 + "strconv"
13 15 )
14 16  
15 17 /*
... ... @@ -49,35 +51,41 @@ func HeroUpLevelRpc(role *models.RoleModel, msg components.IMessage) (int32, int
49 51 logger.Error("loginRpc err: %v", err)
50 52 return 1, nil
51 53 }
52   - if req.Count <= 0 {
53   - req.Count = 1
54   - }
  54 + items := common.StringToMapNum(req.Items)
  55 + var hero *models.HeroModel
  56 + for id, count := range items {
  57 + itemId, err := strconv.Atoi(id)
  58 + if err != nil {
  59 + continue
  60 + }
55 61  
56   - item := csvdata.Get().TbItemData.Get(req.ItemId)
57   - if item == nil {
58   - return 2, nil
59   - }
60   - if item.Type != 2003 {
61   - return 3, nil
62   - }
  62 + item := csvdata.Get().TbItemData.Get(int32(itemId))
  63 + if item == nil {
  64 + return 2, nil
  65 + }
  66 + if item.Type != 2003 {
  67 + return 3, nil
  68 + }
63 69  
64   - itemExp := csvdata.Get().TbExpItemData.Get(item.ID)
65   - if itemExp == nil {
66   - return 4, nil
67   - }
  70 + itemExp := csvdata.Get().TbExpItemData.Get(item.ID)
  71 + if itemExp == nil {
  72 + return 4, nil
  73 + }
68 74  
69   - hero, ok := role.Heros[req.HeroId]
70   - if !ok {
71   - return 5, nil
72   - }
  75 + h := role.Heros[req.HeroId]
  76 + if h == nil {
  77 + return 5, nil
  78 + }
  79 +
  80 + if !role.CostItem(fmt.Sprintf("%d", item.ID), count) {
  81 + return 6, nil
  82 + }
73 83  
74   - if !role.CostItem(fmt.Sprintf("%d", item.ID), req.Count) {
75   - return 6, nil
  84 + hero = h.(*models.HeroModel)
  85 + level, exp := hero.UpLevel(itemExp.Exp)
  86 + h.SetProperty("level", level)
  87 + h.SetProperty("exp", exp)
76 88 }
77 89  
78   - h := hero.(*models.HeroModel)
79   - level, exp := h.UpLevel(itemExp.Exp)
80   - h.SetProperty("level", level)
81   - h.SetProperty("exp", exp)
82   - return 0, h.Hero
  90 + return 0, hero.Hero
83 91 }
... ...
pb/game.pb.go
... ... @@ -972,8 +972,7 @@ type HeroUpLevelReq struct {
972 972 unknownFields protoimpl.UnknownFields
973 973  
974 974 HeroId string `protobuf:"bytes,1,opt,name=heroId,proto3" json:"heroId,omitempty"`
975   - ItemId int32 `protobuf:"varint,2,opt,name=itemId,proto3" json:"itemId,omitempty"`
976   - Count int32 `protobuf:"varint,3,opt,name=count,proto3" json:"count,omitempty"`
  975 + Items string `protobuf:"bytes,2,opt,name=items,proto3" json:"items,omitempty"` // [itemId1=count1, itemId2=count2]
977 976 }
978 977  
979 978 func (x *HeroUpLevelReq) Reset() {
... ... @@ -1015,18 +1014,11 @@ func (x *HeroUpLevelReq) GetHeroId() string {
1015 1014 return ""
1016 1015 }
1017 1016  
1018   -func (x *HeroUpLevelReq) GetItemId() int32 {
  1017 +func (x *HeroUpLevelReq) GetItems() string {
1019 1018 if x != nil {
1020   - return x.ItemId
1021   - }
1022   - return 0
1023   -}
1024   -
1025   -func (x *HeroUpLevelReq) GetCount() int32 {
1026   - if x != nil {
1027   - return x.Count
  1019 + return x.Items
1028 1020 }
1029   - return 0
  1021 + return ""
1030 1022 }
1031 1023  
1032 1024 var File_game_proto protoreflect.FileDescriptor
... ... @@ -1111,14 +1103,12 @@ var file_game_proto_rawDesc = []byte{
1111 1103 0x22, 0x3a, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64,
1112 1104 0x52, 0x73, 0x70, 0x12, 0x27, 0x0a, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01,
1113 1105 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x45, 0x71, 0x75, 0x69,
1114   - 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x22, 0x56, 0x0a, 0x0e,
  1106 + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x22, 0x3e, 0x0a, 0x0e,
1115 1107 0x48, 0x65, 0x72, 0x6f, 0x55, 0x70, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x16,
1116 1108 0x0a, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
1117   - 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64,
1118   - 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x14,
1119   - 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63,
1120   - 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62,
1121   - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
  1109 + 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18,
  1110 + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x42, 0x0a, 0x5a, 0x08,
  1111 + 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
1122 1112 }
1123 1113  
1124 1114 var (
... ...
1   -Subproject commit 753495c6eff899239365191a19507c564f161d37
  1 +Subproject commit cfb6f56c89fb705384c4dd1984782815010f1557
... ...