[Medium] [Task] Combat spec gap: implement sword/melee auto-attack system (spec §2.3, §3.1, §4.3) #256
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Combat Spec Gap: Sword/Melee Auto-Attack System
Gap Summary
The combat tick pipeline (
combat-actions.ts→processCombatTick) only processes spell autocasting. There is no sword/melee auto-attack branch. The spec defines three independent damage sources (staves, swords, golems) but only staves are wired.What Exists
data/equipment/swords.tswithattackSpeedstatgetElementalBonus()incombat-utils.ts(works for both spells and swords)EnemyStatetype has all needed fieldsWhat's Missing
1. Melee progress accumulator (spec §3.1)
meleeSwordProgress: Record<instanceId, number>in combat statemeleeProgresscounter2. Melee damage calculation (spec §4.3)
calcMeleeDamage()function exists3. Melee branch in processCombatTick (spec §3.1)
4. Executioner/Berserker exclusion
Files to Change
stores/combat-state.types.tsmeleeSwordProgress: Record<instanceId, number>stores/combat-actions.tsprocessCombatTick; addcalcMeleeDamage()stores/pipelines/combat-tick.tsonDamageDealtcan distinguish melee from spell (skip specials)utils/combat-utils.tscalcMeleeDamage()functionAcceptance Criteria
Out of Scope
Progress Update: Sword/Melee Auto-Attack System Implementation
Changes Made
New Function:
calcMeleeDamage()(src/lib/game/utils/combat-utils.ts)baseDmg × getElementalBonus(swordElement, enemyElement)New State:
meleeSwordProgress(src/lib/game/stores/combat-state.types.ts+combatStore.ts){}, persisted through localStorageMelee Branch in
processCombatTick(src/lib/game/stores/combat-actions.ts)stats.attackSpeedticks its own progress counterEquipment Stats (
src/lib/game/data/equipment/types.ts+swords.ts)statsfield toEquipmentTypeinterfacebaseDamageandattackSpeedto all 5 sword types:Game Store Integration (
src/lib/game/stores/gameStore.ts)equippedSwordsmap from crafting store'sequippedInstances+equipmentInstancesprocessCombatTickas new parametermeleeSwordProgressto combat storeTests (
src/lib/game/__tests__/melee-auto-attack.test.ts)calcMeleeDamage()and melee auto-attack inprocessCombatTickTest Results
Implementation complete and pushed to master (
8dde423).All acceptance criteria met:
Files changed (10 files, +568/-187 lines):
src/lib/game/utils/combat-utils.ts— AddedcalcMeleeDamage()functionsrc/lib/game/stores/combat-state.types.ts— AddedmeleeSwordProgressstatesrc/lib/game/stores/combatStore.ts— Added initial state and persistencesrc/lib/game/stores/combat-actions.ts— Added melee branch inprocessCombatTicksrc/lib/game/stores/gameStore.ts— WiredequippedSwordsthrough tick pipelinesrc/lib/game/data/equipment/types.ts— Added optionalstatsfieldsrc/lib/game/data/equipment/swords.ts— AddedbaseDamage/attackSpeedto all 5 swordssrc/lib/game/constants/index.ts— ExportedEQUIPMENT_TYPESsrc/lib/game/__tests__/melee-auto-attack.test.ts— 16 new regression testsAll 937 tests pass (46 files, 0 failures). All files under 400-line limit.