diff --git a/cmd/gameserver/action/RoleAction.go b/cmd/gameserver/action/RoleAction.go index 1ede1fe..d541a18 100644 --- a/cmd/gameserver/action/RoleAction.go +++ b/cmd/gameserver/action/RoleAction.go @@ -145,8 +145,19 @@ func RoleClearItemsRpc(role *models.RoleModel, msg components.IMessage) (int32, return 1, nil } - if !role.CostItem(req.Id, req.Count) { - logger.Error("cost err: %s, %d", req.Id, req.Count) + bkup := make(common.IMapStringNum) + for _, item := range req.Items { + for k, v := range common.StringToMapNum(item) { + tmp, ok := bkup[k] + if !ok { + tmp = 0 + } + bkup[k] = v + tmp + } + } + + if !role.CostItems(bkup) { + logger.Error("cost err: %s", common.MapNumToString(bkup)) return 2, nil } return 0, nil diff --git a/models/rolePlugin.go b/models/rolePlugin.go index a841bd1..02f35d2 100644 --- a/models/rolePlugin.go +++ b/models/rolePlugin.go @@ -31,9 +31,10 @@ func (m *RoleModel) CostItems(params common.IMapStringNum) bool { return false } - m.AddItem(k, -v) + params[k] = -v } - return true + + return m.AddItems(params) } func (m *RoleModel) AddItem(key string, count int32) bool { @@ -67,10 +68,11 @@ func (m *RoleModel) AddItems(params common.IMapStringNum) bool { num := c + v if num > 0 { m.Items[k] = num - tmp[k] = num } else { + num = 0 delete(m.Items, k) } + tmp[k] = num } m.SetProperty("items", common.MapNumToString(m.Items)) diff --git a/pb/game.pb.go b/pb/game.pb.go index 9cd0331..0aeb56c 100644 --- a/pb/game.pb.go +++ b/pb/game.pb.go @@ -558,8 +558,7 @@ type RoleClearItemsReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` + Items []string `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` } func (x *RoleClearItemsReq) Reset() { @@ -594,18 +593,11 @@ func (*RoleClearItemsReq) Descriptor() ([]byte, []int) { return file_game_proto_rawDescGZIP(), []int{10} } -func (x *RoleClearItemsReq) GetId() string { +func (x *RoleClearItemsReq) GetItems() []string { if x != nil { - return x.Id - } - return "" -} - -func (x *RoleClearItemsReq) GetCount() int32 { - if x != nil { - return x.Count + return x.Items } - return 0 + return nil } type RoleStartBattleReq struct { @@ -954,10 +946,9 @@ var file_game_proto_rawDesc = []byte{ 0x65, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x22, 0x2a, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, - 0x65, 0x6d, 0x73, 0x22, 0x39, 0x0a, 0x11, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x65, 0x61, 0x72, - 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x50, + 0x65, 0x6d, 0x73, 0x22, 0x29, 0x0a, 0x11, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x65, 0x61, 0x72, + 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x50, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, -- libgit2 0.21.2