<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: NJHHBJSJKAsjdsasa</title>
    <description>The latest articles on DEV Community by NJHHBJSJKAsjdsasa (@njhhbjsjkasjdsasa).</description>
    <link>https://dev.to/njhhbjsjkasjdsasa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3919646%2F5408167f-92a8-4c5c-b512-c2783f6a093c.png</url>
      <title>DEV Community: NJHHBJSJKAsjdsasa</title>
      <link>https://dev.to/njhhbjsjkasjdsasa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/njhhbjsjkasjdsasa"/>
    <language>en</language>
    <item>
      <title>Building a Xianxia Cultivation MMO: How I Built a Self-Evolving Text-Based World with Go Microservices</title>
      <dc:creator>NJHHBJSJKAsjdsasa</dc:creator>
      <pubDate>Fri, 08 May 2026 09:02:44 +0000</pubDate>
      <link>https://dev.to/njhhbjsjkasjdsasa/building-a-xianxia-cultivation-mmo-how-i-built-a-self-evolving-text-based-world-with-go-1cgj</link>
      <guid>https://dev.to/njhhbjsjkasjdsasa/building-a-xianxia-cultivation-mmo-how-i-built-a-self-evolving-text-based-world-with-go-1cgj</guid>
      <description>&lt;p&gt;go microservices gamedev opensource mud xianxia&lt;/p&gt;

&lt;p&gt;Ever wanted to play a cultivation novel — where you start as a mortal, break through realms, form sects, and contend with heavenly tribulations — all in a world that evolves even when you are offline?&lt;br&gt;
I have been building exactly that: an open-source, multiplayer text-based cultivation world (MUD) powered by Go microservices and AI-driven NPCs. Here is the full story — the architecture, the tech choices, the battles with PostgreSQL, and what it is like to let NPCs loose with an LLM brain.&lt;br&gt;
The Vision: A Living Cultivation World&lt;br&gt;
Chinese xianxia novels describe worlds where mortals climb the path of immortality — forging spiritual roots, mastering techniques, enduring heavenly tribulations. I wanted to capture that feeling in a multiplayer game where the world does not wait for you. NPCs cultivate, form their own sects, trigger world events, and remember their interactions with players.&lt;br&gt;
The core design goals were:&lt;br&gt;
• Persistent world — server ticks even when no players are online&lt;br&gt;
• Deep cultivation system — 10 realms, spiritual roots with purity and mutation, spell discovery&lt;br&gt;
• AI-driven NPCs — not scripted dialogue trees, but actual autonomous agents&lt;br&gt;
• Cause and effect — a Heavenly Dao engine that tracks karma and triggers tribulations&lt;br&gt;
• Scale from day one — microservices so combat, AI, and world events do not compete for CPU&lt;br&gt;
Why Go + Microservices?&lt;br&gt;
I chose Go for three reasons: simplicity under concurrency, fast compilation, and excellent gRPC/Protobuf tooling. Each player action (cultivate, explore, combat, trade) maps cleanly to a gRPC operation, and Go goroutines handle hundreds of concurrent WebSocket connections without breaking a sweat.&lt;br&gt;
The architecture breaks into five services:&lt;br&gt;
Gateway — The single entry point. JWT auth, WebSocket upgrade, and message routing. Players connect here and the Gateway forwards their actions to the right backend via gRPC. It is a thin layer — no game logic, just transport.&lt;br&gt;
Game Server — The core. It handles 31+ action types (cultivate, breakthrough, combat, explore, gather, craft, trade, form sects, etc.), manages entity state, and coordinates with other services. Uses the repository pattern with clean interface boundaries — swap PostgreSQL for something else by implementing a handful of interfaces.&lt;br&gt;
Heavenly Dao — The cosmic rules engine. This service calculates cultivation efficiency, breakthrough probabilities, tribulation triggers, and karma balances. It is the most tested service (table-driven tests with testify) because getting the math wrong means angry cultivators.&lt;br&gt;
AI Scheduler — Where the magic happens. NPCs use behavior trees for routine decisions (wander, rest, gather resources) and fall back to DeepSeek LLM calls for complex social interactions. Each NPC has personality traits, long/short-term memory, and autonomous goal pursuit. Yes, NPCs can start their own sects.&lt;br&gt;
World Engine — Region management, resource spawning, and world events. Things like beast tides, heavenly anomalies, spirit tide surges, and secret realm openings. Events cascade — a beast tide in one region can trigger NPC migration, resource scarcity, and sect conflicts.&lt;br&gt;
The Cultivation System Deep Dive&lt;br&gt;
The cultivation system is the heart of the game. Here is how it works under the hood:&lt;br&gt;
Spiritual Roots&lt;br&gt;
On registration, each player gets 1-3 randomly generated spiritual roots (elemental affinities). 5% chance of a mutation — Wind, Lightning, or Ice instead of the basic Metal/Wood/Water/Fire/Earth. Primary roots have 60-90 purity, secondary roots 20-50. This creates meaningful character diversity from the start.&lt;br&gt;
Cultivation Formula&lt;br&gt;
Efficiency = BaseRate x RootBonus x SpellMatch x RealmDecay x MentalState x (1 - AgingPenalty)&lt;br&gt;
Every term is computed by the Heavenly Dao service. RootBonus depends on element matching with ambient qi. SpellMatch checks if your cultivated techniques align with your roots. RealmDecay prevents staying in low realms forever. MentalState tracks meditation and breaks. AgingPenalty adds urgency — cultivate too slowly and your mortal body degrades.&lt;br&gt;
Breakthrough &amp;amp; Tribulation&lt;br&gt;
Advancing to the next realm requires a breakthrough attempt. Probability is:&lt;br&gt;
P = BaseSuccess x Accumulation x SpellQuality x ResourceBonus x MentalState x Luck&lt;br&gt;
Clamped to [5%, 80%] — you always have a chance, but never a guarantee. Past Nascent Soul, breakthroughs trigger heavenly tribulations with lightning calculations, damage, and potential death. Karma matters too — players who commit too many evil acts face darker, stronger tribulations.&lt;br&gt;
AI NPCs: Letting Characters Loose&lt;br&gt;
The NPC system is what makes the world feel alive. Instead of static shopkeepers and quest-givers, every NPC has:&lt;br&gt;
• A behavior tree for routine actions (explore, rest, gather, cultivate)&lt;br&gt;
• An LLM-powered planning system for complex goals (form a sect, seek revenge, pursue an artifact)&lt;br&gt;
• Personality traits that modify decision weights (aggressive NPCs prefer combat, scholarly ones seek knowledge)&lt;br&gt;
• A memory system with short-term (recent events) and long-term (summarized experience) storage&lt;br&gt;
• Autonomous relationships — NPCs can befriend, rival, or attack each other&lt;br&gt;
The dual-loop design is key: the behavior tree handles 90% of decisions efficiently in-memory, while LLM calls (with prompt caching) handle the 10% that need real understanding. This keeps costs reasonable while delivering unexpected, emergent behavior.&lt;br&gt;
The Tech Stack (Why These Choices)&lt;br&gt;
Component   Choice  Why&lt;br&gt;
Language    Go 1.21/1.25    Concurrency, fast builds, great gRPC support&lt;br&gt;
DB  PostgreSQL + Redis  PG for ACID compliance, Redis for caching and pub/sub&lt;br&gt;
RPC gRPC + Protobuf Strong typing, code generation, efficient binary protocol&lt;br&gt;
HTTP/WS Gin Lightweight, well-tested, WebSocket support&lt;br&gt;
AI  DeepSeek LLM    Cost-effective for Chinese and English text generation&lt;br&gt;
Clients CLI / Bubble Tea TUI / Gio GUI  Meet players where they are&lt;br&gt;
Orchestration   Docker Compose  Simple local dev, one command to start everything&lt;br&gt;
Lessons Learned (The Hard Way)&lt;br&gt;
State synchronization is hard: When the Game Server updates a player realm, it needs to notify the Gateway (push to client), Heavenly Dao (recalculate formulas), and World Engine (update visibility). I started with a simple event bus pattern, then migrated to a more robust outbox pattern with Redis streams.&lt;br&gt;
NPC memory management is an unsolved problem: Storing every NPC interaction as raw text grows unboundedly. We use summarization triggers — when short-term memory exceeds a threshold, the LLM summarizes it into long-term memory and discards the raw log. It is not perfect, but it works.&lt;br&gt;
Testing the Heavenly Dao saved us: The karma and tribulation logic is complex — edge cases like: what happens when a player with negative karma faces a tribulation while wearing cursed equipment? The table-driven test pattern in heavenly-dao caught at least a dozen logical errors before they hit production.&lt;br&gt;
CLI-first was the right call: Building the CLI client before the GUI meant we iterated on the protocol and game feel fast. The Bubble Tea TUI came later and reused the same WebSocket message handling. The Gio desktop client taught us what NOT to do in Go GUI development.&lt;br&gt;
What is Next?&lt;br&gt;
The project has come a long way — 5 microservices, 21+ player actions, AI-driven NPCs with personality and memory, a full karma system, world events, mail, shops, leaderboards, and even a Bubble Tea TUI client. But there is more to build:&lt;br&gt;
• Cross-server party dungeons — co-op PVE with friends&lt;br&gt;
• Sect wars and territory control — guild-scale conflict&lt;br&gt;
• A proper Web UI — so players can jump in from a browser&lt;br&gt;
• More world events — player-triggered catastrophes, celestial auctions, wandering demons&lt;br&gt;
Try It Yourself&lt;br&gt;
The entire project is open source on GitHub:&lt;br&gt;
&lt;a href="https://github.com/xiuxianxiuxianxiuxian/diershij" rel="noopener noreferrer"&gt;https://github.com/xiuxianxiuxianxiuxian/diershij&lt;/a&gt;&lt;br&gt;
It is a single docker-compose up to start everything, plus a Go CLI client that connects in seconds. The README has full instructions in both Chinese and English.&lt;br&gt;
Whether you are a xianxia fan, a Go enthusiast, or just curious about AI-driven game worlds — I would love to hear your thoughts. Open an issue, send a PR, or just star the repo and watch the world evolve.&lt;/p&gt;




&lt;p&gt;Built with Go, PostgreSQL, Redis, gRPC, and a healthy obsession with cultivation novels.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>machinelearning</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
