diff --git a/bin/json/game_smithycustomer.json b/bin/json/game_smithycustomer.json index aaad93b63..a3068e3de 100644 --- a/bin/json/game_smithycustomer.json +++ b/bin/json/game_smithycustomer.json @@ -7,7 +7,8 @@ "text": "" }, "goods": [], - "reword": [] + "reword": [], + "weight": 4500 }, { "customer_id": 2, @@ -17,7 +18,8 @@ "text": "" }, "goods": [], - "reword": [] + "reword": [], + "weight": 4500 }, { "customer_id": 3, @@ -27,7 +29,8 @@ "text": "" }, "goods": [], - "reword": [] + "reword": [], + "weight": 500 }, { "customer_id": 4, @@ -37,6 +40,7 @@ "text": "" }, "goods": [], - "reword": [] + "reword": [], + "weight": 500 } ] \ No newline at end of file diff --git a/cmd/v2/ui/app_test.go b/cmd/v2/ui/app_test.go deleted file mode 100644 index 447c3bff0..000000000 --- a/cmd/v2/ui/app_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package ui - -import ( - "fmt" - cfg "go_dreamfactory/cmd/v2/configure/structs" - "go_dreamfactory/cmd/v2/lib/common" - "testing" -) - -func TestGjson(t *testing.T) { - if tables, err := cfg.NewTables(common.Loader); err != nil { - println(err.Error()) - } else { - for _, v := range tables.TestFlow.GetDataList() { - fmt.Println(v.Msg) - } - } -} diff --git a/modules/smithy/comp_configure.go b/modules/smithy/comp_configure.go index 21089c1d1..da10ac116 100644 --- a/modules/smithy/comp_configure.go +++ b/modules/smithy/comp_configure.go @@ -17,9 +17,10 @@ const ( game_smproficiency = "game_smithyproficiency.json" // 铁匠铺熟练度 game_smithystove = "game_smithystovev1.json" // 铁匠铺台子 打造配置 game_smithytools = "game_smithytool.json" // 铁匠铺工具台 + game_smithycustomer = "game_smithycustomer.json" ) -///配置管理基础组件 +// /配置管理基础组件 type configureComp struct { modules.MCompConfigure module *Smithy @@ -29,7 +30,7 @@ type configureComp struct { _mapProficile map[int64]*cfg.GameSmithyProficiencyData // 熟练度 key 卷轴ID+ 等级 } -//组件初始化接口 +// 组件初始化接口 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.module = module.(*Smithy) @@ -55,6 +56,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp err = this.LoadConfigure(game_smithystove, cfg.NewGameSmithyStoveV1) err = this.LoadConfigure(game_smithytools, cfg.NewGameSmithyTool) err = this.LoadConfigure(game_smithystoveold, cfg.NewGameSmithyStove) + err = this.LoadConfigure(game_smithycustomer, cfg.NewGameSmithyCustomer) return } @@ -89,7 +91,7 @@ func (this *configureComp) GetSmithyStoveConfigData(level int32) (data *cfg.Game return } -//加载多个配置文件 +// 加载多个配置文件 func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { err = configure.RegisterConfigure(k, v, nil) @@ -101,7 +103,7 @@ func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err return } -//读取配置数据 +// 读取配置数据 func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } @@ -168,22 +170,11 @@ func (this *configureComp) GetSmithyProficileData(reelid int32, proficile int32) return this._mapProficile[int64(reelid<<16)+int64(proficile)] } -// 获取铁匠铺工作台信息 -func (this *configureComp) GetSmithyStoveConf(star int32) (data *cfg.GameSmithyStoveV1Data) { - if v, err := this.GetConfigure(game_smithystove); err == nil { - if configure, ok := v.(*cfg.GameSmithyStoveV1); ok { - data = configure.Get(int32(star)) - return - } - } - return -} - -// 获取铁匠铺工作台信息 -func (this *configureComp) GetSmithyStoveConf1(id int32) (data *cfg.GameSmithyToolData) { - if v, err := this.GetConfigure(game_smithytools); err == nil { - if configure, ok := v.(*cfg.GameSmithyTool); ok { - data = configure.Get(int32(id)) +// 获取铁匠铺顾客配置 +func (this *configureComp) GetSmithyCustomerConfList() (data []*cfg.GameSmithyCustomerData) { + if v, err := this.GetConfigure(game_smithycustomer); err != nil { + if conf, ok := v.(*cfg.GameSmithyCustomer); ok { + data = conf.GetDataList() return } } diff --git a/modules/smithy/model_trade.go b/modules/smithy/model_trade.go index 2254a8b27..8f9ddb04d 100644 --- a/modules/smithy/model_trade.go +++ b/modules/smithy/model_trade.go @@ -4,6 +4,8 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" + cfg "go_dreamfactory/sys/configure/structs" + "math/rand" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" @@ -24,4 +26,47 @@ func (this *modelTrade) Init(service core.IService, module core.IModule, comp co }) return } -// \ No newline at end of file + +// 权重项目 +type WeightedRandom struct { + items []*cfg.GameSmithyCustomerData + totalWeight int +} + +func newWeightedRandom(items []*cfg.GameSmithyCustomerData) *WeightedRandom { + wr := &WeightedRandom{items: items} + for _, item := range wr.items { + wr.totalWeight += int(item.Weight) + } + return wr +} + +func (wr *WeightedRandom) pick() *cfg.GameSmithyCustomerData { + randomNumber := rand.Intn(wr.totalWeight) + for _, item := range wr.items { + if randomNumber < int(item.Weight) { + return item + } + randomNumber -= int(item.Weight) + } + return nil +} + +// 随机顾客 +func (s *modelTrade) getCustomerRandom() (customerId int32) { + items := s.module.configure.GetSmithyCustomerConfList() + wr := newWeightedRandom(items) + if c := wr.pick(); c != nil { + customerId = c.CustomerId + } + return +} + +// 更新顾客 +func(s *modelTrade) updateCustomer(uid string) { + +} + +//顾客类型策略 + +//交易 diff --git a/sys/configure/structs/Game.SmithyCustomerData.go b/sys/configure/structs/Game.SmithyCustomerData.go index 5f13ad2b8..837eda3fb 100644 --- a/sys/configure/structs/Game.SmithyCustomerData.go +++ b/sys/configure/structs/Game.SmithyCustomerData.go @@ -16,6 +16,7 @@ type GameSmithyCustomerData struct { CustomerSpeak string Goods []*Gameatn Reword []*Gameatn + Weight int32 } const TypeId_GameSmithyCustomerData = 1314583578 @@ -56,6 +57,7 @@ func (_v *GameSmithyCustomerData)Deserialize(_buf map[string]interface{}) (err e } } + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["weight"].(float64); !_ok_ { err = errors.New("weight error"); return }; _v.Weight = int32(_tempNum_) } return }