Skip to content

feat(teleport_items): add table-driven warp routing with strict parser and runtime equip/cooldown checks#4167

Open
boscv wants to merge 8 commits intoOpenKore:masterfrom
boscv:parseTeleportItems
Open

feat(teleport_items): add table-driven warp routing with strict parser and runtime equip/cooldown checks#4167
boscv wants to merge 8 commits intoOpenKore:masterfrom
boscv:parseTeleportItems

Conversation

@boscv
Copy link
Contributor

@boscv boscv commented Mar 10, 2026

Motivation

  • Provide a data-driven way to describe teleport/warp item behavior and destinations through tables/teleport_items.txt.
  • Support item-level constraints (equipment requirements, level range, cooldown) so route planning and execution reflect real in-game usage conditions.
  • Allow map routing to consider item-based warps when route_warpByItem is enabled.

Description

  • Added tables/teleport_items.txt with documented syntax and examples for random, respawn, warp, and any modes.
  • Implemented and hardened parseTeleportItems in src/FileParsers.pm:
    • strict positional optional syntax: [maxLvl] [timeoutSec] [requiredEquipSlot requiredEquipItemID]
    • descriptive warnings for malformed lines
    • numeric field validation
    • equipment slot validation against %equipSlot_rlut (case-insensitive handling for slot names)
  • Integrated table loading in startup flow via src/functions.pl.
  • Extended route planning in src/Task/CalcMapRoute.pm:
    • warp-item candidate discovery for target map
    • propagation of teleport-item metadata (teleportItemID, timeoutSec, required equip slot/item) into map solution steps
  • Updated route execution in src/Task/MapRoute.pm:
    • runtime revalidation of equipment requirement before sendItemUse
    • cooldown-aware item usage checks using last_teleport_item_use
  • Updated teleport item selection fallback:
    • src/Task/Teleport/Random.pm and src/Task/Teleport/Respawn.pm now consult table rules
    • src/Task/Teleport.pm records cooldown timestamps when a rule-based item is used
  • Added/updated parser tests and fixtures:
    • src/test/teleport_items.txt (valid cases)
    • src/test/teleport_items_invalid.txt (invalid/malformed cases)
    • src/test/FileParsersTest.pm assertions for both valid and invalid scenarios
    • src/test/Distfiles updated to include new fixture

Testing

  • Ran parser unit tests:
    • perl -I src src/test/FileParsersTest.pm
  • Verified parsing behavior for:
    • valid entries (including maxLevel, timeoutSec, equip requirements)
    • invalid entries (non-numeric fields, invalid slot name, malformed optional token layouts), ensuring invalid lines are ignored and valid control lines are preserved
  • Performed route-candidate simulations confirming expected selection behavior for warp items by target map, cooldown, level constraints, and equip requirements:
    • prt_q -> 22849
    • pvp_n_room -> 14528
    • un_bk_q -> 22691
    • verus04 -> 22611 only when equip requirement is satisfied
    • cooldown-gated suppression confirmed for 22508 (moc_para01)

boscv added 4 commits March 9, 2026 16:06
Introduce support for a teleport_items table and use teleport/warp items in routing and teleport tasks. Adds tables/teleport_items.txt and a parseTeleportItems loader with a new %teleport_items global, plus unit tests. Implements Misc::getTeleportItemFromTable and integrates warp-by-item logic into Task::CalcMapRoute and Task::MapRoute (populateOpenListWithWarpByItems, candidate selection, per-map forbids and retry handling). Tracks per-item cooldowns (last_teleport_item_use) when sending item-use packets and exposes a config flag route_warpByItem (default 0) in control/config.txt. Also registers the new table in settings and updates test distfiles.
Parse optional equip-requirement fields for teleport items and enforce them when selecting items. FileParsers.pm: accept optional timeoutSec and optional requiredEquipSlot + requiredEquipItemID, validate and store them on each entry (timeout defaults to 0). Misc.pm: add isTeleportItemEquipRequirementSatisfied to verify required slot exists and the required item is equipped in that slot. Use this check in getTeleportItemFromTable and Task/CalcMapRoute.pm when filtering candidate warp items. Tests and fixtures: add teleport_items test fixture and assertions in FileParsersTest, and update tables/teleport_items.txt docs/examples to document the new optional fields.
Parse and enforce an optional max level for teleport/warp items. FileParsers now accepts an extra numeric optional argument (maxLvl) before timeoutSec and stores maxLevel in the entry. Misc and CalcMapRoute skip teleport entries when the character level is above maxLevel. Tests and teleport_items table/docs updated to reflect new syntax and example entries; test fixture updated to assert parsing of maxLevel. This enables items to be limited to characters at or below a specified level (0 disables the check).
Make teleport_items parsing stricter and add equip-requirement support. FileParsers.pm: use Globals equip slot lookup, adopt strict positional optional syntax ([maxLvl] [timeoutSec] [requiredEquipSlot requiredEquipItemID]), validate numeric fields and equip slot names, emit warnings for malformed lines, and skip invalid entries. CalcMapRoute.pm: carry teleportItemRequiredEquipSlot/ItemID through open/close lists. MapRoute.pm: import isTeleportItemEquipRequirementSatisfied and refuse to use teleport items when equip requirement is not satisfied. Tests/fixtures: update teleport_items.txt, add teleport_items_invalid.txt, and adjust FileParsersTest expectations to cover new parsing/validation behavior. tables/teleport_items.txt: document positional optional values and note how to specify only timeout by using maxLvl=0 first.
@boscv
Copy link
Contributor Author

boscv commented Mar 10, 2026

Still need some real testing, but pulling here for any suggestions

boscv added 4 commits March 10, 2026 00:28
Add isTeleportItemEquipRequirementSatisfied to Misc exports, switch MapRoute to call it as Misc::isTeleportItemEquipRequirementSatisfied (remove from import list), and clean up/reorder teleport_items.txt entries and formatting. These changes expose the equip-check function for external use and tidy the teleport item table.
Detect when a Task::Route error (CANNOT_CALCULATE_ROUTE or STUCK) is caused by a same-map warp that changed the map. If the map was changed and the first mapSolution entry refers to the same map (map == dest_map), treat the route as stale: advance to the next portal step (shift mapSolution), clear mapChanged and teleport-related flags (teleport, sentTeleport, teleportTime), and return. Adds a debug log for this case to avoid re-calculating a route invalidated by a same-map warp.
Add _isSameMapPortalStep helper to robustly detect same-map portal steps (prefer map==dest_map, fall back to parsing portal strings). Use this in Task::MapRoute to select the first inter-map portal, mark Route subtasks with stopWhenMapChanged for same-map starts, and advance mapSolution entries when a same-map warp finishes. Update Task::Route to honor stopWhenMapChanged by finishing the current segment on map change instead of recalculating the route. Include a Python runtime simulation test (maproute_same_map_runtime_sim.py) that verifies detection and expected step progression for a moc_para0b -> moc_para0b -> moc_para0b -> prontera -> payon sequence.
@boscv
Copy link
Contributor Author

boscv commented Mar 10, 2026

For some reason, intra-map portals where having calc erros on mapChange (?).
Don't know if it's from the last pull requests i did handling route retries..
Just randomly stumbled onto it doing some route tests using the new teleport_items table.
ANYWAY.. Seems to be fixed!

@boscv boscv marked this pull request as ready for review March 10, 2026 19:20
@Henrybk
Copy link
Contributor

Henrybk commented Mar 10, 2026

ow cool, I'll give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants