diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index 6cf52f6f8..ee52387fe 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -7,20 +7,50 @@ import ( //参数校验 func (this *apiComp) BuyOrSellCheck(session comm.IUserSession, req *pb.CaravanBuyOrSellReq) (code pb.ErrorCode) { - if len(req.Items) == 0 { + if len(req.Items) == 0 || req.City == 0 { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSellReq) (code pb.ErrorCode, data *pb.ErrorData) { - - //update := make(map[string]interface{}) + var ( + update map[string]interface{} + ) + update = make(map[string]interface{}) if code = this.BuyOrSellCheck(session, req); code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - - // this.module.ModuleRtask.SendToRtask(session, comm.Rtype153, 1) - go this.module.ModuleRtask.TriggerTask(session.GetUserId(), comm.GettaskParam(comm.Rtype153, 1)) + caravan, err := this.module.modelCaravan.getCaravanList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_DBError + return + } + if _, ok := caravan.City[req.City]; !ok { + code = pb.ErrorCode_ConfigNoFound + return + } + for k, v := range req.Items { + if v < 0 { // 卖给npc + // 校验背包数据够不够 + if _, ok := caravan.Items[k]; !ok { + this.module.Errorf("背包道具数量不足%s,道具ID:%d,背包数量:%d", session.GetUserId(), k, v) + continue + } + for _, k1 := range caravan.City[req.City].Like { + if k == k1 && v < caravan.Items[k].Count { + caravan.Items[k].Count -= v + } + } + } else if v > 0 { // 买入 + for _, k1 := range caravan.City[req.City].Unlike { + if k == k1 { + caravan.Items[k].Count += v + } + } + } + } + update["item"] = caravan.Items + this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update) return } diff --git a/modules/caravan/model_troll.go b/modules/caravan/model_caravan.go similarity index 100% rename from modules/caravan/model_troll.go rename to modules/caravan/model_caravan.go diff --git a/pb/caravan_msg.pb.go b/pb/caravan_msg.pb.go index aa31fc9e2..a970395e8 100644 --- a/pb/caravan_msg.pb.go +++ b/pb/caravan_msg.pb.go @@ -112,7 +112,8 @@ type CaravanBuyOrSellReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Items map[int32]int32 `protobuf:"bytes,1,rep,name=items,proto3" json:"items" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //买入货物的数量(负数为卖) + City int32 `protobuf:"varint,1,opt,name=city,proto3" json:"city"` // 城市id + Items map[int32]int32 `protobuf:"bytes,2,rep,name=items,proto3" json:"items" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //买入货物的数量(负数为卖) } func (x *CaravanBuyOrSellReq) Reset() { @@ -147,6 +148,13 @@ func (*CaravanBuyOrSellReq) Descriptor() ([]byte, []int) { return file_caravan_caravan_msg_proto_rawDescGZIP(), []int{2} } +func (x *CaravanBuyOrSellReq) GetCity() int32 { + if x != nil { + return x.City + } + return 0 +} + func (x *CaravanBuyOrSellReq) GetItems() map[int32]int32 { if x != nil { return x.Items @@ -201,6 +209,101 @@ func (x *CaravanBuyOrSellResp) GetData() *DBCaravan { return nil } +// 去某个city +type CaravanGotoCityReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + City int32 `protobuf:"varint,1,opt,name=city,proto3" json:"city"` // 城市id +} + +func (x *CaravanGotoCityReq) Reset() { + *x = CaravanGotoCityReq{} + if protoimpl.UnsafeEnabled { + mi := &file_caravan_caravan_msg_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CaravanGotoCityReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CaravanGotoCityReq) ProtoMessage() {} + +func (x *CaravanGotoCityReq) ProtoReflect() protoreflect.Message { + mi := &file_caravan_caravan_msg_proto_msgTypes[4] + 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 CaravanGotoCityReq.ProtoReflect.Descriptor instead. +func (*CaravanGotoCityReq) Descriptor() ([]byte, []int) { + return file_caravan_caravan_msg_proto_rawDescGZIP(), []int{4} +} + +func (x *CaravanGotoCityReq) GetCity() int32 { + if x != nil { + return x.City + } + return 0 +} + +type CaravanGotoCityResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data *DBCaravan `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` +} + +func (x *CaravanGotoCityResp) Reset() { + *x = CaravanGotoCityResp{} + if protoimpl.UnsafeEnabled { + mi := &file_caravan_caravan_msg_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CaravanGotoCityResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CaravanGotoCityResp) ProtoMessage() {} + +func (x *CaravanGotoCityResp) ProtoReflect() protoreflect.Message { + mi := &file_caravan_caravan_msg_proto_msgTypes[5] + 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 CaravanGotoCityResp.ProtoReflect.Descriptor instead. +func (*CaravanGotoCityResp) Descriptor() ([]byte, []int) { + return file_caravan_caravan_msg_proto_rawDescGZIP(), []int{5} +} + +func (x *CaravanGotoCityResp) GetData() *DBCaravan { + if x != nil { + return x.Data + } + return nil +} + var File_caravan_caravan_msg_proto protoreflect.FileDescriptor var file_caravan_caravan_msg_proto_rawDesc = []byte{ @@ -212,20 +315,27 @@ var file_caravan_caravan_msg_proto_rawDesc = []byte{ 0x72, 0x61, 0x76, 0x61, 0x6e, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x22, 0x86, 0x01, 0x0a, 0x13, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x42, 0x75, 0x79, 0x4f, - 0x72, 0x53, 0x65, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x35, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, - 0x6e, 0x42, 0x75, 0x79, 0x4f, 0x72, 0x53, 0x65, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x2e, 0x49, 0x74, - 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x1a, - 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x36, 0x0a, 0x14, 0x43, 0x61, 0x72, - 0x61, 0x76, 0x61, 0x6e, 0x42, 0x75, 0x79, 0x4f, 0x72, 0x53, 0x65, 0x6c, 0x6c, 0x52, 0x65, 0x73, - 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0a, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x22, 0x9a, 0x01, 0x0a, 0x13, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x42, 0x75, 0x79, 0x4f, + 0x72, 0x53, 0x65, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x12, 0x35, 0x0a, 0x05, + 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x43, 0x61, + 0x72, 0x61, 0x76, 0x61, 0x6e, 0x42, 0x75, 0x79, 0x4f, 0x72, 0x53, 0x65, 0x6c, 0x6c, 0x52, 0x65, + 0x71, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x69, 0x74, + 0x65, 0x6d, 0x73, 0x1a, 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x36, 0x0a, + 0x14, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x42, 0x75, 0x79, 0x4f, 0x72, 0x53, 0x65, 0x6c, + 0x6c, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x28, 0x0a, 0x12, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, + 0x47, 0x6f, 0x74, 0x6f, 0x43, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x63, + 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x22, + 0x35, 0x0a, 0x13, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x47, 0x6f, 0x74, 0x6f, 0x43, 0x69, + 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -240,24 +350,27 @@ func file_caravan_caravan_msg_proto_rawDescGZIP() []byte { return file_caravan_caravan_msg_proto_rawDescData } -var file_caravan_caravan_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_caravan_caravan_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_caravan_caravan_msg_proto_goTypes = []interface{}{ (*CaravanGetListReq)(nil), // 0: CaravanGetListReq (*CaravanGetListResp)(nil), // 1: CaravanGetListResp (*CaravanBuyOrSellReq)(nil), // 2: CaravanBuyOrSellReq (*CaravanBuyOrSellResp)(nil), // 3: CaravanBuyOrSellResp - nil, // 4: CaravanBuyOrSellReq.ItemsEntry - (*DBCaravan)(nil), // 5: DBCaravan + (*CaravanGotoCityReq)(nil), // 4: CaravanGotoCityReq + (*CaravanGotoCityResp)(nil), // 5: CaravanGotoCityResp + nil, // 6: CaravanBuyOrSellReq.ItemsEntry + (*DBCaravan)(nil), // 7: DBCaravan } var file_caravan_caravan_msg_proto_depIdxs = []int32{ - 5, // 0: CaravanGetListResp.data:type_name -> DBCaravan - 4, // 1: CaravanBuyOrSellReq.items:type_name -> CaravanBuyOrSellReq.ItemsEntry - 5, // 2: CaravanBuyOrSellResp.data:type_name -> DBCaravan - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 7, // 0: CaravanGetListResp.data:type_name -> DBCaravan + 6, // 1: CaravanBuyOrSellReq.items:type_name -> CaravanBuyOrSellReq.ItemsEntry + 7, // 2: CaravanBuyOrSellResp.data:type_name -> DBCaravan + 7, // 3: CaravanGotoCityResp.data:type_name -> DBCaravan + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_caravan_caravan_msg_proto_init() } @@ -315,6 +428,30 @@ func file_caravan_caravan_msg_proto_init() { return nil } } + file_caravan_caravan_msg_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CaravanGotoCityReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_caravan_caravan_msg_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CaravanGotoCityResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -322,7 +459,7 @@ func file_caravan_caravan_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_caravan_caravan_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 7, NumExtensions: 0, NumServices: 0, },