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 17 PreviewTime int64 // 预告时间
18 18 StartTime int64 // 开始时间
19 19 EndTime int64 // 结束时间
  20 + ReleaseTime int64 // 结算发奖时间
20 21  
21 22 Robot map[int]RobotConfig // 机器人配置
22 23 Room map[int]RoomConfig // 房间配置
... ... @@ -57,9 +58,10 @@ type ActivityConfigRaw struct {
57 58 PreviewTime int64 // 预告时间
58 59 StartTime int64 // 开始时间
59 60 EndTime int64 // 结束时间
  61 + ReleaseTime int64 // 结算发奖时间
60 62  
61   - Robot string // 机器人配置
62   - Room string // 房间配置
  63 + BootConfig string // 机器人配置
  64 + RoomConfig string // 房间配置
63 65  
64 66 Ver string // 版本号
65 67 Status int // 状态 0=关闭 1=开启
... ... @@ -76,20 +78,20 @@ type RobotConfig struct {
76 78 Id int `json:"id"` // id
77 79 MinScore int `json:"min_score"` // 最低分数
78 80 TotalScore int `json:"total_score"` // 总分数
79   - TotalRate int `json:"total_rate"` // 总分浮动范围(%)
  81 + Range int `json:"range"` // 总分浮动范围(%)
80 82 }
81 83  
82 84 // RoomConfig 房间配置
83 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 16 c.PreviewTime = raw.PreviewTime
17 17 c.StartTime = raw.StartTime
18 18 c.EndTime = raw.EndTime
  19 + c.ReleaseTime = raw.ReleaseTime
19 20  
20 21 c.Robot = make(map[int]RobotConfig)
21 22 c.Room = make(map[int]RoomConfig)
... ... @@ -23,9 +24,9 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) {
23 24 // 解析 机器人
24 25 {
25 26 configs := make([]RobotConfig, 0)
26   - err := json.Unmarshal([]byte(raw.Robot), &configs)
  27 + err := json.Unmarshal([]byte(raw.BootConfig), &configs)
27 28 if err != nil {
28   - lxalilog.Errors(err, raw.Robot, gameId, raw.Id)
  29 + lxalilog.Errors(err, raw.BootConfig, gameId, raw.Id)
29 30 return
30 31 }
31 32 for _, i2 := range configs {
... ... @@ -35,9 +36,9 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) {
35 36 // 解析 房间
36 37 {
37 38 configs := make([]RoomConfig, 0)
38   - err := json.Unmarshal([]byte(raw.Room), &configs)
  39 + err := json.Unmarshal([]byte(raw.RoomConfig), &configs)
39 40 if err != nil {
40   - lxalilog.Errors(err, raw.Room, gameId, raw.Id)
  41 + lxalilog.Errors(err, raw.RoomConfig, gameId, raw.Id)
41 42 return
42 43 }
43 44 for _, i2 := range configs {
... ...
controllers/demo.go
1 1 package controllers
2 2  
3 3 import (
4   - "apigame/configs/confroomrank"
5 4 "apigame/models"
6 5 "apigame/service/code-msg"
7 6 "apigame/util/util-lx/lxalilog"
8   - "apigame/util/zjson"
9 7 "fmt"
10 8 )
11 9  
... ... @@ -26,50 +24,6 @@ func (c *DemoController) Demo() {
26 24  
27 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 28 // gameId := "10149"
75 29 // {
... ...
service-common/svconst/mysql.go
... ... @@ -17,7 +17,7 @@ const (
17 17 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励
18 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 2  
3 3 import (
4 4 "apigame/configs/confroomrank"
  5 + "apigame/util/utstring"
  6 + "apigame/util/zjson"
  7 + "fmt"
5 8 )
6 9  
7 10 // TrySettle 尝试判断结算
... ... @@ -16,6 +19,7 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
16 19 if player.ActivityId == config.Id {
17 20 return
18 21 }
  22 + fmt.Println(zjson.Str(player))
19 23 // 查找玩家所在的房间
20 24 room, hasRoom := LoadRoom(gameId, player.ActivityId, player.RoomUid)
21 25 if !hasRoom {
... ... @@ -38,8 +42,8 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
38 42 if !hasConfRoom {
39 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 48 if len(confRoom.SettleScores) > rankIndex {
45 49 player.AddUserScore(confRoom.SettleScores[rankIndex])
... ...
service/roomrank/room.go
... ... @@ -270,7 +270,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro
270 270 }
271 271  
272 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 274 result := int64(confRobot.MinScore) + int64(math.Ceil(score))
275 275 if result < int64(confRobot.MinScore) {
276 276 result = int64(confRobot.MinScore)
... ... @@ -281,7 +281,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro
281 281 // GetRobotScoreMax 从机器人配置里得到最高分
282 282 func GetRobotScoreMax(confRobot *confroomrank.RobotConfig) int64 {
283 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 285 result := int64(confRobot.MinScore) + int64(math.Ceil(score))
286 286 if result < int64(confRobot.MinScore) {
287 287 result = int64(confRobot.MinScore)
... ...