跑商数据初始化+协议优化

This commit is contained in:
meixiongfeng 2023-05-12 20:49:40 +08:00
parent ef4f779ef2
commit dbdc0f17ae
4 changed files with 55 additions and 36 deletions

View File

@ -23,6 +23,13 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe
code = pb.ErrorCode_DBError
return
}
if list.Id == "" { // 初始化门票和虚拟币
if code = this.module.InitCaravanTicket(session, 1); code != pb.ErrorCode_Success {
return
}
}
resp.Data = list
session.SendMsg(string(this.module.GetType()), "getlist", resp)
return

View File

@ -31,25 +31,21 @@ func (this *modelCaravan) Init(service core.IService, module core.IModule, comp
func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err error) {
result = &pb.DBCaravan{
Id: primitive.NewObjectID().Hex(),
Id: "",
Uid: uid,
UseCount: 0,
Items: map[int32]*pb.BagInfo{},
Goods: map[int32]*pb.Goods{},
City: map[int32]*pb.CityInfo{},
Lv: 0,
Num: 0,
Profit: 0,
Resettime: 0,
Curcity: 0,
Task: 0,
Eventid: 0,
Tasktime: 0,
}
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {
// 创建一条数据
result.Id = primitive.NewObjectID().Hex()
result.Resettime = configure.Now().Unix() // 设置起始刷新时间
result.Lv = 1
if conf := this.module.configure.GetCaravanLv(1); conf != nil {
result.Baglimit = conf.Bagtop
}
this.module.InitCaravanCityData(uid, result) // 初始1级
this.module.InitCaravanItemData(uid, result)
err = this.Add(uid, result)

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
)
@ -66,14 +67,7 @@ func (this *Caravan) InitCaravanCityData(uid string, data *pb.DBCaravan) {
city.Like = append(city.Like, v.Special...)
}
if len(v.Exspecial) > int(v.Exspecialnum) {
ids := utils.RandomNumbers(0, len(v.Exspecial), int(v.Exspecialnum))
for _, id := range ids {
city.Like = append(city.Like, v.Exspecial[id])
}
} else {
city.Unlike = append(city.Like, v.Exspecial...)
}
data.City[v.Id] = city
}
@ -97,3 +91,15 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) {
}
}
}
// 初始化门票和虚拟币
func (this *Caravan) InitCaravanTicket(session comm.IUserSession, lv int32) (code pb.ErrorCode) {
code = pb.ErrorCode_ConfigNoFound
if conf := this.modelCaravan.module.configure.GetCaravanLv(lv); conf != nil {
var res []*cfg.Gameatn
res = append(res, conf.Tickettop)
res = append(res, conf.Moneynumtop)
code = this.DispenseRes(session, res, true) // 推送门票和虚拟币资源
}
return
}

View File

@ -228,6 +228,7 @@ type DBCaravan struct {
Task int32 `protobuf:"varint,12,opt,name=task,proto3" json:"task"`
Eventid int32 `protobuf:"varint,13,opt,name=eventid,proto3" json:"eventid"` // 特殊事件ID
Tasktime int32 `protobuf:"varint,14,opt,name=tasktime,proto3" json:"tasktime"` // 任务触发时间
Baglimit int32 `protobuf:"varint,15,opt,name=baglimit,proto3" json:"baglimit"` // 背包上限
}
func (x *DBCaravan) Reset() {
@ -360,6 +361,13 @@ func (x *DBCaravan) GetTasktime() int32 {
return 0
}
func (x *DBCaravan) GetBaglimit() int32 {
if x != nil {
return x.Baglimit
}
return 0
}
var File_caravan_caravan_db_proto protoreflect.FileDescriptor
var file_caravan_caravan_db_proto_rawDesc = []byte{
@ -384,7 +392,7 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{
0x38, 0x01, 0x22, 0x35, 0x0a, 0x07, 0x42, 0x61, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a,
0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f,
0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x05, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0xd3, 0x04, 0x0a, 0x09, 0x44, 0x42,
0x28, 0x05, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0xef, 0x04, 0x0a, 0x09, 0x44, 0x42,
0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65,
@ -409,20 +417,22 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{
0x18, 0x0a, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x05,
0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x73,
0x6b, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x73,
0x6b, 0x74, 0x69, 0x6d, 0x65, 0x1a, 0x42, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e,
0x6b, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, 0x67, 0x6c, 0x69, 0x6d, 0x69,
0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x62, 0x61, 0x67, 0x6c, 0x69, 0x6d, 0x69,
0x74, 0x1a, 0x42, 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, 0x1e, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x08, 0x2e, 0x42, 0x61, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, 0x0a, 0x47, 0x6f, 0x6f, 0x64, 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, 0x1e, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, 0x0a, 0x47, 0x6f, 0x6f,
0x64, 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, 0x1c, 0x0a, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x09, 0x43,
0x69, 0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x43, 0x69, 0x74, 0x79,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x09, 0x43, 0x69, 0x74, 0x79, 0x45,
0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x43, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e,
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (