diff --git a/cmd/cmd.go b/cmd/cmd.go index 68dfd101a..2d1205845 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -3,10 +3,12 @@ package main import ( "fmt" "go_dreamfactory/cmd/robot" + "go_dreamfactory/pb" "os" "github.com/sirupsen/logrus" flag "github.com/spf13/pflag" + "go.mongodb.org/mongo-driver/bson/primitive" "github.com/spf13/cobra" ) @@ -38,8 +40,14 @@ var sid = flag.Int32("sid", 0, "区服ID") var create = flag.Bool("create", false, "是否创建新账号") //false 不创建新账号 var role = flag.Bool("role", false, "创角") +func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) { + newHero = &*hero + newHero.Id = primitive.NewObjectID().Hex() + + return +} func main() { - Execute() + //Execute() } var runCmd = &cobra.Command{ diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index 47fbb0140..8850efdf4 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -22,6 +22,7 @@ import ( "time" "github.com/golang/protobuf/ptypes" + "go.mongodb.org/mongo-driver/bson/primitive" ) var service core.IService @@ -55,8 +56,19 @@ func (this *TestService) InitSys() { } func TestMain(m *testing.M) { + sz := GetMap() + if len(sz) == 0 { + sz = make(map[int32]int32, 0) + } + + sz[2] = 2 + hero := &pb.DBHero{} + hero.Block = false + hero.Lv = 12 + new := CloneNewHero(hero) + fmt.Printf("%v", new) service = newService( - rpcx.SetConfPath("../../bin/conf/worker_2.yaml"), + rpcx.SetConfPath("../../bin/conf/worker_1.yaml"), ) service.OnInstallComp( //装备组件 s_gateComp, //此服务需要接受用户的消息 需要装备网关组件 @@ -73,7 +85,20 @@ func TestMain(m *testing.M) { time.Sleep(time.Second * 2) defer os.Exit(m.Run()) } + +func GetMap() map[int32]int32 { + return nil +} +func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) { + temp := *hero + newHero = &temp + newHero.Block = true + newHero.Lv = 100 + newHero.Id = primitive.NewObjectID().Hex() + return +} func Test_Modules(t *testing.T) { + data, _ := ptypes.MarshalAny(&pb.HeroListReq{}) reply := &pb.RPCMessageReply{} s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62c79d66acc7aa239b07c21e", MainType: "hero", SubType: "list", Message: data}, reply) diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index ea7ad2962..94284f9c8 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -102,7 +102,8 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId string) (hero *pb.DBH // 克隆一个英雄 func (this *ModelHero) CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) { - newHero = &*hero + temp := *hero + newHero = &temp newHero.Id = primitive.NewObjectID().Hex() this.AddList(newHero.Uid, newHero.Id, newHero) return @@ -115,11 +116,12 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int // 添加图鉴 go func(uid, heroCfgId string) { // 携程处理 图鉴数据 if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil { - sz := make(map[string]bool, 0) - for k := range result.GetTujian() { - sz[k] = true - } + if _, ok := result.GetTujian()[heroCfgId]; !ok { + sz := result.GetTujian() + if len(sz) == 0 { + sz = make(map[string]bool, 0) + } sz[heroCfgId] = true initUpdate := map[string]interface{}{ "tujian": sz, diff --git a/modules/hero/model_record.go b/modules/hero/model_record.go index a3afd9ee9..14f6904ae 100644 --- a/modules/hero/model_record.go +++ b/modules/hero/model_record.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" "go_dreamfactory/pb" "time" @@ -33,9 +34,10 @@ func (this *ModelRecord) getUserSession(uid string) (cuser *pb.CacheUser) { //获取用户通过扩展表 func (this *ModelRecord) GetHeroRecord(uid string) (result *pb.DBHeroRecord, err error) { result = &pb.DBHeroRecord{} - if err = this.Get(uid, result); err != nil { + if err = this.Get(uid, result); err != nil && err != redis.RedisNil { return } + err = nil return result, err } diff --git a/modules/user/model_expand.go b/modules/user/model_expand.go index 0b4f0884d..87d3f01d8 100644 --- a/modules/user/model_expand.go +++ b/modules/user/model_expand.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" "go_dreamfactory/pb" ) @@ -34,10 +35,10 @@ func (this *ModelExpand) getUserSession(uid string) (cuser *pb.CacheUser) { //获取用户通过扩展表 func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) { result = &pb.DBUserExpand{} - if err = this.moduleUser.modelExpand.Get(uid, result); err != nil { + if err = this.moduleUser.modelExpand.Get(uid, result); err != nil && redis.RedisNil != err { return } - + err = nil return result, err }