config-registry.go 3.49 KB
package ht_cardholder

import (
	"apigame/lx-util/lxalilog"
	"apigame/service/constd"
	"encoding/json"
	"errors"
)

var (
	Registry RegistryConfigs // 卡牌活动配置
)

// RegistryConfigs 卡牌活动配置
type RegistryConfigs struct {
	ConfigRaws CardActivityConfigRaw // 活动配置 原始数据
	Config     CardActivityConfig    // 活动配置 分析后数据
}

func NewRegistryConfigs() {
	Registry = RegistryConfigs{}
}

// Decode 解析配置原始数据
func (r *RegistryConfigs) Decode(confRaw CardActivityConfigRaw) {
	conf := CardActivityConfig{
		Raw:                    confRaw,
		Id:                     confRaw.Id,
		Awards:                 make(map[string]string),
		AlbumConfig:            make(map[string]AlbumConfig),
		CardConfig:             make(map[int]CardConfig),
		CardholderConfig:       make(map[string]CardholderConfig),
		NormalCardStarSequence: make([]NormalCardStarSequence, 0),
		CardSequenceConfig:     make([]CardSequenceConfig, 0),
	}
	// 解析奖励
	{
		err := json.Unmarshal([]byte(confRaw.Awards), &conf.Awards)
		if err != nil {
			lxalilog.Errors(err, confRaw.Awards, constd.GAME_ID_HT, confRaw.Id)
			return
		}
	}
	// 卡组配置
	{
		configs := make([]AlbumConfig, 0)
		err := json.Unmarshal([]byte(confRaw.AlbumConfig), &configs)
		if err != nil {
			lxalilog.Errors(err, confRaw.AlbumConfig, constd.GAME_ID_HT, confRaw.Id)
			return
		}
		for _, i2 := range configs {
			conf.AlbumConfig[i2.SetId] = i2
		}
	}
	// 卡牌配置
	{
		configs := make([]CardConfig, 0)
		err := json.Unmarshal([]byte(confRaw.CardConfig), &configs)
		if err != nil {
			lxalilog.Errors(err, confRaw.CardConfig, constd.GAME_ID_HT, confRaw.Id)
			return
		}
		for _, i2 := range configs {
			conf.CardConfig[i2.Id] = i2
		}
	}
	// 卡包开卡规则
	{
		configs := make([]CardholderConfig, 0)
		err := json.Unmarshal([]byte(confRaw.CardHolderConfig), &configs)
		if err != nil {
			lxalilog.Errors(err, confRaw.CardHolderConfig, constd.GAME_ID_HT, confRaw.Id)
			return
		}
		for _, i2 := range configs {
			conf.CardholderConfig[i2.Id] = i2
		}
	}
	// 卡片星级配置
	{
		configs := make([]NormalCardStarSequence, 0)
		err := json.Unmarshal([]byte(confRaw.NormalCardStarSequence), &configs)
		if err != nil {
			lxalilog.Errors(err, confRaw.NormalCardStarSequence, constd.GAME_ID_HT, confRaw.Id)
			return
		}
		for _, i2 := range configs {
			conf.NormalCardStarSequence = append(conf.NormalCardStarSequence, i2)
		}
	}
	// 卡片星级对应卡牌配置
	{
		configs := make([]CardSequenceConfig, 0)
		err := json.Unmarshal([]byte(confRaw.CardSequenceConfig), &configs)
		if err != nil {
			lxalilog.Errors(err, confRaw.CardSequenceConfig, constd.GAME_ID_HT, confRaw.Id)
			return
		}
		for _, i2 := range configs {
			conf.CardSequenceConfig = append(conf.CardSequenceConfig, i2)
		}
	}

	r.Config = conf
	//logs.Debug(conf.Awards)
	//logs.Debug(conf.AlbumConfig)
	//logs.Debug(conf.CardConfig)
	//logs.Debug(conf.CardholderConfig)
	//logs.Debug("🐸", conf.NormalCardStarSequence)
	//logs.Debug("🐸", conf.CardSequenceConfig)
}

// FindCardSequenceConfig 查找配置 星级ID对应的卡片
func FindCardSequenceConfig(id, sequenceId, cohort string) (conf CardSequenceConfig, has bool) {
	conf = CardSequenceConfig{}
	has = false
	for _, c := range Registry.Config.CardSequenceConfig {
		if c.Id == id &&
			c.SequenceId == sequenceId &&
			c.Cohort == cohort {
			has = true
			return
		}
	}
	if !has {
		lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), " LoadData Error", id, sequenceId, cohort)
	}
	return
}