go_dreamfactory/modules/pagoda/module.go

264 lines
7.1 KiB
Go

package pagoda
import (
"context"
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Pagoda struct {
modules.ModuleBase
modelPagoda *ModelPagoda
modelSeasonPagoda *ModelSeasonPagoda
api *apiComp
modulerank *ModelRank
configure *configureComp
battle comm.IBattle
service base.IRPCXService
mail comm.Imail
}
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.(base.IRPCXService)
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)
if module, err = this.service.GetModule(comm.ModuleMail); err != nil {
return
}
this.mail = module.(comm.Imail)
//this.service.RegisterFunctionName(string(comm.Rpc_ModuleSeasonPagodaReward), this.Rpc_ModuleSeasonPagodaReward)
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
// 通关校验
Nomalcfg := this.configure.GetPagodaConfigData(level + 1)
if Nomalcfg == nil {
list.Complete = true
mapData["complete"] = true
}
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
}
// redis 排序 tableName:"pagodaList"
func (this *Pagoda) SetPagodaRankList(tableName string, score int64, uid string) {
if !this.IsCross() {
if conn, err := db.Cross(); err == nil {
var (
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
menbers *redis.Z
)
menbers = &redis.Z{Score: float64(score), Member: uid}
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
dock, err1 := cmd.Result()
if err1 != nil {
this.Errorln(dock, err1)
}
}
if _, err = pipe.Exec(); err != nil {
this.Errorln(err)
return
}
}
}
}
//红点查询
func (this *Pagoda) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) {
reddot = make(map[comm.ReddotType]bool)
for _, v := range rid {
switch v {
case comm.Reddot6:
reddot[comm.Reddot6] = this.CheckPoint6(session.GetUserId())
break
case comm.Reddot7:
reddot[comm.Reddot7] = this.CheckPoint7(session.GetUserId())
break
}
}
return
}
// 红点检测
func (this *Pagoda) CheckPoint6(uid string) bool {
list, err := this.modelPagoda.getPagodaList(uid)
if err != nil {
return false
}
maxFloor := this.configure.GetPagodaFloor(list.Type)
if list.PagodaId < maxFloor { // 层数不够 显示红点
return true
}
// 检测赛季塔
season, err := this.modelSeasonPagoda.getSeasonPagodaList(uid)
if err != nil {
return false
}
maxFloor = this.configure.GetPagodaFloor(list.Type)
if season.PagodaId < maxFloor { // 层数不够 显示红点
return true
}
return true
}
func (this *Pagoda) Rpc_ModuleSeasonPagodaReward(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) {
this.Debug("Rpc_ModuleSeasonPagodaReward", log.Field{Key: "args", Value: args.String()})
// this.modulerank.seasonSettlement()
}
func (this *Pagoda) CheckPoint7(uid string) bool {
list, _ := this.modelPagoda.getPagodaList(uid)
if list.Id == "" { // 普通塔
return false
}
if len(list.Reward) > 0 {
return true
}
season, _ := this.modelSeasonPagoda.getSeasonPagodaList(uid)
if season.Id == "" { // 普通塔
return false
}
if len(season.Reward) > 0 {
return true
}
return true
}
// 给随机任务提供的接口查询当前塔的通关层数
func (this *Pagoda) CheckPagodaMaxFloor(uid string, pagodaType int32) int32 {
if pagodaType == 1 {
if list, err := this.modelPagoda.getPagodaList(uid); err != nil {
return list.PagodaId
}
} else if pagodaType == 2 {
if pagoda, err := this.modelPagoda.getPagodaList(uid); err != nil {
return pagoda.PagodaId
}
}
return 0
}
// 赛季塔跳转
func (this *Pagoda) ModifySeasonPagodaFloor(session comm.IUserSession, level int32) (code pb.ErrorCode) {
list, _ := this.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
if list.Id == "" {
list.Id = primitive.NewObjectID().Hex()
list.Uid = session.GetUserId()
list.PagodaId = level
if conn, err := db.Cross(); err == nil {
rst := conn.Mgo.FindOne(comm.TableSeasonData, bson.M{})
server := &pb.DBServerData{}
rst.Decode(server)
list.Type = server.SeasonType
}
this.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), list)
session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list})
} else {
list.PagodaId = level
mapData := make(map[string]interface{}, 0)
mapData["pagodaId"] = level
code = this.ModifySeasonPagodaData(session.GetUserId(), mapData)
session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list})
}
return
}