package uigame import ( "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "go_dreamfactory/modules" ) type UiGame struct { modules.ModuleBase modelPuzzle *modelPuzzle api *apiComp configure *configureComp service base.IRPCXService modelLattice *modelLattice } func NewModule() core.IModule { return &UiGame{} } func (this *UiGame) GetType() core.M_Modules { return comm.ModulePuzzle } func (this *UiGame) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) return } func (this *UiGame) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelPuzzle = this.RegisterComp(new(modelPuzzle)).(*modelPuzzle) this.modelLattice = this.RegisterComp(new(modelLattice)).(*modelLattice) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } func (this *UiGame) Start() (err error) { err = this.ModuleBase.Start() return } func (this *UiGame) HDPSTodayConsum(uid string, ps int32) { activity := this.ModuleActivity.GetAllHdInfo() curTime := configure.Now().Unix() if v, ok := activity[pb.HdType_HdPuzzle]; ok { // 拼图小游戏 if v.Stime <= curTime && curTime <= v.Etime { // 活动时间范围内 if rst, err := this.modelPuzzle.getPuzzleList(uid, v.Id); err == nil { if conf, err := this.configure.GetPuzzleConsumConf(); err == nil { update := make(map[string]interface{}) // 清除每日获得的碎片数据 if !utils.IsToday(rst.Lasttime) { rst.Lasttime = configure.Now().Unix() rst.Val = 0 update["val"] = rst.Val update["lasttime"] = rst.Lasttime } if conf.Getmax > rst.Val { // 超过今日上限 tmp := ps / conf.Usepawer if tmp > rst.Val { l := rst.Val rst.Val = tmp if conf.Getmax < rst.Val { // 超过今日上限 rst.Val = conf.Getmax } sub := rst.Val - l // 增长的 s, ok := this.GetUserSession(uid) if sub > 0 { var res *cfg.Gameatn res = &cfg.Gameatn{ A: conf.Itemget.A, T: conf.Itemget.T, N: conf.Itemget.N * sub, } this.DispenseRes(s, []*cfg.Gameatn{res}, true) } update["val"] = rst.Val this.modelPuzzle.modifyPuzzleListByObjId(uid, update) // 推送活动数据进度变化 if ok { s.SendMsg(string(this.GetType()), "puzzlechange", &pb.UiGamePuzzleChangePush{ Data: rst, }) s.Push() } } } } } } } }