|
|
|
|
@ -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
|
|
|
|
|
|