fix: restore battle entry and character profile initialization

This commit is contained in:
CAtlas0784 committed 2026-10-17 11:58:20 +07:00
1 parent cfbbc7b970
commit 5c4d0d4149
16 files changed
+888 -228

No files matched your search

+27 -9
View File
@@ -199,6 +199,23 @@ func (a *AvatarJson) SPMaxVal() uint32 {
return 10000
}
// Battle SP is a ratio in ten-thousandths (PearlSR createBattleAvatar).
// FreeSR imports may instead carry absolute energy and its capacity; use
// their ratio so both absolute and already scaled imports serialize alike.
const battleRatioScale uint32 = 10000
func (a *AvatarJson) BattleSPCur() uint32 {
maximum := a.SPMaxVal()
if maximum == 0 {
return 0
}
current := a.SPCur()
if current > maximum {
current = maximum
}
return uint32(uint64(current) * uint64(battleRatioScale) / uint64(maximum))
}
// ---------------------------------------------------------------------------
// Battle config (freesr-data.json)
// ---------------------------------------------------------------------------
@@ -253,15 +270,16 @@ type RogueMagicScepter struct {
}
type BattleConfig struct {
BattleType BattleType `json:"battle_type"`
Monsters [][]Monster `json:"monsters"`
Blessings []BattleBuffJson `json:"blessings"`
StageID uint32 `json:"stage_id"`
CycleCount uint32 `json:"cycle_count"`
PathResonanceID uint32 `json:"path_resonance_id"`
CustomStats []SubAffix `json:"custom_stats"`
Scepters []RogueMagicScepter `json:"scepters"`
CustomBattleLineup map[uint32]uint32 `json:"custom_battle_lineup"`
EnableInvasionSupport bool `json:"enable_invasion_support"`
BattleType BattleType `json:"battle_type"`
Monsters [][]Monster `json:"monsters"`
Blessings []BattleBuffJson `json:"blessings"`
StageID uint32 `json:"stage_id"`
CycleCount uint32 `json:"cycle_count"`
PathResonanceID uint32 `json:"path_resonance_id"`
CustomStats []SubAffix `json:"custom_stats"`
Scepters []RogueMagicScepter `json:"scepters"`
CustomBattleLineup map[uint32]uint32 `json:"custom_battle_lineup"`
}
func DefaultBattleConfig() BattleConfig {
+10 -12
View File
@@ -206,8 +206,8 @@ func (a *AvatarJson) ToBattleAvatarProto(index uint32, lightcone *Lightcone, rel
EnhancedId: enhancedID,
IGDEHGIKFJA: exRanks,
SpBar: &goproto.SpBarInfo{
CurSp: a.SPCur(),
MaxSp: a.SPMaxVal(),
CurSp: a.BattleSPCur(),
MaxSp: battleRatioScale,
},
}
@@ -227,11 +227,12 @@ func (a *AvatarJson) ToBattleAvatarProto(index uint32, lightcone *Lightcone, rel
var buffs []*goproto.BattleBuff
for _, buffID := range a.Techniques {
buffs = append(buffs, &goproto.BattleBuff{
Id: buffID,
Level: 1,
OwnerId: index,
WaveFlag: 0xffffffff,
DynamicValues: map[string]float32{"SkillIndex": 2.0},
Id: buffID,
Level: 1,
OwnerId: index,
WaveFlag: 0xffffffff,
TargetIndexList: []uint32{0},
DynamicValues: map[string]float32{"SkillIndex": 0},
})
}
@@ -310,13 +311,10 @@ func ToLineupInfo(lineups map[uint32]uint32) *goproto.LineupInfo {
// ---------------------------------------------------------------------------
func (m *Monster) ToSceneMonster() *goproto.SceneMonster {
hp := m.MaxHP
if hp == 0 {
hp = 10000
}
return &goproto.SceneMonster{
MonsterId: m.MonsterID,
MaxHp: hp,
// Zero requests the stage's normal HP, as in PearlSR addMonsterWaves.
MaxHp: m.MaxHP,
}
}
+18 -1
View File
@@ -75,6 +75,7 @@ type LevelOutputConfig struct {
type AvatarConfig struct {
WeaknessBuffID uint32 `json:"weaknessBuffId"`
DamageType string `json:"damageType"`
}
type JsonConfig struct {
@@ -185,6 +186,23 @@ func GameRes() (*JsonConfig, error) {
}
func loadSupplementaryResources(res *JsonConfig) {
// PearlSR's resource export keeps avatar data in AvatarConfig.json;
// res.json may legitimately contain an empty avatarConfigs object.
if raw, err := readResourceFile("resources/AvatarConfig.json"); err == nil {
var avatars struct {
Entries []struct {
ID uint32 `json:"AvatarID"`
DamageType string `json:"DamageType"`
} `json:"avatar_config"`
}
if err := json.Unmarshal(raw, &avatars); err == nil {
for _, avatar := range avatars.Entries {
cfg := res.AvatarConfigs[avatar.ID]
cfg.DamageType = avatar.DamageType
res.AvatarConfigs[avatar.ID] = cfg
}
}
}
entrancesByEntry := map[uint32]MapEntranceEntry{}
if raw, err := readResourceFile("resources/MapEntrance.json", "MapEntrance.json"); err == nil {
var list []MapEntranceEntry
@@ -369,4 +387,3 @@ func Teleports() map[uint32]map[uint32]TeleportInfo {
})
return teleportDB
}