Commit 64c263aaff8876fdc5c9cc45d726b1dbe85b0780

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

feat:抽卡(非保底部分)

service/ht-cardholder/config-registry.go
... ... @@ -22,14 +22,14 @@ func NewConfigs() {
22 22 // ConfigDecode 解析配置原始数据
23 23 func ConfigDecode() {
24 24 Config = CardActivityConfig{
25   - Raw: ConfigRaws,
26   - Id: ConfigRaws.Id,
27   - Awards: make(map[string]string),
28   - AlbumConfig: make(map[string]AlbumConfig),
29   - CardConfig: make(map[int]CardConfig),
30   - CardholderConfig: make(map[string]CardholderConfig),
31   - NormalCardStarSequence: make(map[string]NormalCardStarSequence),
32   - CardSequenceConfig: make(map[string]CardSequenceConfig),
  25 + Raw: ConfigRaws,
  26 + Id: ConfigRaws.Id,
  27 + Awards: make(map[string]string),
  28 + AlbumConfig: make(map[string]AlbumConfig),
  29 + CardConfig: make(map[int]CardConfig),
  30 + CardholderConfig: make(map[string]CardholderConfig),
  31 + NormalCardStarConfig: make(map[string]NormalCardStarConfig),
  32 + CardSequenceConfig: make(map[string]CardSequenceConfig),
33 33 }
34 34 // 解析奖励
35 35 {
... ... @@ -77,7 +77,7 @@ func ConfigDecode() {
77 77 }
78 78 // 卡片星级配置
79 79 {
80   - configs := make([]NormalCardStarSequence, 0)
  80 + configs := make([]NormalCardStarConfig, 0)
81 81 err := json.Unmarshal([]byte(ConfigRaws.NormalCardStarSequence), &configs)
82 82 if err != nil {
83 83 lxalilog.Errors(err, ConfigRaws.NormalCardStarSequence, constd.GAME_ID_HT, ConfigRaws.Id)
... ... @@ -86,7 +86,7 @@ func ConfigDecode() {
86 86 for _, i2 := range configs {
87 87 i2.NormalCardSequenceIds = strings.Split(i2.NormalCardSequenceId, ",")
88 88 combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)
89   - Config.NormalCardStarSequence[combineId] = i2
  89 + Config.NormalCardStarConfig[combineId] = i2
90 90 }
91 91 }
92 92 // 卡片星级对应卡牌配置
... ... @@ -108,7 +108,7 @@ func ConfigDecode() {
108 108 //logs.Debug(Config.AlbumConfig)
109 109 //logs.Debug(Config.CardConfig)
110 110 //logs.Debug(Config.CardholderConfig)
111   - //logs.Debug("🐸", Config.NormalCardStarSequence)
  111 + //logs.Debug("🐸", Config.NormalCardStarConfig)
112 112 //logs.Debug("🐸", Config.CardSequenceConfig)
113 113 }
114 114  
... ... @@ -117,12 +117,22 @@ func CombineIdSequenceIdCohort(id, sequenceId, cohort string) string {
117 117 return fmt.Sprintf("%s_%s_%s", id, sequenceId, cohort)
118 118 }
119 119  
  120 +// FindNormalCardStarConfig 查找配置 非保底卡星级ID
  121 +func FindNormalCardStarConfig(id, sequenceId, cohort string) (conf NormalCardStarConfig, has bool) {
  122 + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
  123 + conf, has = Config.NormalCardStarConfig[combineId]
  124 + if !has {
  125 + lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort)
  126 + }
  127 + return
  128 +}
  129 +
120 130 // FindCardSequenceConfig 查找配置 星级ID对应的卡片
121 131 func FindCardSequenceConfig(id, sequenceId, cohort string) (conf CardSequenceConfig, has bool) {
122 132 combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
123 133 conf, has = Config.CardSequenceConfig[combineId]
124 134 if !has {
125   - lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), " LoadData Error", id, sequenceId, cohort)
  135 + lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort)
126 136 }
127 137 return
128 138 }
... ...
service/ht-cardholder/config.go
... ... @@ -11,14 +11,14 @@ type CardActivityUpdateConfig struct {
11 11  
12 12 // CardActivityConfig 卡牌活动配置 分析后数据
13 13 type CardActivityConfig struct {
14   - Raw CardActivityConfigRaw
15   - Id int64 // ID
16   - Awards map[string]string // 奖励配置
17   - AlbumConfig map[string]AlbumConfig // 卡组配置
18   - CardConfig map[int]CardConfig // 卡牌配置
19   - CardholderConfig map[string]CardholderConfig // 卡包开卡规则
20   - NormalCardStarSequence map[string]NormalCardStarSequence // k=ID_用户序列_用户分组 卡片星级配置
21   - CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置
  14 + Raw CardActivityConfigRaw
  15 + Id int64 // ID
  16 + Awards map[string]string // 奖励配置
  17 + AlbumConfig map[string]AlbumConfig // 卡组配置
  18 + CardConfig map[int]CardConfig // 卡牌配置
  19 + CardholderConfig map[string]CardholderConfig // 卡包开卡规则
  20 + NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置
  21 + CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置
22 22 }
23 23  
24 24 func (c *CardActivityConfig) TableName() string {
... ... @@ -63,15 +63,15 @@ type CardConfig struct {
63 63 // CardholderConfig 卡包开卡规则表
64 64 type CardholderConfig struct {
65 65 Id string `json:"id"` // ID
66   - GuaranteedStar string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID
67 66 IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包
68 67 IsNew int `json:"is_new"` // 是否是新卡包
  68 + GuaranteedStarCardId string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID
69 69 NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量
70 70 MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID
71 71 }
72 72  
73   -// NormalCardStarSequence 非保底卡星级ID
74   -type NormalCardStarSequence struct {
  73 +// NormalCardStarConfig 非保底卡星级ID
  74 +type NormalCardStarConfig struct {
75 75 Id string `json:"id"` // ID
76 76 SequenceId string `json:"user_sequence_id"` // 用户序列组ID
77 77 Cohort string `json:"cohort"` // 用户分组
... ...
service/ht-cardholder/handle.go
... ... @@ -4,6 +4,7 @@ import (
4 4 "apigame/dto"
5 5 "apigame/service/constd"
6 6 "apigame/util/uttype"
  7 + "fmt"
7 8 "strconv"
8 9 )
9 10  
... ... @@ -101,21 +102,49 @@ func HandleOpen(req *dto.ReqHtCardHolderOpen) (code string, rsp dto.RspHtCardHol
101 102 } else {
102 103 // 正常抽卡
103 104 // 先抽保底卡
104   - if confCardholder.GuaranteedStar != "0" {
105   - confGuaranteed, hasGuaranteed := FindCardSequenceConfig(confCardholder.GuaranteedStar, sequenceId, cohort)
106   - if hasGuaranteed {
107   - combineId := CombineIdSequenceIdCohort(confCardholder.GuaranteedStar, sequenceId, cohort)
  105 + if confCardholder.GuaranteedStarCardId != "0" {
  106 + confCardSequence, hasCardSequence := FindCardSequenceConfig(confCardholder.GuaranteedStarCardId, sequenceId, cohort)
  107 + if hasCardSequence {
  108 + combineId := CombineIdSequenceIdCohort(confCardholder.GuaranteedStarCardId, sequenceId, cohort)
108 109 scale := gameData.Details.CardSequenceScales[combineId]
109   - cardId := GetOneFromArray(confGuaranteed.CardIdLists, scale)
  110 + cardId := GetOneFromArray(confCardSequence.CardIdLists, scale)
110 111 cardIdInt := uttype.StringToInt(cardId)
111 112 // 增加刻度
112 113 gameData.Details.CardSequenceScales[combineId] = scale + 1
113 114 // 增加卡牌
114 115 gameData.Details.Cards[cardIdInt] += 1
  116 + fmt.Println("🐸🐸🐸保底卡ID", cardIdInt)
115 117 rsp.NewCards = append(rsp.NewCards, cardIdInt)
116 118 }
117 119 }
118   -
  120 + // 非保底卡
  121 + if confCardholder.NormalCardNumber > 0 {
  122 + count := confCardholder.NormalCardNumber
  123 + confNormalCardStar, hasNormalCardStar := FindNormalCardStarConfig(confCardholder.MinimumGuaranteeCardId, sequenceId, cohort)
  124 + if hasNormalCardStar {
  125 + combineIdStar := CombineIdSequenceIdCohort(confCardholder.MinimumGuaranteeCardId, sequenceId, cohort)
  126 + scaleStar := gameData.Details.StarSequenceScales[combineIdStar]
  127 + starIds := GetListFromArray(confNormalCardStar.NormalCardSequenceIds, scaleStar, count)
  128 + // 增加星级刻度
  129 + gameData.Details.StarSequenceScales[combineIdStar] = scaleStar + count
  130 + // 遍历星级刻度抽取n张卡牌
  131 + for _, id := range starIds {
  132 + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
  133 + scale := gameData.Details.CardSequenceScales[combineId]
  134 + confCardSequence, hasCardSequence := FindCardSequenceConfig(id, sequenceId, cohort)
  135 + if hasCardSequence {
  136 + cardId := GetOneFromArray(confCardSequence.CardIdLists, scale)
  137 + cardIdInt := uttype.StringToInt(cardId)
  138 + // 增加刻度
  139 + gameData.Details.CardSequenceScales[combineId] = scale + 1
  140 + // 增加卡牌
  141 + gameData.Details.Cards[cardIdInt] += 1
  142 + rsp.NewCards = append(rsp.NewCards, cardIdInt)
  143 + fmt.Println("😊😊😊非保底卡ID", cardIdInt)
  144 + }
  145 + }
  146 + }
  147 + }
119 148 }
120 149  
121 150 // 删除一个卡包
... ...