This commit is contained in:
liwei1dao 2022-11-02 18:37:50 +08:00
commit 505b1f3e34
3 changed files with 41 additions and 30 deletions

View File

@ -1,9 +1,11 @@
package troll
import (
"crypto/rand"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"math/big"
"time"
"google.golang.org/protobuf/proto"
@ -67,12 +69,19 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq)
session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain})
return
}
trainNum := this.configure.GetTrollMaxTraintNum()
trolltrain.Shop = make(map[int32]int32) // 清空商人的购买数据
update["shop"] = trolltrain.Shop
circleCount = (int32(t) / circletime) // 经过的周期数
if circleCount > 1 {
trolltrain.Circle += circleCount
n, _ := rand.Int(rand.Reader, big.NewInt(int64(trainNum)))
n2, _ := rand.Int(rand.Reader, big.NewInt(int64(maxCoefficient)))
trolltrain.SurpriseID[int32(n.Int64())+1] = int32(n2.Int64()) + 1
}
leftTime = (int32(t) % circletime)
// 循环次数
trainNum := this.configure.GetTrollMaxTraintNum()
index += circleCount * trainNum // 计算火车的位置信息
for _, v := range sz {
if leftTime <= v {

View File

@ -48,6 +48,8 @@ func (this *modelTroll) getTrollList(uid string) (result *pb.DBTrollTrain, err e
AiCount: 0,
Shop: map[int32]int32{},
Ctime: time.Now().Unix(),
Circle: 0,
SurpriseID: map[int32]int32{},
}
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {
// 创建一条数据

View File

@ -43,8 +43,8 @@ type DBTrollTrain struct {
AiCount int32 `protobuf:"varint,15,opt,name=aiCount,proto3" json:"aiCount"` //@go_tags(`bson:"aiCount"` AI 交易次数
Shop map[int32]int32 `protobuf:"bytes,16,rep,name=shop,proto3" json:"shop" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 商人的限购数量
Ctime int64 `protobuf:"varint,17,opt,name=ctime,proto3" json:"ctime"`
Surprise map[int32]int32 `protobuf:"bytes,18,rep,name=surprise,proto3" json:"surprise" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 惊喜
SurpriseID int32 `protobuf:"varint,19,opt,name=surpriseID,proto3" json:"surpriseID"` // 惊喜ID
Circle int32 `protobuf:"varint,18,opt,name=circle,proto3" json:"circle"` // 循环商人的次数
SurpriseID map[int32]int32 `protobuf:"bytes,19,rep,name=surpriseID,proto3" json:"surpriseID" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //key商人id value惊喜货物ID
}
func (x *DBTrollTrain) Reset() {
@ -198,18 +198,18 @@ func (x *DBTrollTrain) GetCtime() int64 {
return 0
}
func (x *DBTrollTrain) GetSurprise() map[int32]int32 {
func (x *DBTrollTrain) GetCircle() int32 {
if x != nil {
return x.Surprise
return x.Circle
}
return nil
return 0
}
func (x *DBTrollTrain) GetSurpriseID() int32 {
func (x *DBTrollTrain) GetSurpriseID() map[int32]int32 {
if x != nil {
return x.SurpriseID
}
return 0
return nil
}
var File_troll_troll_db_proto protoreflect.FileDescriptor
@ -249,28 +249,28 @@ var file_troll_troll_db_proto_rawDesc = []byte{
0x70, 0x18, 0x10, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c,
0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x68, 0x6f, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79,
0x52, 0x04, 0x73, 0x68, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18,
0x11, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x37, 0x0a, 0x08,
0x73, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b,
0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x75,
0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x73, 0x75, 0x72,
0x70, 0x72, 0x69, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73,
0x65, 0x49, 0x44, 0x18, 0x13, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72,
0x69, 0x73, 0x65, 0x49, 0x44, 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, 0x1a,
0x38, 0x0a, 0x0a, 0x50, 0x72, 0x69, 0x63, 0x65, 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, 0x1a, 0x3c, 0x0a, 0x0e, 0x4e, 0x70, 0x63,
0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x11, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x63, 0x69,
0x72, 0x63, 0x6c, 0x65, 0x12, 0x3d, 0x0a, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65,
0x49, 0x44, 0x18, 0x13, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f,
0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65,
0x49, 0x44, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73,
0x65, 0x49, 0x44, 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, 0x1a, 0x38, 0x0a,
0x0a, 0x50, 0x72, 0x69, 0x63, 0x65, 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, 0x1a, 0x37, 0x0a, 0x09, 0x53, 0x68, 0x6f, 0x70, 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,
0x1a, 0x3b, 0x0a, 0x0d, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x45, 0x6e, 0x74, 0x72,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3c, 0x0a, 0x0e, 0x4e, 0x70, 0x63, 0x52, 0x65,
0x77, 0x61, 0x72, 0x64, 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, 0x1a, 0x37, 0x0a, 0x09, 0x53, 0x68, 0x6f, 0x70, 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, 0x1a, 0x3d,
0x0a, 0x0f, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 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, 0x42, 0x06, 0x5a,
@ -296,14 +296,14 @@ var file_troll_troll_db_proto_goTypes = []interface{}{
nil, // 2: DBTrollTrain.PriceEntry
nil, // 3: DBTrollTrain.NpcRewardEntry
nil, // 4: DBTrollTrain.ShopEntry
nil, // 5: DBTrollTrain.SurpriseEntry
nil, // 5: DBTrollTrain.SurpriseIDEntry
}
var file_troll_troll_db_proto_depIdxs = []int32{
1, // 0: DBTrollTrain.items:type_name -> DBTrollTrain.ItemsEntry
2, // 1: DBTrollTrain.price:type_name -> DBTrollTrain.PriceEntry
3, // 2: DBTrollTrain.npcReward:type_name -> DBTrollTrain.NpcRewardEntry
4, // 3: DBTrollTrain.shop:type_name -> DBTrollTrain.ShopEntry
5, // 4: DBTrollTrain.surprise:type_name -> DBTrollTrain.SurpriseEntry
5, // 4: DBTrollTrain.surpriseID:type_name -> DBTrollTrain.SurpriseIDEntry
5, // [5:5] is the sub-list for method output_type
5, // [5:5] is the sub-list for method input_type
5, // [5:5] is the sub-list for extension type_name