Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into meixiongfeng
This commit is contained in:
commit
0eb8fa425d
@ -44,7 +44,7 @@ func (this *apiComp) SellItem(session comm.IUserSession, req *pb.ItemsSellItemRe
|
||||
this.module.Errorf("SellItemCheck over all amount:[%d:%d]", req.Amount, item.Amount)
|
||||
return
|
||||
}
|
||||
sale = make([]*cfg.Gameatn, len(itemcf.DecomposeDeplete))
|
||||
sale = make([]*cfg.Gameatn, len(itemcf.Sale))
|
||||
for i, v := range itemcf.Sale {
|
||||
temp := *v
|
||||
sale[i] = &temp
|
||||
|
81
modules/items/api_sellinbulk.go
Normal file
81
modules/items/api_sellinbulk.go
Normal file
@ -0,0 +1,81 @@
|
||||
package items
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) SellinbulkCheck(session comm.IUserSession, req *pb.ItemsSellinbulkReq) (code pb.ErrorCode) {
|
||||
if req.Grids == nil || req.Amount == nil || len(req.Grids) != len(req.Amount) {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//批量出售
|
||||
func (this *apiComp) Sellinbulk(session comm.IUserSession, req *pb.ItemsSellinbulkReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
err error
|
||||
items []*pb.DB_UserItemData
|
||||
cids []string
|
||||
itemcf []*cfg.GameItemData
|
||||
issucc []bool
|
||||
sale []*cfg.Gameatn
|
||||
)
|
||||
if code = this.SellinbulkCheck(session, req); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
if items, err = this.module.modelItems.QueryUserPackByGridIds(session.GetUserId(), req.Grids); err != nil {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
cids = make([]string, len(items))
|
||||
for i, v := range items {
|
||||
cids[i] = v.ItemId
|
||||
}
|
||||
if itemcf, err = this.module.configure.GetItemConfigures(cids); err != nil {
|
||||
code = pb.ErrorCode_ConfigurationException
|
||||
return
|
||||
}
|
||||
issucc = make([]bool, len(items))
|
||||
for i, v := range itemcf {
|
||||
issucc[i] = true
|
||||
if v.Sale == nil || len(v.Sale) == 0 {
|
||||
issucc[i] = false
|
||||
this.module.Errorf("Sellinbulk Sale is nill id:%s", v.Id)
|
||||
continue
|
||||
}
|
||||
if req.Amount[i] > items[i].Amount {
|
||||
issucc[i] = false
|
||||
this.module.Errorf("Sellinbulk over all amount:[%d:%d]", req.Amount[i], items[i].Amount)
|
||||
continue
|
||||
}
|
||||
sale = make([]*cfg.Gameatn, len(v.Sale))
|
||||
for i, v := range v.Sale {
|
||||
temp := *v
|
||||
sale[i] = &temp
|
||||
sale[i].N = v.N * int32(req.Amount[i])
|
||||
}
|
||||
items[i].Amount = items[i].Amount - req.Amount[i]
|
||||
}
|
||||
|
||||
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
||||
if err = this.module.modelItems.UpdateUserPack(session.GetUserId(), items...); err != nil {
|
||||
this.module.Errorln(err)
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
if err = this.module.itemsChangePush(session, items); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellinbulkResp{Grids: req.Grids, Amount: req.Amount, Issucc: issucc})
|
||||
return
|
||||
}
|
@ -83,6 +83,28 @@ func (this *ConfigureComp) GetItemConfigure(id string) (item *cfg.GameItemData,
|
||||
return
|
||||
}
|
||||
|
||||
//读取物品配置
|
||||
func (this *ConfigureComp) GetItemConfigures(ids []string) (item []*cfg.GameItemData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = this.GetConfigure(game_item); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
} else {
|
||||
item = make([]*cfg.GameItemData, len(ids))
|
||||
for i, v1 := range ids {
|
||||
if item[i], ok = v.(*cfg.GameItem).GetDataMap()[v1]; !ok {
|
||||
err = fmt.Errorf("no found item:%s configure", v1)
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//获取指定类型的物品列表
|
||||
func (this *ConfigureComp) GetPackItemByType(itmes []*pb.DB_UserItemData, bagtype int32) (result []*pb.DB_UserItemData) {
|
||||
result = make([]*pb.DB_UserItemData, 0, len(itmes))
|
||||
|
@ -81,6 +81,30 @@ func (this *ModelItemsComp) QueryUserPackByGridId(uId string, grid string) (itme
|
||||
return
|
||||
}
|
||||
|
||||
///查询用户指定格子的物品数据
|
||||
func (this *ModelItemsComp) QueryUserPackByGridIds(uId string, grids []string) (itme []*pb.DB_UserItemData, err error) {
|
||||
var (
|
||||
model *db.DBModel
|
||||
)
|
||||
|
||||
itme = make([]*pb.DB_UserItemData, len(grids))
|
||||
if this.module.IsCross() {
|
||||
if model, err = this.module.GetDBModuleByUid(uId, this.TableName, this.Expired); err != nil {
|
||||
this.module.Errorln(err)
|
||||
} else {
|
||||
if err = model.GetListObjs(uId, grids, &itme); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err = this.GetListObjs(uId, grids, &itme); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//更新用户的背包信息
|
||||
func (this *ModelItemsComp) AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) {
|
||||
data := make(map[string]*pb.DB_UserItemData)
|
||||
|
@ -49,11 +49,19 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
|
||||
return
|
||||
}
|
||||
|
||||
//初始体力
|
||||
var ps int32
|
||||
gpd := this.module.configure.GetPlayerlvConf(self.Lv)
|
||||
if gpd != nil {
|
||||
ps = gpd.PsCeiling
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
"name": req.NickName, //设置昵称
|
||||
"created": true, //创角标识
|
||||
"figure": req.Figure, //设置形象
|
||||
"gender": req.Gender, //设置性别
|
||||
"ps": ps, //设置初始体力
|
||||
}
|
||||
|
||||
globalConf := this.module.globalConf
|
||||
|
@ -660,6 +660,126 @@ func (x *ItemsBuyPhysicalResp) GetAsets() []*UserAssets {
|
||||
return nil
|
||||
}
|
||||
|
||||
//批量出售接口
|
||||
type ItemsSellinbulkReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Grids []string `protobuf:"bytes,1,rep,name=grids,proto3" json:"grids"` //格子Id
|
||||
Amount []uint32 `protobuf:"varint,2,rep,packed,name=amount,proto3" json:"amount"` //出售数量
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkReq) Reset() {
|
||||
*x = ItemsSellinbulkReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_items_items_msg_proto_msgTypes[11]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ItemsSellinbulkReq) ProtoMessage() {}
|
||||
|
||||
func (x *ItemsSellinbulkReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_items_items_msg_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 ItemsSellinbulkReq.ProtoReflect.Descriptor instead.
|
||||
func (*ItemsSellinbulkReq) Descriptor() ([]byte, []int) {
|
||||
return file_items_items_msg_proto_rawDescGZIP(), []int{11}
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkReq) GetGrids() []string {
|
||||
if x != nil {
|
||||
return x.Grids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkReq) GetAmount() []uint32 {
|
||||
if x != nil {
|
||||
return x.Amount
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//批量出售接口
|
||||
type ItemsSellinbulkResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Grids []string `protobuf:"bytes,1,rep,name=grids,proto3" json:"grids"` //格子Id
|
||||
Amount []uint32 `protobuf:"varint,2,rep,packed,name=amount,proto3" json:"amount"` //出售数量
|
||||
Issucc []bool `protobuf:"varint,3,rep,packed,name=issucc,proto3" json:"issucc"` //是否成功
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkResp) Reset() {
|
||||
*x = ItemsSellinbulkResp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_items_items_msg_proto_msgTypes[12]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ItemsSellinbulkResp) ProtoMessage() {}
|
||||
|
||||
func (x *ItemsSellinbulkResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_items_items_msg_proto_msgTypes[12]
|
||||
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 ItemsSellinbulkResp.ProtoReflect.Descriptor instead.
|
||||
func (*ItemsSellinbulkResp) Descriptor() ([]byte, []int) {
|
||||
return file_items_items_msg_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkResp) GetGrids() []string {
|
||||
if x != nil {
|
||||
return x.Grids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkResp) GetAmount() []uint32 {
|
||||
if x != nil {
|
||||
return x.Amount
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ItemsSellinbulkResp) GetIssucc() []bool {
|
||||
if x != nil {
|
||||
return x.Issucc
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_items_items_msg_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_items_items_msg_proto_rawDesc = []byte{
|
||||
@ -721,8 +841,18 @@ var file_items_items_msg_proto_rawDesc = []byte{
|
||||
0x75, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x50, 0x68, 0x79,
|
||||
0x73, 0x69, 0x63, 0x61, 0x6c, 0x42, 0x75, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x21, 0x0a, 0x05, 0x61,
|
||||
0x73, 0x65, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, 0x65,
|
||||
0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x05, 0x61, 0x73, 0x65, 0x74, 0x73, 0x42, 0x06,
|
||||
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x05, 0x61, 0x73, 0x65, 0x74, 0x73, 0x22, 0x42,
|
||||
0x0a, 0x12, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x53, 0x65, 0x6c, 0x6c, 0x69, 0x6e, 0x62, 0x75, 0x6c,
|
||||
0x6b, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20,
|
||||
0x03, 0x28, 0x09, 0x52, 0x05, 0x67, 0x72, 0x69, 0x64, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d,
|
||||
0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75,
|
||||
0x6e, 0x74, 0x22, 0x5b, 0x0a, 0x13, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x53, 0x65, 0x6c, 0x6c, 0x69,
|
||||
0x6e, 0x62, 0x75, 0x6c, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x69,
|
||||
0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x67, 0x72, 0x69, 0x64, 0x73, 0x12,
|
||||
0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x52,
|
||||
0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63,
|
||||
0x63, 0x18, 0x03, 0x20, 0x03, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x42,
|
||||
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -737,7 +867,7 @@ func file_items_items_msg_proto_rawDescGZIP() []byte {
|
||||
return file_items_items_msg_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_items_items_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
||||
var file_items_items_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 13)
|
||||
var file_items_items_msg_proto_goTypes = []interface{}{
|
||||
(*ItemsGetlistReq)(nil), // 0: ItemsGetlistReq
|
||||
(*ItemsGetlistResp)(nil), // 1: ItemsGetlistResp
|
||||
@ -750,13 +880,15 @@ var file_items_items_msg_proto_goTypes = []interface{}{
|
||||
(*ItemsDecomposeResp)(nil), // 8: ItemsDecomposeResp
|
||||
(*ItemsBuyPhysicalReq)(nil), // 9: ItemsBuyPhysicalReq
|
||||
(*ItemsBuyPhysicalResp)(nil), // 10: ItemsBuyPhysicalResp
|
||||
(*DB_UserItemData)(nil), // 11: DB_UserItemData
|
||||
(*UserAssets)(nil), // 12: UserAssets
|
||||
(*ItemsSellinbulkReq)(nil), // 11: ItemsSellinbulkReq
|
||||
(*ItemsSellinbulkResp)(nil), // 12: ItemsSellinbulkResp
|
||||
(*DB_UserItemData)(nil), // 13: DB_UserItemData
|
||||
(*UserAssets)(nil), // 14: UserAssets
|
||||
}
|
||||
var file_items_items_msg_proto_depIdxs = []int32{
|
||||
11, // 0: ItemsGetlistResp.Grids:type_name -> DB_UserItemData
|
||||
11, // 1: ItemsChangePush.Grids:type_name -> DB_UserItemData
|
||||
12, // 2: ItemsBuyPhysicalResp.asets:type_name -> UserAssets
|
||||
13, // 0: ItemsGetlistResp.Grids:type_name -> DB_UserItemData
|
||||
13, // 1: ItemsChangePush.Grids:type_name -> DB_UserItemData
|
||||
14, // 2: ItemsBuyPhysicalResp.asets:type_name -> UserAssets
|
||||
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
|
||||
@ -904,6 +1036,30 @@ func file_items_items_msg_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_items_items_msg_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ItemsSellinbulkReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_items_items_msg_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ItemsSellinbulkResp); 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{
|
||||
@ -911,7 +1067,7 @@ func file_items_items_msg_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_items_items_msg_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 11,
|
||||
NumMessages: 13,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user