215 lines
6.2 KiB
Go
215 lines
6.2 KiB
Go
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
|
|
modelMiner *modelMiner
|
|
}
|
|
|
|
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) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
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.modelMiner = this.RegisterComp(new(modelMiner)).(*modelMiner)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
func (this *UiGame) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
|
|
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)
|
|
|
|
go this.AsynHandleSession(s.Clone(), func(session comm.IUserSession) {
|
|
this.WriteUserLog(s.GetUserId(), 0, "HDPSTodayConsum", res)
|
|
})
|
|
}
|
|
|
|
update["val"] = rst.Val
|
|
|
|
this.modelPuzzle.modifyPuzzleListByObjId(uid, update)
|
|
// 推送活动数据进度变化
|
|
if ok {
|
|
s.SendMsg(string(this.GetType()), "puzzlechange", &pb.UiGamePuzzleChangePush{
|
|
Data: rst,
|
|
})
|
|
s.Push()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if v, ok := activity[pb.HdType_HdLattice]; ok { // 迷宫小游戏
|
|
if v.Stime <= curTime && curTime <= v.Etime { // 活动时间范围内
|
|
if rst, err := this.modelLattice.getLatticeList(uid, v.Id); err == nil {
|
|
if conf, err := this.configure.GetLatticeConsumConf(); 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)
|
|
go this.AsynHandleSession(s.Clone(), func(session comm.IUserSession) {
|
|
this.WriteUserLog(s.GetUserId(), 0, "HDPSTodayConsum", res)
|
|
})
|
|
}
|
|
|
|
update["val"] = rst.Val
|
|
|
|
this.modelLattice.modifyLatticeListByObjId(uid, update)
|
|
// 推送活动数据进度变化
|
|
if ok {
|
|
s.SendMsg(string(this.GetType()), "latticechange", &pb.UiGameLatticeChangePush{
|
|
Data: rst,
|
|
})
|
|
s.Push()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if v, ok := activity[pb.HdType_HdMiner]; ok { // 矿工小游戏
|
|
if v.Stime <= curTime && curTime <= v.Etime { // 活动时间范围内
|
|
if rst, err := this.modelMiner.getMinerList(uid, v.Id); err == nil {
|
|
if conf, err := this.configure.GetMinerConsumConf(); 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)
|
|
go this.AsynHandleSession(s.Clone(), func(session comm.IUserSession) {
|
|
this.WriteUserLog(s.GetUserId(), 0, "HDPSTodayConsum", res)
|
|
})
|
|
}
|
|
|
|
update["val"] = rst.Val
|
|
|
|
this.modelMiner.modifyMinerListByObjId(uid, update)
|
|
// 推送活动数据进度变化
|
|
if ok {
|
|
s.SendMsg(string(this.GetType()), "minerchange", &pb.UiGameMinerChangePush{
|
|
Data: rst,
|
|
})
|
|
s.Push()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|