111 lines
3.0 KiB
Go
111 lines
3.0 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
type Pagoda struct {
|
|
modules.ModuleBase
|
|
modelPagoda *ModelPagoda
|
|
modelSeasonPagoda *ModelSeasonPagoda
|
|
api *apiComp
|
|
modulerank *ModelRank
|
|
configure *configureComp
|
|
battle comm.IBattle
|
|
service core.IService
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Pagoda{}
|
|
}
|
|
|
|
func (this *Pagoda) GetType() core.M_Modules {
|
|
return comm.ModulePagoda
|
|
}
|
|
|
|
func (this *Pagoda) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *Pagoda) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelPagoda = this.RegisterComp(new(ModelPagoda)).(*ModelPagoda)
|
|
this.modelSeasonPagoda = this.RegisterComp(new(ModelSeasonPagoda)).(*ModelSeasonPagoda)
|
|
this.modulerank = this.RegisterComp(new(ModelRank)).(*ModelRank)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 接口信息
|
|
func (this *Pagoda) ModifyPagodaData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
|
|
err := this.modelPagoda.modifyPagodaDataByObjId(uid, data)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
return
|
|
}
|
|
|
|
// 修改赛季塔信息
|
|
func (this *Pagoda) ModifySeasonPagodaData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
|
|
err := this.modelSeasonPagoda.modifySeasonPagodaDataByObjId(uid, data)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
return
|
|
}
|
|
func (this *Pagoda) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
|
|
return
|
|
}
|
|
|
|
this.battle = module.(comm.IBattle)
|
|
return
|
|
}
|
|
|
|
// 给gm 调用修改爬塔层数
|
|
func (this *Pagoda) ModifyPagodaFloor(session comm.IUserSession, level int32) (code pb.ErrorCode) {
|
|
list, _ := this.modelPagoda.getPagodaList(session.GetUserId())
|
|
if list != nil {
|
|
|
|
list.PagodaId = level
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["pagodaId"] = level
|
|
code = this.ModifyPagodaData(session.GetUserId(), mapData)
|
|
session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list})
|
|
}
|
|
return
|
|
}
|
|
|
|
// 查询玩家
|
|
func (this *Pagoda) CheckUserBasePagodaInfo(uid string) (data *pb.DBPagodaRecord) {
|
|
|
|
list, _ := this.modelPagoda.getPagodaList(uid)
|
|
if list != nil { // redis没有数据
|
|
data = this.modulerank.getPagodaRankListByFloorid(uid, list.PagodaId)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 清除赛季塔信息
|
|
func (this *Pagoda) CleanSeasonPagodaData() (code pb.ErrorCode) {
|
|
seasonMaxCount := this.modelPagoda.module.configure.GetPagodaFloor(201)
|
|
|
|
for iPos := 0; iPos < int(seasonMaxCount); iPos++ {
|
|
key := fmt.Sprintf("%s-%d-rank", floorRankKey, iPos+1)
|
|
if err := this.modelSeasonPagoda.Redis.Ltrim(key, 0, -1); err != nil {
|
|
log.Errorf("delete failed")
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|