添加叠加字段
This commit is contained in:
parent
9c697977da
commit
cfc67b5bef
@ -77,3 +77,8 @@ const (
|
|||||||
CardTypeSkill int32 = 4 //技能升级卡
|
CardTypeSkill int32 = 4 //技能升级卡
|
||||||
CardTypeMonster int32 = 5 //怪物卡
|
CardTypeMonster int32 = 5 //怪物卡
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ResGold = "gold" //金币
|
||||||
|
ResExp = "exp" //经验
|
||||||
|
)
|
||||||
|
@ -61,6 +61,7 @@ func TestMain(m *testing.M) {
|
|||||||
go func() {
|
go func() {
|
||||||
lego.Run(service, //运行模块
|
lego.Run(service, //运行模块
|
||||||
module,
|
module,
|
||||||
|
//
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
@ -88,3 +89,12 @@ func TestHeroList(t *testing.T) {
|
|||||||
heroes, err := module.modelHero.getHeroList("u1")
|
heroes, err := module.modelHero.getHeroList("u1")
|
||||||
fmt.Printf("%v %v", heroes, err)
|
fmt.Printf("%v %v", heroes, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModify(t *testing.T) {
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"lv": 2,
|
||||||
|
"exp": 1000,
|
||||||
|
}
|
||||||
|
err := module.modelHero.modifyHero("u1", "62b534bebf4745d4117acabe", data)
|
||||||
|
fmt.Printf("%v ", err)
|
||||||
|
}
|
||||||
|
@ -40,7 +40,8 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DBHero {
|
|||||||
Star: heroCfg.Star, //初始星级
|
Star: heroCfg.Star, //初始星级
|
||||||
Lv: 1, //初始等级
|
Lv: 1, //初始等级
|
||||||
NormalSkill: []*pb.SkillData{}, //初始技能
|
NormalSkill: []*pb.SkillData{}, //初始技能
|
||||||
|
IsOverlying: true, //是否允许叠加,
|
||||||
|
Block: false, //未锁定
|
||||||
Skins: []int32{},
|
Skins: []int32{},
|
||||||
EquipID: make([]string, 6), //初始装备
|
EquipID: make([]string, 6), //初始装备
|
||||||
AddProperty: make(map[int32]int32),
|
AddProperty: make(map[int32]int32),
|
||||||
@ -91,9 +92,9 @@ func (this *ModelHero) consumeOneHeroCard(uid, heroId string) error {
|
|||||||
return this.moduleHero.modelHero.DelListlds(uid, heroId)
|
return this.moduleHero.modelHero.DelListlds(uid, heroId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Hero) ModifyHero(heroId *pb.DBHero) (*pb.DBHero, pb.ErrorCode) {
|
//更新英雄数据
|
||||||
|
func (this *ModelHero) modifyHero(uid, heroId string, data map[string]interface{}) error {
|
||||||
return nil, pb.ErrorCode_HeroNoExist
|
return this.moduleHero.modelHero.ChangeList(uid, heroId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取玩家的英雄列表
|
//获取玩家的英雄列表
|
||||||
|
@ -105,17 +105,13 @@ func (this *Hero) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) {
|
|||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Hero) QueryCardAmount(uId string, cardId int32) (amount uint32) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 给指定英雄加经验
|
// 给指定英雄加经验
|
||||||
func (this *Hero) AddCardExp(uid string, cardid string, exp int32) (code pb.ErrorCode) {
|
func (this *Hero) AddCardExp(uid string, heroId string, exp int32) (code pb.ErrorCode) {
|
||||||
var (
|
var (
|
||||||
curExp int32
|
curExp int32
|
||||||
curLv int32
|
curLv int32
|
||||||
)
|
)
|
||||||
_hero, err := this.GetHero(uid, cardid) // 获取英雄信息
|
_hero, err := this.GetHero(uid, heroId) // 获取英雄信息
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
code = pb.ErrorCode_HeroNoExist
|
code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
return
|
||||||
@ -152,10 +148,16 @@ func (this *Hero) AddCardExp(uid string, cardid string, exp int32) (code pb.Erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_hero.Lv = curLv
|
// _hero.Lv = curLv
|
||||||
_hero.Exp = curExp
|
// _hero.Exp = curExp
|
||||||
|
update := map[string]interface{}{
|
||||||
|
"lv": curLv,
|
||||||
|
"exp": curExp,
|
||||||
|
}
|
||||||
|
|
||||||
this.ModifyHero(_hero) // 修改英雄数据
|
if err := this.modelHero.modifyHero(uid, heroId, update); err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
} // 修改英雄数据
|
||||||
} else {
|
} else {
|
||||||
code = pb.ErrorCode_HeroNoExist
|
code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
return
|
||||||
|
@ -3,6 +3,7 @@ package user
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"time"
|
"time"
|
||||||
@ -22,7 +23,7 @@ type ModelUser struct {
|
|||||||
|
|
||||||
func (this *ModelUser) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *ModelUser) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
err = this.MCompModel.Init(service, module, comp, options)
|
err = this.MCompModel.Init(service, module, comp, options)
|
||||||
this.TableName = "user"
|
this.TableName = string(TableUser)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,3 +47,18 @@ func (this *ModelUser) User_Create(user *pb.DB_UserData) (err error) {
|
|||||||
_, err = this.DB.InsertOne(TableUser, user)
|
_, err = this.DB.InsertOne(TableUser, user)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取用户
|
||||||
|
func (this *ModelUser) getUser(uid string) *pb.DB_UserData {
|
||||||
|
dbUser := &pb.DB_UserData{}
|
||||||
|
if err := this.Get(uid, dbUser); err != nil {
|
||||||
|
log.Errorf("getUser err:%v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return dbUser
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置属性
|
||||||
|
func (this *ModelUser) updateUserAttr(uid string, data map[string]interface{}) error {
|
||||||
|
return this.Change(uid, data)
|
||||||
|
}
|
||||||
|
@ -42,10 +42,31 @@ func (this *User) GetHeroList(uid string) []*pb.DBHero {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//查询用户属性值 例如 金币 经验
|
||||||
func (this *User) QueryAttributeValue(uid string, attr string) (value int32) {
|
func (this *User) QueryAttributeValue(uid string, attr string) (value int32) {
|
||||||
|
user := this.modelUser.getUser(uid)
|
||||||
|
switch attr {
|
||||||
|
case comm.ResGold:
|
||||||
|
return user.Gold
|
||||||
|
case comm.ResExp:
|
||||||
|
return user.Exp
|
||||||
|
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//用户资源
|
||||||
func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) {
|
func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) {
|
||||||
|
update := make(map[string]interface{})
|
||||||
|
switch attr {
|
||||||
|
case comm.ResGold:
|
||||||
|
update[comm.ResGold] = add
|
||||||
|
case comm.ResExp:
|
||||||
|
update[comm.ResExp] = add
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := this.modelUser.updateUserAttr(uid, update); err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ type DBHero struct {
|
|||||||
SameCount int32 `protobuf:"varint,21,opt,name=sameCount,proto3" json:"sameCount" bson:"sameCount"` // 卡片叠加数量
|
SameCount int32 `protobuf:"varint,21,opt,name=sameCount,proto3" json:"sameCount" bson:"sameCount"` // 卡片叠加数量
|
||||||
SuiteId int32 `protobuf:"varint,22,opt,name=suiteId,proto3" json:"suiteId" bson:"suiteId"` // 套装Id
|
SuiteId int32 `protobuf:"varint,22,opt,name=suiteId,proto3" json:"suiteId" bson:"suiteId"` // 套装Id
|
||||||
SuiteExtId int32 `protobuf:"varint,23,opt,name=suiteExtId,proto3" json:"suiteExtId"` // go_tags(`bson:"suiteExtId"`) 扩展套装Id
|
SuiteExtId int32 `protobuf:"varint,23,opt,name=suiteExtId,proto3" json:"suiteExtId"` // go_tags(`bson:"suiteExtId"`) 扩展套装Id
|
||||||
|
IsOverlying bool `protobuf:"varint,24,opt,name=isOverlying,proto3" json:"isOverlying"` // go_tags(`bson:"isOverlying"`) 是否允许叠加 默认true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBHero) Reset() {
|
func (x *DBHero) Reset() {
|
||||||
@ -298,6 +299,13 @@ func (x *DBHero) GetSuiteExtId() int32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *DBHero) GetIsOverlying() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsOverlying
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
var File_hero_hero_db_proto protoreflect.FileDescriptor
|
var File_hero_hero_db_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_hero_hero_db_proto_rawDesc = []byte{
|
var file_hero_hero_db_proto_rawDesc = []byte{
|
||||||
@ -306,7 +314,7 @@ var file_hero_hero_db_proto_rawDesc = []byte{
|
|||||||
0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44,
|
0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44,
|
||||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x12,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x12,
|
||||||
0x18, 0x0a, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x4c, 0x76, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
|
0x18, 0x0a, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x4c, 0x76, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
|
||||||
0x52, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x4c, 0x76, 0x22, 0x90, 0x07, 0x0a, 0x06, 0x44, 0x42,
|
0x52, 0x07, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x4c, 0x76, 0x22, 0xb2, 0x07, 0x0a, 0x06, 0x44, 0x42,
|
||||||
0x48, 0x65, 0x72, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
0x48, 0x65, 0x72, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x44,
|
0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x44,
|
||||||
@ -352,19 +360,21 @@ var file_hero_hero_db_proto_rawDesc = []byte{
|
|||||||
0x69, 0x74, 0x65, 0x49, 0x64, 0x18, 0x16, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x75, 0x69,
|
0x69, 0x74, 0x65, 0x49, 0x64, 0x18, 0x16, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x75, 0x69,
|
||||||
0x74, 0x65, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x75, 0x69, 0x74, 0x65, 0x45, 0x78, 0x74,
|
0x74, 0x65, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x75, 0x69, 0x74, 0x65, 0x45, 0x78, 0x74,
|
||||||
0x49, 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x75, 0x69, 0x74, 0x65, 0x45,
|
0x49, 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x75, 0x69, 0x74, 0x65, 0x45,
|
||||||
0x78, 0x74, 0x49, 0x64, 0x1a, 0x3b, 0x0a, 0x0d, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79,
|
0x78, 0x74, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x73, 0x4f, 0x76, 0x65, 0x72, 0x6c, 0x79,
|
||||||
0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01,
|
0x69, 0x6e, 0x67, 0x18, 0x18, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 0x73, 0x4f, 0x76, 0x65,
|
||||||
0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
|
0x72, 0x6c, 0x79, 0x69, 0x6e, 0x67, 0x1a, 0x3b, 0x0a, 0x0d, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72,
|
||||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
|
0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
|
||||||
0x01, 0x1a, 0x3e, 0x0a, 0x10, 0x41, 0x64, 0x64, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79,
|
0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c,
|
||||||
0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01,
|
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
|
||||||
0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
|
0x02, 0x38, 0x01, 0x1a, 0x3e, 0x0a, 0x10, 0x41, 0x64, 0x64, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72,
|
||||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
|
0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
|
||||||
0x01, 0x1a, 0x39, 0x0a, 0x0b, 0x45, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79,
|
0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c,
|
||||||
0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b,
|
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
|
||||||
0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x02, 0x38, 0x01, 0x1a, 0x39, 0x0a, 0x0b, 0x45, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x45, 0x6e, 0x74,
|
||||||
0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04,
|
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||||
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
|
||||||
|
0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06,
|
||||||
|
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,4 +34,5 @@ message DBHero {
|
|||||||
int32 sameCount = 21; // @go_tags(`bson:"sameCount"`) 卡片叠加数量
|
int32 sameCount = 21; // @go_tags(`bson:"sameCount"`) 卡片叠加数量
|
||||||
int32 suiteId = 22; //@go_tags(`bson:"suiteId"`) 套装Id
|
int32 suiteId = 22; //@go_tags(`bson:"suiteId"`) 套装Id
|
||||||
int32 suiteExtId = 23; // go_tags(`bson:"suiteExtId"`) 扩展套装Id
|
int32 suiteExtId = 23; // go_tags(`bson:"suiteExtId"`) 扩展套装Id
|
||||||
|
bool isOverlying = 24; // go_tags(`bson:"isOverlying"`) 是否允许叠加 默认true
|
||||||
}
|
}
|
2
test/module_test.go
Normal file
2
test/module_test.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
package test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user