feat(monsters): add compact MonstersTable backend and migrate plugins to API#4198
Draft
boscv wants to merge 3 commits intoOpenKore:masterfrom
Draft
feat(monsters): add compact MonstersTable backend and migrate plugins to API#4198boscv wants to merge 3 commits intoOpenKore:masterfrom
boscv wants to merge 3 commits intoOpenKore:masterfrom
Conversation
Introduce MonstersTable.pm to centralize access to monsters_table data and provide helper APIs (monster_exists, monster_field, monster_hp, monster_level, monster_is_looter_by_ai, monster_is_aggressive_by_ai, compact backend management, etc.). Refactor plugins to use the new API instead of directly reading %monstersTable or duplicating AI flag logic: - plugins/checkAggressive: use MonstersTable functions, remove local AI constant/flag parsing, and use monster_level() in debug messages. - plugins/checkLooter: use monster_is_looter_by_ai(), log-warning path preserved, remove duplicated AI parsing. - plugins/eCast: use monster_field()/monster_hp()/monster_level(), add improved packet message HP injection, track element changes, fix map_calc_dir_xy argument bug, and rename onPacketSkillUseNoDmg -> onPacketSkillUseNoDamage for clarity. Startup change: initialize MonstersTable compact backend at load (purging legacy %monstersTable by default) via functions.pl to enable compact storage and precompute AI flags. Overall this centralizes monster data handling, removes duplicated AI constants/logic, and enables a compact backend for performance and memory improvements.
Introduce MonstersTable::load_compact_backend_from_file to load compact-format monster data directly from a file (with optional purge_legacy). The new loader parses compact rows, builds internal compact_rows/enum structures, enables the compact backend, and rebuilds AI flags. monster_get now warns once and returns early when the compact backend is enabled, and reset_backend_state clears that warning flag. In loadDataFiles, switch the Settings table loader for monsters_table.txt to a no-op and attempt a direct compact load from the file; if that fails or yields no rows, fall back to legacy parsing and then initialize the compact backend. The startup message now reports the number of rows and the source (direct-file or legacy-fallback).
Introduce _as_number to coerce numeric fields with optional fallback and use it to initialize numeric monster fields in initialize_compact_backend and load_compact_backend_from_file. Also replace the hard-coded Ai field index (11) with $FIELD_INDEX{Ai} in _rebuild_ai_flags_cache. These changes normalize undefined/empty values, ensure consistent defaults (e.g. ElementLevel fallback to 1), and remove a magic array index.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This PR refactors how
monsters_tableis loaded and accessed by replacing direct%monstersTableusage with a dedicatedMonstersTableAPI and introducing a compact backend with legacy fallback.What changed
1) New module:
src/MonstersTable.pmmonster_exists,monster_field,monster_hp,monster_levelmonster_is_looter_by_ai,monster_is_aggressive_by_ai%compact_rows(array-indexed records)%compact_enums(deduplicated repeated strings likeSize,Race,Element,Ai)looter/aggressive) for fast checks._as_numberFIELD_INDEX{Ai}2) Loading flow updates in
src/functions.plmonsters_table.txtis no longer parsed directly duringaddTableFile.Settings::loadAll, the system now:MonstersTable::load_compact_backend_from_file(...);initialize_compact_backend(...)if needed;direct-fileorlegacy-fallback).3) Plugin migration to API (decoupling from global hash)
plugins/checkAggressive/checkAggressive.plmonster_exists,monster_is_aggressive_by_ai,monster_levelplugins/checkLooter/checkLooter.plmonster_exists,monster_is_looter_by_aiplugins/eCast/eCast.pl%monstersTablereads tomonster_field/monster_hp/monster_levelhasFreeCellBehinddirection computation (targetPos->{y}usage)onPacketSkillUseNoDamageBenefits
Notes
Testing
perl -I src -c src/MonstersTable.pmStorable::nfreezecomparison (legacy vs compact representation) to estimate payload reduction.Results (mean ± stddev)
Run benchmark (bash + perl)