爬塔测试
This commit is contained in:
parent
121e7c94d2
commit
3c3b0743bb
@ -9,6 +9,7 @@ const (
|
||||
PagodaGetListResp = "getlist"
|
||||
PagodaChallengeResp = "challenge"
|
||||
PagodaGetRewardResp = "getreward"
|
||||
PagodaRankListResp = "ranklist"
|
||||
)
|
||||
|
||||
type apiComp struct {
|
||||
@ -21,6 +22,7 @@ type apiComp struct {
|
||||
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.MCompGate.Init(service, module, comp, options)
|
||||
this.module = module.(*Pagoda)
|
||||
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -28,26 +29,48 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.PagodaChalleng
|
||||
code = pb.ErrorCode_PagodaNotFound
|
||||
return
|
||||
}
|
||||
req.PagodaType = 101
|
||||
cfg := this.module.configure.GetPagodaConfigData(req.PagodaType, req.LevelID)
|
||||
if cfg == nil {
|
||||
code = pb.ErrorCode_PagodaNotFound
|
||||
return
|
||||
}
|
||||
if cfg.LayerNum != pagoda.PagodaId {
|
||||
if pagoda.Type == cfg.PagodaType && cfg.LayerNum != pagoda.PagodaId {
|
||||
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
||||
return
|
||||
}
|
||||
|
||||
//// todo 战斗相关
|
||||
mapData := make(map[string]interface{}, 0)
|
||||
if pagoda.Type != cfg.PagodaType {
|
||||
pagoda.Type = cfg.PagodaType
|
||||
mapData["type"] = pagoda.Type
|
||||
}
|
||||
pagoda.Type = req.PagodaType
|
||||
|
||||
pagoda.PagodaId = cfg.NextLevel // 更新层数
|
||||
/////
|
||||
rst, _ := this.module.modulerank.GetUserRandData(session.GetUserId())
|
||||
if rst.Uid == "" {
|
||||
rst.Uid = session.GetUserId()
|
||||
rst.Id = primitive.NewObjectID().Hex()
|
||||
rst.Type = req.PagodaType
|
||||
rst.Nickname = "123"
|
||||
rst.PagodaId = pagoda.PagodaId
|
||||
this.module.modulerank.AddRank(session.GetUserId(), rst)
|
||||
} else {
|
||||
mapData := make(map[string]interface{}, 0)
|
||||
mapData["pagodaId"] = pagoda.PagodaId
|
||||
mapData["type"] = pagoda.Type
|
||||
|
||||
this.module.modulerank.ChangeUserRank(session.GetUserId(), mapData)
|
||||
}
|
||||
/////
|
||||
// 通关奖励
|
||||
code = this.module.DispenseRes(session, cfg.Reward, true)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
mapData := make(map[string]interface{}, 0)
|
||||
pagoda.PagodaId = cfg.NextLevel // 更新层数
|
||||
mapData["pagodaId"] = cfg.NextLevel
|
||||
code = this.module.ModifyPagodaData(session.GetUserId(), mapData)
|
||||
session.SendMsg(string(this.module.GetType()), PagodaChallengeResp, &pb.PagodaChallengeResp{Data: pagoda})
|
||||
|
29
modules/pagoda/api_ranklist.go
Normal file
29
modules/pagoda/api_ranklist.go
Normal file
@ -0,0 +1,29 @@
|
||||
package pagoda
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) RankLisCheck(session comm.IUserSession, req *pb.PagodaRankListReq) (code pb.ErrorCode) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) RankLis(session comm.IUserSession, req *pb.PagodaRankListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
|
||||
code = this.RankLisCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
// 临时测试用
|
||||
szRank, err := this.module.modulerank.GetRankData(req.FloorId, req.Type)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), PagodaRankListResp, &pb.PagodaRankListResp{Ranks: szRank})
|
||||
return
|
||||
}
|
@ -47,7 +47,6 @@ func (this *ModelPagoda) modifyPagodaDataByObjId(uid string, data map[string]int
|
||||
|
||||
// 创建一个新的塔数据
|
||||
func (this *ModelPagoda) addNewPagoda(uId string, data *pb.DBPagoda) (err error) {
|
||||
|
||||
if err = this.Add(uId, data); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
|
@ -1,10 +1,15 @@
|
||||
package pagoda
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type ModelRank struct {
|
||||
@ -29,20 +34,52 @@ func (this *ModelRank) getUserSession(uid string) (cuser *pb.CacheUser) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelRank) AddRank(uId string, data *pb.DBPagodaRank) (err error) {
|
||||
if err = this.Add(uId, data); err != nil {
|
||||
//this.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//获取用户通过扩展表
|
||||
// func (this *ModelRank) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) {
|
||||
// result = &pb.DBUserExpand{}
|
||||
// if err = this.moduleUser.modelExpand.Get(uid, result); err != nil && redis.RedisNil != err {
|
||||
// return
|
||||
// }
|
||||
// err = nil
|
||||
// return result, err
|
||||
// }
|
||||
func (this *ModelRank) GetUserRandData(uid string) (result *pb.DBPagodaRank, err error) {
|
||||
result = &pb.DBPagodaRank{}
|
||||
if err = this.Get(uid, result); err != nil && redis.RedisNil != err {
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
return result, err
|
||||
}
|
||||
|
||||
// func (this *ModelRank) ChangeUserExpand(uid string, value map[string]interface{}) (err error) {
|
||||
// if len(value) == 0 {
|
||||
// return nil
|
||||
// }
|
||||
// return this.moduleUser.modelExpand.Change(uid, value)
|
||||
func (this *ModelRank) ChangeUserRank(uid string, value map[string]interface{}) (err error) {
|
||||
if len(value) == 0 {
|
||||
return nil
|
||||
}
|
||||
return this.Change(uid, value)
|
||||
}
|
||||
|
||||
// }
|
||||
// 临时测试
|
||||
func (this *ModelRank) GetRankData(floorId int32, pagodaType int32) (data []*pb.DBPagodaRank, err error) {
|
||||
if floorId == 0 {
|
||||
if _data, err := this.DB.Find(comm.TablePagodaRank, bson.M{"type": pagodaType}, options.Find().SetSort(bson.M{"pagodaId": 1})); err == nil {
|
||||
for _data.Next(context.TODO()) {
|
||||
temp := &pb.DBPagodaRank{}
|
||||
if err = _data.Decode(temp); err == nil {
|
||||
data = append(data, temp)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if _data, err := this.DB.Find(comm.TablePagodaRank, bson.M{"pagodaId": bson.M{"$gte": floorId}, "type": pagodaType}, options.Find().SetSort(bson.M{"pagodaId": 1})); err == nil {
|
||||
for _data.Next(context.TODO()) {
|
||||
temp := &pb.DBPagodaRank{}
|
||||
if err = _data.Decode(temp); err == nil {
|
||||
data = append(data, temp)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ type Pagoda struct {
|
||||
modules.ModuleBase
|
||||
modelPagoda *ModelPagoda
|
||||
api *apiComp
|
||||
modulerank *ModelRank
|
||||
configure *configureComp
|
||||
}
|
||||
|
||||
@ -32,6 +33,7 @@ func (this *Pagoda) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||
this.modelPagoda = this.RegisterComp(new(ModelPagoda)).(*ModelPagoda)
|
||||
this.modulerank = this.RegisterComp(new(ModelRank)).(*ModelRank)
|
||||
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
||||
}
|
||||
|
||||
|
@ -310,6 +310,9 @@ type PagodaRankListReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FloorId int32 `protobuf:"varint,1,opt,name=floorId,proto3" json:"floorId"` // 层数
|
||||
Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type"` // 塔类型
|
||||
}
|
||||
|
||||
func (x *PagodaRankListReq) Reset() {
|
||||
@ -344,6 +347,20 @@ func (*PagodaRankListReq) Descriptor() ([]byte, []int) {
|
||||
return file_pagoda_pagoda_msg_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *PagodaRankListReq) GetFloorId() int32 {
|
||||
if x != nil {
|
||||
return x.FloorId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *PagodaRankListReq) GetType() int32 {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type PagodaRankListResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -415,13 +432,16 @@ var file_pagoda_pagoda_msg_proto_rawDesc = []byte{
|
||||
0x61, 0x54, 0x79, 0x70, 0x65, 0x22, 0x34, 0x0a, 0x13, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x43,
|
||||
0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x04,
|
||||
0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x44, 0x42, 0x50,
|
||||
0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x13, 0x0a, 0x11, 0x50,
|
||||
0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x41, 0x0a, 0x11, 0x50,
|
||||
0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71,
|
||||
0x22, 0x39, 0x0a, 0x12, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x61, 0x6e, 0x6b, 0x4c, 0x69,
|
||||
0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x18,
|
||||
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61,
|
||||
0x52, 0x61, 0x6e, 0x6b, 0x52, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e,
|
||||
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x12, 0x18, 0x0a, 0x07, 0x66, 0x6c, 0x6f, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x07, 0x66, 0x6c, 0x6f, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79,
|
||||
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x39,
|
||||
0x0a, 0x12, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, 0x74,
|
||||
0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x18, 0x01, 0x20,
|
||||
0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x61,
|
||||
0x6e, 0x6b, 0x52, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70,
|
||||
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user