skills logic review

Guide for skills logic review

Legends of Hastinapur: Skill System Logic Review

This document outlines the current implementation of skill logic in the codebase (loh-game). It is intended to verify alignment with game design expectations.

1. Core Skill System

File: src/systems/player/skills.rs
  • XP Formula: OSRS-style exponential curve.
    • Points formula: floor(level + 300 * 2^(level/7.0))
    • Level 99 cap enforced.
  • Skill List (23 defined):
    • Combat: Attack, Strength, Defence, Ranged, Magic, Prayer, Hitpoints.
    • Gathering: Mining, Fishing, Woodcutting, Farming, Hunter.
    • Crafting: Smithing, Cooking, Fletching, Crafting, Runecraft, construction.
    • Support: Agility, Thieving, Slayer, Firemaking, Ayurveda (Herblore equivalent).
  • Combat Level: Base + Max(Melee, Ranged, Magic) where Base = 0.25 * (Def + HP + Prayer/2).

2. Combat Skills Implementation

Melee, Ranged & Defense

File: src/systems/combat/mod.rs
  • Stats: CombatStats component tracks Atk/Str/Def/HP.
  • Sync: Player CombatStats are overwritten every frame to match their Skill levels (e.g. stats.attack = skills.attack).
    • Issue Note: max_hp is set to Hitpoints level. If OSRS style (10 HP = level 10), typically starts at 10. Current code uses raw level (so Level 10 = 10 HP). CombatStats::new uses 10 + lvl*2, creating a discrepancy between Players and NPCs.
  • Turn-Based Ticks: Default global attack speed is 2.4s.
  • Accuracy Roll:
    • Attacker Roll = Rand(0 .. Attack(adj) + 8)
    • Defender Roll = Rand(0 .. Defense(adj) + 8)
    • Hit if Attack > Defense.
  • Max Hit: 1 + (Strength(adj) / 10). (Likely too low for typical OSRS numbers, implies divides by 10).
  • Ranged Logic:
    • Requires Ammo in slot. Checks specific IDs (e.g. Sharanga bow fires 2 arrows).
    • Spawns projectile (speed 20.0).
    • Ammo Retrieval: 0% (basic) to 90% (Garuda's Plume quiver) chance to recover ammo on kill.

Magic

File: src/systems/skills/magic.rs
  • System: Separate from standard combat loop. Uses CastSpellEvent.
  • Requirements:
    • Rune/Bija cost (consumed from inventory).
    • Level requirement check.
  • Damage:
    • Accuracy: Fixed 90% hit chance (Random > 0.1). Note: Ignores opponent's Magic Defense/Magic Level.
    • Damage: Random(0 to MaxHit).
  • Spells: Defined in data/mantras.json (e.g. "Agni", "Vayu").

3. Gathering Skills

Woodcutting

File: src/systems/skills/woodcutting.rs
  • Mechanic: Player interacts with Tree entity.
  • Checks: Level requirement against data/woodcutting_trees.json.
  • Tool: Placeholder logic for Axe requirement (currently commented out or partial).
  • Success: Instant success (no tick-based chance).
  • Regeneration: Tree turns to Stump, respawns after X seconds defined in JSON.

Farming

File: src/systems/skills/farming.rs
  • Mechanic: Patch-based state machine (Empty -> Planted -> Growing -> Grown).
  • Growth: Time-based (seconds). Updates when player is near/every frame? (Checks time.elapsed).
  • risk:
    • Disease: Chance per stage check. Reduced by Compost (Reg: 20%, Super: 50%, Ultra: 80%).
    • Death: Diseased plants die after 3 days if not cured.
  • Harvest: Yields Min-Max quantity (random).
  • Data: Seeds defined in data/farming_seeds.json.

4. Crafting Skills

Smithing

File: src/systems/skills/smithing.rs
  • Smelting: Furnace interaction. Converts Ores to Bars.
    • Success Rate: Defined in JSON (e.g. Iron 50%). Improved Furnace adds +10%.
  • Smithing: Anvil interaction. Converts Bars to Items.
    • Success: Always succeeds.
  • Data: Recipes in data/smelting_recipes.json and data/smithing_recipes.json.

5. Data Architecture

File: src/systems/data/mod.rs
  • Centralized Loading: All skill data is loaded from data/*.json into a SkillsData resource at startup.
  • Validation: Checks for duplicate IDs on load to prevent collisions.
  • String IDs: Uses a hash of the string ID (e.g. "bronze_sword") for referencing items in code.

6. Observations & Potential Gaps

  1. Magic Accuracy: Magic currently ignores target defense entirely (fixed 90% hit chance).
  2. HP Scaling: Player MaxHP definition (hp_level) vs NPC MaxHP (10 + lvl*2) methodology differs.
  3. Tool Checks: Woodcutting axe checks seemed incomplete/simplified in the viewed code.
  4. Damage Formula: 1 + Str/10 is very conservative. A level 99 strength player + bonuses maxing at ~10-15 damage? (OSRS max hits are 40-80+).