package activity import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" "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 mail comm.Imail warorder comm.IWarorder // 战令 pay comm.IPay // 支付 shopcenter comm.IShopcenter // 活动中心 } 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() var module core.IModule if module, err = this.service.GetModule(comm.ModuleMail); err != nil { return } this.mail = module.(comm.Imail) if module, err = this.service.GetModule(comm.ModuleWarorder); err != nil { return } this.warorder = module.(comm.IWarorder) if module, err = this.service.GetModule(comm.ModulePay); err != nil { return } this.pay = module.(comm.IPay) if module, err = this.service.GetModule(comm.ModuleShopCenter); err != nil { return } this.shopcenter = module.(comm.IShopcenter) event.RegisterGO(comm.EventUserLogin, this.EventUserLogin) if !db.IsCross() { this.modelhdList.LoadActivityData() for k, v := range this.modelhdList.activity { switch k { case pb.HdType_HdTypeWarorder: this.warorder.ActivityOpenNotice(v) break case pb.HdType_HdTypePay, pb.HdType_ShopCenterPayPakcge: this.pay.ActivityOpenNotice(v) break case pb.HdType_XSFundPhysical, pb.HdType_XSFundRecruit, pb.HdType_XSFundExp: this.pay.ActivityOpenNotice(v) break } } } 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(pb.HdType_HdCelebration); activity != nil { // for _, v := range activity { if configure.Now().Unix() > activity.Stime && configure.Now().Unix() < activity.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(), activity.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()-activity.Stime)/24*3600) + 1 update["lasttime"] = data.Lasttime update["val"] = data.Val update["gotarr"] = data.Gotarr bChange = true } if data.Val == 0 { var pos int32 _sub := int32((configure.Now().Unix()-activity.Stime)/(24*3600)) + 1 _days := this.configure.GetHDCelebrationData() for index, v := range _days { for i := 0; i < int(v); i++ { pos++ if _sub == pos { data.Val = int32(index) + 1 // 计算val 值 update["val"] = data.Val break } } } data.Val = 1 } if conf, err := this.configure.GetHDCelebration(data.Val); 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 { var sz []*pb.DBActivityData this.modelhdData.ModifyActivityList(session.GetUserId(), data.Id, update) // 推送活动数据进度变化 sz = append(sz, data) session.SendMsg(string(this.GetType()), "datachange", &pb.ActivityDataChangePush{ Data: sz, }) } } } // } } return bDouble } func (this *Activity) EventUserLogin(session comm.IUserSession) { // 转盘活动 if a, err := this.GetHdInfoByItype(pb.HdType_HdTypeTurntable); err == nil { // bEnd := false // for _, v := range a { if configure.Now().Unix() > a.Etime { bEnd = true } // } if bEnd { // 活动结束 活动道具转换 t := this.ModuleTools.GetGlobalConf().VenturegiftsDraw var reward []*pb.UserAssets if item, err := this.configure.GetItemConfigureData(t); err != nil { amount := this.ModuleItems.QueryItemAmount(session.GetUserId(), t) if amount > 0 { this.ModuleItems.AddItem(session, t, -int32(amount), true) for _, v := range item.Sale { reward = append(reward, &pb.UserAssets{ A: v.A, T: v.T, N: v.N * int32(amount), }) } // 发邮件 this.mail.SendMailByCid(session, comm.Venturegifts, reward) } } } } } func (this *Activity) GetHdData(session comm.IUserSession, oids []string) (result []*pb.DBActivityData) { var ( activity *pb.DBHuodong err error list *pb.DBActivityData ) curTime := configure.Now().Unix() for _, id := range oids { if activity, err = this.modelhdList.getHdListByHdId(id); err != nil { if activity.Stime > curTime || curTime > activity.Etime { // 不在活动范围内数据不给活动记录数据 continue } } list, _ = this.modelhdData.getHddataByOid(session.GetUserId(), id) if activity.Itype == pb.HdType_HdTypeSign && !utils.IsToday(list.Lasttime) { list.Lasttime = curTime list.Val += 1 update := make(map[string]interface{}) update["lasttime"] = list.Lasttime update["val"] = list.Val this.modelhdData.ModifyActivityList(session.GetUserId(), list.Id, update) } // 开服等级活动 if activity.Itype == pb.HdType_HdLevel { if user := this.ModuleUser.GetUser(session.GetUserId()); user != nil { if list.Val != user.Lv { list.Val = user.Lv list.Lasttime = curTime update := make(map[string]interface{}) update["lasttime"] = list.Lasttime update["val"] = list.Val this.modelhdData.ModifyActivityList(session.GetUserId(), list.Id, update) } } } // 获取开服庆典活动 if activity.Itype == pb.HdType_HdCelebration { // key := fmt.Sprintf("%s-%s", session.GetUserId(), id) if list, err = this.modelhdData.getHddataByOid(session.GetUserId(), id); err == nil { if !utils.IsToday(list.Lasttime) || list.Val == 0 { // 不是今天重置 list.Lasttime = configure.Now().Unix() list.Gotarr = make(map[int32]int32) update := make(map[string]interface{}) // 计算进度 update["lasttime"] = list.Lasttime update["gotarr"] = list.Gotarr _days := this.configure.GetHDCelebrationData() var pos int32 _sub := int32((configure.Now().Unix()-activity.Stime)/(24*3600)) + 1 for index, v := range _days { for i := 0; i < int(v); i++ { pos++ if _sub == pos { list.Val = int32(index) + 1 // 计算val 值 update["val"] = list.Val break } } } this.modelhdData.ModifyActivityList(session.GetUserId(), list.Id, update) } } } if list != nil { result = append(result, list) } } return }