diff --git a/backend/internal/game/movement.go b/backend/internal/game/movement.go index e948e2b..44f4c6f 100644 --- a/backend/internal/game/movement.go +++ b/backend/internal/game/movement.go @@ -1,55 +1,13 @@ package game import ( - "encoding/json" "math" "math/rand" - "os" - "path/filepath" "time" "github.com/denisovdennis/autohero/internal/model" ) -// #region agent log -func agentDebugLog(hypothesisID, location, message string, data map[string]any) { - wd, err := os.Getwd() - if err != nil { - return - } - logPath := filepath.Join(wd, "debug-cbb64d.log") - if filepath.Base(wd) == "backend" { - logPath = filepath.Join(wd, "..", "debug-cbb64d.log") - } - payload := map[string]any{ - "sessionId": "cbb64d", - "hypothesisId": hypothesisID, - "location": location, - "message": message, - "data": data, - "timestamp": time.Now().UnixMilli(), - } - b, err := json.Marshal(payload) - if err != nil { - return - } - candidates := []string{logPath} - if filepath.Base(wd) == "backend" { - candidates = append([]string{filepath.Join(wd, "..", "debug-cbb64d.log")}, candidates...) - } - for _, p := range candidates { - f, err := os.OpenFile(p, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - continue - } - _, _ = f.Write(append(b, '\n')) - _ = f.Close() - return - } -} - -// #endregion - const ( // BaseMoveSpeed is the hero's base movement speed in world-units per second. BaseMoveSpeed = 2.0 @@ -288,12 +246,6 @@ func (hm *HeroMovement) assignRoad(graph *RoadGraph) { road = graph.FindRoad(nearest, hm.DestinationTownID) } if road == nil { - // #region agent log - agentDebugLog("H5", "movement.go:assignRoad", "no road after nearest retry", map[string]any{ - "currentTownID": hm.CurrentTownID, "destinationTownID": hm.DestinationTownID, - "x": hm.CurrentX, "y": hm.CurrentY, "runId": "post-fix", - }) - // #endregion // No road available, will retry next tick. return } @@ -758,19 +710,6 @@ func ProcessSingleHeroMovementTick( hm.assignRoad(graph) } hm.tryStartAdventure(now) - // #region agent log - if hm.Road == nil { - agentDebugLog("H1", "movement.go:StateWalking", "walking with nil Road", map[string]any{ - "heroID": heroID, "currentTownID": hm.CurrentTownID, "destinationTownID": hm.DestinationTownID, - "x": hm.CurrentX, "y": hm.CurrentY, "runId": "post-fix", - }) - } else if len(hm.Road.Waypoints) < 2 { - agentDebugLog("H2", "movement.go:StateWalking", "road has fewer than 2 waypoints", map[string]any{ - "heroID": heroID, "roadID": hm.Road.ID, "waypointCount": len(hm.Road.Waypoints), - "runId": "post-fix", - }) - } - // #endregion reachedTown := hm.AdvanceTick(now, graph) if reachedTown { @@ -805,15 +744,6 @@ func ProcessSingleHeroMovementTick( if canRollEncounter && (onEncounter != nil || sender != nil || onMerchantEncounter != nil) { monster, enemy, hit := hm.rollRoadEncounter(now) if hit { - // #region agent log - nWP := len(hm.Road.Waypoints) - agentDebugLog("H3", "movement.go:encounter", "road encounter", map[string]any{ - "heroID": heroID, "waypointCount": nWP, "monster": monster, - "wilderness": hm.wildernessFactor(now), - "x": hm.CurrentX, "y": hm.CurrentY, - "runId": "post-fix", - }) - // #endregion if monster { if onEncounter != nil { hm.LastEncounterAt = now diff --git a/backend/migrations/000014_unified_gear.sql b/backend/migrations/000014_unified_gear.sql index 417bff5..0e120c9 100644 --- a/backend/migrations/000014_unified_gear.sql +++ b/backend/migrations/000014_unified_gear.sql @@ -27,20 +27,23 @@ CREATE TABLE IF NOT EXISTS hero_gear ( ); CREATE INDEX IF NOT EXISTS idx_hero_gear_hero ON hero_gear(hero_id); --- Migrate existing weapon data to gear table +-- Migrate existing weapon data to gear table (safe to re-run if migration retried) INSERT INTO gear (id, slot, name, subtype, rarity, ilvl, base_primary, primary_stat, stat_type, speed_modifier, crit_chance, special_effect) SELECT id, 'main_hand', name, type, rarity, ilvl, damage, damage, 'attack', speed, crit_chance, special_effect -FROM weapons; +FROM weapons +ON CONFLICT (id) DO NOTHING; -- Migrate existing armor data to gear table (offset IDs by 1000 to avoid conflicts) INSERT INTO gear (id, slot, name, subtype, rarity, ilvl, base_primary, primary_stat, stat_type, speed_modifier, agility_bonus, set_name, special_effect) SELECT id + 1000, 'chest', name, type, rarity, ilvl, defense, defense, 'defense', speed_modifier, agility_bonus, set_name, special_effect -FROM armor; +FROM armor +ON CONFLICT (id) DO NOTHING; -- Migrate equipment_items to gear (offset by 2000) INSERT INTO gear (id, slot, form_id, name, rarity, ilvl, base_primary, primary_stat, stat_type) SELECT id + 2000, slot, form_id, name, rarity, ilvl, base_primary, primary_stat, stat_type -FROM equipment_items; +FROM equipment_items +ON CONFLICT (id) DO NOTHING; -- Migrate hero weapon/armor refs to hero_gear INSERT INTO hero_gear (hero_id, slot, gear_id)