94 lines
2.9 KiB
Go
94 lines
2.9 KiB
Go
package catalogs
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
var _ = json.RawMessage{}
|
|
var _ = sync.Mutex{}
|
|
var _ = os.ReadFile
|
|
var _ = filepath.Join
|
|
|
|
//
|
|
// Whitelist of AgentConfig templates whose client-side enemy HUD actually binds.
|
|
// Why this exists: the enemy HP bar is not created by anything the server pushes. From
|
|
// EnemyHUDCtrl.lua the HUD binds only when AgentConfig[agentId].ShowHPBar is
|
|
// true, and RefreshHpVisible additionally needs no hide / near-death state. Pushing
|
|
// SyncUnitAttrs (attr 1) + SyncUnitHp + SyncUnitAttacked is enough to render and flash a bar
|
|
// on a template that has one, and is not enough to conjure one on a template that does not.
|
|
// The general summon catalog (AgentSummonCatalog.json, 9015 rows) is the unfiltered
|
|
// AgentConfig projection: 7051 of its rows carry InitWeaponId = 0. Those templates have
|
|
// no HP bar, so an enemy spawned from them fights, takes damage and dies with no visible bar —
|
|
// which reads as "I cannot kill it". This file is the filtered set (ShowHPBar && InitWeaponId >
|
|
// 0): every id here is guaranteed to bind a bar.
|
|
//
|
|
var (
|
|
EnemyHpBarCatalog4229938_cacheLock sync.RWMutex
|
|
EnemyHpBarCatalog4229938_cached = false
|
|
EnemyHpBarCatalog4229938_entries []any
|
|
)
|
|
|
|
// LoadEnemyHpBarCatalog4229938 loads catalog records from client config directory
|
|
func LoadEnemyHpBarCatalog4229938(configDir string) ([]any, error) {
|
|
EnemyHpBarCatalog4229938_cacheLock.RLock()
|
|
if EnemyHpBarCatalog4229938_cached {
|
|
defer EnemyHpBarCatalog4229938_cacheLock.RUnlock()
|
|
return EnemyHpBarCatalog4229938_entries, nil
|
|
}
|
|
EnemyHpBarCatalog4229938_cacheLock.RUnlock()
|
|
|
|
EnemyHpBarCatalog4229938_cacheLock.Lock()
|
|
defer EnemyHpBarCatalog4229938_cacheLock.Unlock()
|
|
if EnemyHpBarCatalog4229938_cached { return EnemyHpBarCatalog4229938_entries, nil }
|
|
|
|
filePath := filepath.Join(configDir, "EnemyHpBarCatalog.json.json")
|
|
data, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var raw struct {
|
|
Records []json.RawMessage `json:"records"`
|
|
}
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var result []any
|
|
for _, item := range raw.Records {
|
|
var m map[string]any
|
|
if err := json.Unmarshal(item, &m); err == nil {
|
|
result = append(result, m)
|
|
}
|
|
}
|
|
|
|
EnemyHpBarCatalog4229938_entries = result
|
|
EnemyHpBarCatalog4229938_cached = true
|
|
return result, nil
|
|
}
|
|
|
|
// True when spawning gives the enemy a visible HP bar.
|
|
func EnemyHpBarCatalog4229938_HasHpBar(agentId uint32) bool {
|
|
// Catalog helper EnemyHpBarCatalog4229938_HasHpBar
|
|
return false
|
|
}
|
|
|
|
func EnemyHpBarCatalog4229938_Find(agentId uint32) *EnemyHpBarRow4229938 {
|
|
// Catalog helper EnemyHpBarCatalog4229938_Find
|
|
return nil
|
|
}
|
|
|
|
// One AgentConfig template that binds a client-side enemy HP bar.
|
|
type EnemyHpBarRow4229938 struct {
|
|
Id uint32 `json:"id"`
|
|
Name string `json:"name"`
|
|
Camp uint32 `json:"camp"`
|
|
AiSetting uint32 `json:"aiSetting"`
|
|
WeaponId uint32 `json:"weaponId"`
|
|
EnemyClassType uint32 `json:"enemyClassType"`
|
|
}
|
|
|