diff --git a/service-common/svcommon/simulate.go b/service-common/svcommon/simulate.go index 3b6187e..c38623e 100644 --- a/service-common/svcommon/simulate.go +++ b/service-common/svcommon/simulate.go @@ -52,6 +52,28 @@ func GetAvatar(gameId string) string { return "lisi_icon" } +func GetIndexAvatars(gameId string, amount int) []int { + list := make([]int, 0) + config, err := confglobal.GetConfig(gameId) + if err == nil { + count := len(config.Avatars) + if count > 0 { + return zmisc.RandomMultiple(amount, 0, count) + } + } + return list +} + +func GetIndexAvatar(gameId string, index int) string { + config, err := confglobal.GetConfig(gameId) + if err == nil { + if len(config.Avatars) > index { + return config.Avatars[index] + } + } + return "lisi_icon" +} + // GetAvatarPath 随机模拟玩家头像路径 func GetAvatarPath(gameId string) string { config, err := confglobal.GetConfig(gameId) diff --git a/service/roomrank/dto-room.go b/service/roomrank/dto-room.go index 8bcbdf0..257bcf2 100644 --- a/service/roomrank/dto-room.go +++ b/service/roomrank/dto-room.go @@ -50,8 +50,9 @@ type RoomPlayer struct { // RoomDetails 详情 type RoomDetails struct { - Players []*RoomPlayer // 房间玩家列表 - IndexNames []int // 房间玩家名字列表 + Players []*RoomPlayer // 房间玩家列表 + IndexNames []int // 房间玩家名字列表 + IndexAvatars []int // 房间玩家头像列表 } // Encode 打包数据 @@ -67,8 +68,9 @@ func (d *Room) Encode() { // Decode 分包数据 func (d *Room) Decode() { d.Details = &RoomDetails{ - Players: make([]*RoomPlayer, 0), - IndexNames: make([]int, 0), + Players: make([]*RoomPlayer, 0), + IndexNames: make([]int, 0), + IndexAvatars: make([]int, 0), } err := json.Unmarshal([]byte(d.DetailsText), d.Details) if err != nil { diff --git a/service/roomrank/player.go b/service/roomrank/player.go index 3f346fb..847dfbb 100644 --- a/service/roomrank/player.go +++ b/service/roomrank/player.go @@ -50,7 +50,7 @@ func NewRoomRobot(gameId string, room *Room, robotConfigId int, userType int) *R //Uid: rand.Int63(), //Uid: int64(utuuid.GetUint32()), //Name: svcommon.GetName(gameId), - Icon: svcommon.GetAvatar(gameId), + //Icon: svcommon.GetAvatar(gameId), Score: 0, JoinTime: lxtime.NowUninx(), UserType: userType, @@ -62,7 +62,13 @@ func NewRoomRobot(gameId string, room *Room, robotConfigId int, userType int) *R } else { d.Name = svcommon.GetName(gameId) } - d.Uid = 9900_0000 + int64(len(room.Details.Players)) + if len(room.Details.IndexAvatars) > 0 { + d.Icon = svcommon.GetIndexAvatar(gameId, room.Details.IndexAvatars[0]) + room.Details.IndexAvatars = room.Details.IndexAvatars[1:] + } else { + d.Icon = svcommon.GetAvatar(gameId) + } + d.Uid = int64(len(room.Details.Players)) return d } diff --git a/service/roomrank/room.go b/service/roomrank/room.go index f8452fa..b7da051 100644 --- a/service/roomrank/room.go +++ b/service/roomrank/room.go @@ -61,6 +61,7 @@ func CreateRoom(gameId string, topType int, config *confroomrank.ActivityConfig, details := new(RoomDetails) details.Players = make([]*RoomPlayer, 0) details.IndexNames = make([]int, 0) + details.IndexAvatars = make([]int, 0) room.Details = details err := svmysql.Save(room, gameId) @@ -148,6 +149,7 @@ func TryFindRoom(gameId string, topType int, player *Player, config *confroomran room = roomCreate room.Details.IndexNames = svcommon.GetIndexNames(gameId, roomConfig.TotalPlayer) + room.Details.IndexAvatars = svcommon.GetIndexAvatars(gameId, roomConfig.TotalPlayer) // 配置原生机器人 JoinInitRobot(gameId, room, roomConfig) -- libgit2 0.21.0