72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package gameserver
|
|
|
|
import (
|
|
"fmt"
|
|
"gac-hkrpg-go/internal/common"
|
|
pb "gac-hkrpg-go/protocol/proto"
|
|
)
|
|
|
|
// Inspect actual battle buffs, rather than ChallengeStageID or a reused stage ID.
|
|
// This covers an imported custom battle that already includes Corruption.
|
|
func (r *battleRules) applyAhaHelp(battle *pb.SceneBattleInfo, legacyEnabled bool, owner uint32) error {
|
|
var corruption uint32
|
|
for _, buff := range battle.BuffList {
|
|
for _, id := range r.InvasionBuffs {
|
|
if buff.Id == id {
|
|
corruption = id
|
|
}
|
|
}
|
|
}
|
|
if corruption == 0 {
|
|
return nil
|
|
}
|
|
selected, err := common.ReadAhaHelpLevel()
|
|
if err != nil {
|
|
return fmt.Errorf("battle Aha help setting: %w", err)
|
|
}
|
|
rows, err := common.LoadAhaHelpLevels()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var support, level uint32
|
|
if selected == nil {
|
|
if legacyEnabled {
|
|
support = r.InvasionSupportBuff
|
|
}
|
|
} else if *selected != 0 {
|
|
for _, row := range rows {
|
|
if row.BuffLevel == *selected {
|
|
support, level = row.BuffID, row.BuffLevel
|
|
}
|
|
}
|
|
if support == 0 {
|
|
return fmt.Errorf("battle Aha help level %d is not configured", *selected)
|
|
}
|
|
}
|
|
// The selected/off setting owns this family. Remove old imported support buffs
|
|
// to avoid stacking multiple levels or ignoring an explicit off selection.
|
|
filtered := battle.BuffList[:0]
|
|
for _, buff := range battle.BuffList {
|
|
isSupport := buff.Id == r.InvasionSupportBuff
|
|
for _, row := range rows {
|
|
isSupport = isSupport || buff.Id == row.BuffID
|
|
}
|
|
if !isSupport {
|
|
filtered = append(filtered, buff)
|
|
}
|
|
}
|
|
battle.BuffList = filtered
|
|
if support != 0 {
|
|
battle.BuffList = append(battle.BuffList, battleBuff(support, owner, map[string]float32{"SkillIndex": 1}))
|
|
}
|
|
SceneDebugLog("AHA_HELP stage=%d corruption=%d selected=%v legacy=%t support=%d level=%d", battle.StageId, corruption, selectedValue(selected), legacyEnabled, support, level)
|
|
return nil
|
|
}
|
|
|
|
func selectedValue(value *uint32) any {
|
|
if value == nil {
|
|
return "freesr"
|
|
}
|
|
return *value
|
|
}
|