获取hero接口修改
This commit is contained in:
parent
b6c265e44c
commit
469225f6ab
@ -31,7 +31,7 @@ type (
|
|||||||
AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode)
|
AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode)
|
||||||
// 获取英雄
|
// 获取英雄
|
||||||
// heroId 英雄ID
|
// heroId 英雄ID
|
||||||
GetHero(heroId string) (*pb.DB_HeroData, pb.ErrorCode)
|
GetHero(uid, heroId string) (*pb.DB_HeroData, pb.ErrorCode)
|
||||||
// 佩戴装备
|
// 佩戴装备
|
||||||
UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment) (code pb.ErrorCode)
|
UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment) (code pb.ErrorCode)
|
||||||
}
|
}
|
||||||
|
79
modules/hero/hero_test.go
Normal file
79
modules/hero/hero_test.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package hero
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/lego"
|
||||||
|
"go_dreamfactory/lego/base/rpcx"
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/services"
|
||||||
|
"go_dreamfactory/sys/cache"
|
||||||
|
"go_dreamfactory/sys/configure"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var service core.IService
|
||||||
|
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||||
|
|
||||||
|
var module = new(Hero)
|
||||||
|
|
||||||
|
type TestService struct {
|
||||||
|
rpcx.RPCXService
|
||||||
|
}
|
||||||
|
|
||||||
|
func newService(ops ...rpcx.Option) core.IService {
|
||||||
|
s := new(TestService)
|
||||||
|
s.Configure(ops...)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化相关系统
|
||||||
|
func (this *TestService) InitSys() {
|
||||||
|
this.RPCXService.InitSys()
|
||||||
|
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
|
||||||
|
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
|
||||||
|
} else {
|
||||||
|
log.Infof("init sys.cache success!")
|
||||||
|
}
|
||||||
|
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||||
|
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||||
|
} else {
|
||||||
|
log.Infof("init sys.db success!")
|
||||||
|
}
|
||||||
|
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("E:\\projects\\workspace\\go_dreamfactory\\bin\\json")); err != nil {
|
||||||
|
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
||||||
|
} else {
|
||||||
|
log.Infof("init sys.configure success!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
service = newService(
|
||||||
|
rpcx.SetConfPath("../../bin/conf/worker_2.yaml"),
|
||||||
|
)
|
||||||
|
service.OnInstallComp( //装备组件
|
||||||
|
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
|
||||||
|
)
|
||||||
|
go func() {
|
||||||
|
lego.Run(service, //运行模块
|
||||||
|
module,
|
||||||
|
)
|
||||||
|
}()
|
||||||
|
time.Sleep(time.Second * 2)
|
||||||
|
defer os.Exit(m.Run())
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建一个英雄s
|
||||||
|
func TestCreateOneHero(t *testing.T) {
|
||||||
|
err := module.model_hero.createOneHero("u1", 25001)
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取玩家英雄
|
||||||
|
func TestGetOneHero(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,8 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelHero struct {
|
type ModelHero struct {
|
||||||
@ -20,28 +22,42 @@ func (this *ModelHero) Init(service core.IService, module core.IModule, comp cor
|
|||||||
}
|
}
|
||||||
|
|
||||||
//创建一个指定的英雄
|
//创建一个指定的英雄
|
||||||
func (this *ModelHero) createOneHero(uid string, heroId int32) error {
|
func (this *ModelHero) createOneHero(uid string, heroCfgId int32) error {
|
||||||
heroCfg, err := this.moduleHero.configure_comp.GetHeroConfigure()
|
heroCfg, err := this.moduleHero.configure_comp.GetHeroConfigure()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%v", err)
|
log.Errorf("%v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if heroCfg != nil {
|
if heroCfg != nil {
|
||||||
oneHeroCfg := heroCfg.Get(heroId)
|
oneHeroCfg := heroCfg.Get(heroCfgId)
|
||||||
if oneHeroCfg != nil {
|
if oneHeroCfg != nil {
|
||||||
|
objId := primitive.NewObjectID().Hex()
|
||||||
newHero := &pb.DB_HeroData{
|
newHero := &pb.DB_HeroData{
|
||||||
Uid: uid,
|
Id: objId,
|
||||||
HeroID: oneHeroCfg.Id,
|
Uid: uid,
|
||||||
Star: oneHeroCfg.Star,
|
HeroID: oneHeroCfg.Id,
|
||||||
Lv: 1, //初始等级
|
Star: oneHeroCfg.Star,
|
||||||
|
Lv: 1, //初始等级
|
||||||
|
NormalSkill: []*pb.SkillData{},
|
||||||
|
Skins: []int32{},
|
||||||
|
EquipID: make([]string, 6),
|
||||||
|
AddProperty: make(map[int32]int32),
|
||||||
|
Energy: make(map[int32]int32),
|
||||||
|
Property: make(map[int32]int32),
|
||||||
}
|
}
|
||||||
return this.moduleHero.model_hero.Add(uid, newHero)
|
|
||||||
|
return this.moduleHero.model_hero.AddList(uid, objId, newHero)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取一个英雄
|
||||||
|
func (this *ModelHero) getOneHero(heroId string) (*pb.DB_HeroData, pb.ErrorCode) {
|
||||||
|
return nil, pb.ErrorCode_HeroNoExist
|
||||||
|
}
|
||||||
|
|
||||||
//指定英雄升级
|
//指定英雄升级
|
||||||
func (this *ModelHero) levelUp(uid string, heroId int32) error {
|
func (this *ModelHero) levelUp(uid string, heroId int32) error {
|
||||||
var heroes []*pb.DB_HeroData
|
var heroes []*pb.DB_HeroData
|
||||||
|
@ -45,7 +45,7 @@ func (this *Hero) GetHeroInfoByObjID(id string) (*pb.DB_HeroData, pb.ErrorCode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取英雄
|
//获取英雄
|
||||||
func (this *Hero) GetHero(heroId int32) (*pb.DB_HeroData, pb.ErrorCode) {
|
func (this *Hero) GetHero(uid, heroId int32) (*pb.DB_HeroData, pb.ErrorCode) {
|
||||||
|
|
||||||
return nil, pb.ErrorCode_HeroNoExist
|
return nil, pb.ErrorCode_HeroNoExist
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user