Files
MMGame/backend/internal/agents/dm.go
T
gmh01 7614e79d12 refactor: rewrite backend in Go, replacing Python FastAPI
Port the FastAPI backend to Go 1.26, preserving all API functionality:
- auth (register/login/guest/logout/profile/history) with JWT + bcrypt
- scripts (list/detail) backed by embedded sample_data.json
- games (create/join/start/chat/phase/clue/vote/state/replay) + WebSocket
- rule-based NPC agent plus DeepSeek/Ollama AI backends
- SQLite persistence via modernc.org/sqlite (pure Go, no cgo)

Frontend and documents are unchanged.
2026-08-03 11:39:53 +08:00

39 lines
962 B
Go

package agents
import (
"fmt"
"mmgame/internal/scripts"
)
type DMAgent struct {
Script *scripts.Script
currentPhaseIndex int
releasedClues []string
}
func NewDMAgent(script *scripts.Script) *DMAgent {
return &DMAgent{Script: script}
}
func (a *DMAgent) GetOpening() string {
return fmt.Sprintf("欢迎来到【%s】。%s", a.Script.Title, a.Script.Background)
}
func (a *DMAgent) Act(phaseIndex int, playerProgress, context string) map[string]interface{} {
result := DMGenerate(a.Script, phaseIndex, a.releasedClues, context)
if len(result) > 0 {
return result
}
phases := a.Script.Phases
phase := &phases[len(phases)-1]
if phaseIndex < len(phases) {
phase = &phases[phaseIndex]
}
return map[string]interface{}{"action": "narrate", "content": "【" + phase.Name + "】" + phase.Description}
}
func (a *DMAgent) GetReplaySummary() string {
return fmt.Sprintf("剧本:%s\n真相:%s", a.Script.Title, a.Script.Truth)
}