Commit c99d59cc6f619ed6acbb609d0db9b69120e43052
1 parent
f74e34e3
fix: 批量删除物品
Showing
3 changed files
with
25 additions
and
21 deletions
Show diff stats
cmd/gameserver/action/RoleAction.go
@@ -145,8 +145,19 @@ func RoleClearItemsRpc(role *models.RoleModel, msg components.IMessage) (int32, | @@ -145,8 +145,19 @@ func RoleClearItemsRpc(role *models.RoleModel, msg components.IMessage) (int32, | ||
145 | return 1, nil | 145 | return 1, nil |
146 | } | 146 | } |
147 | 147 | ||
148 | - if !role.CostItem(req.Id, req.Count) { | ||
149 | - logger.Error("cost err: %s, %d", req.Id, req.Count) | 148 | + bkup := make(common.IMapStringNum) |
149 | + for _, item := range req.Items { | ||
150 | + for k, v := range common.StringToMapNum(item) { | ||
151 | + tmp, ok := bkup[k] | ||
152 | + if !ok { | ||
153 | + tmp = 0 | ||
154 | + } | ||
155 | + bkup[k] = v + tmp | ||
156 | + } | ||
157 | + } | ||
158 | + | ||
159 | + if !role.CostItems(bkup) { | ||
160 | + logger.Error("cost err: %s", common.MapNumToString(bkup)) | ||
150 | return 2, nil | 161 | return 2, nil |
151 | } | 162 | } |
152 | return 0, nil | 163 | return 0, nil |
models/rolePlugin.go
@@ -31,9 +31,10 @@ func (m *RoleModel) CostItems(params common.IMapStringNum) bool { | @@ -31,9 +31,10 @@ func (m *RoleModel) CostItems(params common.IMapStringNum) bool { | ||
31 | return false | 31 | return false |
32 | } | 32 | } |
33 | 33 | ||
34 | - m.AddItem(k, -v) | 34 | + params[k] = -v |
35 | } | 35 | } |
36 | - return true | 36 | + |
37 | + return m.AddItems(params) | ||
37 | } | 38 | } |
38 | 39 | ||
39 | func (m *RoleModel) AddItem(key string, count int32) bool { | 40 | func (m *RoleModel) AddItem(key string, count int32) bool { |
@@ -67,10 +68,11 @@ func (m *RoleModel) AddItems(params common.IMapStringNum) bool { | @@ -67,10 +68,11 @@ func (m *RoleModel) AddItems(params common.IMapStringNum) bool { | ||
67 | num := c + v | 68 | num := c + v |
68 | if num > 0 { | 69 | if num > 0 { |
69 | m.Items[k] = num | 70 | m.Items[k] = num |
70 | - tmp[k] = num | ||
71 | } else { | 71 | } else { |
72 | + num = 0 | ||
72 | delete(m.Items, k) | 73 | delete(m.Items, k) |
73 | } | 74 | } |
75 | + tmp[k] = num | ||
74 | } | 76 | } |
75 | 77 | ||
76 | m.SetProperty("items", common.MapNumToString(m.Items)) | 78 | m.SetProperty("items", common.MapNumToString(m.Items)) |
pb/game.pb.go
@@ -558,8 +558,7 @@ type RoleClearItemsReq struct { | @@ -558,8 +558,7 @@ type RoleClearItemsReq struct { | ||
558 | sizeCache protoimpl.SizeCache | 558 | sizeCache protoimpl.SizeCache |
559 | unknownFields protoimpl.UnknownFields | 559 | unknownFields protoimpl.UnknownFields |
560 | 560 | ||
561 | - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` | ||
562 | - Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` | 561 | + Items []string `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` |
563 | } | 562 | } |
564 | 563 | ||
565 | func (x *RoleClearItemsReq) Reset() { | 564 | func (x *RoleClearItemsReq) Reset() { |
@@ -594,18 +593,11 @@ func (*RoleClearItemsReq) Descriptor() ([]byte, []int) { | @@ -594,18 +593,11 @@ func (*RoleClearItemsReq) Descriptor() ([]byte, []int) { | ||
594 | return file_game_proto_rawDescGZIP(), []int{10} | 593 | return file_game_proto_rawDescGZIP(), []int{10} |
595 | } | 594 | } |
596 | 595 | ||
597 | -func (x *RoleClearItemsReq) GetId() string { | 596 | +func (x *RoleClearItemsReq) GetItems() []string { |
598 | if x != nil { | 597 | if x != nil { |
599 | - return x.Id | ||
600 | - } | ||
601 | - return "" | ||
602 | -} | ||
603 | - | ||
604 | -func (x *RoleClearItemsReq) GetCount() int32 { | ||
605 | - if x != nil { | ||
606 | - return x.Count | 598 | + return x.Items |
607 | } | 599 | } |
608 | - return 0 | 600 | + return nil |
609 | } | 601 | } |
610 | 602 | ||
611 | type RoleStartBattleReq struct { | 603 | type RoleStartBattleReq struct { |
@@ -954,10 +946,9 @@ var file_game_proto_rawDesc = []byte{ | @@ -954,10 +946,9 @@ var file_game_proto_rawDesc = []byte{ | ||
954 | 0x65, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x22, 0x2a, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x55, | 946 | 0x65, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x22, 0x2a, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x55, |
955 | 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x73, 0x70, 0x12, 0x14, 0x0a, | 947 | 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x73, 0x70, 0x12, 0x14, 0x0a, |
956 | 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, | 948 | 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, |
957 | - 0x65, 0x6d, 0x73, 0x22, 0x39, 0x0a, 0x11, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x65, 0x61, 0x72, | ||
958 | - 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, | ||
959 | - 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, | ||
960 | - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x50, | 949 | + 0x65, 0x6d, 0x73, 0x22, 0x29, 0x0a, 0x11, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x65, 0x61, 0x72, |
950 | + 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, | ||
951 | + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x50, | ||
961 | 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x42, 0x61, 0x74, 0x74, 0x6c, | 952 | 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x42, 0x61, 0x74, 0x74, 0x6c, |
962 | 0x65, 0x52, 0x65, 0x71, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x5f, | 953 | 0x65, 0x52, 0x65, 0x71, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x5f, |
963 | 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, | 954 | 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, |