Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev

This commit is contained in:
meixiongfeng 2022-09-07 19:08:40 +08:00
commit ddb72771ca
9 changed files with 56 additions and 26 deletions

View File

@ -17,7 +17,7 @@ import (
"go_dreamfactory/services" "go_dreamfactory/services"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"os" "reflect"
"testing" "testing"
"time" "time"
@ -55,7 +55,13 @@ func (this *TestService) InitSys() {
} }
} }
func TestMain(m *testing.M) { func Test_Main(t *testing.T) {
oldHero := new(pb.DBHero)
oldHero.Lv = 2
new := copyPoint(oldHero)
fmt.Printf("%v", new)
oldHero.Lv = 8
currentTime := time.Unix(1637420154, 0) currentTime := time.Unix(1637420154, 0)
startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location()) startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location())
fmt.Print(startTime.Unix()) fmt.Print(startTime.Unix())
@ -76,14 +82,25 @@ func TestMain(m *testing.M) {
) )
}() }()
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
defer os.Exit(m.Run())
} }
func GetMap() map[int32]int32 { func GetMap() map[int32]int32 {
return nil return nil
} }
func copyPoint(m *pb.DBHero) *pb.DBHero {
vt := reflect.TypeOf(m).Elem()
fmt.Println(vt)
newoby := reflect.New(vt)
newoby.Elem().Set(reflect.ValueOf(m).Elem())
newoby.Interface().(*pb.DBHero).Lv = 1111
return newoby.Interface().(*pb.DBHero)
}
func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) { func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
newHero = new(pb.DBHero) newHero = new(pb.DBHero)
*newHero = *hero *newHero = *hero
newHero.Block = true newHero.Block = true
@ -92,7 +109,9 @@ func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
return return
} }
func Test_Modules(t *testing.T) { func Test_Modules(t *testing.T) {
oldHero := new(pb.DBHero)
new := copyPoint(oldHero)
fmt.Printf("%v", new)
data, _ := ptypes.MarshalAny(&pb.HeroListReq{}) data, _ := ptypes.MarshalAny(&pb.HeroListReq{})
reply := &pb.RPCMessageReply{} reply := &pb.RPCMessageReply{}
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62c79d66acc7aa239b07c21e", MainType: "hero", SubType: "list", Message: data}, reply) s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62c79d66acc7aa239b07c21e", MainType: "hero", SubType: "list", Message: data}, reply)

View File

@ -11,6 +11,7 @@ import (
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"math" "math"
"math/big" "math/big"
"reflect"
mengine "github.com/dengsgo/math-engine/engine" mengine "github.com/dengsgo/math-engine/engine"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
@ -103,10 +104,18 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId string) (hero *pb.DBH
return return
} }
// 拷贝一个指针对象
func (this *ModelHero) copyPoint(m *pb.DBHero) *pb.DBHero {
vt := reflect.TypeOf(m).Elem()
newoby := reflect.New(vt)
newoby.Elem().Set(reflect.ValueOf(m).Elem())
return newoby.Interface().(*pb.DBHero)
}
// 克隆一个英雄 // 克隆一个英雄
func (this *ModelHero) CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) { func (this *ModelHero) CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
newHero = new(pb.DBHero) newHero = new(pb.DBHero)
*newHero = *hero *newHero = *hero //*this.copyPoint(hero)
newHero.Id = primitive.NewObjectID().Hex() newHero.Id = primitive.NewObjectID().Hex()
this.AddList(newHero.Uid, newHero.Id, newHero) this.AddList(newHero.Uid, newHero.Id, newHero)
return return

View File

@ -62,7 +62,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallen
return return
} }
hunting.Boss[req.BossType] += 1 hunting.Boss[req.BossType] += 1
mapData["boos"] = hunting.Boss mapData["boss"] = hunting.Boss
//hunting.BossTime[] = 0 // todo 耗时 //hunting.BossTime[] = 0 // todo 耗时
mapData["challengeTime"] = hunting.BossTime mapData["challengeTime"] = hunting.BossTime

View File

@ -4,7 +4,6 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"strconv"
"time" "time"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -28,14 +27,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListRe
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
if len(list.Boss) == 0 {
_cfg := this.module.configure.GetHuntingBossTypeConfigData()
for k := range _cfg {
list.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_0"
list.BossTime[str] = 0
}
}
// 校验 是不是当天 // 校验 是不是当天
if !utils.IsToday(list.CTime) { if !utils.IsToday(list.CTime) {
list.CTime = time.Now().Unix() list.CTime = time.Now().Unix()

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"strconv"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
@ -45,6 +46,14 @@ func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err
return return
} }
if mgo.MongodbNil == err { if mgo.MongodbNil == err {
if len(result.Boss) == 0 {
_cfg := this.module.configure.GetHuntingBossTypeConfigData()
for k := range _cfg {
result.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_0"
result.BossTime[str] = 0
}
}
this.module.modelHunting.Add(uid, result) this.module.modelHunting.Add(uid, result)
} }
err = nil err = nil

View File

@ -4,7 +4,6 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"strconv"
"time" "time"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -28,14 +27,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
if len(list.Boss) == 0 {
_cfg := this.module.configure.GetVikingBossTypeConfigData()
for k := range _cfg {
list.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_0"
list.BossTime[str] = 0
}
}
// 校验 是不是当天 // 校验 是不是当天
if !utils.IsToday(list.CTime) { if !utils.IsToday(list.CTime) {
list.CTime = time.Now().Unix() list.CTime = time.Now().Unix()

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"strconv"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
@ -40,6 +41,14 @@ func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err err
return return
} }
if mgo.MongodbNil == err { if mgo.MongodbNil == err {
if len(result.Boss) == 0 {
_cfg := this.module.configure.GetVikingBossTypeConfigData()
for k := range _cfg {
result.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_0"
result.BossTime[str] = 0
}
}
this.module.modelViking.Add(uid, result) this.module.modelViking.Add(uid, result)
} }
err = nil err = nil

View File

@ -28,7 +28,7 @@ type DBHunting struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID
ChallengeCount int32 `protobuf:"varint,3,opt,name=challengeCount,proto3" json:"challengeCount" bson:"challengeCount"` //挑战次数 ChallengeCount int32 `protobuf:"varint,3,opt,name=challengeCount,proto3" json:"challengeCount" bson:"challengeCount"` //挑战次数
Boss map[int32]int32 `protobuf:"bytes,4,rep,name=boss,proto3" json:"boss" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key boos 类型 value 难度 Boss map[int32]int32 `protobuf:"bytes,4,rep,name=boss,proto3" json:"boss" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key boss 类型 value 难度
BuyCount int32 `protobuf:"varint,5,opt,name=buyCount,proto3" json:"buyCount" bson:"buyCount"` //购买次数 BuyCount int32 `protobuf:"varint,5,opt,name=buyCount,proto3" json:"buyCount" bson:"buyCount"` //购买次数
CTime int64 `protobuf:"varint,6,opt,name=cTime,proto3" json:"cTime" bson:"cTime"` //修改时间 CTime int64 `protobuf:"varint,6,opt,name=cTime,proto3" json:"cTime" bson:"cTime"` //修改时间
BossTime map[string]int32 `protobuf:"bytes,7,rep,name=bossTime,proto3" json:"bossTime" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"bossTime"` // BossTime map[string]int32 `protobuf:"bytes,7,rep,name=bossTime,proto3" json:"bossTime" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"bossTime"` //

View File

@ -111,7 +111,7 @@ type HuntingChallengeReq struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
BossType int32 `protobuf:"varint,1,opt,name=bossType,proto3" json:"bossType"` // boos 类型 BossType int32 `protobuf:"varint,1,opt,name=bossType,proto3" json:"bossType"` // boss 类型
Difficulty int32 `protobuf:"varint,2,opt,name=difficulty,proto3" json:"difficulty"` // 难度 Difficulty int32 `protobuf:"varint,2,opt,name=difficulty,proto3" json:"difficulty"` // 难度
} }