simulate.go 581 Bytes
package svcommon

import (
	"apigame/configs/confglobal"
	"math/rand"
)

// GetName 随机模拟玩家名字
func GetName(gameId string) string {
	config, err := confglobal.GetConfig(gameId)
	if err == nil {
		count := len(config.Names)
		if count > 0 {
			return config.Names[rand.Intn(count)]
		}
	}
	return "李四"
}

// GetAvatar 随机模拟玩家头像
func GetAvatar(gameId string) string {
	config, err := confglobal.GetConfig(gameId)
	if err == nil {
		count := len(config.Avatars)
		if count > 0 {
			return config.Avatars[rand.Intn(count)]
		}
	}
	return "lisi_icon"
}