package activity import ( "fmt" "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/sys/db" "go_dreamfactory/utils" ) type Activity struct { modules.ModuleBase api *apiComp configure *configureComp service core.IService modelhdList *modelHdList modelhdData *modelhdData //warorder comm.IWarorder // 战令 } func NewModule() core.IModule { return &Activity{} } func (this *Activity) GetType() core.M_Modules { return comm.ModuleActivity } func (this *Activity) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service // ticker := time.NewTicker(time.Second * 10) // go func() { // for { // select { // case <-ticker.C: // this.CreateHdData() // return // } // } // }() return } func (this *Activity) Start() (err error) { err = this.ModuleBase.Start() if !db.IsCross() { if rst, err := this.modelhdList.getHdInfoByHdType(comm.HdTypeWarorder); err == nil { // 服务启动 获取活动信息 var module core.IModule if module, err = this.service.GetModule(comm.ModuleWarorder); err == nil { if m, ok := module.(comm.IWarorder); ok { m.ActivityOpenNotice(rst) } } } if rst, err := this.modelhdList.getHdInfoByHdType(comm.HdTypePay); err == nil { // 服务启动 获取活动信息 var module core.IModule if module, err = this.service.GetModule(comm.ModulePay); err == nil { if m, ok := module.(comm.IPay); ok { m.ActivityOpenNotice(rst) } } } // ac := &pb.DBActivityData{ // Id: "", // Uid: "", // Hdoid: "64c8a90e510317d18960964a", // Gotarr: map[int32]bool{}, // Lasttime: configure.Now().Unix(), // Val: 1, // } // this.modelhdData.InsertHddata("", ac) this.modelhdList.LoadActivityData() } return } func (this *Activity) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.modelhdData = this.RegisterComp(new(modelhdData)).(*modelhdData) this.modelhdList = this.RegisterComp(new(modelHdList)).(*modelHdList) } // 创建一条活动数据 // func (this *Activity) CreateHdData() (err error) { // var db *pb.DBHuodong // db = &pb.DBHuodong{ // Id: primitive.NewObjectID().Hex(), // Hdid: 10001, // Rtime: 1680105599, // Itype: 0, // Name: "累计充值活动", // Img: "", // Showtime: "03月15日00:00-03月20日23:59", // PressImg: "huodong_btn4_1.png", // Intr: "累计充值,限时福利", // Etime: 1680105599, // NormalImg: "huodong_btn4.png", // Stime: 1679414400, // Tab: 2, // Ttype: 0, // Icon: "ico_event_yxjl", // Open: 1, // Order: 102, // Stype: 10009, // Htype: 9, // Data: &pb.ActivityInfo{}, // } // for i := 0; i < 6; i++ { // var p []*pb.UserAssets // p = append(p, &pb.UserAssets{ // A: "item", // T: "10000001", // N: 1, // }) // db.Data.Prize = append(db.Data.Prize, &pb.Arr{ // Prize: p, // Val: int32(i) + 1, // }) // } // this.modelhdList.addHdInfo(db) // fmt.Printf("%v", db) // return // } func (this *Activity) CreateHdData() (err error) { this.modelhdList.getHdInfo() return } func (this *Activity) GetAllHdInfo() (activity map[pb.HdType][]*pb.DBHuodong) { return this.modelhdList.getHdInfo() } func (this *Activity) GetHdInfoByItype(itype pb.HdType) (result []*pb.DBHuodong, err error) { if c := this.modelhdList.getHdInfo(); c != nil { if _, ok := c[itype]; ok { result = c[itype] return } } err = fmt.Errorf("Not found :%d type activity", itype) return } // 通过活动ID查找 func (this *Activity) GetHdInfoByHdId(oid string) (result *pb.DBHuodong, err error) { result, err = this.modelhdList.getHdListByHdId(oid) return } // 大转盘奖励 func (this *Activity) Turntable(drawIndex int32, reward []int32) (item *cfg.Gameatn, drawkey int32, err error) { var ( conf *cfg.GameVenturegiftsDrawData szW []int32 // 权重 szpool []int32 // drawkey ) if conf, err = this.configure.GetVenturegiftsDraw(drawIndex); err != nil { return } // 过滤已经获得的道具 for _, v := range this.configure.pool1 { bFound := false for _, v1 := range reward { if v.Drawkey == v1 { bFound = true break } } if !bFound { szW = append(szW, v.Weight) szpool = append(szpool, v.Drawkey) } } if conf.Type == 2 { for _, v := range this.configure.pool2 { bFound := false for _, v1 := range reward { if v.Drawkey == v1 { bFound = true break } } if !bFound { szW = append(szW, v.Weight) szpool = append(szpool, v.Drawkey) } } } if c, err := this.configure.GetVenturegiftsDraw(szpool[comm.GetRandW(szW)]); err == nil { item = c.Id // 最终获得的道具 drawkey = c.Drawkey } return } // 统计庆典活动完成情况 func (this *Activity) HDCelebration(session comm.IUserSession, systemtype int32, bosstype int32) bool { bDouble := false // 是否开启双倍奖励 if activity := this.modelhdList.getHdInfoByType(comm.HdCelebration); activity != nil { for _, v := range activity { if configure.Now().Unix() > v.Stime && configure.Now().Unix() < v.Etime { // 活动范围内 update := make(map[string]interface{}) bChange := false // 查询玩家活动记录 //key := fmt.Sprintf("%s-%s", session.GetUserId(), v.Id) if data, err := this.modelhdData.getHddataByOid(session.GetUserId(), v.Id); err != nil { // 注意 Gotarr:map[int32]int32 key value 已经挑战的次数 if !utils.IsToday(data.Lasttime) { // 不是今天重置 data.Lasttime = configure.Now().Unix() data.Gotarr = make(map[int32]int32) // 计算进度 data.Val = int32((configure.Now().Unix()-v.Stime)/24*3600) + 1 update["lasttime"] = data.Lasttime update["val"] = data.Val update["gotarr"] = data.Gotarr bChange = true } var pos int32 for index, v := range this.configure.GetHDCelebrationData() { for i := 0; i < int(v); i++ { pos++ if data.Val == pos { if conf, err := this.configure.GetHDCelebration(int32(index) + 1); err != nil { if conf.Systemtype == systemtype { data.Gotarr[bosstype] += 1 // 天数 var idays int32 for i, v1 := range conf.Bosstype { if v1 == systemtype || v1 == 0 { // bosstype 为0 表示所有的boss 类型都算 idays = conf.Num[i] break } } // 更新信息 update["gotarr"] = data.Gotarr bChange = true if data.Gotarr[bosstype] <= idays { bDouble = true } } } } } } if bChange { this.modelhdData.ModifyActivityList(session.GetUserId(), data.Id, update) // 推送活动数据进度变化 session.SendMsg(string(this.GetType()), "change", &pb.ActivityDataChangePush{ Data: []*pb.DBActivityData{data}, }) } } } } } return bDouble }