simulate.go
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package svcommon
import (
"apigame/configs-db/confglobal"
"apigame/util/zmisc"
"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 "李四"
}
func GetIndexNames(gameId string, amount int) []int {
list := make([]int, 0)
config, err := confglobal.GetConfig(gameId)
if err == nil {
count := len(config.Names)
if count > 0 {
return zmisc.RandomMultiple(amount, 0, count)
}
}
return list
}
func GetIndexName(gameId string, index int) string {
config, err := confglobal.GetConfig(gameId)
if err == nil {
if len(config.Names) > index {
return config.Names[index]
}
}
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"
}
// GetAvatarPath 随机模拟玩家头像路径
func GetAvatarPath(gameId string) string {
config, err := confglobal.GetConfig(gameId)
if err == nil {
return config.AvatarPath
}
return ""
}