圣遗物追加词条优化

This commit is contained in:
UnKownOwO
2023-02-19 16:44:29 +08:00
parent aaaaaccf26
commit 795b3e79f5
2 changed files with 26 additions and 34 deletions

View File

@@ -46,13 +46,24 @@ func GetReliquaryAffixDataByDepotIdAndPropId(appendPropDepotId int32, appendProp
return value[appendPropId]
}
func GetReliquaryAffixDataRandomByDepotId(appendPropDepotId int32) *ReliquaryAffixData {
func GetReliquaryAffixDataRandomByDepotId(appendPropDepotId int32, excludeTypeList ...uint32) *ReliquaryAffixData {
appendPropMap, exist := CONF.ReliquaryAffixDataMap[appendPropDepotId]
if !exist {
return nil
}
choices := make([]weightedrand.Choice, 0, len(appendPropMap))
for _, data := range appendPropMap {
isBoth := false
// 排除列表中的属性类型是否相同
for _, propType := range excludeTypeList {
if propType == uint32(data.PropType) {
isBoth = true
break
}
}
if isBoth {
continue
}
choices = append(choices, weightedrand.NewChoice(data, uint(data.RandomWeight)))
}
chooser, err := weightedrand.NewChooser(choices...)

View File

@@ -74,44 +74,25 @@ func (g *GameManager) AppendReliquaryProp(reliquary *model.Reliquary, count int3
}
// 圣遗物追加属性的次数
for i := 0; i < int(count); i++ {
// 要排除的属性类型
excludeTypeList := make([]uint32, 0, len(reliquary.AppendPropIdList)+1)
// 排除主属性
excludeTypeList = append(excludeTypeList, uint32(reliquaryMainConfig.PropType))
// 排除追加的属性
for _, propId := range reliquary.AppendPropIdList {
targetAffixConfig := gdconf.GetReliquaryAffixDataByDepotIdAndPropId(reliquaryConfig.AppendPropDepotId, int32(propId))
if targetAffixConfig == nil {
logger.Error("target affix config error, propId: %v", propId)
return
}
excludeTypeList = append(excludeTypeList, uint32(targetAffixConfig.PropType))
}
// 将要添加的属性
appendAffixConfig := gdconf.GetReliquaryAffixDataRandomByDepotId(reliquaryConfig.AppendPropDepotId)
appendAffixConfig := gdconf.GetReliquaryAffixDataRandomByDepotId(reliquaryConfig.AppendPropDepotId, excludeTypeList...)
if appendAffixConfig == nil {
logger.Error("append affix config error, appendPropDepotId: %v", reliquaryConfig.AppendPropDepotId)
return
}
isNotBoth := false
// 如果圣遗物词条为0就直接加不用校验是否相同
for len(reliquary.AppendPropIdList) > 0 {
if isNotBoth {
break
}
// 追加的属性类型不能相同
for i, propId := range reliquary.AppendPropIdList {
targetAffixConfig := gdconf.GetReliquaryAffixDataByDepotIdAndPropId(reliquaryConfig.AppendPropDepotId, int32(propId))
if targetAffixConfig == nil {
logger.Error("target affix config error, propId: %v", propId)
return
}
// 如果类型相同则重新随机获取一个属性
// 追加的属性还不能和主属性相同
if appendAffixConfig.PropType == targetAffixConfig.PropType || appendAffixConfig.PropType == reliquaryMainConfig.PropType {
reliquaryAffixConfig := gdconf.GetReliquaryAffixDataRandomByDepotId(reliquaryConfig.AppendPropDepotId)
if reliquaryAffixConfig == nil {
logger.Error("reliquary affix config error, appendPropDepotId: %v", reliquaryConfig.AppendPropDepotId)
return
}
// 将属性赋值并重新查找
appendAffixConfig = reliquaryAffixConfig
break
}
// 如果循环到最后一个还不匹配那就是没有相同的了
if i == len(reliquary.AppendPropIdList)-1 {
isNotBoth = true
}
}
}
// 圣遗物添加词条
reliquary.AppendPropIdList = append(reliquary.AppendPropIdList, uint32(appendAffixConfig.AppendPropId))
}