Commit 044c1035c1c840632165f9f4be247fadca3c88e3
1 parent
9cb54a8d
Exists in
master
and in
1 other branch
feat✨:机器人随机ID
Showing
4 changed files
with
10 additions
and
5 deletions
Show diff stats
main.go
| @@ -11,6 +11,8 @@ import ( | @@ -11,6 +11,8 @@ import ( | ||
| 11 | "github.com/astaxie/beego" | 11 | "github.com/astaxie/beego" |
| 12 | "github.com/astaxie/beego/logs" | 12 | "github.com/astaxie/beego/logs" |
| 13 | "github.com/astaxie/beego/plugins/cors" | 13 | "github.com/astaxie/beego/plugins/cors" |
| 14 | + "math/rand" | ||
| 15 | + "time" | ||
| 14 | ) | 16 | ) |
| 15 | 17 | ||
| 16 | func main() { | 18 | func main() { |
| @@ -42,6 +44,8 @@ func Init() bool { | @@ -42,6 +44,8 @@ func Init() bool { | ||
| 42 | 44 | ||
| 43 | svconst.AppName = beego.AppConfig.String("appname") | 45 | svconst.AppName = beego.AppConfig.String("appname") |
| 44 | 46 | ||
| 47 | + rand.NewSource(time.Now().UnixNano()) | ||
| 48 | + | ||
| 45 | svlog.Init() | 49 | svlog.Init() |
| 46 | 50 | ||
| 47 | if beego.BConfig.RunMode != "dev" { | 51 | if beego.BConfig.RunMode != "dev" { |
service/roomrank/dto-room.go
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | "encoding/json" | 8 | "encoding/json" |
| 9 | "fmt" | 9 | "fmt" |
| 10 | "github.com/samber/lo" | 10 | "github.com/samber/lo" |
| 11 | + "math/rand" | ||
| 11 | ) | 12 | ) |
| 12 | 13 | ||
| 13 | // Room 房间排行持久数据 | 14 | // Room 房间排行持久数据 |
| @@ -46,7 +47,7 @@ type RoomPlayer struct { | @@ -46,7 +47,7 @@ type RoomPlayer struct { | ||
| 46 | 47 | ||
| 47 | func NewRoomRobot(robotConfigId int, userType int) *RoomPlayer { | 48 | func NewRoomRobot(robotConfigId int, userType int) *RoomPlayer { |
| 48 | d := &RoomPlayer{ | 49 | d := &RoomPlayer{ |
| 49 | - Uid: 0, | 50 | + Uid: rand.Int63(), |
| 50 | Score: 0, | 51 | Score: 0, |
| 51 | JoinTime: lxtime.NowUninx(), | 52 | JoinTime: lxtime.NowUninx(), |
| 52 | UserType: userType, | 53 | UserType: userType, |
service/roomrank/room.go
| @@ -6,7 +6,7 @@ import ( | @@ -6,7 +6,7 @@ import ( | ||
| 6 | "apigame/util/util-lx/lxalilog" | 6 | "apigame/util/util-lx/lxalilog" |
| 7 | "apigame/util/util-lx/lxtime" | 7 | "apigame/util/util-lx/lxtime" |
| 8 | "math" | 8 | "math" |
| 9 | - "math/rand/v2" | 9 | + "math/rand" |
| 10 | "sort" | 10 | "sort" |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| @@ -270,7 +270,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro | @@ -270,7 +270,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro | ||
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | score := (float64(confRobot.TotalScore-confRobot.MinScore) * | 272 | score := (float64(confRobot.TotalScore-confRobot.MinScore) * |
| 273 | - float64(100-confRobot.TotalRate+rand.IntN(confRobot.TotalRate*2)) / 100) * percent / 100 | 273 | + float64(100-confRobot.TotalRate+rand.Intn(confRobot.TotalRate*2)) / 100) * percent / 100 |
| 274 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) | 274 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) |
| 275 | if result < int64(confRobot.MinScore) { | 275 | if result < int64(confRobot.MinScore) { |
| 276 | result = int64(confRobot.MinScore) | 276 | result = int64(confRobot.MinScore) |
| @@ -281,7 +281,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro | @@ -281,7 +281,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro | ||
| 281 | // GetRobotScoreMax 从机器人配置里得到最高分 | 281 | // GetRobotScoreMax 从机器人配置里得到最高分 |
| 282 | func GetRobotScoreMax(confRobot *confroomrank.RobotConfig) int64 { | 282 | func GetRobotScoreMax(confRobot *confroomrank.RobotConfig) int64 { |
| 283 | score := float64(confRobot.TotalScore-confRobot.MinScore) * | 283 | score := float64(confRobot.TotalScore-confRobot.MinScore) * |
| 284 | - float64(100-confRobot.TotalRate+rand.IntN(confRobot.TotalRate*2)) / float64(100) | 284 | + float64(100-confRobot.TotalRate+rand.Intn(confRobot.TotalRate*2)) / float64(100) |
| 285 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) | 285 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) |
| 286 | if result < int64(confRobot.MinScore) { | 286 | if result < int64(confRobot.MinScore) { |
| 287 | result = int64(confRobot.MinScore) | 287 | result = int64(confRobot.MinScore) |