Commit e5dea5ddc01d5a71c9b70cb0e3425712d962536b

Authored by 王家文
1 parent 13d06609
Exists in master

feat:机器人昵称和头像

service-common/svcommon/simulate.go
@@ -52,6 +52,28 @@ func GetAvatar(gameId string) string { @@ -52,6 +52,28 @@ func GetAvatar(gameId string) string {
52 return "lisi_icon" 52 return "lisi_icon"
53 } 53 }
54 54
  55 +func GetIndexAvatars(gameId string, amount int) []int {
  56 + list := make([]int, 0)
  57 + config, err := confglobal.GetConfig(gameId)
  58 + if err == nil {
  59 + count := len(config.Avatars)
  60 + if count > 0 {
  61 + return zmisc.RandomMultiple(amount, 0, count)
  62 + }
  63 + }
  64 + return list
  65 +}
  66 +
  67 +func GetIndexAvatar(gameId string, index int) string {
  68 + config, err := confglobal.GetConfig(gameId)
  69 + if err == nil {
  70 + if len(config.Avatars) > index {
  71 + return config.Avatars[index]
  72 + }
  73 + }
  74 + return "lisi_icon"
  75 +}
  76 +
55 // GetAvatarPath 随机模拟玩家头像路径 77 // GetAvatarPath 随机模拟玩家头像路径
56 func GetAvatarPath(gameId string) string { 78 func GetAvatarPath(gameId string) string {
57 config, err := confglobal.GetConfig(gameId) 79 config, err := confglobal.GetConfig(gameId)
service/roomrank/dto-room.go
@@ -50,8 +50,9 @@ type RoomPlayer struct { @@ -50,8 +50,9 @@ type RoomPlayer struct {
50 50
51 // RoomDetails 详情 51 // RoomDetails 详情
52 type RoomDetails struct { 52 type RoomDetails struct {
53 - Players []*RoomPlayer // 房间玩家列表  
54 - IndexNames []int // 房间玩家名字列表 53 + Players []*RoomPlayer // 房间玩家列表
  54 + IndexNames []int // 房间玩家名字列表
  55 + IndexAvatars []int // 房间玩家头像列表
55 } 56 }
56 57
57 // Encode 打包数据 58 // Encode 打包数据
@@ -67,8 +68,9 @@ func (d *Room) Encode() { @@ -67,8 +68,9 @@ func (d *Room) Encode() {
67 // Decode 分包数据 68 // Decode 分包数据
68 func (d *Room) Decode() { 69 func (d *Room) Decode() {
69 d.Details = &RoomDetails{ 70 d.Details = &RoomDetails{
70 - Players: make([]*RoomPlayer, 0),  
71 - IndexNames: make([]int, 0), 71 + Players: make([]*RoomPlayer, 0),
  72 + IndexNames: make([]int, 0),
  73 + IndexAvatars: make([]int, 0),
72 } 74 }
73 err := json.Unmarshal([]byte(d.DetailsText), d.Details) 75 err := json.Unmarshal([]byte(d.DetailsText), d.Details)
74 if err != nil { 76 if err != nil {
service/roomrank/player.go
@@ -50,7 +50,7 @@ func NewRoomRobot(gameId string, room *Room, robotConfigId int, userType int) *R @@ -50,7 +50,7 @@ func NewRoomRobot(gameId string, room *Room, robotConfigId int, userType int) *R
50 //Uid: rand.Int63(), 50 //Uid: rand.Int63(),
51 //Uid: int64(utuuid.GetUint32()), 51 //Uid: int64(utuuid.GetUint32()),
52 //Name: svcommon.GetName(gameId), 52 //Name: svcommon.GetName(gameId),
53 - Icon: svcommon.GetAvatar(gameId), 53 + //Icon: svcommon.GetAvatar(gameId),
54 Score: 0, 54 Score: 0,
55 JoinTime: lxtime.NowUninx(), 55 JoinTime: lxtime.NowUninx(),
56 UserType: userType, 56 UserType: userType,
@@ -62,7 +62,13 @@ func NewRoomRobot(gameId string, room *Room, robotConfigId int, userType int) *R @@ -62,7 +62,13 @@ func NewRoomRobot(gameId string, room *Room, robotConfigId int, userType int) *R
62 } else { 62 } else {
63 d.Name = svcommon.GetName(gameId) 63 d.Name = svcommon.GetName(gameId)
64 } 64 }
65 - d.Uid = 9900_0000 + int64(len(room.Details.Players)) 65 + if len(room.Details.IndexAvatars) > 0 {
  66 + d.Icon = svcommon.GetIndexAvatar(gameId, room.Details.IndexAvatars[0])
  67 + room.Details.IndexAvatars = room.Details.IndexAvatars[1:]
  68 + } else {
  69 + d.Icon = svcommon.GetAvatar(gameId)
  70 + }
  71 + d.Uid = int64(len(room.Details.Players))
66 return d 72 return d
67 } 73 }
68 74
service/roomrank/room.go
@@ -61,6 +61,7 @@ func CreateRoom(gameId string, topType int, config *confroomrank.ActivityConfig, @@ -61,6 +61,7 @@ func CreateRoom(gameId string, topType int, config *confroomrank.ActivityConfig,
61 details := new(RoomDetails) 61 details := new(RoomDetails)
62 details.Players = make([]*RoomPlayer, 0) 62 details.Players = make([]*RoomPlayer, 0)
63 details.IndexNames = make([]int, 0) 63 details.IndexNames = make([]int, 0)
  64 + details.IndexAvatars = make([]int, 0)
64 room.Details = details 65 room.Details = details
65 66
66 err := svmysql.Save(room, gameId) 67 err := svmysql.Save(room, gameId)
@@ -148,6 +149,7 @@ func TryFindRoom(gameId string, topType int, player *Player, config *confroomran @@ -148,6 +149,7 @@ func TryFindRoom(gameId string, topType int, player *Player, config *confroomran
148 room = roomCreate 149 room = roomCreate
149 150
150 room.Details.IndexNames = svcommon.GetIndexNames(gameId, roomConfig.TotalPlayer) 151 room.Details.IndexNames = svcommon.GetIndexNames(gameId, roomConfig.TotalPlayer)
  152 + room.Details.IndexAvatars = svcommon.GetIndexAvatars(gameId, roomConfig.TotalPlayer)
151 153
152 // 配置原生机器人 154 // 配置原生机器人
153 JoinInitRobot(gameId, room, roomConfig) 155 JoinInitRobot(gameId, room, roomConfig)