178 lines
4.0 KiB
Go
178 lines
4.0 KiB
Go
package turntable
|
|
|
|
import (
|
|
"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"
|
|
)
|
|
|
|
type Turntable struct {
|
|
modules.ModuleBase
|
|
service core.IService
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelt *ModelTurntable
|
|
mail comm.Imail
|
|
open bool
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Turntable{}
|
|
}
|
|
|
|
func (this *Turntable) GetType() core.M_Modules {
|
|
return comm.ModuleTurntable
|
|
}
|
|
|
|
func (this *Turntable) 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
|
|
return
|
|
}
|
|
|
|
func (this *Turntable) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
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
|
|
}
|
|
event.Register(comm.EventUserLogin, this.EventUserLogin)
|
|
return
|
|
}
|
|
|
|
func (this *Turntable) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelt = this.RegisterComp(new(ModelTurntable)).(*ModelTurntable)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 活动开启
|
|
func (this *Turntable) ActivityOpenNotice(hdlist *pb.DBHuodong) {
|
|
switch hdlist.Itype {
|
|
case pb.HdType_KFSevenTask:
|
|
this.open = true
|
|
break
|
|
}
|
|
}
|
|
|
|
// 活动关闭
|
|
func (this *Turntable) ActivityCloseNotice(hdlist *pb.DBHuodong) {
|
|
switch hdlist.Itype {
|
|
case pb.HdType_KFSevenTask:
|
|
this.open = false
|
|
break
|
|
}
|
|
}
|
|
|
|
// 大转盘奖励
|
|
func (this *Turntable) 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 *Turntable) EventUserLogin(session comm.IUserSession) {
|
|
// 转盘活动
|
|
var (
|
|
bEnd bool
|
|
turntable *pb.DBTurntable
|
|
err error
|
|
)
|
|
endTime := this.ModuleTools.GetGlobalConf().SignAccount
|
|
if user, err := this.ModuleUser.GetUser(session.GetUserId()); err == nil {
|
|
if configure.Now().Unix() > user.Ctime+int64(endTime*24*3600) {
|
|
bEnd = true
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
if !bEnd {
|
|
return
|
|
}
|
|
|
|
if turntable, err = this.modelt.getUserTurntable(session.GetUserId()); err != nil {
|
|
|
|
return
|
|
}
|
|
if turntable.Reward {
|
|
return
|
|
}
|
|
|
|
// 活动结束 活动道具转换
|
|
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)
|
|
}
|
|
}
|
|
turntable.Reward = true
|
|
this.modelt.Change(session.GetUserId(), map[string]interface{}{
|
|
"reward": turntable.Reward,
|
|
})
|
|
}
|