diff --git a/cmd/gameserver/action/GmAction.go b/cmd/gameserver/action/GmAction.go index c348f5c..93a239a 100644 --- a/cmd/gameserver/action/GmAction.go +++ b/cmd/gameserver/action/GmAction.go @@ -1,8 +1,6 @@ package action import ( - "github.com/golang/protobuf/proto" - "pro2d/common/db/mongoproxy" "pro2d/common/logger" "pro2d/models" "pro2d/pb" @@ -31,32 +29,3 @@ func (gm *GmAction) AddEquip(role *models.RoleModel, params ...interface{}) { } role.AddEquip(equip) } - -func (gm *GmAction) DelEquip(role *models.RoleModel, params ...interface{}) { - logger.Debug(params) - id := params[0].(string) - if err := mongoproxy.DelOne("equip", "id", id); err != nil { - logger.Error(err.Error()) - return - } - delete(role.Equipments, id) - update := &pb.EquipmentDelRsp{Id: id} - if rsp, err := proto.Marshal(update); err != nil { - logger.Error(" err:", err.Error()) - return - } else { - if role.GetConn() != nil { - role.GetConn().SendSuccess(uint32(pb.ProtoCode_EquipmentDelRsp), rsp) - } - } -} - -func (gm *GmAction) DelItem(role *models.RoleModel, params ...interface{}) { - logger.Debug(params) - id := params[0].(string) - count := params[1].(int32) - - if !role.CostItem(id, count) { - logger.Error("item cost error: ", id) - } -} diff --git a/cmd/gameserver/action/RoleAction.go b/cmd/gameserver/action/RoleAction.go index 9702453..2ec1b38 100644 --- a/cmd/gameserver/action/RoleAction.go +++ b/cmd/gameserver/action/RoleAction.go @@ -5,6 +5,7 @@ import ( "github.com/golang/protobuf/proto" "pro2d/common" "pro2d/common/components" + "pro2d/common/db/mongoproxy" "pro2d/common/db/redisproxy" "pro2d/common/logger" "pro2d/models" @@ -148,3 +149,41 @@ func HeroEquipReferRpc(agent components.IAgent, msg components.IMessage) (int32, } return 0, nil } + +func RoleClearItemsRpc(agent components.IAgent, msg components.IMessage) (int32, interface{}) { + req := pb.RoleClearItemsReq{} + if err := proto.Unmarshal(msg.GetData(), &req); err != nil { + logger.Error("loginRpc err: %v", err) + return 1, nil + } + role := agent.GetSchema().(*models.RoleModel) + if role == nil { + return 2, nil + } + + if !role.CostItem(req.Id, req.Count) { + logger.Error("cost err: %s, %d", req.Id, req.Count) + return 3, nil + } + return 0, nil +} + +func EquipmentDelRpc(agent components.IAgent, msg components.IMessage) (int32, interface{}) { + req := pb.EquipmentDelReq{} + if err := proto.Unmarshal(msg.GetData(), &req); err != nil { + logger.Error("loginRpc err: %v", err) + return 1, nil + } + role := agent.GetSchema().(*models.RoleModel) + if role == nil { + return 2, nil + } + + if err := mongoproxy.DelOne("equip", "id", req.Id); err != nil { + logger.Error(err.Error()) + return 3, nil + } + delete(role.Equipments, req.Id) + + return 0, nil +} diff --git a/cmd/gameserver/action/protocode.go b/cmd/gameserver/action/protocode.go index dc6be55..7629c39 100644 --- a/cmd/gameserver/action/protocode.go +++ b/cmd/gameserver/action/protocode.go @@ -13,6 +13,8 @@ func GetActionMap() map[interface{}]interface{} { am[uint32(pb.ProtoCode_CreateReq)] = CreateRpc am[uint32(pb.ProtoCode_ChangeTeamReq)] = ChangeTeamRpc am[uint32(pb.ProtoCode_HeroEquipReferReq)] = HeroEquipReferRpc + am[uint32(pb.ProtoCode_RoleClearItemsReq)] = RoleClearItemsRpc + am[uint32(pb.ProtoCode_EquipmentDelReq)] = EquipmentDelRpc return am } diff --git a/pb/game.pb.go b/pb/game.pb.go index 80f5add..6288fa8 100644 --- a/pb/game.pb.go +++ b/pb/game.pb.go @@ -514,17 +514,17 @@ func (x *RoleUpdateItemsRsp) GetItems() string { return "" } -//ResponseCmd EquipmentAddRsp -type EquipmentAddRsp struct { +type RoleClearItemsReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Equip *Equipment `protobuf:"bytes,1,opt,name=equip,proto3" json:"equip,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` } -func (x *EquipmentAddRsp) Reset() { - *x = EquipmentAddRsp{} +func (x *RoleClearItemsReq) Reset() { + *x = RoleClearItemsReq{} if protoimpl.UnsafeEnabled { mi := &file_game_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -532,13 +532,13 @@ func (x *EquipmentAddRsp) Reset() { } } -func (x *EquipmentAddRsp) String() string { +func (x *RoleClearItemsReq) String() string { return protoimpl.X.MessageStringOf(x) } -func (*EquipmentAddRsp) ProtoMessage() {} +func (*RoleClearItemsReq) ProtoMessage() {} -func (x *EquipmentAddRsp) ProtoReflect() protoreflect.Message { +func (x *RoleClearItemsReq) ProtoReflect() protoreflect.Message { mi := &file_game_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -550,19 +550,26 @@ func (x *EquipmentAddRsp) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use EquipmentAddRsp.ProtoReflect.Descriptor instead. -func (*EquipmentAddRsp) Descriptor() ([]byte, []int) { +// Deprecated: Use RoleClearItemsReq.ProtoReflect.Descriptor instead. +func (*RoleClearItemsReq) Descriptor() ([]byte, []int) { return file_game_proto_rawDescGZIP(), []int{9} } -func (x *EquipmentAddRsp) GetEquip() *Equipment { +func (x *RoleClearItemsReq) GetId() string { if x != nil { - return x.Equip + return x.Id } - return nil + return "" +} + +func (x *RoleClearItemsReq) GetCount() int32 { + if x != nil { + return x.Count + } + return 0 } -type EquipmentDelRsp struct { +type EquipmentDelReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -570,8 +577,8 @@ type EquipmentDelRsp struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } -func (x *EquipmentDelRsp) Reset() { - *x = EquipmentDelRsp{} +func (x *EquipmentDelReq) Reset() { + *x = EquipmentDelReq{} if protoimpl.UnsafeEnabled { mi := &file_game_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -579,13 +586,13 @@ func (x *EquipmentDelRsp) Reset() { } } -func (x *EquipmentDelRsp) String() string { +func (x *EquipmentDelReq) String() string { return protoimpl.X.MessageStringOf(x) } -func (*EquipmentDelRsp) ProtoMessage() {} +func (*EquipmentDelReq) ProtoMessage() {} -func (x *EquipmentDelRsp) ProtoReflect() protoreflect.Message { +func (x *EquipmentDelReq) ProtoReflect() protoreflect.Message { mi := &file_game_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -597,18 +604,66 @@ func (x *EquipmentDelRsp) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use EquipmentDelRsp.ProtoReflect.Descriptor instead. -func (*EquipmentDelRsp) Descriptor() ([]byte, []int) { +// Deprecated: Use EquipmentDelReq.ProtoReflect.Descriptor instead. +func (*EquipmentDelReq) Descriptor() ([]byte, []int) { return file_game_proto_rawDescGZIP(), []int{10} } -func (x *EquipmentDelRsp) GetId() string { +func (x *EquipmentDelReq) GetId() string { if x != nil { return x.Id } return "" } +//ResponseCmd EquipmentAddRsp +type EquipmentAddRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Equip *Equipment `protobuf:"bytes,1,opt,name=equip,proto3" json:"equip,omitempty"` +} + +func (x *EquipmentAddRsp) Reset() { + *x = EquipmentAddRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_game_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EquipmentAddRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EquipmentAddRsp) ProtoMessage() {} + +func (x *EquipmentAddRsp) ProtoReflect() protoreflect.Message { + mi := &file_game_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EquipmentAddRsp.ProtoReflect.Descriptor instead. +func (*EquipmentAddRsp) Descriptor() ([]byte, []int) { + return file_game_proto_rawDescGZIP(), []int{11} +} + +func (x *EquipmentAddRsp) GetEquip() *Equipment { + if x != nil { + return x.Equip + } + return nil +} + var File_game_proto protoreflect.FileDescriptor var file_game_proto_rawDesc = []byte{ @@ -652,14 +707,17 @@ var file_game_proto_rawDesc = []byte{ 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, 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, 0x21, - 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, 0x6c, 0x52, 0x73, - 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, - 0x64, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 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, 0x21, 0x0a, + 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, 0x6c, 0x52, 0x65, 0x71, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, + 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, 0x42, 0x0a, 0x5a, 0x08, + 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -674,7 +732,7 @@ func file_game_proto_rawDescGZIP() []byte { return file_game_proto_rawDescData } -var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_game_proto_goTypes = []interface{}{ (*HeartReq)(nil), // 0: game.HeartReq (*HeartRsp)(nil), // 1: game.HeartRsp @@ -685,21 +743,22 @@ var file_game_proto_goTypes = []interface{}{ (*RoleRsp)(nil), // 6: game.RoleRsp (*RoleUpdatePropertyRsp)(nil), // 7: game.RoleUpdatePropertyRsp (*RoleUpdateItemsRsp)(nil), // 8: game.RoleUpdateItemsRsp - (*EquipmentAddRsp)(nil), // 9: game.EquipmentAddRsp - (*EquipmentDelRsp)(nil), // 10: game.EquipmentDelRsp - (*Team)(nil), // 11: models.Team - (*Role)(nil), // 12: models.Role - (*Hero)(nil), // 13: models.Hero - (*Equipment)(nil), // 14: models.Equipment + (*RoleClearItemsReq)(nil), // 9: game.RoleClearItemsReq + (*EquipmentDelReq)(nil), // 10: game.EquipmentDelReq + (*EquipmentAddRsp)(nil), // 11: game.EquipmentAddRsp + (*Team)(nil), // 12: models.Team + (*Role)(nil), // 13: models.Role + (*Hero)(nil), // 14: models.Hero + (*Equipment)(nil), // 15: models.Equipment } var file_game_proto_depIdxs = []int32{ - 11, // 0: game.ChangeTeamReq.team:type_name -> models.Team - 12, // 1: game.RoleRsp.role:type_name -> models.Role - 13, // 2: game.RoleRsp.hero:type_name -> models.Hero - 11, // 3: game.RoleRsp.team:type_name -> models.Team - 14, // 4: game.RoleRsp.equipments:type_name -> models.Equipment - 12, // 5: game.RoleUpdatePropertyRsp.role:type_name -> models.Role - 14, // 6: game.EquipmentAddRsp.equip:type_name -> models.Equipment + 12, // 0: game.ChangeTeamReq.team:type_name -> models.Team + 13, // 1: game.RoleRsp.role:type_name -> models.Role + 14, // 2: game.RoleRsp.hero:type_name -> models.Hero + 12, // 3: game.RoleRsp.team:type_name -> models.Team + 15, // 4: game.RoleRsp.equipments:type_name -> models.Equipment + 13, // 5: game.RoleUpdatePropertyRsp.role:type_name -> models.Role + 15, // 6: game.EquipmentAddRsp.equip:type_name -> models.Equipment 7, // [7:7] is the sub-list for method output_type 7, // [7:7] is the sub-list for method input_type 7, // [7:7] is the sub-list for extension type_name @@ -823,7 +882,7 @@ func file_game_proto_init() { } } file_game_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EquipmentAddRsp); i { + switch v := v.(*RoleClearItemsReq); i { case 0: return &v.state case 1: @@ -835,7 +894,19 @@ func file_game_proto_init() { } } file_game_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EquipmentDelRsp); i { + switch v := v.(*EquipmentDelReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_game_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EquipmentAddRsp); i { case 0: return &v.state case 1: @@ -853,7 +924,7 @@ func file_game_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_game_proto_rawDesc, NumEnums: 0, - NumMessages: 11, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/protocode.pb.go b/pb/protocode.pb.go index 56c8d30..9acfd45 100644 --- a/pb/protocode.pb.go +++ b/pb/protocode.pb.go @@ -34,8 +34,9 @@ const ( ProtoCode_RoleRsp ProtoCode = 8 ProtoCode_RoleUpdatePropertyRsp ProtoCode = 9 ProtoCode_RoleUpdateItemsRsp ProtoCode = 10 - ProtoCode_EquipmentAddRsp ProtoCode = 11 - ProtoCode_EquipmentDelRsp ProtoCode = 12 + ProtoCode_RoleClearItemsReq ProtoCode = 11 + ProtoCode_EquipmentDelReq ProtoCode = 12 + ProtoCode_EquipmentAddRsp ProtoCode = 13 ) // Enum value maps for ProtoCode. @@ -52,8 +53,9 @@ var ( 8: "RoleRsp", 9: "RoleUpdatePropertyRsp", 10: "RoleUpdateItemsRsp", - 11: "EquipmentAddRsp", - 12: "EquipmentDelRsp", + 11: "RoleClearItemsReq", + 12: "EquipmentDelReq", + 13: "EquipmentAddRsp", } ProtoCode_value = map[string]int32{ "UNKNOWN": 0, @@ -67,8 +69,9 @@ var ( "RoleRsp": 8, "RoleUpdatePropertyRsp": 9, "RoleUpdateItemsRsp": 10, - "EquipmentAddRsp": 11, - "EquipmentDelRsp": 12, + "RoleClearItemsReq": 11, + "EquipmentDelReq": 12, + "EquipmentAddRsp": 13, } ) @@ -103,7 +106,7 @@ var File_protocode_proto protoreflect.FileDescriptor var file_protocode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x09, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2a, 0xf3, 0x01, 0x0a, + 0x6f, 0x12, 0x09, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2a, 0x8a, 0x02, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x73, 0x70, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x48, 0x65, 0x61, 0x72, 0x74, 0x52, 0x65, @@ -116,11 +119,12 @@ var file_protocode_proto_rawDesc = []byte{ 0x52, 0x73, 0x70, 0x10, 0x08, 0x12, 0x19, 0x0a, 0x15, 0x52, 0x6f, 0x6c, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x52, 0x73, 0x70, 0x10, 0x09, 0x12, 0x16, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x74, - 0x65, 0x6d, 0x73, 0x52, 0x73, 0x70, 0x10, 0x0a, 0x12, 0x13, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, - 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x10, 0x0b, 0x12, 0x13, 0x0a, - 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, 0x6c, 0x52, 0x73, 0x70, - 0x10, 0x0c, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x6d, 0x73, 0x52, 0x73, 0x70, 0x10, 0x0a, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x6f, 0x6c, 0x65, + 0x43, 0x6c, 0x65, 0x61, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x10, 0x0b, 0x12, + 0x13, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, 0x6c, 0x52, + 0x65, 0x71, 0x10, 0x0c, 0x12, 0x13, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x10, 0x0d, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, + 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( -- libgit2 0.21.2