Commit d5ff2efa83757861f539514ad9d372e6bcf7b352

Authored by 王家文
1 parent f1f886fc
Exists in master and in 1 other branch dev-wjw

feat✨:房间排行活动:配置接入

configs/confroomrank/config.go
@@ -17,6 +17,7 @@ type ActivityConfig struct { @@ -17,6 +17,7 @@ type ActivityConfig struct {
17 PreviewTime int64 // 预告时间 17 PreviewTime int64 // 预告时间
18 StartTime int64 // 开始时间 18 StartTime int64 // 开始时间
19 EndTime int64 // 结束时间 19 EndTime int64 // 结束时间
  20 + ReleaseTime int64 // 结算发奖时间
20 21
21 Robot map[int]RobotConfig // 机器人配置 22 Robot map[int]RobotConfig // 机器人配置
22 Room map[int]RoomConfig // 房间配置 23 Room map[int]RoomConfig // 房间配置
@@ -57,9 +58,10 @@ type ActivityConfigRaw struct { @@ -57,9 +58,10 @@ type ActivityConfigRaw struct {
57 PreviewTime int64 // 预告时间 58 PreviewTime int64 // 预告时间
58 StartTime int64 // 开始时间 59 StartTime int64 // 开始时间
59 EndTime int64 // 结束时间 60 EndTime int64 // 结束时间
  61 + ReleaseTime int64 // 结算发奖时间
60 62
61 - Robot string // 机器人配置  
62 - Room string // 房间配置 63 + BootConfig string // 机器人配置
  64 + RoomConfig string // 房间配置
63 65
64 Ver string // 版本号 66 Ver string // 版本号
65 Status int // 状态 0=关闭 1=开启 67 Status int // 状态 0=关闭 1=开启
@@ -76,20 +78,20 @@ type RobotConfig struct { @@ -76,20 +78,20 @@ type RobotConfig struct {
76 Id int `json:"id"` // id 78 Id int `json:"id"` // id
77 MinScore int `json:"min_score"` // 最低分数 79 MinScore int `json:"min_score"` // 最低分数
78 TotalScore int `json:"total_score"` // 总分数 80 TotalScore int `json:"total_score"` // 总分数
79 - TotalRate int `json:"total_rate"` // 总分浮动范围(%) 81 + Range int `json:"range"` // 总分浮动范围(%)
80 } 82 }
81 83
82 // RoomConfig 房间配置 84 // RoomConfig 房间配置
83 type RoomConfig struct { 85 type RoomConfig struct {
84 - Id int `json:"id"` // id  
85 - Levels []int `json:"levels"` // 等级范围  
86 - UserClass int `json:"user_class"` // 评级  
87 - UserScore []int `json:"user_score"` // 分数范围  
88 - TotalPlayer int `json:"total_player"` // 房间总人数  
89 - PlayerTypeCount [][]int `json:"player_type_count"` // 玩家类型数量  
90 - AutoRobot []int `json:"auto_robot"` // 自动填充机器人  
91 - InitRobot [][]int `json:"init_robot"` // 配置机器人  
92 - Awards []string `json:"awards"` // 奖励  
93 - SettleScores []int `json:"settle_scores"` // 结算分数调整  
94 - SettleUserType []int `json:"settle_user_type"` // 结算用户类型 86 + Id int `json:"id"` // id
  87 + Levels []int `json:"level_range"` // 等级范围
  88 + UserClass int `json:"rating"` // 评级
  89 + UserScore []int `json:"score_range"` // 分数范围
  90 + TotalPlayer int `json:"room_user_number"` // 房间总人数
  91 + PlayerTypeCount [][]int `json:"user_type_number"` // 玩家类型数量
  92 + AutoRobot []int `json:"auto_room"` // 自动填充机器人
  93 + InitRobot [][]int `json:"disposition_robots"` // 配置机器人
  94 + Awards map[string]string `json:"rewards"` // 奖励
  95 + SettleScores []int `json:"score_adjest"` // 结算分数调整
  96 + SettleUserType []int `json:"user_type"` // 结算用户类型
95 } 97 }
configs/confroomrank/decode.go
@@ -16,6 +16,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { @@ -16,6 +16,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) {
16 c.PreviewTime = raw.PreviewTime 16 c.PreviewTime = raw.PreviewTime
17 c.StartTime = raw.StartTime 17 c.StartTime = raw.StartTime
18 c.EndTime = raw.EndTime 18 c.EndTime = raw.EndTime
  19 + c.ReleaseTime = raw.ReleaseTime
19 20
20 c.Robot = make(map[int]RobotConfig) 21 c.Robot = make(map[int]RobotConfig)
21 c.Room = make(map[int]RoomConfig) 22 c.Room = make(map[int]RoomConfig)
@@ -23,9 +24,9 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { @@ -23,9 +24,9 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) {
23 // 解析 机器人 24 // 解析 机器人
24 { 25 {
25 configs := make([]RobotConfig, 0) 26 configs := make([]RobotConfig, 0)
26 - err := json.Unmarshal([]byte(raw.Robot), &configs) 27 + err := json.Unmarshal([]byte(raw.BootConfig), &configs)
27 if err != nil { 28 if err != nil {
28 - lxalilog.Errors(err, raw.Robot, gameId, raw.Id) 29 + lxalilog.Errors(err, raw.BootConfig, gameId, raw.Id)
29 return 30 return
30 } 31 }
31 for _, i2 := range configs { 32 for _, i2 := range configs {
@@ -35,9 +36,9 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { @@ -35,9 +36,9 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) {
35 // 解析 房间 36 // 解析 房间
36 { 37 {
37 configs := make([]RoomConfig, 0) 38 configs := make([]RoomConfig, 0)
38 - err := json.Unmarshal([]byte(raw.Room), &configs) 39 + err := json.Unmarshal([]byte(raw.RoomConfig), &configs)
39 if err != nil { 40 if err != nil {
40 - lxalilog.Errors(err, raw.Room, gameId, raw.Id) 41 + lxalilog.Errors(err, raw.RoomConfig, gameId, raw.Id)
41 return 42 return
42 } 43 }
43 for _, i2 := range configs { 44 for _, i2 := range configs {
controllers/demo.go
1 package controllers 1 package controllers
2 2
3 import ( 3 import (
4 - "apigame/configs/confroomrank"  
5 "apigame/models" 4 "apigame/models"
6 "apigame/service/code-msg" 5 "apigame/service/code-msg"
7 "apigame/util/util-lx/lxalilog" 6 "apigame/util/util-lx/lxalilog"
8 - "apigame/util/zjson"  
9 "fmt" 7 "fmt"
10 ) 8 )
11 9
@@ -26,50 +24,6 @@ func (c *DemoController) Demo() { @@ -26,50 +24,6 @@ func (c *DemoController) Demo() {
26 24
27 lxalilog.Errors("DemoController.demo") 25 lxalilog.Errors("DemoController.demo")
28 26
29 - {  
30 - list := make([]confroomrank.RobotConfig, 0)  
31 - list = append(list, confroomrank.RobotConfig{  
32 - Id: 1,  
33 - MinScore: 10,  
34 - TotalScore: 30,  
35 - TotalRate: 10,  
36 - })  
37 - list = append(list, confroomrank.RobotConfig{  
38 - Id: 2,  
39 - MinScore: 20,  
40 - TotalScore: 50,  
41 - TotalRate: 6,  
42 - })  
43 - list = append(list, confroomrank.RobotConfig{  
44 - Id: 3,  
45 - MinScore: 50,  
46 - TotalScore: 200,  
47 - TotalRate: 5,  
48 - })  
49 - fmt.Println(zjson.Str(list))  
50 - }  
51 - {  
52 - list := make([]confroomrank.RoomConfig, 0)  
53 - {  
54 - room := confroomrank.RoomConfig{}  
55 - room.Id = 1  
56 - room.Levels = []int{1, 9999}  
57 - room.UserClass = 0  
58 - room.UserScore = []int{0, 0}  
59 - room.TotalPlayer = 50  
60 - room.PlayerTypeCount = [][]int{{0, 5}}  
61 - room.AutoRobot = []int{1}  
62 - room.InitRobot = [][]int{{1, 5}, {2, 10}, {3, 30}}  
63 - for i := 0; i < 50; i++ {  
64 - room.Awards = append(room.Awards, "award")  
65 - room.SettleScores = append(room.SettleScores, 50-i)  
66 - room.SettleUserType = append(room.SettleUserType, 1)  
67 - }  
68 - list = append(list, room)  
69 - }  
70 - fmt.Println(zjson.Str(list))  
71 - }  
72 -  
73 //{ 27 //{
74 // gameId := "10149" 28 // gameId := "10149"
75 // { 29 // {
service-common/svconst/mysql.go
@@ -17,7 +17,7 @@ const ( @@ -17,7 +17,7 @@ const (
17 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励 17 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励
18 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround" // 开卡包活动日志领取轮次奖励 18 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround" // 开卡包活动日志领取轮次奖励
19 19
20 - MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity" // 房间排行活动配置  
21 - MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player" // 房间排行玩家数据  
22 - MYSQL_TABLE_S_ROOMRANK_ROOM = "s_roomrank_room" // 房间排行房间数据 20 + MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_beach_rank_activity" // 房间排行活动配置
  21 + MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player" // 房间排行玩家数据
  22 + MYSQL_TABLE_S_ROOMRANK_ROOM = "s_roomrank_room" // 房间排行房间数据
23 ) 23 )
service/roomrank/logic.go
@@ -2,6 +2,9 @@ package roomrank @@ -2,6 +2,9 @@ package roomrank
2 2
3 import ( 3 import (
4 "apigame/configs/confroomrank" 4 "apigame/configs/confroomrank"
  5 + "apigame/util/utstring"
  6 + "apigame/util/zjson"
  7 + "fmt"
5 ) 8 )
6 9
7 // TrySettle 尝试判断结算 10 // TrySettle 尝试判断结算
@@ -16,6 +19,7 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi @@ -16,6 +19,7 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
16 if player.ActivityId == config.Id { 19 if player.ActivityId == config.Id {
17 return 20 return
18 } 21 }
  22 + fmt.Println(zjson.Str(player))
19 // 查找玩家所在的房间 23 // 查找玩家所在的房间
20 room, hasRoom := LoadRoom(gameId, player.ActivityId, player.RoomUid) 24 room, hasRoom := LoadRoom(gameId, player.ActivityId, player.RoomUid)
21 if !hasRoom { 25 if !hasRoom {
@@ -38,8 +42,8 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi @@ -38,8 +42,8 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
38 if !hasConfRoom { 42 if !hasConfRoom {
39 return 43 return
40 } 44 }
41 - if len(confRoom.Awards) > rankIndex {  
42 - player.SettleAward = confRoom.Awards[rankIndex] 45 + if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rankIndex)]; hasConfAward {
  46 + player.SettleAward = confAward
43 } 47 }
44 if len(confRoom.SettleScores) > rankIndex { 48 if len(confRoom.SettleScores) > rankIndex {
45 player.AddUserScore(confRoom.SettleScores[rankIndex]) 49 player.AddUserScore(confRoom.SettleScores[rankIndex])
service/roomrank/room.go
@@ -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.Range+rand.Intn(confRobot.Range*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.Range+rand.Intn(confRobot.Range*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)