From 6f8a8e38310b7158502aae4d6a259f3315bd497d Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 28 Oct 2022 20:01:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A8=E5=85=BD=E5=95=86=E9=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/pagoda/api_getlist.go | 46 ------------- modules/pagoda/pagoda_test.go | 47 ++++---------- modules/troll/api.go | 1 + modules/troll/api_buyorsell.go | 111 ++++++++++++++++++++++++++++++++ modules/troll/api_getlist.go | 11 +--- modules/troll/comp_configure.go | 90 +++++++++++++++----------- modules/troll/model_gourmet.go | 26 +++++++- modules/troll/module.go | 41 ++++++++++++ modules/viking/model_viking.go | 2 +- pb/troll_db.pb.go | 111 +++++++++++++++++++++----------- services/worker/main.go | 2 + 11 files changed, 323 insertions(+), 165 deletions(-) create mode 100644 modules/troll/api_buyorsell.go diff --git a/modules/pagoda/api_getlist.go b/modules/pagoda/api_getlist.go index 95b326918..1009e57b0 100644 --- a/modules/pagoda/api_getlist.go +++ b/modules/pagoda/api_getlist.go @@ -1,13 +1,10 @@ package pagoda import ( - "context" "go_dreamfactory/comm" - "go_dreamfactory/lego/sys/redis/pipe" "go_dreamfactory/pb" "go_dreamfactory/sys/db" - "github.com/go-redis/redis/v8" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" @@ -15,50 +12,7 @@ import ( //参数校验 func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.PagodaGetListReq) (code pb.ErrorCode) { - uid := session.GetUserId() - if !this.module.IsCross() { - if conn, err := db.Cross(); err == nil { - //userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) - // newData := &pb.DBPagodaRecord{ - // Id: primitive.NewObjectID().Hex(), - // Uid: session.GetUserId(), - // PagodaId: 111, - // Type: 201, - // Nickname: userinfo.Name, - // Icon: "", // icon 暂无 - // Lv: userinfo.Lv, - // CostTime: 1002, - // } - //conn.Mgo.InsertOne(comm.TablePagodaRecord, newData) - var ( - pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO()) - menbers *redis.Z - ) - - menbers = &redis.Z{Score: float64(500), Member: uid} - - if cmd := pipe.ZAdd("pagodaList", menbers); cmd != nil { - this.module.Errorln(err) - - dock, err1 := cmd.Result() - this.module.Errorln(dock, err1) - } - if _, err = pipe.Exec(); err != nil { - this.module.Errorln(err) - return - } - //rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567") - rd := pipe.ZRange("pagodaList", 1, 5) - if _, err = pipe.Exec(); err != nil { - this.module.Errorln(err) - return - } - _data3 := rd.Val() - _data, err2 := rd.Result() - this.module.Errorln(_data, err2, _data3) - } - } return } diff --git a/modules/pagoda/pagoda_test.go b/modules/pagoda/pagoda_test.go index 36d9b2d01..24af1d03d 100644 --- a/modules/pagoda/pagoda_test.go +++ b/modules/pagoda/pagoda_test.go @@ -118,7 +118,17 @@ func TestXxx(t *testing.T) { // menbers[i] = &redis.Z{Score: float64(i), Member: uid} // } - // if cmd := pipe.ZAdd("pagodaList", menbers...); cmd != nil { + // uid := session.GetUserId() + // if !this.module.IsCross() { + // if conn, err := db.Cross(); err == nil { + // var ( + // pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO()) + // menbers *redis.Z + // ) + + // menbers = &redis.Z{Score: float64(500), Member: uid} + + // if cmd := pipe.ZAdd("pagodaList", menbers); cmd != nil { // this.module.Errorln(err) // dock, err1 := cmd.Result() @@ -128,8 +138,8 @@ func TestXxx(t *testing.T) { // this.module.Errorln(err) // return // } - // rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567") - // //rd := pipe.ZRange("pagodaList", 1, 5) + // //rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567") + // rd := pipe.ZRange("pagodaList", 1, 5) // if _, err = pipe.Exec(); err != nil { // this.module.Errorln(err) // return @@ -139,35 +149,4 @@ func TestXxx(t *testing.T) { // this.module.Errorln(_data, err2, _data3) // } // } - - // if !this.module.IsCross() { - // if conn, err := db.Cross(); err == nil { - // userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) - // newData := &pb.DBPagodaRecord{ - // Id: primitive.NewObjectID().Hex(), - // Uid: session.GetUserId(), - // PagodaId: 100, - // Type: 201, - // Nickname: userinfo.Name, - // Icon: "", // icon 暂无 - // Lv: userinfo.Lv, - // CostTime: 1001, - // } - // menbers := make([]*redis.Z, 2) - - // menbers[0] = &redis.Z{Score: float64(123), Member: "dfmxf_001"} - // menbers[1] = &redis.Z{Score: float64(13), Member: "dfmxf_002"} - // pipe := conn.Redis.RedisPipe(context.TODO()) - // if cmd := pipe.ZAdd("ranklist", menbers...); err != nil { - // this.module.Errorln(err) - // } else { - // if _, err = cmd.Result(); err != nil { - // this.module.Errorln(err) - // return - // } - // } - - // conn.Mgo.InsertOne(comm.TablePagodaRecord, newData) - // } - // } } diff --git a/modules/troll/api.go b/modules/troll/api.go index fdaa51db2..1c4c0891d 100644 --- a/modules/troll/api.go +++ b/modules/troll/api.go @@ -7,6 +7,7 @@ import ( const ( TrollGetListResp = "getlist" + TrollBuyOrSellResp = "buyorsell" GourmetCreateOrderResp = "createorder" GourmetSkillLvResp = "skilllv" TrollNpcRewardResp = "npcreward" diff --git a/modules/troll/api_buyorsell.go b/modules/troll/api_buyorsell.go new file mode 100644 index 000000000..898523a26 --- /dev/null +++ b/modules/troll/api_buyorsell.go @@ -0,0 +1,111 @@ +package troll + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + "strconv" + "time" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) BuyOrSellCheck(session comm.IUserSession, req *pb.TrollBuyOrSellReq) (code pb.ErrorCode) { + if len(req.Items) == 0 { + code = pb.ErrorCode_ReqParameterError + } + return +} + +///获取美食城基本信息 +func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSellReq) (code pb.ErrorCode, data proto.Message) { + + var ( + //bSell bool // 是否有出售 + gold int32 // 当次交易 获得的金币 + earn int32 // 只统计赚的金币 + update map[string]interface{} + ) + update = make(map[string]interface{}) + if code = this.BuyOrSellCheck(session, req); code != pb.ErrorCode_Success { + return // 参数校验失败直接返回 + } + trolltrain, err := this.module.modelTroll.getTrollList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_DBError + return + } + + for k, v := range req.Items { + if v < 0 { + //bSell = true + trolltrain.SellCount += 1 // 交易次数+1 + } + trolltrain.Items[k] += v + // 校验 是否大于买入最大限制 + goods := this.configure.GetTrollGoods(k) + if goods == nil { + return + } + if goods.Max < trolltrain.Items[k] { // 判断是否有效交易 + // TODO 买入上限 直接返回 + //code = pb.ErrorCode_ + return + } else if trolltrain.Items[k] < 0 { + // TODO 卖出数量不足 直接返回 + return + } + + // 第一次购买商品 + if trolltrain.TarinPos == 0 { + trolltrain.Price[k] = goods.Goodsprice * goods.StarMoney / 1000 + trolltrain.RefreshTime = time.Now().Unix() + //消耗的金币 + gold = trolltrain.Price[k] * trolltrain.Items[k] + } else { + p := this.configure.GetTrollCoefficient(trolltrain.TarinPos) + if p == nil { + return + } + if v < 0 { // 卖出 + // 卖出价格 + var sellPrice int32 + if trolltrain.TarinPos == 0 { + sellPrice = goods.Goodsprice * goods.StarMoney / 1000 + } else { + + num, _ := strconv.Atoi(p.Coefficient) + sellPrice = int32(num) * goods.Goodsprice / 1000 + } + if sellPrice > trolltrain.Price[k] { // 赚了 + earn += (sellPrice - trolltrain.Price[k]) * trolltrain.Items[k] + } + gold += (sellPrice - trolltrain.Price[k]) * trolltrain.Items[k] + } else { // 买入 计算平均价格 + totalGold := trolltrain.Items[k] * trolltrain.Price[k] + num, _ := strconv.Atoi(p.Coefficient) + sellPrice := int32(num) * goods.Goodsprice / 1000 + totalGold += v * goods.Goodsprice * sellPrice + trolltrain.Price[k] = totalGold / (trolltrain.Items[k] + v) + } + } + if gold < 0 { + if code = this.module.CheckRes(session, []*cfg.Gameatn{&cfg.Gameatn{ + A: "attr", + T: "gold", + N: earn, + }}); code != pb.ErrorCode_Success { + return + } + } + } + + trolltrain.TotalEarn += int64(earn) // 累计获得的金币 + update["items"] = trolltrain.Items + update["price"] = trolltrain.Price + update["totalEarn"] = trolltrain.TotalEarn + this.module.ModifyTrollData(session.GetUserId(), update) + session.SendMsg(string(this.module.GetType()), TrollBuyOrSellResp, &pb.TrollBuyOrSellResp{Data: trolltrain}) + return +} diff --git a/modules/troll/api_getlist.go b/modules/troll/api_getlist.go index d8bed52e4..7819f87f7 100644 --- a/modules/troll/api_getlist.go +++ b/modules/troll/api_getlist.go @@ -3,7 +3,6 @@ package troll import ( "go_dreamfactory/comm" "go_dreamfactory/pb" - "time" "google.golang.org/protobuf/proto" ) @@ -17,19 +16,15 @@ func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.TrollGetLis ///获取美食城基本信息 func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) (code pb.ErrorCode, data proto.Message) { - code = this.GetListCheck(session, req) - if code != pb.ErrorCode_Success { + if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - _gourmet, err := this.module.modelTroll.getTrollList(session.GetUserId()) + trolltrain, err := this.module.modelTroll.getTrollList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } - if _gourmet.Ctime == 0 { - _gourmet.Ctime = time.Now().Unix() - } - session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: _gourmet}) + session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) return } diff --git a/modules/troll/comp_configure.go b/modules/troll/comp_configure.go index fc6543feb..260f2cde5 100644 --- a/modules/troll/comp_configure.go +++ b/modules/troll/comp_configure.go @@ -10,46 +10,29 @@ import ( ) const ( - game_gourmet = "game_gourmet.json" - game_gourmetskill = "game_gourmetskill.json" + game_trollgoods = "game_trollgoods.json" + game_trollcoefficient = "game_trollcoefficient.json" + game_trolltrain = "game_trolltrain.json" + game_trollrule = "game_trollrule.json" ) ///配置管理基础组件 type configureComp struct { hlock sync.RWMutex modules.MCompConfigure - _gourmetMap map[int64]*cfg.GameGourmetData } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompConfigure.Init(service, module, comp, options) - - this._gourmetMap = make(map[int64]*cfg.GameGourmetData, 0) - configure.RegisterConfigure(game_gourmet, cfg.NewGameGourmet, func() { - if v, err := this.GetConfigure(game_gourmet); err == nil { - if configure, ok := v.(*cfg.GameGourmet); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._gourmetMap[int64(value.Type<<16)+int64(value.Level)] = value - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) + this.LoadConfigure(game_trollgoods, cfg.NewGameTrollGoods) + this.LoadConfigure(game_trollcoefficient, cfg.NewGameTrollCoefficient) + this.LoadConfigure(game_trolltrain, cfg.NewGameTrollTrain) + this.LoadConfigure(game_trollrule, cfg.NewGameTrollRule) return } -// 获取美食馆配置数据 -func (this *configureComp) GetGourmetConfigData(gourmetType int32, level int32) (data *cfg.GameGourmetData) { - - return this._gourmetMap[int64(gourmetType<<16)+int64(level)] -} - //加载多个配置文件 func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { @@ -66,19 +49,54 @@ func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } -func (this *configureComp) GetGourmetSkillConfigBySkillType(skillType int32) (data []int32) { - data = make([]int32, 0) - if v, err := this.GetConfigure(game_gourmet); err == nil { - if configure, ok := v.(*cfg.GameGourmet); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - if value.SkillType == skillType && value.Initial == 1 { - data = append(data, value.Type) - } - } + +// 获取列车货物信息 +func (this *configureComp) GetTrollGoods(itemId int32) (data *cfg.GameTrollGoodsData) { + if v, err := this.GetConfigure(game_trollgoods); err == nil { + if configure, ok := v.(*cfg.GameTrollGoods); ok { + data = configure.Get(itemId) return } + } else { + log.Errorf("get GameTrollGoodsData conf err:%v", err) + } + return +} + +// 获取商人位置信息 +func (this *configureComp) GetTrollTrain(id int32) (data *cfg.GameTrollTrainData) { + if v, err := this.GetConfigure(game_trolltrain); err == nil { + if configure, ok := v.(*cfg.GameTrollTrain); ok { + data = configure.Get(id) + return + } + } else { + log.Errorf("get GameTrollTrainData conf err:%v", err) + } + return +} + +// 获取基本规则 +func (this *configureComp) GetTrollRule(id int32) (data *cfg.GameTrollRuleData) { + if v, err := this.GetConfigure(game_trollrule); err == nil { + if configure, ok := v.(*cfg.GameTrollRule); ok { + data = configure.Get(id) + return + } + } else { + log.Errorf("get GameTrollRuleData conf err:%v", err) + } + return +} + +func (this *configureComp) GetTrollCoefficient(id int32) (data *cfg.GameTrollCoefficientData) { + if v, err := this.GetConfigure(game_trollcoefficient); err == nil { + if configure, ok := v.(*cfg.GameTrollCoefficient); ok { + data = configure.Get(id) + return + } + } else { + log.Errorf("get GameTrollCoefficientData conf err:%v", err) } return } diff --git a/modules/troll/model_gourmet.go b/modules/troll/model_gourmet.go index 606e87a1f..7504ee4d9 100644 --- a/modules/troll/model_gourmet.go +++ b/modules/troll/model_gourmet.go @@ -3,9 +3,12 @@ package troll import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "time" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -27,9 +30,26 @@ func (this *modelTroll) Init(service core.IService, module core.IModule, comp co } func (this *modelTroll) getTrollList(uid string) (result *pb.DBTrollTrain, err error) { - result = &pb.DBTrollTrain{} - if err = this.Get(uid, result); err != nil { - + result = &pb.DBTrollTrain{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Items: map[int32]int32{}, + Price: map[int32]int32{}, + GridNum: 0, + TarinPos: 1, + RangeId: 0, + Buy: 0, + Sell: 0, + NpcLv: 0, + NpcReward: map[int32]int32{}, + TotalEarn: 0, + SellCount: 0, + RefreshTime: time.Now().Unix(), + Ctime: time.Now().Unix(), + } + if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err { + // 创建一条数据 + err = this.Add(uid, result) return } err = nil diff --git a/modules/troll/module.go b/modules/troll/module.go index b799045a3..9cd28229b 100644 --- a/modules/troll/module.go +++ b/modules/troll/module.go @@ -10,6 +10,8 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + "strconv" + "time" ) type Troll struct { @@ -48,3 +50,42 @@ func (this *Troll) ModifyTrollData(uid string, data map[string]interface{}) (cod } return } + +// AI 玩法 +func (this *Troll) TrollAI(uid string, troll *pb.DBTrollTrain) (code pb.ErrorCode) { + if troll.Buy != 0 && troll.Sell != 0 { + return + } + var fTime [3]int32 + for i := 0; i < 3; i++ { + if conf := this.configure.GetTrollTrain(int32(i) + 1); conf != nil { + fTime[i] = conf.Time + } + } + var ( + index int32 + crossTime int32 // 经过的时间 + ) + // 计算时间差 + crossTime = int32(time.Now().Unix() - troll.RefreshTime) + for i := 0; ; i++ { + + index = int32(i) % 3 + if crossTime > fTime[index] { // 获取 + troll.RangeId += 1 + if _d := this.configure.GetTrollCoefficient(troll.RangeId); _d != nil { + num, _ := strconv.Atoi(_d.Coefficient) + if troll.Buy <= int32(num) { // + + } + } + crossTime -= fTime[index] + if crossTime < 0 { + break + } + } + + } + + return +} diff --git a/modules/viking/model_viking.go b/modules/viking/model_viking.go index 6e9270c5b..29c254769 100644 --- a/modules/viking/model_viking.go +++ b/modules/viking/model_viking.go @@ -49,7 +49,7 @@ func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err err result.BossTime[str] = 0 } } - this.module.modelViking.Add(uid, result) + this.Add(uid, result) } err = nil return result, err diff --git a/pb/troll_db.pb.go b/pb/troll_db.pb.go index 165a4e500..998f89a31 100644 --- a/pb/troll_db.pb.go +++ b/pb/troll_db.pb.go @@ -26,18 +26,21 @@ type DBTrollTrain struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID - Items map[int32]int32 `protobuf:"bytes,3,rep,name=items,proto3" json:"items" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物 - GridNum int32 `protobuf:"varint,4,opt,name=gridNum,proto3" json:"gridNum" bson:"gridNum"` //当前使用格子数量 - TarinPos int32 `protobuf:"varint,5,opt,name=tarinPos,proto3" json:"tarinPos" bson:"tarinPos"` //火车位置 - RangeId int32 `protobuf:"varint,6,opt,name=rangeId,proto3" json:"rangeId" bson:"rangeId"` //增长幅度 - Buy int32 `protobuf:"varint,7,opt,name=buy,proto3" json:"buy"` // 挂机进货标准/千分比 - Sell int32 `protobuf:"varint,8,opt,name=sell,proto3" json:"sell"` //挂机卖出标准/千分比 - NpcLv int32 `protobuf:"varint,9,opt,name=npcLv,proto3" json:"npcLv" bson:"npcLv"` //npc 等级 - NpcReward map[int32]int32 `protobuf:"bytes,10,rep,name=npcReward,proto3" json:"npcReward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"npcReward"` //npc奖励 - TotalEarn int64 `protobuf:"varint,11,opt,name=totalEarn,proto3" json:"totalEarn" bson:"totalEarn"` //累计赚的钱 - Ctime int64 `protobuf:"varint,12,opt,name=ctime,proto3" json:"ctime"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + Items map[int32]int32 `protobuf:"bytes,3,rep,name=items,proto3" json:"items" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物 key 货物ID + Price map[int32]int32 `protobuf:"bytes,4,rep,name=price,proto3" json:"price" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物买入价格 key 货物ID + GridNum int32 `protobuf:"varint,5,opt,name=gridNum,proto3" json:"gridNum" bson:"gridNum"` //当前使用格子数量 + TarinPos int32 `protobuf:"varint,6,opt,name=tarinPos,proto3" json:"tarinPos" bson:"tarinPos"` //火车位置 (商人位置) + RangeId int32 `protobuf:"varint,7,opt,name=rangeId,proto3" json:"rangeId" bson:"rangeId"` //增长幅度 + Buy int32 `protobuf:"varint,8,opt,name=buy,proto3" json:"buy"` // 挂机进货标准/千分比 + Sell int32 `protobuf:"varint,9,opt,name=sell,proto3" json:"sell"` //挂机卖出标准/千分比 + NpcLv int32 `protobuf:"varint,10,opt,name=npcLv,proto3" json:"npcLv" bson:"npcLv"` //npc 等级 + NpcReward map[int32]int32 `protobuf:"bytes,11,rep,name=npcReward,proto3" json:"npcReward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"npcReward"` //npc奖励 + TotalEarn int64 `protobuf:"varint,12,opt,name=totalEarn,proto3" json:"totalEarn" bson:"totalEarn"` //累计赚的钱 + SellCount int32 `protobuf:"varint,13,opt,name=sellCount,proto3" json:"sellCount" bson:"sellCount"` //今天已经卖出次数 + RefreshTime int64 `protobuf:"varint,14,opt,name=refreshTime,proto3" json:"refreshTime" bson:"refreshTime"` //最后一次刷新的时间 通过这个计算下一次刷新时间 + Ctime int64 `protobuf:"varint,15,opt,name=ctime,proto3" json:"ctime"` } func (x *DBTrollTrain) Reset() { @@ -93,6 +96,13 @@ func (x *DBTrollTrain) GetItems() map[int32]int32 { return nil } +func (x *DBTrollTrain) GetPrice() map[int32]int32 { + if x != nil { + return x.Price + } + return nil +} + func (x *DBTrollTrain) GetGridNum() int32 { if x != nil { return x.GridNum @@ -149,6 +159,20 @@ func (x *DBTrollTrain) GetTotalEarn() int64 { return 0 } +func (x *DBTrollTrain) GetSellCount() int32 { + if x != nil { + return x.SellCount + } + return 0 +} + +func (x *DBTrollTrain) GetRefreshTime() int64 { + if x != nil { + return x.RefreshTime + } + return 0 +} + func (x *DBTrollTrain) GetCtime() int64 { if x != nil { return x.Ctime @@ -160,37 +184,48 @@ var File_troll_troll_db_proto protoreflect.FileDescriptor var file_troll_troll_db_proto_rawDesc = []byte{ 0x0a, 0x14, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5f, 0x64, 0x62, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd4, 0x03, 0x0a, 0x0c, 0x44, 0x42, 0x54, 0x72, 0x6f, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xfe, 0x04, 0x0a, 0x0c, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 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, 0x2e, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x67, 0x72, 0x69, - 0x64, 0x4e, 0x75, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x67, 0x72, 0x69, 0x64, + 0x72, 0x79, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x2e, 0x0a, 0x05, 0x70, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, + 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x67, 0x72, 0x69, + 0x64, 0x4e, 0x75, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x67, 0x72, 0x69, 0x64, 0x4e, 0x75, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x72, 0x69, 0x6e, 0x50, 0x6f, 0x73, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x72, 0x69, 0x6e, 0x50, 0x6f, 0x73, 0x12, - 0x18, 0x0a, 0x07, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, + 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x72, 0x69, 0x6e, 0x50, 0x6f, 0x73, 0x12, + 0x18, 0x0a, 0x07, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x49, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x75, 0x79, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x75, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x73, - 0x65, 0x6c, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x65, 0x6c, 0x6c, 0x12, - 0x14, 0x0a, 0x05, 0x6e, 0x70, 0x63, 0x4c, 0x76, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x75, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x73, + 0x65, 0x6c, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x65, 0x6c, 0x6c, 0x12, + 0x14, 0x0a, 0x05, 0x6e, 0x70, 0x63, 0x4c, 0x76, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6e, 0x70, 0x63, 0x4c, 0x76, 0x12, 0x3a, 0x0a, 0x09, 0x6e, 0x70, 0x63, 0x52, 0x65, 0x77, 0x61, - 0x72, 0x64, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, + 0x72, 0x64, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x4e, 0x70, 0x63, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, 0x6e, 0x70, 0x63, 0x52, 0x65, 0x77, 0x61, 0x72, - 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x61, 0x72, 0x6e, 0x18, 0x0b, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x61, 0x72, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x45, 0x61, 0x72, 0x6e, 0x12, - 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x1c, 0x0a, 0x09, 0x73, 0x65, 0x6c, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0d, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x09, 0x73, 0x65, 0x6c, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x20, 0x0a, + 0x0b, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x0e, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x0b, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 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, - 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, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 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, + 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, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -205,20 +240,22 @@ func file_troll_troll_db_proto_rawDescGZIP() []byte { return file_troll_troll_db_proto_rawDescData } -var file_troll_troll_db_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_troll_troll_db_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_troll_troll_db_proto_goTypes = []interface{}{ (*DBTrollTrain)(nil), // 0: DBTrollTrain nil, // 1: DBTrollTrain.ItemsEntry - nil, // 2: DBTrollTrain.NpcRewardEntry + nil, // 2: DBTrollTrain.PriceEntry + nil, // 3: DBTrollTrain.NpcRewardEntry } var file_troll_troll_db_proto_depIdxs = []int32{ 1, // 0: DBTrollTrain.items:type_name -> DBTrollTrain.ItemsEntry - 2, // 1: DBTrollTrain.npcReward:type_name -> DBTrollTrain.NpcRewardEntry - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 2, // 1: DBTrollTrain.price:type_name -> DBTrollTrain.PriceEntry + 3, // 2: DBTrollTrain.npcReward:type_name -> DBTrollTrain.NpcRewardEntry + 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 } func init() { file_troll_troll_db_proto_init() } @@ -246,7 +283,7 @@ func file_troll_troll_db_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_troll_troll_db_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 4, NumExtensions: 0, NumServices: 0, }, diff --git a/services/worker/main.go b/services/worker/main.go index d0ba28d69..884e1f979 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -28,6 +28,7 @@ import ( "go_dreamfactory/modules/smithy" "go_dreamfactory/modules/sys" "go_dreamfactory/modules/task" + "go_dreamfactory/modules/troll" "go_dreamfactory/modules/user" "go_dreamfactory/modules/viking" "go_dreamfactory/pb" @@ -90,6 +91,7 @@ func main() { linestory.NewModule(), library.NewModule(), arena.NewModule(), + troll.NewModule(), ) }