290 lines
7.5 KiB
Go
290 lines
7.5 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"context"
|
|
"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/configure"
|
|
"go_dreamfactory/sys/db"
|
|
"go_dreamfactory/utils"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
var _ comm.IPagoda = (*Pagoda)(nil)
|
|
|
|
type Pagoda struct {
|
|
modules.ModuleBase
|
|
modelPagoda *ModelPagoda
|
|
//modelSeasonPagoda *ModelSeasonPagoda
|
|
api *apiComp
|
|
modulerank *ModelRank
|
|
configure *configureComp
|
|
battle comm.IBattle
|
|
service base.IRPCXService
|
|
mail comm.Imail
|
|
friend comm.IFriend
|
|
modelRacePagoda *ModelRace
|
|
modelCyclePagoda *ModelCycle
|
|
battlerecord comm.IBattleRecord // 战报模块
|
|
}
|
|
|
|
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) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
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)
|
|
this.modelRacePagoda = this.RegisterComp(new(ModelRace)).(*ModelRace)
|
|
this.modelCyclePagoda = this.RegisterComp(new(ModelCycle)).(*ModelCycle)
|
|
}
|
|
|
|
// 接口信息
|
|
func (this *Pagoda) ModifyPagodaData(uid string, data map[string]interface{}) (errdata *pb.ErrorData) {
|
|
err := this.modelPagoda.modifyPagodaDataByObjId(uid, data)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Pagoda) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
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)
|
|
if module, err = this.service.GetModule(comm.ModuleFriend); err != nil {
|
|
return
|
|
}
|
|
this.friend = module.(comm.IFriend)
|
|
|
|
if module, err = this.service.GetModule(comm.ModuleBattleRecord); err != nil {
|
|
return
|
|
}
|
|
this.battlerecord = module.(comm.IBattleRecord)
|
|
//this.service.RegisterFunctionName(string(comm.Rpc_ModuleSeasonPagodaReward), this.Rpc_ModuleSeasonPagodaReward)
|
|
return
|
|
}
|
|
|
|
// 给gm 调用修改爬塔层数
|
|
func (this *Pagoda) ModifyPagodaFloor(session comm.IUserSession, d1 int32, d2 int32) (errdata *pb.ErrorData) {
|
|
list, _ := this.modelPagoda.getPagodaList(session.GetUserId())
|
|
//参数校验
|
|
_, err := this.configure.GetPagodaConfBytab(d1, d2)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
list.Data[d1] = d2
|
|
list.PagodaId = d2
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["data"] = list.Data
|
|
mapData["pagodaId"] = list.PagodaId
|
|
errdata = 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) {
|
|
data = this.modulerank.getcrossPagodaRankList(uid)
|
|
return
|
|
}
|
|
|
|
// redis 排序 tableName:"pagodaList"
|
|
func (this *Pagoda) SetPagodaRankList(tableName string, score int32, 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 map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
|
|
var (
|
|
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot6, comm.Reddot29101}
|
|
ok bool
|
|
)
|
|
items = make(map[comm.ReddotType]*pb.ReddotItem)
|
|
for _, v := range selfrid {
|
|
if _, ok = rid[v]; ok {
|
|
break
|
|
}
|
|
}
|
|
if ok {
|
|
return
|
|
}
|
|
|
|
for _, v := range selfrid {
|
|
if _, ok = rid[v]; ok {
|
|
switch v {
|
|
case comm.Reddot6:
|
|
items[comm.Reddot6] = &pb.ReddotItem{
|
|
Rid: int32(comm.Reddot6),
|
|
Activated: this.CheckPoint6(session.GetUserId()),
|
|
}
|
|
break
|
|
case comm.Reddot29101:
|
|
activity, process := this.CheckPoint29101(session.GetUserId())
|
|
items[comm.Reddot29101] = &pb.ReddotItem{
|
|
Rid: int32(comm.Reddot29101),
|
|
Activated: activity,
|
|
Progress: process,
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Pagoda) CheckPoint29101(uid string) (activated bool, progress int32) {
|
|
|
|
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
|
|
}
|
|
|
|
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) GetSeasonData() (endSeasonTime int64) {
|
|
|
|
endSeasonTime = utils.GetMonthEnd(configure.Now().Unix()) //+ int64((6-d)*3600*24)
|
|
|
|
return endSeasonTime
|
|
}
|
|
|
|
func (this *Pagoda) CheckCompletePagoda(uid string) (bComplete bool) {
|
|
|
|
if list, err := this.modelPagoda.getPagodaList(uid); err != nil {
|
|
return list.Complete
|
|
}
|
|
|
|
return false
|
|
}
|
|
func (this *Pagoda) SetRacePagodaRankList(tableName string, score int32, uid string, objID string) {
|
|
if !this.IsCross() {
|
|
if conn, err := db.Cross(); err == nil {
|
|
|
|
var (
|
|
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
|
menbers *redis.Z
|
|
)
|
|
|
|
strKey := "pagodarace:" + uid + "-" + objID // 自定义key
|
|
menbers = &redis.Z{Score: float64(score), Member: strKey}
|
|
|
|
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
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// Gm 跳转
|
|
func (this *Pagoda) GMModifyRacePagoda(uid string, floor int32) {
|
|
update := make(map[string]interface{}, 0)
|
|
if data, err := this.modelRacePagoda.getPagodaRaceList(uid); err == nil {
|
|
data.Data = make(map[int32]*pb.RaceData)
|
|
data.Rtime = configure.Now().Unix()
|
|
data.Battlecount = 0
|
|
data.Maxfloor = floor
|
|
for i := 1; i <= int(floor); i++ {
|
|
data.Data[int32(i)] = &pb.RaceData{ // GM跳转 值随便填
|
|
Consttime: 10,
|
|
Star: 7,
|
|
Line: &pb.LineData{},
|
|
}
|
|
}
|
|
update["data"] = data.Data
|
|
update["rtime"] = data.Rtime
|
|
update["battlecount"] = data.Battlecount
|
|
update["maxfloor"] = data.Maxfloor
|
|
this.modelRacePagoda.ModifyPagodaRaceData(uid, update)
|
|
}
|
|
return
|
|
}
|