package caravan import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" ) type Caravan struct { modules.ModuleBase modelCaravan *modelCaravan api *apiComp configure *configureComp } func NewModule() core.IModule { return &Caravan{} } func (this *Caravan) GetType() core.M_Modules { return comm.ModuleTroll } func (this *Caravan) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) return } func (this *Caravan) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelCaravan = this.RegisterComp(new(modelCaravan)).(*modelCaravan) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } // 接口信息 修改数据 func (this *Caravan) ModifyCaravanData(uid string, data map[string]interface{}) (code pb.ErrorCode) { err := this.modelCaravan.modifyCaravanDataByObjId(uid, data) if err != nil { code = pb.ErrorCode_DBError } return } // 初始化城市信息 func (this *Caravan) InitCaravanCityData(uid string, data *pb.DBCaravan) { list := this.configure.GetAllCaravanCity() data.City = make(map[int32]*pb.CityInfo, 0) for _, v := range list { city := &pb.CityInfo{ Like: []int32{}, Unlike: []int32{}, Count: map[int32]int32{}, } if len(v.Special) > int(v.Citytypenum) { ids := utils.RandomNumbers(0, len(v.Special), int(v.Citytypenum)) for _, id := range ids { city.Like = append(city.Like, v.Special[id]) } } else { city.Like = append(city.Like, v.Special...) } city.Unlike = append(city.Like, v.Exspecial...) data.City[v.Id] = city } } // 初始化货物信息 func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) { items := this.configure.GetAllCaravanItem() data.Goods = make(map[int32]*pb.Goods, 0) for _, v := range items { goods := &pb.Goods{ Period: 0, // 变动周期 CurPeriod: 1, // 当前变动周期 Price: 0, // 当前价格 Time: configure.Now().Unix(), // 刷新时间 } if len(v.Changeperiod) == 2 { goods.Period = comm.GetRandNum(v.Changeperiod[0], v.Changeperiod[1]) goods.Price = v.Goodsprice data.Goods[v.Id] = goods } } } // 初始化门票和虚拟币 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 }