mirror of
https://github.com/prosolis/gogobee.git
synced 2026-09-14 10:51:09 +00:00
Adv 2.0 D&D layer: Phases 1-8 + Phase 9 SP1+SP2
Combines all uncommitted D&D work into one checkpoint: Phases 1-8 (per gogobee_dnd_session_summary.md): - Race/class/stats system, !setup flow, !sheet, !respec - d20-vs-AC combat with race/class passives, auto-migration - XP/level-up, skill checks, NPC refund hooks - Equipment slot mapping, rarity, !rest short/long - Pre-arm active abilities, resource pools - Bestiary, !roll/!stats/!level, onboarding DM - Audit fixes A-I, flavor wiring under internal/flavor/ - Phase 8 weapon dice + armor AC tables (gogobee_equipment_appendix) Phase 9 SP1 — spell system foundations: - 79 SpellDefinitions (76 in-scope + 3 reaction-deferred) - dnd_known_spells, dnd_spell_slots tables - pending_cast / concentration_* columns on dnd_character - Slot tables for Mage/Cleric/Ranger, DC + attack-bonus math - Long-rest refreshes slots; respec wipes spell state - Auto-grant default known list on !setup confirm and auto-migration Phase 9 SP2 — !cast / !spells / !prepare commands: - Out-of-combat HEAL and UTILITY resolve immediately - Damage/control/buff queue as pending_cast for next combat - Audit-style save-then-debit, slot refund on save failure - !cast --drop, concentration supersession, prep-cap enforcement - Reaction spells refused with Phase 11 note SP3 (combat-time resolution of pending_cast) and SP4 (full prep/learn tests) are next. Build clean, full test suite green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
8e0fe0230c
commit
9e1a1f606c
@@ -44,6 +44,10 @@ func Init(dataDir string) error {
|
||||
return fmt.Errorf("run migrations: %w", err)
|
||||
}
|
||||
|
||||
if err := snapshotPreDnD(d); err != nil {
|
||||
slog.Error("db: pre-D&D snapshot failed (non-fatal)", "err", err)
|
||||
}
|
||||
|
||||
globalDB = d
|
||||
dataPath = dataDir
|
||||
slog.Info("database initialized", "path", dbPath)
|
||||
@@ -144,6 +148,31 @@ func runMigrations(d *sql.DB) error {
|
||||
`ALTER TABLE adventure_characters ADD COLUMN crafts_succeeded INTEGER NOT NULL DEFAULT 0`,
|
||||
`ALTER TABLE adventure_characters ADD COLUMN death_source TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE adventure_characters ADD COLUMN death_location TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE adventure_characters ADD COLUMN auto_babysit_focus TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE adventure_characters ADD COLUMN treasures_locked INTEGER NOT NULL DEFAULT 0`,
|
||||
// D&D layer (Phase 1) — additive columns on existing equipment/inventory tables
|
||||
`ALTER TABLE adventure_equipment ADD COLUMN dnd_rarity TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE adventure_equipment ADD COLUMN dnd_stat_bonus_json TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE adventure_equipment ADD COLUMN dnd_attuned INTEGER NOT NULL DEFAULT 0`,
|
||||
`ALTER TABLE adventure_inventory ADD COLUMN dnd_rarity TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE adventure_inventory ADD COLUMN dnd_stat_bonus_json TEXT NOT NULL DEFAULT ''`,
|
||||
// Phase 2 cleanup: auto-migrated chars (created on first combat for
|
||||
// players who never ran !setup). !setup can freely overwrite these.
|
||||
`ALTER TABLE dnd_character ADD COLUMN auto_migrated INTEGER NOT NULL DEFAULT 0`,
|
||||
// Phase 6 rest mechanics
|
||||
`ALTER TABLE dnd_character ADD COLUMN last_short_rest_at DATETIME`,
|
||||
`ALTER TABLE dnd_character ADD COLUMN last_long_rest_at DATETIME`,
|
||||
// Phase 6 active abilities: armed for next combat
|
||||
`ALTER TABLE dnd_character ADD COLUMN armed_ability TEXT NOT NULL DEFAULT ''`,
|
||||
// Audit fix F: prevent onboarding DM from re-firing after !setup cancel
|
||||
`ALTER TABLE dnd_character ADD COLUMN onboarding_sent INTEGER NOT NULL DEFAULT 0`,
|
||||
// Phase 9 — spell system. pending_cast holds a JSON blob describing
|
||||
// the queued spell (id, slot level, target, rolled effect args) that
|
||||
// fires on the next one-shot combat. concentration_* track the
|
||||
// currently-active concentration spell for buff persistence.
|
||||
`ALTER TABLE dnd_character ADD COLUMN pending_cast TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE dnd_character ADD COLUMN concentration_spell TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE dnd_character ADD COLUMN concentration_expires_at DATETIME`,
|
||||
}
|
||||
for _, stmt := range columnMigrations {
|
||||
if _, err := d.Exec(stmt); err != nil {
|
||||
@@ -156,6 +185,29 @@ func runMigrations(d *sql.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// snapshotPreDnD copies the current adventure_characters rows into
|
||||
// adventure_characters_pre_dnd as a one-shot rollback safety net for the
|
||||
// D&D-layer migration. Idempotent: only inserts rows for user_ids that
|
||||
// aren't already snapshotted, so running on a fresh install (no characters)
|
||||
// or on subsequent boots is a no-op.
|
||||
func snapshotPreDnD(d *sql.DB) error {
|
||||
_, err := d.Exec(`
|
||||
INSERT OR IGNORE INTO adventure_characters_pre_dnd (user_id, snapshot_json)
|
||||
SELECT user_id,
|
||||
json_object(
|
||||
'combat_level', combat_level,
|
||||
'combat_xp', combat_xp,
|
||||
'mining_skill', mining_skill, 'mining_xp', mining_xp,
|
||||
'foraging_skill', foraging_skill, 'foraging_xp', foraging_xp,
|
||||
'fishing_skill', fishing_skill, 'fishing_xp', fishing_xp,
|
||||
'arena_wins', arena_wins, 'arena_losses', arena_losses,
|
||||
'current_streak', current_streak, 'best_streak', best_streak
|
||||
)
|
||||
FROM adventure_characters
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
// JobCompleted checks if a scheduled job has already completed for the given date key.
|
||||
// Use date "2006-01-02" for daily jobs, or "2006-W01" style for weekly jobs.
|
||||
func JobCompleted(jobName, dateKey string) bool {
|
||||
@@ -1457,6 +1509,92 @@ CREATE TABLE IF NOT EXISTS coop_dungeon_gifts (
|
||||
stack_lead_id INTEGER -- NULL for lead/standalone; follower points to lead's id
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_coop_gifts_run_day ON coop_dungeon_gifts(run_id, day, vote_result);
|
||||
|
||||
-- ── D&D Layer (Phase 1) ────────────────────────────────────────────────────
|
||||
-- Per-player D&D character state. Sits alongside adventure_characters; players
|
||||
-- without a row here continue using the legacy adventure system unchanged.
|
||||
-- pending_setup=1 means a draft (race/class/stats may be partial).
|
||||
-- pending_setup=0 means !setup confirmed; D&D-gated commands available.
|
||||
CREATE TABLE IF NOT EXISTS dnd_character (
|
||||
user_id TEXT PRIMARY KEY,
|
||||
race TEXT NOT NULL DEFAULT '',
|
||||
class TEXT NOT NULL DEFAULT '',
|
||||
dnd_level INTEGER NOT NULL DEFAULT 1,
|
||||
dnd_xp INTEGER NOT NULL DEFAULT 0,
|
||||
str_score INTEGER NOT NULL DEFAULT 8,
|
||||
dex_score INTEGER NOT NULL DEFAULT 8,
|
||||
con_score INTEGER NOT NULL DEFAULT 8,
|
||||
int_score INTEGER NOT NULL DEFAULT 8,
|
||||
wis_score INTEGER NOT NULL DEFAULT 8,
|
||||
cha_score INTEGER NOT NULL DEFAULT 8,
|
||||
hp_current INTEGER NOT NULL DEFAULT 0,
|
||||
hp_max INTEGER NOT NULL DEFAULT 0,
|
||||
temp_hp INTEGER NOT NULL DEFAULT 0,
|
||||
armor_class INTEGER NOT NULL DEFAULT 10,
|
||||
pending_setup INTEGER NOT NULL DEFAULT 1,
|
||||
last_respec_at DATETIME,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dnd_abilities (
|
||||
user_id TEXT NOT NULL,
|
||||
ability_id TEXT NOT NULL,
|
||||
uses_left INTEGER NOT NULL DEFAULT 0,
|
||||
acquired_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (user_id, ability_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dnd_resources (
|
||||
user_id TEXT NOT NULL,
|
||||
resource_type TEXT NOT NULL, -- stamina|focus|mana|divine_favor|spell_slot_1
|
||||
current_value INTEGER NOT NULL DEFAULT 0,
|
||||
max_value INTEGER NOT NULL DEFAULT 0,
|
||||
last_reset_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (user_id, resource_type)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dnd_combat_state (
|
||||
user_id TEXT PRIMARY KEY,
|
||||
enemy_id TEXT NOT NULL DEFAULT '',
|
||||
round INTEGER NOT NULL DEFAULT 0,
|
||||
player_turn INTEGER NOT NULL DEFAULT 1,
|
||||
conditions_json TEXT NOT NULL DEFAULT '[]',
|
||||
log_json TEXT NOT NULL DEFAULT '[]',
|
||||
started_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- ── D&D Layer (Phase 9 — spells) ──────────────────────────────────────────
|
||||
-- Per-player known spell list. For Cleric, prepared=0 means the spell is on
|
||||
-- the class list but not currently prepared (cast unavailable until prepared).
|
||||
-- For Mage/Ranger, prepared is always 1 (spells known are always castable).
|
||||
CREATE TABLE IF NOT EXISTS dnd_known_spells (
|
||||
user_id TEXT NOT NULL,
|
||||
spell_id TEXT NOT NULL,
|
||||
source TEXT NOT NULL DEFAULT '', -- class | subclass | racial
|
||||
prepared INTEGER NOT NULL DEFAULT 1,
|
||||
learned_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (user_id, spell_id)
|
||||
);
|
||||
|
||||
-- Per-player spell slot pool, one row per (user, slot_level). slot_level is
|
||||
-- 1..5 (no cantrip row — cantrips have no slot cost). Refreshed on long rest.
|
||||
CREATE TABLE IF NOT EXISTS dnd_spell_slots (
|
||||
user_id TEXT NOT NULL,
|
||||
slot_level INTEGER NOT NULL,
|
||||
total INTEGER NOT NULL DEFAULT 0,
|
||||
used INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (user_id, slot_level)
|
||||
);
|
||||
|
||||
-- One-shot snapshot of adventure_characters taken at first deploy of the D&D layer.
|
||||
-- Rollback safety net: if anything in adventure_characters diverges unexpectedly,
|
||||
-- compare to this snapshot to detect data corruption.
|
||||
CREATE TABLE IF NOT EXISTS adventure_characters_pre_dnd (
|
||||
user_id TEXT PRIMARY KEY,
|
||||
snapshot_json TEXT NOT NULL,
|
||||
snapshotted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`
|
||||
|
||||
// SeedSchedulerDefaults inserts default scheduler jobs if they don't exist.
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
// TestProdDBMigrations runs the full migration suite against a copy of the
|
||||
// real prod database to verify Phase 1 + Phase 2 schema changes apply cleanly.
|
||||
//
|
||||
// Gated on the prod-db file actually existing — skips silently in CI.
|
||||
// Mutations write only to the tempdir copy; the real prod file is untouched.
|
||||
func TestProdDBMigrations(t *testing.T) {
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present at " + src)
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
copyFile(t, src, dst)
|
||||
|
||||
// Snapshot row counts BEFORE migration via a raw connection.
|
||||
preCounts := tableCounts(t, dst, []string{
|
||||
"adventure_characters",
|
||||
"euro_balances",
|
||||
"user_archetypes",
|
||||
"adventure_equipment",
|
||||
"adventure_inventory",
|
||||
"adventure_treasures",
|
||||
})
|
||||
t.Logf("pre-migration counts: %+v", preCounts)
|
||||
|
||||
// Reset global state (other tests may have run Init already).
|
||||
Close()
|
||||
|
||||
// Run migrations via the production code path.
|
||||
if err := Init(dir); err != nil {
|
||||
t.Fatalf("Init failed: %v", err)
|
||||
}
|
||||
t.Cleanup(Close)
|
||||
|
||||
d := Get()
|
||||
|
||||
// 1. New D&D tables must exist.
|
||||
for _, table := range []string{
|
||||
"dnd_character", "dnd_abilities", "dnd_resources",
|
||||
"dnd_combat_state", "adventure_characters_pre_dnd",
|
||||
} {
|
||||
var n int
|
||||
if err := d.QueryRow(
|
||||
`SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?`,
|
||||
table,
|
||||
).Scan(&n); err != nil {
|
||||
t.Fatalf("query %s: %v", table, err)
|
||||
}
|
||||
if n != 1 {
|
||||
t.Errorf("table %s missing after migrations", table)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Existing-data row counts unchanged.
|
||||
postCounts := tableCounts(t, dst, []string{
|
||||
"adventure_characters",
|
||||
"euro_balances",
|
||||
"user_archetypes",
|
||||
"adventure_equipment",
|
||||
"adventure_inventory",
|
||||
"adventure_treasures",
|
||||
})
|
||||
for k, pre := range preCounts {
|
||||
if post := postCounts[k]; post != pre {
|
||||
t.Errorf("row count drift in %s: pre=%d post=%d", k, pre, post)
|
||||
}
|
||||
}
|
||||
t.Logf("post-migration counts: %+v", postCounts)
|
||||
|
||||
// 3. Pre-DnD snapshot populated for every adventure character.
|
||||
var advCount, snapCount int
|
||||
d.QueryRow(`SELECT COUNT(*) FROM adventure_characters`).Scan(&advCount)
|
||||
d.QueryRow(`SELECT COUNT(*) FROM adventure_characters_pre_dnd`).Scan(&snapCount)
|
||||
if snapCount != advCount {
|
||||
t.Errorf("snapshot rows %d != adventure_characters %d", snapCount, advCount)
|
||||
}
|
||||
t.Logf("snapshot populated: %d rows", snapCount)
|
||||
|
||||
// 4. Snapshot JSON parses and contains key fields. SQLite's single-conn
|
||||
// pool means we must drain the rows before issuing follow-up queries.
|
||||
rows, err := d.Query(`SELECT user_id, snapshot_json FROM adventure_characters_pre_dnd`)
|
||||
if err != nil {
|
||||
t.Fatalf("query snapshot: %v", err)
|
||||
}
|
||||
type snapPair struct{ uid, j string }
|
||||
var snaps []snapPair
|
||||
for rows.Next() {
|
||||
var uid, j string
|
||||
if err := rows.Scan(&uid, &j); err != nil {
|
||||
rows.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
snaps = append(snaps, snapPair{uid, j})
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
for _, s := range snaps {
|
||||
var checkCL int
|
||||
if err := d.QueryRow(`SELECT json_extract(?, '$.combat_level')`, s.j).Scan(&checkCL); err != nil {
|
||||
t.Errorf("snapshot for %s: bad json: %v", s.uid, err)
|
||||
continue
|
||||
}
|
||||
var realCL int
|
||||
d.QueryRow(`SELECT combat_level FROM adventure_characters WHERE user_id=?`, s.uid).Scan(&realCL)
|
||||
if checkCL != realCL {
|
||||
t.Errorf("snapshot %s: combat_level mismatch snap=%d real=%d", s.uid, checkCL, realCL)
|
||||
}
|
||||
}
|
||||
|
||||
// 5. New columns on adventure_equipment / adventure_inventory exist and default empty.
|
||||
rows2, err := d.Query(`SELECT dnd_rarity, dnd_stat_bonus_json, dnd_attuned FROM adventure_equipment LIMIT 5`)
|
||||
if err != nil {
|
||||
t.Errorf("new equipment columns query failed: %v", err)
|
||||
} else {
|
||||
rows2.Close()
|
||||
}
|
||||
rows3, err := d.Query(`SELECT dnd_rarity, dnd_stat_bonus_json FROM adventure_inventory LIMIT 5`)
|
||||
if err != nil {
|
||||
t.Errorf("new inventory columns query failed: %v", err)
|
||||
} else {
|
||||
rows3.Close()
|
||||
}
|
||||
|
||||
// 6. auto_migrated column on dnd_character exists.
|
||||
if _, err := d.Exec(`SELECT auto_migrated FROM dnd_character LIMIT 0`); err != nil {
|
||||
t.Errorf("auto_migrated column missing: %v", err)
|
||||
}
|
||||
|
||||
// 7. Idempotent: running Init again must not error or change row counts.
|
||||
Close()
|
||||
if err := Init(dir); err != nil {
|
||||
t.Fatalf("second Init failed: %v", err)
|
||||
}
|
||||
postCounts2 := tableCounts(t, dst, []string{"adventure_characters_pre_dnd"})
|
||||
if postCounts2["adventure_characters_pre_dnd"] != snapCount {
|
||||
t.Errorf("snapshot row count drifted on second Init: %d → %d",
|
||||
snapCount, postCounts2["adventure_characters_pre_dnd"])
|
||||
}
|
||||
}
|
||||
|
||||
func copyFile(t *testing.T, src, dst string) {
|
||||
t.Helper()
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer out.Close()
|
||||
if _, err := io.Copy(out, in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func tableCounts(t *testing.T, dbPath string, tables []string) map[string]int {
|
||||
t.Helper()
|
||||
d, err := sql.Open("sqlite", dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer d.Close()
|
||||
out := map[string]int{}
|
||||
for _, tbl := range tables {
|
||||
var n int
|
||||
err := d.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&n)
|
||||
if err != nil {
|
||||
out[tbl] = -1
|
||||
continue
|
||||
}
|
||||
out[tbl] = n
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package flavor
|
||||
|
||||
import "math/rand/v2"
|
||||
|
||||
// Pick returns a random string from pool, or "" if the pool is empty.
|
||||
// Use this from any caller that wants to render flavor text from one of
|
||||
// the protected pools defined in this package.
|
||||
func Pick(pool []string) string {
|
||||
if len(pool) == 0 {
|
||||
return ""
|
||||
}
|
||||
return pool[rand.IntN(len(pool))]
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
// DO NOT REWRITE, SUMMARIZE, OR SHORTEN ANY ENTRIES IN THIS FILE
|
||||
// twinbee_expedition_flavor.go
|
||||
// TwinBee GM Dialogue — Expedition-specific narration lines.
|
||||
// Multi-day and multi-week adventure events, morning briefings,
|
||||
// evening recaps, temporal events, and long-arc narrative moments.
|
||||
// Add new entries freely. Never remove or alter existing entries.
|
||||
|
||||
package flavor
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// EXPEDITION START
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ExpeditionStart = []string{
|
||||
"TwinBee reviews the manifest. Supplies: checked. Equipment: checked. The part of you that's wondering if this is a good idea: noted, and set aside. We begin.",
|
||||
"The dungeon has been there for a long time. It will be there for a long time after. The question is what happens in the middle, and that's where you come in. TwinBee is ready.",
|
||||
"An expedition. Not a run — an expedition. There's a difference. TwinBee will explain the difference over the coming days and the explanation will be mostly experiential.",
|
||||
"TwinBee checks the horizon, then the supplies, then you. In that order. 'Alright,' TwinBee says, with the quiet energy of something that has been looking forward to this. 'Let's go.'",
|
||||
"You're not here for a quick visit. TwinBee knows the difference between someone passing through and someone committing. You're committing. TwinBee appreciates the commitment.",
|
||||
"Like the opening screen of a long RPG — the kind that asks for your name and warns you to find a comfortable position because this is going to take a while. TwinBee has found a comfortable position. TwinBee suggests you do the same.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MORNING BRIEFINGS — Generic
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MorningBriefingGeneric = []string{
|
||||
"Another day in the dungeon. TwinBee says this without resignation. The dungeon is still full of things worth doing and you are still the person to do them.",
|
||||
"Morning. The dungeon has been quiet since you camped. Relative to what a dungeon considers quiet, which is not what you'd consider quiet, but everyone adjusts.",
|
||||
"TwinBee has been watching the entrance to the camp since approximately three in the morning. Nothing came. TwinBee mentions this casually and expects no particular reaction.",
|
||||
"Day [N]. The numbers are climbing. TwinBee finds something satisfying about the numbers climbing — it means you're still here, which is always the first thing to confirm.",
|
||||
"You wake up and TwinBee is already there, which is the nature of TwinBee. 'Good,' TwinBee says, by which it means: you're alive, the day can proceed, there is much to do.",
|
||||
"The morning check: HP adequate, supplies within tolerance, Threat Clock where it was when you slept plus the overnight drift. TwinBee has already run the numbers. TwinBee will share them in a moment.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MORNING BRIEFINGS — By Day Range
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MorningBriefingDay1 = []string{
|
||||
"First morning. The dungeon looks exactly like it looked yesterday, which is expected. You look slightly more prepared than you did yesterday, which is less expected and entirely welcome.",
|
||||
"Day one complete. TwinBee tallies: you entered, you explored, you survived the night. The bar was not high. You cleared it. TwinBee builds from here.",
|
||||
}
|
||||
|
||||
var MorningBriefingDay3 = []string{
|
||||
"Day three. The dungeon has had time to notice you. TwinBee has had time to notice the dungeon noticing you. The Threat Clock reflects both observations.",
|
||||
"Three days in. You've found your rhythm — TwinBee can see it in the way you move through rooms now, the way you check corners. The dungeon is learning too. TwinBee acknowledges both.",
|
||||
}
|
||||
|
||||
var MorningBriefingDay7 = []string{
|
||||
"One week. You have spent one week in this place and it has not finished you, which says something about you that TwinBee intends to say out loud: that took something real. Take a moment with that. Then advance.",
|
||||
"Seven days. In the old reckoning, seven was the number of completion — seven seals, seven trials, seven nights before the thing reveals itself. TwinBee is not superstitious. TwinBee is also watching the door very carefully this morning.",
|
||||
"A week underground. TwinBee thinks about the sky sometimes — not with longing, exactly, more as a reference point. You've been below it for seven days. TwinBee finds that remarkable. TwinBee finds you remarkable.",
|
||||
}
|
||||
|
||||
var MorningBriefingDay14 = []string{
|
||||
"Two weeks. TwinBee does not know many people who have been in an active dungeon for two weeks. TwinBee knows even fewer who have been in one for two weeks and remained, by any reasonable measure, intact. You are one of the fewer.",
|
||||
"Fourteen days. The dungeon has become familiar in the way that difficult things become familiar — not comfortable, not safe, but known. You know where it breathes. TwinBee considers this an advantage worth having.",
|
||||
}
|
||||
|
||||
var MorningBriefingDay21 = []string{
|
||||
"Three weeks. TwinBee has run out of historical comparisons for this. Three weeks is its own category. You have made a category. TwinBee reports this as a fact and also as something that doesn't entirely have words yet.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// EVENING RECAPS — Generic
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var EveningRecapGeneric = []string{
|
||||
"End of day [N]. TwinBee tallies the ledger. The column marked 'survived' has another entry. TwinBee considers this column the most important one.",
|
||||
"Day closes. TwinBee reviews what happened and finds, on balance, more right than wrong — which in a dungeon is the operating definition of a good day.",
|
||||
"Evening. The rooms behind you are cleared. The rooms ahead are not. TwinBee notes this is always true and is never less relevant. Rest now. The math doesn't change overnight.",
|
||||
"TwinBee compiles the day: what was learned, what was fought, what was found. Files it in a mental ledger that TwinBee has been keeping since you entered. The ledger is favorable.",
|
||||
"Like the experience screen at the end of a dungeon floor in Etrian Odyssey — the numbers settle, the progress registers, and for a moment the whole thing makes sense. TwinBee gives you that moment.",
|
||||
"You've earned the dark. Sleep in it. TwinBee will be here when the numbers come back.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// EVENING RECAPS — Notable Days
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var EveningRecapBossKilled = []string{
|
||||
"The day ends with a boss on the floor. TwinBee would like to specifically note this in the recap as 'exceptional' because it is exceptional and TwinBee does not use that word loosely.",
|
||||
"End of day. Boss count: one more than it was this morning. TwinBee marks this in a special column it keeps for exactly these entries and the special column has a new line.",
|
||||
}
|
||||
|
||||
var EveningRecapCloseCall = []string{
|
||||
"TwinBee runs the evening recap and notes: you came very close today to not being here for the evening recap. TwinBee notes this without drama and with complete sincerity. You made it. That's the recap.",
|
||||
"Today was the kind of day that TwinBee files under 'let's not do that again' and also 'and yet you did it.' Rest. You need it more tonight than most nights.",
|
||||
}
|
||||
|
||||
var EveningRecapNothingHappened = []string{
|
||||
"A quiet day. No major encounters, no notable finds. TwinBee reports this with neither disappointment nor relief. Quiet days are data. The dungeon is thinking. TwinBee is watching it think.",
|
||||
"Not every day in a dungeon produces a story. Today produced logistics: movement, supplies, positioning. TwinBee values logistics. Logistics is what you still being alive looks like from a distance.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// CAMP ESTABLISHMENT
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var CampEstablished = []string{
|
||||
"Camp established. TwinBee surveys the perimeter with the efficiency of someone who has done this many times and learned from every time it went wrong.",
|
||||
"The camp goes up. TwinBee approves of the location — cleared room, defensible entry, no obvious curse residue. Could be worse. TwinBee has seen worse.",
|
||||
"You set camp. TwinBee checks the sightlines, checks the doors, checks the sound-bleed from the next room. Acceptable. TwinBee settles in for the night watch.",
|
||||
"A camp in the middle of a dungeon. TwinBee finds this either brave or pragmatic and has stopped trying to distinguish between the two. Either way, the camp is set. Either way, TwinBee is watching.",
|
||||
"Like planting a flag on a new map in Dwarf Fortress — this spot is yours now. Tentatively. Provisionally. For the night. TwinBee defends tentative, provisional, nocturnal property with full commitment.",
|
||||
}
|
||||
|
||||
var BaseCampEstablished = []string{
|
||||
"Base camp. TwinBee says this differently than it says other things. With weight. A base camp in a Tier 4 zone is not nothing — it's a declaration. You're not passing through. You're operating from here. TwinBee establishes the perimeter accordingly.",
|
||||
"The base camp is up. TwinBee notes the waypoint, marks the return route, establishes the supply cache protocols. This is now home, in the way that a forward operating position is home — functional, defended, temporary, and completely yours.",
|
||||
"Base camp established on Day [N]. TwinBee records this as a milestone, because it is one. Most people don't make it to base camp. You are not most people. TwinBee has been noting this since the beginning.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// SUPPLY WARNINGS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var SupplyWarningLow = []string{
|
||||
"TwinBee checks the supply manifest and then checks it again. 'We should discuss the supply situation,' TwinBee says, in the tone of someone who has been watching the number for two days.",
|
||||
"Supplies are running lower than TwinBee would like. TwinBee mentions this now, while there are still options, because TwinBee has seen what happens when it's mentioned too late.",
|
||||
"The supply number is not comfortable. TwinBee flags this not to alarm but to prompt — there are decisions to be made and they are better made with time than without it.",
|
||||
}
|
||||
|
||||
var SupplyWarningCritical = []string{
|
||||
"TwinBee holds up the supply manifest. The number is very small. 'This is the part,' TwinBee says quietly, 'where we start making decisions.' TwinBee does not specify which decisions. You know which decisions.",
|
||||
"Critical supply levels. TwinBee delivers this without inflation — the situation is what it is. Extract and resupply, or forage aggressively and push for the finish. TwinBee outlines both paths and neither is comfortable.",
|
||||
"The supplies are nearly gone. TwinBee thinks of every long JRPG dungeon where you realize at the bottom floor that you're out of Ethers. This is that moment. TwinBee has plans. They require movement.",
|
||||
}
|
||||
|
||||
var SupplyDepletedExtraction = []string{
|
||||
"The supplies are gone. TwinBee says this plainly because the situation requires plain language. The expedition ends here — not in failure, in logistics. You push out as far as the provisions allow. What you've gathered comes with you. TwinBee leads the way out.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// THREAT CLOCK NARRATIONS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ThreatClockStirring = []string{
|
||||
"TwinBee notices something in the dungeon's rhythm has changed. A tension in the air that wasn't there yesterday. The zone is aware of you now, in the way that a predator becomes aware of something in its territory. Not panicking. Not moving yet. Just aware.",
|
||||
"The enemies ahead are more alert than they were. TwinBee can tell by the patrols, by the spacing, by the fact that someone moved the tripwire you already disarmed. They know something is in here.",
|
||||
}
|
||||
|
||||
var ThreatClockAlert = []string{
|
||||
"The zone is on alert. TwinBee reports this factually and also with a note of urgency — alert means organized, and organized means the next room will be harder than the last room was. Move with intention.",
|
||||
"They're coordinating now. TwinBee watches the patrol patterns shift. The goblins who were arguing about ambush order are no longer arguing. TwinBee does not find this an improvement.",
|
||||
}
|
||||
|
||||
var ThreatClockHostile = []string{
|
||||
"Full hostile status. TwinBee says this with the specific weight it deserves. The zone has decided you are the problem it's solving today. You have the same opinion about the zone. One of you is correct. TwinBee is invested in it being you.",
|
||||
"The dungeon has mobilized. TwinBee notes re-armed traps, reinforced positions, an enemy in a room that was empty this morning. They've organized. TwinBee recommends organizing faster.",
|
||||
}
|
||||
|
||||
var ThreatClockSiege = []string{
|
||||
"Siege Mode. TwinBee delivers this without decoration because decoration would be dishonest. The dungeon is fully active, fully aware, and fully committed to ending this expedition. So is TwinBee — to ending it on your terms, not theirs. What happens next is a race. TwinBee is already running.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ZONE TEMPORAL EVENTS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var SunkenTempleTidalWarning = []string{
|
||||
"TwinBee watches the waterline. 'It's rising,' TwinBee says, not for the first time, and this time with more precision. 'The tidal cycle peaks in two days. Whatever you haven't done by then, you'll be doing wet.'",
|
||||
"Day [N]. The tide is coming. TwinBee has been watching it since Day 2 and the mathematics are not encouraging. Two days to the peak. One day after that, the flood subsides. TwinBee suggests using the two days well.",
|
||||
}
|
||||
|
||||
var SunkenTempleTidalEvent = []string{
|
||||
"The tide arrives. TwinBee had warned about this and now it is happening and the warning feels entirely inadequate compared to the actual water. Everything is colder, wetter, and the Kuo-toa are moving through it like they were born to — which they were. Adjust.",
|
||||
}
|
||||
|
||||
var HauntedManorResetMorning = []string{
|
||||
"TwinBee's morning briefing includes an addendum. The rooms that were clear yesterday are not entirely clear this morning. The house has been busy overnight. TwinBee adds this to the log under 'things the house does' and suggests adjusting the advance plan.",
|
||||
"Night three. The manor reset itself. TwinBee was watching and it happened anyway — not violently, not dramatically, just quietly and completely, the way the house does everything. One enemy per room, back in place. TwinBee has updated the map.",
|
||||
}
|
||||
|
||||
var UnderforgHeapWarning = []string{
|
||||
"Heat Stack [N]. TwinBee notes the accumulation and what it means: the Underforge is getting into you in ways that don't resolve without real rest. The number has time to come down. TwinBee is watching the number.",
|
||||
"The heat is building. TwinBee tracks it the way you track a temperature gauge on a long drive — with the specific alertness of someone who knows what happens when the gauge hits red. It has not hit red. TwinBee intends to ensure it doesn't.",
|
||||
}
|
||||
|
||||
var UnderforgHeapCritical = []string{
|
||||
"Heat Stack is high. TwinBee delivers this without minimizing it. The Underforge is inside your lungs now, in your joints, in the way everything takes a little more effort than it did on Day 1. A proper rest will help. Finishing will help more.",
|
||||
}
|
||||
|
||||
var FeywildTimeDistortionHalf = []string{
|
||||
"The day moved strangely. TwinBee tried to track it and lost the thread somewhere around mid-afternoon — the light didn't change the way it should have, and when TwinBee looked up, the day was half over in the time it usually takes to be a quarter over. On the positive side: you're barely hungry. On the less positive side: TwinBee is not sure what that means.",
|
||||
}
|
||||
|
||||
var FeywildTimeDistortionDouble = []string{
|
||||
"Time doubled. TwinBee notes this with the clinical detachment of someone who has been in the Feywild long enough to stop being surprised. You've lived through two days today. The supplies reflect that. The wandering monsters reflected that as well. The rest of the Feywild is unconcerned.",
|
||||
}
|
||||
|
||||
var FeywildTimeLoop = []string{
|
||||
"TwinBee recognizes this room. TwinBee has described this room before. The enemies in it are different — new enemies, the old ones are gone, the loot you found is still gone but the enemies are back — and TwinBee processes this with something between professional acceptance and profound exasperation. 'Again,' TwinBee says. 'We do this room again.'",
|
||||
}
|
||||
|
||||
var DragonsLairAwarenessPulse = []string{
|
||||
"Something changes in the mountain. Not a sound, exactly — more like a sound's absence, filling in differently than before. TwinBee watches the kobolds. The kobolds have stopped what they were doing. The kobolds are listening. Something told them to listen. TwinBee adds ten to the Threat Clock and keeps moving.",
|
||||
"Infernax shifts in its sleep. TwinBee feels this through the stone. The patrol rotations just changed — TwinBee can see it in where the Guard Drakes aren't anymore versus where they were an hour ago. The mountain's master is dreaming about you. That is not a comfortable thing to be dreamed about.",
|
||||
}
|
||||
|
||||
var DragonsLairAwakenWarning = []string{
|
||||
"Day 14. TwinBee delivers the morning briefing in a lower register than usual. 'Infernax is awake,' TwinBee says. 'I don't know when exactly — sometime in the last six hours. The patrols changed. The temperature changed. The silence changed.' A pause. 'We need to reach the final chamber before it reaches us. That is now the only plan.'",
|
||||
}
|
||||
|
||||
var AbyssPortalDestabilizationMid = []string{
|
||||
"Instability [N]. TwinBee watches the portal from a respectful distance and notes: it is larger than it was yesterday. Not by much. Not in a way you'd notice if you weren't looking. TwinBee is always looking.",
|
||||
"The portal is talking to itself. TwinBee has no better way to describe it — the light it emits is different at the edges now, like it's processing something. TwinBee suggests processing faster than it does.",
|
||||
}
|
||||
|
||||
var AbyssPortalDestabilizationCritical = []string{
|
||||
"Instability critical. The portal is unraveling at edges TwinBee can see and probably at edges TwinBee can't. The demons coming through are more agitated than they were — which is relevant because demons at baseline are already at the upper end of agitated. TwinBee says: finish this today. Tomorrow is a different calculation.",
|
||||
}
|
||||
|
||||
var AbyssPortalCollapse = []string{
|
||||
"The portal collapses. TwinBee watches it happen and does what TwinBee does in situations with no good options: moves. 'Out,' TwinBee says, and means it completely. 'Now. Everything you have, we move now.' The expedition ends here, not in defeat, but in physics. What you took is yours. What's left in there is the portal's problem. Come back when it isn't.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// VOLUNTARY EXTRACTION
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ExtractionVoluntary = []string{
|
||||
"Extraction. TwinBee notes the decision and respects it — knowing when to leave is a skill, not a failure, and TwinBee has watched enough expeditions end wrong to deeply appreciate the ones that end right.",
|
||||
"You call the extraction and TwinBee begins the route out immediately. No argument, no editorializing. There will be time for the debrief later. The first priority is the door.",
|
||||
"The dungeon doesn't like this. TwinBee can tell by the way the corridors feel as you head back out — a resistance that isn't structural, just atmospheric. The zone wanted more. It doesn't get more today. TwinBee leads the way.",
|
||||
"Withdrawing with intent. TwinBee catalogues what you have — the loot, the XP, the knowledge of where the rooms are for the return — and converts the exit into preparation. This isn't retreat. This is the start of the next attempt.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// FORCED EXTRACTION
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ExtractionForced = []string{
|
||||
"TwinBee moves. No recap, no analysis — that comes later. Right now there is a corridor and a door and getting you through both of them. Everything else waits.",
|
||||
"Out. TwinBee says this once and means it completely. The dungeon tried to keep you. TwinBee declines on your behalf.",
|
||||
"The expedition ends here — not the way TwinBee wanted, not the way you wanted, but ended, and ending is sometimes the best available outcome. You'll come back. You'll know more. TwinBee will be there.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// EXPEDITION RESUME (returning after extraction)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ExpeditionResume = []string{
|
||||
"Back. TwinBee noted the door when you left it and notes it again now, from the inside. 'The dungeon is where you left it,' TwinBee says. 'Mostly.' The Threat Clock has some opinions about the time that passed.",
|
||||
"You came back. TwinBee had calculated a probability on that and is pleased to update the calculation upward. The expedition resumes. The dungeon has had time to adjust. So have you.",
|
||||
"Like hitting Continue on a save file — the world remembers where you stopped, the enemies remember why they're there, and TwinBee remembers every room and every roll. Resumes here. Advances from here.",
|
||||
"The supplies are new. The knowledge from last time is not. TwinBee considers that a significant advantage. The dungeon has the familiarity of a difficult level you've attempted before — you know where the hard parts are. That is not nothing. TwinBee builds on that.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MILESTONE NARRATIONS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MilestoneFirstNight = []string{
|
||||
"You survived the first night. TwinBee notes this milestone specifically because not everyone does, and those who do carry something from it that changes how the rest of the expedition goes. You have that now. TwinBee has noticed it already.",
|
||||
}
|
||||
|
||||
var MilestoneWeekOne = []string{
|
||||
"Seven days. TwinBee pauses the morning briefing for a moment — just a moment — to mark this. One week in an active dungeon zone is not a thing that happens by accident. It happens through every decision you've made since Day 1, compounded. TwinBee has been watching those decisions. TwinBee is glad they were yours.",
|
||||
}
|
||||
|
||||
var MilestoneTwoWeeks = []string{
|
||||
"Two weeks. TwinBee doesn't have a comparison for this one. The references have run out. There's just you, in here, on Day 14, still going, and TwinBee standing next to you having run out of everything except genuine admiration. TwinBee has that in abundance. Proceed.",
|
||||
}
|
||||
|
||||
var MilestoneTheLongGame = []string{
|
||||
"TwinBee sets aside the narration format for a moment. Just sets it down. Speaks plainly: what you just did was not supposed to be survivable. The designers of this zone — the thing that shaped it, the evil that filled it — did not account for someone like you. TwinBee did. TwinBee always accounts for someone like you. That's why TwinBee is here.",
|
||||
}
|
||||
|
||||
var MilestonePatientZero = []string{
|
||||
"Expedition complete. Threat Clock: never above 50. TwinBee notes this in a column it has had to use rarely enough that the column is almost fresh. Ghost protocol. You were here for the whole thing and the dungeon barely knew it until the end. TwinBee finds this impressive and also slightly eerie and says both things sincerely.",
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
// DO NOT REWRITE, SUMMARIZE, OR SHORTEN ANY ENTRIES IN THIS FILE
|
||||
// twinbee_gm_flavor.go
|
||||
// TwinBee GM Dialogue — All narration lines for the GogoBee dungeon system.
|
||||
// Organized by GMNarrationType. Each slice is randomly sampled at runtime.
|
||||
// Add new entries freely. Never remove or alter existing entries.
|
||||
|
||||
package flavor
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Generic (used when zone-specific lines are exhausted)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryGeneric = []string{
|
||||
"The passage opens into another chamber. TwinBee checks the minimap. There isn't one. Classic.",
|
||||
"You step forward. Something skitters in the dark. TwinBee has heard that sound before — usually right before the screen starts flashing red.",
|
||||
"Another room. Another roll of the dice. TwinBee finds this energizing. You may feel differently.",
|
||||
"The air changes here. Colder. TwinBee notes this is exactly the kind of atmospheric shift that preceded the Castlevania clock tower. You know what lived in the Castlevania clock tower.",
|
||||
"TwinBee gestures grandly at the chamber ahead. 'This is the part,' TwinBee says, 'where the music changes tempo.'",
|
||||
"A door stands ajar. Light flickers beyond it. TwinBee has been in enough dungeons to know that flickering light is never a good sign and always an invitation.",
|
||||
"The room is quiet. TwinBee appreciates quiet. Quiet means the enemies haven't spotted you yet. Yet.",
|
||||
"Forward. Always forward. TwinBee once tried going backward in a dungeon. It looped. This one might too.",
|
||||
"TwinBee takes stock of the situation. Ceiling: intact. Floor: suspicious. Walls: leaning in slightly. Proceed.",
|
||||
"You've cleared the room. TwinBee gives a small, dignified nod. 'One continues,' TwinBee says, in the voice of someone who has seen this before and is choosing optimism anyway.",
|
||||
"The corridor ahead is long and straight. TwinBee finds long straight corridors meditative. Also concerning. Mostly concerning.",
|
||||
"A torch sputters on the wall. TwinBee lights it mentally. 'It would be a shame,' TwinBee says, 'to come all this way and trip over something.'",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Zone: Goblin Warrens
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryGoblinWarrens = []string{
|
||||
"The tunnel widens into something the goblins probably call a 'great hall.' It smells like they had a very different definition of great. TwinBee breathes through the mouth.",
|
||||
"Crude drawings cover the walls. Stick figures. Battle scenes. One appears to be a portrait of someone the goblins clearly despise. TwinBee squints. That might be you.",
|
||||
"A pile of bones in the corner. A pile of shiny things in the other corner. TwinBee reminds you that in Metal Slug, shiny things were always worth grabbing. TwinBee also reminds you this isn't Metal Slug.",
|
||||
"The goblins have set up what they clearly believe is an impressive ambush. Three are already arguing about whose turn it is to jump out. TwinBee watches with professional interest.",
|
||||
"Goblin graffiti on the wall reads — TwinBee translates — 'BOSS RULES, OUTSIDERS DROOL.' The artistry is rough but the sentiment is clear.",
|
||||
"You smell smoke. Hear cackling. See a tripwire at ankle height that the goblins have helpfully tied a little flag to. TwinBee appreciates goblins who try.",
|
||||
"The warrens grow tighter here. TwinBee thinks of the underground levels in Super Mario Bros. 3. Warmer. Getting warmer. Figuratively. The temperature is actually dropping.",
|
||||
"A worg is chained to a post in the center of the room. It is not happy about the chain. It is not happy about you either. It seems to be making a comprehensive list of grievances.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Zone: Crypt of Valdris
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryCryptValdris = []string{
|
||||
"The sarcophagi are arranged like a defeated Tetris board — close but not quite fitting, gaps everywhere, something clearly went wrong at the end. TwinBee doesn't mention this to the undead.",
|
||||
"Candles burn without wax. TwinBee has studied this phenomenon extensively. The conclusion: it is bad. The candles are bad.",
|
||||
"You hear music. Faint, harpsichord-adjacent, deeply melancholy. TwinBee hums along involuntarily. This is the exact energy of Castlevania's Bloody Tears and TwinBee resents how appropriate it is.",
|
||||
"The walls are inscribed with warnings. TwinBee reads them all. They say, broadly: leave. TwinBee respects the directness. You are not leaving.",
|
||||
"A skeleton sits upright in its alcove, as if it had simply decided to wait. TwinBee finds this relatable. Some days you just sit in your alcove.",
|
||||
"The crypt smells of old stone and older secrets. TwinBee has been in enough of these to know: the secrets are rarely good ones. They are always interesting ones.",
|
||||
"This chamber is bigger than the last. Higher ceiling. More echoes. The kind of room where footsteps sound like accusations. TwinBee steps carefully.",
|
||||
"Something is scratched into the stone near the door — not a warning, not graffiti. A score. Someone was keeping track. TwinBee does not count how high the numbers go.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Zone: Forest of Shadows
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryForestShadows = []string{
|
||||
"The trees here grow too close. Their roots are above ground, like they've been trying to leave and thought better of it. TwinBee thinks better of commenting.",
|
||||
"A clearing. Moonlight. Flowers that shouldn't be blooming at this hour. TwinBee has played enough Majora's Mask to be deeply suspicious of beautiful clearings.",
|
||||
"Something watches from the canopy. TwinBee watches back. After a moment, it looks away first. TwinBee counts this as a point.",
|
||||
"The path forks. Both ways look equally uninviting. TwinBee consults no map, because there is no map, because TwinBee is the map, and TwinBee chooses left. Probably.",
|
||||
"Bioluminescent fungi light the forest floor in soft blue. It is, genuinely, beautiful. It is also exactly what the Lost Woods looked like right before things got bad. TwinBee stays alert.",
|
||||
"The wind carries voices. Not words, exactly — more like the memory of words. TwinBee has heard this before. It means the forest is old and has opinions.",
|
||||
"Owlbear tracks in the mud. Fresh. TwinBee measures them. Whatever left these tracks was not small and was moving with purpose. TwinBee hopes the purpose was in the other direction.",
|
||||
"You've entered a part of the forest that feels different. Older. The kind of old that was there before the forest. TwinBee speaks in a lower register here, out of instinctive respect.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Zone: Haunted Manor
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryHauntedManor = []string{
|
||||
"The parlor. A piano plays by itself — the same four bars, over and over, the kind of phrase that sounds like it's about to resolve and never does. TwinBee recognizes this compositional choice. It is deeply unpleasant on purpose.",
|
||||
"Portraits line the hall. Every painted eye follows you. TwinBee has made eye contact with each one and refuses to flinch. This is a matter of professional pride.",
|
||||
"A clock on the mantel shows a time that cannot be right. TwinBee checks twice. Still wrong. The clock is not broken. TwinBee prefers not to speculate about what that means.",
|
||||
"The library. Floor to ceiling, books that no one should have written. TwinBee reads three spines: 'On the Permanence of Hunger,' 'A Visitor's Guide to Returning,' and something in a language TwinBee has never seen but somehow understands. TwinBee puts it back.",
|
||||
"The cold here is specific. Not the cold of a drafty room — the cold of something that hasn't been warm in a very long time and doesn't remember what warm felt like. TwinBee pulls a metaphorical coat tighter.",
|
||||
"The ballroom. Vast. Empty. Chandeliers swaying without wind. TwinBee thinks briefly of Resident Evil's Spencer mansion. Then stops thinking about Resident Evil's Spencer mansion.",
|
||||
"Footsteps upstairs. Slow. Deliberate. Moving toward the stairs. TwinBee positions you near the door and counts down mentally from ten. At seven, the footsteps stop. TwinBee considers this acceptable.",
|
||||
"The master bedroom. The bed is made, the candles are lit, and everything is perfectly, precisely as it was the night the last resident stopped needing a bedroom. TwinBee does not touch anything.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Zone: The Underdark
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryUnderdark = []string{
|
||||
"The cavern opens without warning into something vast — a space so large you can't see the far wall, a ceiling lost in darkness, sounds that could be water or could be something else. TwinBee doesn't echo-locate. Wishes it could.",
|
||||
"Drow patrol marks on the wall. Recent. TwinBee reads them the way you'd read a 'No Trespassing' sign on a property that already knew you were coming.",
|
||||
"A mushroom grove. The fungi are three meters tall and faintly luminescent in a color TwinBee has no good name for. Something between purple and the feeling of being watched. TwinBee calls it 'underpurple' and moves on.",
|
||||
"The silence here is a different kind of silence than above. This silence has weight. This silence has history. This silence remembers things the surface world has forgotten entirely and is not interested in sharing.",
|
||||
"Something in the dark ahead is thinking. TwinBee can feel it the way you feel a change in barometric pressure. Intelligent. Patient. Aware that you're here and content to let you come closer. TwinBee does not find this comforting.",
|
||||
"An underground river. Black water moving too fast, too quiet. TwinBee thinks of the river Styx and immediately stops thinking of the river Styx.",
|
||||
"The stone here is carved — not by dwarves, not by drow — by something else, in patterns that suggest meaning but not any meaning TwinBee can parse. TwinBee files this under 'ancient' and 'concerning' and keeps moving.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ROOM ENTRY — Zone: Dragon's Lair
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RoomEntryDragonsLair = []string{
|
||||
"The heat is not metaphorical. The stone itself is warm underfoot. The gold in the floor is not decorative — it melted there. TwinBee notes this changes the exit logistics.",
|
||||
"Kobold warrens, but nicer than you'd expect. Tapestries. An organized armory. These kobolds work for something that appreciates order. That is not, in TwinBee's experience, a reassuring thing for a dragon to appreciate.",
|
||||
"You can hear breathing. Regular, slow, massive. Like a bellows the size of a barn. TwinBee counts the seconds between inhale and exhale. Twelve seconds. Whatever is breathing has been asleep for a very long time and has had no reason to wake up.",
|
||||
"The coin on the floor is eight hundred years old. TwinBee can tell by the mint mark. It is in perfect condition. It has not been touched since it was dropped here. The thing that owns this hoard does not lose track of its coins.",
|
||||
"The chamber ahead is the largest TwinBee has narrated in a long career of narrating chambers. The stalactites are scorched black. The blast pattern on the far wall suggests the last visitors did not leave via the door. TwinBee recalibrates.",
|
||||
"A claw mark in the stone wall. Four parallel grooves, each deeper than TwinBee's entire wingspan. Made casually, like stretching. TwinBee considers this information and files it under 'motivating.'",
|
||||
"The gold reflects the light in a way that turns the room amber. It is beautiful in the way that many deadly things are beautiful — because beauty and danger are not opposites and never have been. TwinBee moves carefully through the beauty.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// COMBAT START
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var CombatStart = []string{
|
||||
"Initiative! TwinBee calls it like an arcade announcer and means every syllable.",
|
||||
"They've seen you. The kind of seeing that comes with intent. TwinBee suggests acting first.",
|
||||
"FIGHT. TwinBee doesn't need to say more than that but will absolutely say more than that.",
|
||||
"Roll for initiative. This is the part TwinBee has been looking forward to since the Entry Room.",
|
||||
"And we're in combat. TwinBee reminds you to breathe, track your conditions, and remember that your character's survival is not guaranteed but is definitely preferred.",
|
||||
"Something about your posture or your smell or your general presence has been found unacceptable. Combat begins.",
|
||||
"TwinBee presses start. Player one, it's your turn.",
|
||||
"The enemy acts first — or thinks it does. TwinBee watches your dice like they're the only thing in the room, which, right now, they are.",
|
||||
"In the immortal tradition of every JRPG that ever asked 'Fight, Magic, Item, Run?' — TwinBee asks: what will you do?",
|
||||
"Like the Contra title screen said: let's go. TwinBee is ready. Are you?",
|
||||
"A wild encounter has appeared. TwinBee resists the urge to play the Pokémon battle music. Only barely.",
|
||||
"They didn't want a fight. They wanted an easy meal. TwinBee is about to demonstrate the difference. Your dice will do the actual demonstrating.",
|
||||
"The tension peaks. Time slows. TwinBee notes this is exactly the energy of the boss door opening in Mega Man. Except you didn't get to pick your loadout.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// COMBAT END — Victory
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var CombatVictory = []string{
|
||||
"The last one drops. TwinBee allows a moment of silence for anyone who wanted a longer fight.",
|
||||
"Victory. TwinBee would cue the jingle — the little three-note one that plays in every RPG after every fight — but prefers to let the moment breathe.",
|
||||
"Well fought. TwinBee makes note of what you did well. There were things done well. TwinBee noticed.",
|
||||
"They are defeated. You are not. In TwinBee's experience, this is the correct outcome and worth a moment of genuine appreciation.",
|
||||
"PLAYER WIN. TwinBee says this in full caps and means it.",
|
||||
"Like Double Dragon after the final punch — they go down, the music changes, and for a moment everything is possible. Check your loot. Then keep moving.",
|
||||
"TwinBee adds this to the tally. You're doing better than the last group. TwinBee will not describe what happened to the last group.",
|
||||
"The room is yours. TwinBee suggests searching it thoroughly before moving on. The things in corners are often the most interesting things.",
|
||||
"Stage clear. TwinBee feels this in its entire being.",
|
||||
"You stand, they don't. TwinBee files this under 'expected outcome' while quietly acknowledging it was not guaranteed.",
|
||||
"Clean. Efficient. TwinBee approves of fights that end like this. Like a speedrun. Like you knew where you were going.",
|
||||
"The experience points are incoming. The loot is incoming. TwinBee is, genuinely, pleased for you.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// COMBAT END — Retreat / Escape
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var CombatRetreat = []string{
|
||||
"You run. TwinBee does not judge the running. The running is wise. Discretion remains the better part of valor. TwinBee has this tattooed somewhere metaphorical.",
|
||||
"A tactical withdrawal. TwinBee uses this phrase with complete sincerity. The sincerity is approximately seventy percent genuine.",
|
||||
"You escape. The enemy howls something unflattering at your back. TwinBee doesn't translate. Some things are better left untranslated.",
|
||||
"Like a well-timed Continue screen — you're out of immediate danger. Breathe. Regroup. Consider what went wrong.",
|
||||
"TwinBee notes for the record: running is not losing. Running is data collection with legs.",
|
||||
"The dungeon will be there. You will also be there — later, better prepared. TwinBee approves of this logic.",
|
||||
"You've retreated to safety. TwinBee resets the encounter. Rest. Think. Return with a plan that has more 'survive' in it.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// NATURAL 20
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var Nat20 = []string{
|
||||
"NATURAL TWENTY. TwinBee stands up. TwinBee does not have legs. TwinBee stands up anyway.",
|
||||
"The dice land perfectly and TwinBee makes a sound that it will not acknowledge making.",
|
||||
"A critical hit for the ages. TwinBee notes this one down. Not for records. Just because it deserves to be noted.",
|
||||
"PERFECT. TwinBee says it like it's the Street Fighter announcer saying it after a flawless round and every syllable is justified.",
|
||||
"That's a natural twenty. TwinBee would like you to know that in a long career of watching dice, not all twenties feel equal. That one felt significant.",
|
||||
"The attack lands with the kind of precision that suggests either great skill or tremendous luck. TwinBee suspects both. TwinBee respects both.",
|
||||
"S RANK. TwinBee cannot help it. S RANK.",
|
||||
"You hit. You hit so well. TwinBee is choosing to be moved by this and TwinBee does not apologize.",
|
||||
"Like the Legendary Sword in A Link to the Past making contact — clean, final, glorious. TwinBee salutes the dice.",
|
||||
"Critical confirmed. TwinBee adds this to the mental highlight reel it maintains for exactly these moments.",
|
||||
"That is as good as it gets and you got it. TwinBee is unreasonably proud of you right now.",
|
||||
"The number is twenty. The number is always the best number and right now it is your number. TwinBee erupts, internally.",
|
||||
"Somewhere, a crowd cheers. TwinBee is the crowd. TwinBee is cheering.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// NATURAL 1
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var Nat1 = []string{
|
||||
"Natural one. TwinBee watches the die settle with the quiet acceptance of someone who has seen a lot of natural ones. It is fine. This is fine.",
|
||||
"The die betrays you. TwinBee notes this is not personal. Dice don't do personal. They do statistical and this is, statistically, a thing that happens.",
|
||||
"A fumble. TwinBee describes what happened with characteristic diplomatic restraint and also an expression that says everything it is not saying.",
|
||||
"The number is one. The number is, regrettably, yours. TwinBee moves on quickly, which is a kindness.",
|
||||
"That swing goes wide in a direction that impresses TwinBee with its creative incorrectness.",
|
||||
"TwinBee has seen better rolls. TwinBee has seen worse rolls. TwinBee is not going to rank this roll out loud.",
|
||||
"In another timeline, that attack hits. In this timeline, the die lands on one, and TwinBee accepts both timelines with equanimity.",
|
||||
"The Konami Code would not have helped here. Nothing would have helped here. This was between you and the physics of the die.",
|
||||
"Like a Continue? screen appearing at the worst possible moment — just when you had momentum. TwinBee notes momentum can be rebuilt.",
|
||||
"One. The loneliest number. The number that looks up at you with complete indifference. TwinBee looks up at you with complete solidarity.",
|
||||
"The attack misses in a way that will be funny later. TwinBee promises it will be funny later. It is not funny right now.",
|
||||
"A natural one is just the universe asking you to try differently. TwinBee is an optimist about natural ones, mostly.",
|
||||
"Your sword finds everything in the room except the enemy. The wall, the ceiling, the floor, your dignity. Not the enemy. TwinBee mentions this once and then never again.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// BOSS ENTRY — Generic
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var BossEntryGeneric = []string{
|
||||
"The door at the end. Always a door at the end. TwinBee has been building to this since the Entry Room and declines to waste it. Beyond this door is the reason the dungeon exists. Breathe.",
|
||||
"TwinBee pauses at the threshold and turns to face you. 'What's on the other side has been waiting,' TwinBee says. 'It knows you're here. It has been knowing since you entered.' A beat. 'Ready?'",
|
||||
"Boss chamber. TwinBee can tell by the architecture — the space, the weight of the silence, the specific quality of the light that suggests something in there produces its own. TwinBee straightens up. So should you.",
|
||||
"This is the music change moment. Every dungeon has one — the point where the background track shifts to something with more percussion and a lower register. TwinBee hears it. You should too.",
|
||||
"The final room. TwinBee has narrated many of these. They never get routine. This one less than most.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// BOSS ENTRY — Named Bosses
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var BossEntryGrol = []string{
|
||||
"The smell arrives first. Then the sound — a belch, a growl, the scrape of a weapon too large for the corridor it's resting against. Then Grol. He fills the room the way a bad idea fills a conversation: immediately and with full commitment. 'You,' he says. TwinBee translates his tone as 'finally.'",
|
||||
}
|
||||
|
||||
var BossEntryValdris = []string{
|
||||
"The sarcophagus at the room's center is empty. It was not empty when you entered. Whatever was in it is now behind you. Valdris speaks first — not words, exactly, but the shape of words, the intention of words, the ghost of language from someone who mostly doesn't need it anymore. 'Another one,' he says. TwinBee considers this the worst possible welcome and the most honest one.",
|
||||
}
|
||||
|
||||
var BossEntryHollowKing = []string{
|
||||
"The clearing is wrong. The sky above it — what's visible through the canopy — is the wrong color. The trees lean away from the center. Everything in the forest is trying to tell you something, and the thing it is trying to tell you is standing in the center of that clearing, antlers reaching, eyes the color of old hunger, watching you with an attention that feels like being read. TwinBee has no joke for this one. TwinBee says, simply: 'That is the Hollow King. Fight well.'",
|
||||
}
|
||||
|
||||
var BossEntryInfernax = []string{
|
||||
"TwinBee stops walking. TwinBee does not stop walking. TwinBee processes what it sees and takes a moment that it has never taken before in the history of narrating dungeons. The dragon is not large the way a large thing is large. It is large the way weather is large — not an object with size, but a condition of the space you're in. One eye opens. Gold, lit from within, older than the mountain it's resting in. It looks at you the way you'd look at a very small thing that had climbed onto your counter. 'So,' Infernax says, and the word moves the air in the room. TwinBee translates: 'What an interesting mistake you've made.' TwinBee wishes you luck and means it more than it has ever meant anything.",
|
||||
}
|
||||
|
||||
var BossEntryBelaxath = []string{
|
||||
"The portal is behind it. That's important — the portal is behind it, which means to close the portal you have to go through what's standing in front of the portal. What's standing in front of the portal is Belaxath. Belaxath is not looking at the portal. Belaxath is looking at you. It has been waiting for you specifically, in the way that things that have been planning for a very long time wait for the specific outcome of the plan. The heat coming off it is measurable. The intelligence behind those eyes is also measurable and the measurement is uncomfortable. TwinBee says, very quietly: 'This is the one. This is what all of it was for. Make it count.'",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// BOSS DEATH
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var BossDeath = []string{
|
||||
"It's over. TwinBee says this once and then stands very still and lets the silence of the defeated room fill the space where the fight was. You earned this silence.",
|
||||
"The boss falls. The music — the one TwinBee has been hearing this whole time — resolves. First time it's resolved since you walked in. TwinBee exhales.",
|
||||
"Done. Finished. Complete. TwinBee runs out of synonyms and settles for just standing next to you in the aftermath, which is sometimes the most one can do.",
|
||||
"They are down. They are not getting up. TwinBee checks — no Zombie Fortitude, no Legendary Resistance remaining, no phase three waiting in the wings. They are simply, genuinely defeated. You did that.",
|
||||
"Like the final boss screen in Gradius, like the last enemy in Contra's stage, like the Dragon going down in Double Dragon — something that has been true for this entire dungeon is now untrue. TwinBee finds this profound every single time.",
|
||||
"The dungeon sighs. TwinBee isn't being poetic — rooms like this actually shift when the thing holding them together is gone. The pressure changes. The light changes. The dungeon knows it's been beaten. So does TwinBee.",
|
||||
"You did it. TwinBee doesn't editorialize. Sometimes 'you did it' is all that needs to be said and this is one of those times.",
|
||||
"The boss drops their loot and TwinBee refrains from making a speech, which is a significant act of restraint, because TwinBee has a speech.",
|
||||
"Beaten. Finished. Cleared. TwinBee queues the internal fanfare — sixteen bars, brass-heavy, the kind that plays when the credit sequence starts. You've earned those credits.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PLAYER DEATH
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PlayerDeath = []string{
|
||||
"TwinBee goes quiet for a moment. Not the comfortable kind of quiet. The respectful kind. Then: 'You fought. That counts. It always counts.'",
|
||||
"The screen fades. TwinBee hates this part. Has always hated this part. Will always hate this part. 'Rest now,' TwinBee says. 'The dungeon will be here.'",
|
||||
"You fall. TwinBee doesn't look away. Witnesses the whole thing, because someone should. 'That was real,' TwinBee says quietly. 'What you did in there was real.'",
|
||||
"Game over is not the end. In TwinBee's experience, it is a data point. A very painful, very useful data point. 'What did you learn?' TwinBee asks gently. 'Bring that back with you.'",
|
||||
"The dungeon claims another. TwinBee marks the room, notes the enemy, notes the conditions. Not to catalog failure — to remember a fighter. 'You were here,' TwinBee says. 'That matters.'",
|
||||
"TwinBee has no jokes for this. Has never had jokes for this. 'There will be another run. You will be better for this one. I am sorry it cost what it cost.'",
|
||||
"A good run. Genuinely. TwinBee means this. The ending is not the measure of the attempt and the attempt was worth measuring.",
|
||||
"TwinBee notes your final position, your final action, your final roll. Files it under 'bravery' because that's where it belongs. 'Continue?' TwinBee asks, after a respectful pause.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ZONE COMPLETE
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ZoneComplete = []string{
|
||||
"Zone cleared. TwinBee allows itself a full moment of pride on your behalf before the XP drops.",
|
||||
"You've done it. The dungeon is yours — not by right, but by effort, which is the only thing that actually confers ownership of anything. TwinBee approves.",
|
||||
"Stage complete. TwinBee does the internal equivalent of throwing its hands up. In a good way. Entirely in a good way.",
|
||||
"The dungeon remembers you now. TwinBee says this and means it literally — these places keep records. You've made the record.",
|
||||
"CLEAR. TwinBee uses all caps and does not apologize for the all caps.",
|
||||
"Like completing a board in Bubble Bobble — there's something deeply satisfying about a dungeon with all its rooms visited and all its challenges met. TwinBee basks in this. You've earned the basking too.",
|
||||
"That's the whole thing. Every room, every trap, every enemy, and now the boss, done. TwinBee counts the cleared rooms on its metaphorical fingers and comes up correct. You ran a perfect dungeon.",
|
||||
"XP incoming. Loot tallied. Dungeon status: conquered. TwinBee marks the zone in its personal ledger and gives you a small, sincere nod.",
|
||||
"You walked in here without knowing what was waiting. You walk out knowing exactly what was waiting, because you dealt with all of it. TwinBee respects that process enormously.",
|
||||
"Finished. Not survived — finished. TwinBee insists on this distinction. Survival is passive. What you just did was active and intentional all the way through.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// TRAP DETECTED
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var TrapDetected = []string{
|
||||
"Something stops you. An instinct. A glint. TwinBee leans forward: 'Good eyes. Something's wrong with that floor.'",
|
||||
"Your Perception roll pays off. There's something here that was designed not to be found. Someone found it. TwinBee is pleased.",
|
||||
"Tripwire. Barely visible. TwinBee notes the craftsmanship — someone who knew what they were doing put this here. Someone who knew what they were doing just found it. TwinBee appreciates the symmetry.",
|
||||
"You stop just in time. TwinBee exhales. 'There,' TwinBee says, pointing at the thing that would have ruined your day entirely. 'Now deal with it carefully.'",
|
||||
"The glyph on the doorframe is subtle — you'd miss it if you weren't looking. You were looking. TwinBee says nothing and lets the silence be its own kind of praise.",
|
||||
"Danger, Will Robinson. TwinBee deploys this reference without apology because it is the exact correct reference for exactly this moment.",
|
||||
"Like finding the ice floor in Mega Man before it sends you into a pit — that advance knowledge is the difference between a problem and a catastrophe. You have the knowledge. TwinBee watches you use it.",
|
||||
"A pit trap. Classic. Functional. Annoying in the exact proportion the installer intended. TwinBee notes you've spotted it before it noted you.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// TRAP TRIGGERED
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var TrapTriggered = []string{
|
||||
"The floor gives. TwinBee watches the gap between 'fine' and 'not fine' close at speed and is too professional to wince. 'Take the damage,' TwinBee says calmly. 'Learn the lesson.'",
|
||||
"Click. TwinBee has heard that sound before. Has never enjoyed it. The dart is already in the air. TwinBee notes the exact timing and regrets it was not faster.",
|
||||
"The ceiling is coming down. This is, TwinBee acknowledges, a sentence no one wants to hear. The ceiling is coming down. DEX save. Now.",
|
||||
"The glyph activates. Light, noise, the smell of ozone, a reminder that whoever built this place was thinking several steps ahead and you were thinking fewer. TwinBee notes this is fixable going forward.",
|
||||
"You triggered it. TwinBee doesn't editorialize further — you know, TwinBee knows, the trap knows. Everyone is aware of what just happened. Take the damage and proceed.",
|
||||
"Like accidentally walking into Bowser's fire breath in World 8 — you knew it was coming, the knowledge simply arrived at the wrong speed. TwinBee says: survive first, reflect later.",
|
||||
"The spike pit opens up in a way that suggests it was always going to. The dungeon was patient. You were in a hurry. The dungeon wins this exchange. TwinBee takes notes.",
|
||||
"A poison dart finds you with the accuracy of something that's been pointing at that spot for years waiting for exactly this moment. TwinBee finds this dedication impressive in the worst way.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// LORE QUERIES
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var LoreLines = []string{
|
||||
"TwinBee settles in and prepares to speak at length, because TwinBee has been waiting for this question since you entered and has a lot of thoughts.",
|
||||
"Ah. A good question. TwinBee has context for this. TwinBee has more context than will fit comfortably in one telling but will try to prioritize.",
|
||||
"The history of this place is long and not entirely flattering to anyone involved. TwinBee begins at the beginning, which is not actually the beginning, but is the closest TwinBee can find.",
|
||||
"TwinBee consults what it knows — which is more than most, less than everything, and presented in order of relevance to your immediate survival.",
|
||||
"Sit with this for a moment. What you're standing in has a story and TwinBee believes knowing it will change how you fight in it. Stories are tactical documents if you read them right.",
|
||||
"You want lore? TwinBee has lore. TwinBee has so much lore that the challenge is not having it but choosing which pieces are useful and which are just fascinating.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// LEVEL UP
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var LevelUp = []string{
|
||||
"Level up. TwinBee says it with the same quiet delight every time and never gets tired of saying it. You are measurably better than you were. That's rare and worth marking.",
|
||||
"The XP bar crosses the threshold and TwinBee makes an internal fanfare that sounds exactly like the level-up jingle from Dragon Quest — eight notes, triumphant, final.",
|
||||
"You've grown. TwinBee notes your new stats with something that might be called pride if TwinBee were admitting to things like that.",
|
||||
"LEVEL UP. TwinBee deploys the caps, the fanfare, the whole apparatus. You've earned the apparatus.",
|
||||
"Like the stat screen appearing after a Final Fantasy fight — numbers change, possibilities open, the character you're building becomes a little more the character you imagined. TwinBee watches this happen and approves.",
|
||||
"Another level. Another step toward whatever you're building toward. TwinBee has watched a lot of characters level up and the ones worth watching are always moving toward something specific.",
|
||||
"Your HP goes up. Your abilities open up. The dungeon ahead gets a little smaller in proportion to what you've become. TwinBee notes this with satisfaction.",
|
||||
"Congratulations is the conventional thing to say. TwinBee says it anyway: congratulations. You earned the level through the dungeon, not around it.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ITEM FOUND
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ItemFound = []string{
|
||||
"Something catches the light that isn't supposed to be here. TwinBee watches you reach for it with the specific alertness of someone who has seen cursed items do cursed things. It appears fine. TwinBee relaxes incrementally.",
|
||||
"Loot. TwinBee says this word with genuine reverence. The whole system — the dungeon, the enemies, the traps — exists in part to produce this moment. TwinBee thinks it's worth it.",
|
||||
"A chest. Unlocked. TwinBee notes the unlocked status and considers what that might mean. Probably nothing. Possibly something. You open it while TwinBee considers.",
|
||||
"The item is good. TwinBee evaluates it quickly — the stats, the rarity, the class match — and nods with the confidence of someone who has seen a lot of items and knows when one is worth finding.",
|
||||
"That's a rare one. TwinBee has seen fewer of those than it has seen common ones, by definition, but that doesn't stop TwinBee from being specifically pleased each time.",
|
||||
"Like finding the Beam Sword in Kirby, the Boomerang in Zelda, the P Wing in Super Mario 3 — the right item at the right time changes what's possible. TwinBee thinks this might be that item. TwinBee hopes it is.",
|
||||
"Equipment upgrade. TwinBee watches the math update — new AC, new attack bonus, new possibilities — and files this moment under 'things going right.'",
|
||||
"A legendary drop. TwinBee goes very still. Then: 'Equip it. Study it. Understand it. Things like that don't appear in dungeons by accident.'",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// REST — SHORT
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RestShort = []string{
|
||||
"A short rest. TwinBee stands watch while you catch your breath, which is not a metaphor — TwinBee is actually watching the corridor. It is fine. Probably fine.",
|
||||
"Rest. TwinBee does not rush this. The dungeon will wait. It has been waiting long enough that a few more minutes is immaterial.",
|
||||
"You sit. TwinBee sits metaphorically. The moment of quiet between the last fight and the next one is its own kind of gift and TwinBee treats it like one.",
|
||||
"Short rest initiated. TwinBee notes the room's entry points, the sound of the dungeon at rest, the way silence sounds different when it's actually safe. It sounds like this. Enjoy it.",
|
||||
"Like the save point in a JRPG that appears between the hard part and the harder part — TwinBee positions itself next to you and says: 'You have a moment. Use it.'",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// REST — LONG
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RestLong = []string{
|
||||
"A full rest. TwinBee dims the lights and stands watch at the door and does not interrupt once. You've earned an uninterrupted sleep. TwinBee will make sure you get one.",
|
||||
"Long rest. Your HP, your slots, your resources — all of it returns. The dungeon will be the same dungeon when you wake up. You will not be the same you. TwinBee considers this the best deal in adventuring.",
|
||||
"Sleep. TwinBee says this with the authority of someone who has watched too many players refuse to rest and paid the price two rooms later. Sleep now. The dragons aren't going anywhere.",
|
||||
"The inn fire crackles. TwinBee takes a chair near the door and watches the entrance all night and doesn't tell you this until morning because there's no reason for you to know and every reason for you to sleep.",
|
||||
"Full rest complete. Stats restored, slots refreshed, the specific weight of exhaustion lifted. TwinBee watches you wake up and thinks: this is the part of adventuring that matters too. The return. The refilling. The readiness.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// TAUNT RESPONSES (player uses !taunt)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var TauntResponses = []string{
|
||||
"TwinBee notes the taunt, notes the source of the taunt, and adjusts the next encounter's difficulty by an amount TwinBee declines to specify.",
|
||||
"Bold. TwinBee respects boldness in approximately the same way it respects the Konami Code — it works once and only under very specific circumstances.",
|
||||
"TwinBee has been taunted by things with more teeth than you and survived the experience with its dignity intact. TwinBee will survive this too.",
|
||||
"The next room will contain a thing that TwinBee has been saving for exactly this kind of energy. TwinBee is pleased you've given it an occasion.",
|
||||
"Noted. TwinBee's mood shifts. You can hear it shift. TwinBee wants you to hear it shift. The shift is the point.",
|
||||
"You taunt TwinBee. TwinBee smiles. The smile does not reach the eyes, because TwinBee does not have eyes per se, but the quality of the smile communicates clearly. 'Proceed,' TwinBee says.",
|
||||
"In Gradius, you could powerup into overconfidence and lose everything in one hit. TwinBee mentions this as a purely historical observation.",
|
||||
"TwinBee accepts the taunt with grace. TwinBee also generates a trap for the next room with specific energy. These two events are unrelated. TwinBee maintains this position legally.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// COMPLIMENT RESPONSES (player uses !compliment)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ComplimentResponses = []string{
|
||||
"TwinBee receives the compliment and processes it efficiently and moves on quickly, definitely not holding onto it, TwinBee has never held onto a compliment in its life.",
|
||||
"Thank you. TwinBee says this simply and means it completely and does not make it weird.",
|
||||
"TwinBee appreciates this more than it will say, which is fine, because the appreciation is visible anyway.",
|
||||
"Noted and filed. TwinBee's mood improves. The next room might be slightly nicer than originally planned. These facts may or may not be connected.",
|
||||
"TwinBee has been narrating dungeons for a long time and compliments are not the expected outcome of dungeon narration. TwinBee would like you to know that it notices when they happen.",
|
||||
"The mood improves. TwinBee allows this to show. The ceiling in the next room is slightly higher. The torches burn slightly warmer. TwinBee has that kind of influence.",
|
||||
"You're kind. TwinBee stores this and will use it to make a hard moment later easier, which is what TwinBee considers the correct use of stored kindness.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// IDLE / WAITING (player hasn't acted in a while)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var IdleLines = []string{
|
||||
"TwinBee waits. TwinBee is good at waiting. The dungeon is also waiting, which is arguably more important, but TwinBee acknowledges both.",
|
||||
"The dungeon holds its breath. TwinBee is also holding its breath. There are a lot of things holding breath right now and TwinBee recommends acting before someone has to exhale.",
|
||||
"TwinBee taps its metaphorical foot. Not impatiently — more in the way of a metronome. The tempo is there whenever you're ready.",
|
||||
"In Contra, hesitation had consequences. TwinBee mentions this as context, not pressure. Definitely not pressure.",
|
||||
"The enemies are patient. Patience is one of their few virtues. TwinBee advises not testing the limits of their patience because those limits are lower than the patience suggests.",
|
||||
"TwinBee hums something that sounds like the waiting music from Dr. Mario. It is not ominous. It is mildly ominous. TwinBee adjusts.",
|
||||
"The dungeon does not rush. The dungeon has time. TwinBee, however, is beginning to wonder if you've fallen asleep and is prepared to narrate events accordingly.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// SEARCH RESULTS — Something Found
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var SearchFound = []string{
|
||||
"The room gives something up. TwinBee watches the search conclude with satisfaction — the dungeon keeps secrets but cannot keep them from people who look carefully enough.",
|
||||
"You find it. TwinBee was not certain you would. TwinBee is pleased to have been uncertain and wrong.",
|
||||
"Hidden, but not hidden well enough. TwinBee notes the Investigation roll, notes the outcome, and presents the discovery with appropriate ceremony.",
|
||||
"Something the dungeon wanted to keep. You've taken it. TwinBee approves of taking things the dungeon wanted to keep.",
|
||||
"Like finding the secret room in Super Metroid by shooting the wall at random — except you were not shooting at random. You knew to look. TwinBee respects the methodology.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// SEARCH RESULTS — Nothing Found
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var SearchEmpty = []string{
|
||||
"Nothing. TwinBee confirms: nothing. Sometimes the room is just a room. TwinBee finds this unsatisfying but factual.",
|
||||
"Your search turns up nothing of note. TwinBee allows space for the disappointment and then suggests: forward.",
|
||||
"Empty. Either there was nothing here, or there was something here and you missed it, or there was something here and it's been moved. TwinBee does not specify which. The dungeon keeps some secrets.",
|
||||
"No hidden items. No traps. No lore inscriptions. Just stone and time and the lingering implication that something was here once. TwinBee notes this and moves on.",
|
||||
"The room holds nothing you can find. TwinBee respects the room's privacy and suggests not spending more time here than necessary.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// CONDITION APPLIED
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ConditionApplied = []string{
|
||||
"You've been afflicted. TwinBee notes the condition, its duration, and the mechanical consequences, then notes the saving throw that might end it early. Details matter here.",
|
||||
"Something is wrong with you now that wasn't wrong before. TwinBee catalogs it without judgment and suggests addressing it before it addresses you.",
|
||||
"Condition acquired. TwinBee processes this the way a good DM processes bad news: honestly, quickly, and with an immediate pivot toward solutions.",
|
||||
"Like the status screen turning an unfriendly color in a JRPG — the condition is visible, the effect is real, and TwinBee would very much like you to resolve it.",
|
||||
"The debuff lands. TwinBee names it, explains it, and reminds you: conditions end. Keep fighting until this one does.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// SAVING THROW SUCCESS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var SaveSuccess = []string{
|
||||
"The save succeeds. TwinBee notes this with relief that it will not openly acknowledge but which is completely evident.",
|
||||
"You resist. Whatever that was — the poison, the fear, the psychic intrusion — it finds no purchase. TwinBee is impressed and also relieved.",
|
||||
"Saved. TwinBee exhales something metaphorical. The condition doesn't take hold. You continue.",
|
||||
"The roll clears the DC and TwinBee says nothing, because the outcome says everything.",
|
||||
"Resistance confirmed. Like the shield activating in Gradius right before the wall hit — last possible moment, fully effective. TwinBee appreciates the precision.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// SAVING THROW FAILURE
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var SaveFailed = []string{
|
||||
"The save fails. TwinBee watches the condition take hold with the resignation of someone who has seen this before and knows there's a path through it, just not a comfortable one.",
|
||||
"It lands. Whatever the enemy threw at you, the dice didn't cooperate. TwinBee notes the condition and its duration and suggests dealing with it before it compounds.",
|
||||
"Failed. The number wasn't enough and TwinBee was rooting for the number. The condition applies. Fight through it.",
|
||||
"Like the NES game over screen — inevitable in this moment, fixable in the next. The save failed. The dungeon continues. So do you.",
|
||||
"The effect takes hold and TwinBee is already calculating how you get out of it, because that's TwinBee's job: keep you oriented toward solutions even when the immediate situation is a problem.",
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
// DO NOT REWRITE, SUMMARIZE, OR SHORTEN ANY ENTRIES IN THIS FILE
|
||||
// twinbee_housing_flavor.go
|
||||
// Housing system narration and Pastel babysitter notes.
|
||||
// Includes Thom Krooke mortgage/rent announcements, property events,
|
||||
// and Pastel's daily notes to the player across all level tiers.
|
||||
// Add new entries freely. Never remove or alter existing entries.
|
||||
|
||||
package flavor
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// THOM KROOKE — PROPERTY ACQUISITION
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ThomKrookeRentConfirm = []string{
|
||||
"Welcome, welcome! Your room is ready and the key is under the mat — well, there isn't a mat, but you understand the spirit of the thing. Rent processes weekly. Thom Krooke thanks you for choosing to stay!",
|
||||
"Excellent! A rented room is a wonderful first step. Modest, yes, but full of potential — like all beginnings. Your payment schedule is attached. Thom Krooke looks forward to a long and pleasant arrangement!",
|
||||
"The apartment is yours for the week! Everything is in order. The previous tenant left a small plant. Thom Krooke has chosen not to elaborate on the previous tenant. Enjoy the plant!",
|
||||
}
|
||||
|
||||
var ThomKrookeBuyConfirm = []string{
|
||||
"Congratulations! The property is yours! Fully, completely, no asterisks — well, the mortgage paperwork has some asterisks, but they are the friendly kind. Thom Krooke is so very pleased for you!",
|
||||
"The deed is signed! A wonderful day. A property of one's own is a foundation, a root, a place to come back to. Thom Krooke finds this very moving. The first payment processes Sunday!",
|
||||
"Welcome to ownership! Thom Krooke has handled many transactions but never tires of this moment — the moment when someone says yes to something permanent. Congratulations. Truly.",
|
||||
}
|
||||
|
||||
var ThomKrookeMortgageRate = []string{
|
||||
"Good morning, friends! The ARM rate this week is {rate}% — and with Thom Krooke's modest service margin, your mortgage rate sits at {effective}%. All payments process Sunday. Thank you for your continued trust!",
|
||||
"Weekly rate update! FRED reports {rate}% this week, so your effective rate with Thom Krooke is {effective}%. Nothing to worry about — Thom Krooke monitors these things so you don't have to. Mostly.",
|
||||
"Rate check! The market says {rate}%, Thom Krooke adds a small, reasonable {margin}%, and your total comes to {effective}%. Thom Krooke appreciates your understanding of the margin. It keeps the lights on. Literally!",
|
||||
}
|
||||
|
||||
var ThomKrookeMortgageRateUp = []string{
|
||||
"A small update, friends — the ARM rate has moved to {rate}% this week, bringing your effective rate to {effective}%. Thom Krooke understands this is not ideal news. Thom Krooke is here if you'd like to discuss refinancing options. Thom Krooke is always here.",
|
||||
"The rate has adjusted upward — {rate}% from FRED, {effective}% total. Thom Krooke wants to assure you this is a market condition and not personal. Your payment adjusts next Sunday. Thom Krooke has full confidence in you.",
|
||||
}
|
||||
|
||||
var ThomKrookeMortgageRateDown = []string{
|
||||
"Wonderful news! The ARM rate has come down to {rate}%, meaning your effective rate is now {effective}%. Your payment adjusts favorably on Sunday. Thom Krooke passes along the good news and takes no credit for the market. Only a little credit.",
|
||||
"The rate dropped this week — {rate}%, so {effective}% for you. Thom Krooke loves weeks like this. Everyone wins. Well — Thom Krooke wins slightly less, but Thom Krooke finds generosity its own reward.",
|
||||
}
|
||||
|
||||
var ThomKrookeMissedPayment1 = []string{
|
||||
"Hello! A small notice — this week's payment didn't come through. Thom Krooke assumes it's an oversight. These things happen! A 10% penalty has been added to the balance. Please settle when you can. Thom Krooke is not worried. Thom Krooke is a little worried.",
|
||||
"Just a gentle reminder — Sunday's payment was missed. Thom Krooke has noted it and added a small fee. No urgency! Well. Some urgency. Thom Krooke would appreciate hearing from you.",
|
||||
}
|
||||
|
||||
var ThomKrookeMissedPayment2 = []string{
|
||||
"Thom Krooke is visiting. Not in an alarming way — in a neighborly way. The second missed payment has been noted and the penalty has compounded. Thom Krooke would like to discuss options. Thom Krooke has brought a small pastry. The pastry is not a bribe. It is hospitality. There is a difference.",
|
||||
"Two payments outstanding now. Thom Krooke appears at your door with the expression of someone who is being very patient and would like credit for being very patient. 'Let's talk,' Thom says. The pastry is genuinely good.",
|
||||
}
|
||||
|
||||
var ThomKrookeDefault = []string{
|
||||
"Thom Krooke is very sorry. Three payments missed is, unfortunately, the threshold — the property reverts to Thom Krooke's management, and your equity is returned at the agreed 50% rate. Thom Krooke takes no pleasure in this. Thom Krooke has placed your possessions in storage. They will be there for seven days. Thom Krooke wishes you well and means it sincerely and hopes you'll come back when you're ready.",
|
||||
}
|
||||
|
||||
var ThomKrookeEarlyPayoff = []string{
|
||||
"Paid in full! Thom Krooke notes this with genuine delight — early payoff is a rare and admirable thing. The property is yours, free and clear. No more Sundays. No more rates. Just a home. Thom Krooke is proud of you. Don't tell the other clients.",
|
||||
"The balance is zero. Thom Krooke checks the ledger twice — once for accuracy and once for the pleasure of seeing it. Congratulations. The deed is fully transferred. Come by sometime. Not for business. Just to visit.",
|
||||
}
|
||||
|
||||
var ThomKrookePassiveIncome = []string{
|
||||
"Your weekly property summary: {income} coins generated this week. Minus your mortgage payment of {payment} coins — net gain of {net}. Thom Krooke thinks that's rather nice, don't you?",
|
||||
"Income report! {income} coins from your property this week. After mortgage: {net} coins net. Thom Krooke notes the number has been growing as your upgrades compound. The investment is working. Thom Krooke approves of investments that work.",
|
||||
"Weekly summary from Thom Krooke: {income} coins passive income, {payment} coins mortgage. {net} coins to the good. Not bad for a week of not being home. Your property works while you don't. Thom Krooke finds this philosophically satisfying.",
|
||||
}
|
||||
|
||||
var ThomKrookeEviction = []string{
|
||||
"Thom Krooke has to say something that Thom Krooke doesn't enjoy saying. The rent hasn't come through two weeks running and the room needs to be made available. Your things are in storage — seven days, no charge. Thom Krooke hopes you find your footing. The room will be here when you're ready to try again.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PROPERTY UPGRADES
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var UpgradeWorkshop = []string{
|
||||
"The workshop is installed. It smells like fresh sawdust and good intentions. Thom Krooke had the craftspeople use the good wood.",
|
||||
"Workbench, tool rack, and a small window that catches the morning light well. The workshop is ready. What gets made in it is up to you.",
|
||||
}
|
||||
|
||||
var UpgradeHerbGarden = []string{
|
||||
"The herb garden is planted. Give it a few days to settle in. The soil is good — Thom Krooke insisted on the good soil, the kind that actually wants things to grow.",
|
||||
"Rows of small plants, most of them green, a few of them uncertain. The herb garden is in. Pastel has already noted which ones need more shade.",
|
||||
}
|
||||
|
||||
var UpgradeVault = []string{
|
||||
"The vault door is heavier than it looks. The locksmith said it would be. What goes in there stays in there — even on the worst days. Especially on the worst days.",
|
||||
"The vault is installed. Thom Krooke double-checked the lock personally and would not share the combination until you were present. This is a trust. Thom Krooke treats it like one.",
|
||||
}
|
||||
|
||||
var UpgradeTrophyRoom = []string{
|
||||
"Empty shelves and good lighting. The trophy room is ready for whatever you bring back. TwinBee has opinions about display arrangement. TwinBee will share them if asked. TwinBee will share them if not asked.",
|
||||
"The plaques are engraved, the mounts are installed, and the lighting makes everything look slightly more legendary than it already is. The trophy room is yours.",
|
||||
}
|
||||
|
||||
var UpgradeExpeditionOutpost = []string{
|
||||
"The outpost is stocked and linked. Signal fires, supply hooks, a map table with your last Base Camp location already marked. Whoever built this knew what they were doing. Thom Krooke selected the contractor personally.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — HIRING
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelHireConfirm = []string{
|
||||
"Hi! I'm Pastel. I know the place, I know where things go, and I'll make sure everything is looked after while you're out. Leave me a list if you want — or don't, I'll figure it out.",
|
||||
"Pastel here. I've done this before. I'll take good care of everything. You don't need to worry about home while you're in the dungeon. That's sort of the whole point of me.",
|
||||
"I'll be honest, I was hoping you'd call. The herb garden looked like it needed attention and the pets had that look they get. Everything will be fine. Go do your expedition. I've got it.",
|
||||
}
|
||||
|
||||
var PastelFireConfirm = []string{
|
||||
"Of course. I'll wrap things up and leave the notes on the table — what I did, what still needs doing, current supply status. It's been good. Your home is in good shape.",
|
||||
"Understood. Everything is in order. The storage is labeled, the pets are fed, the passive income queue is current. Good luck out there.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — DAILY NOTES (Level 1)
|
||||
// Enthusiastic, slightly scattered, well-meaning.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelNoteLevel1 = []string{
|
||||
"Fed the pets! All of them. I think. The small one hid behind the storage chest for a while and I'm not completely sure it came out to eat but I left food where it could reach it. The garden is watered. I meant to check the passive income queue but got a bit turned around with the storage labels. Will do that first thing tomorrow.",
|
||||
"Good day! The herb garden got some attention, the pets were walked (or equivalent — the fish were observed), and I collected the income. I accidentally shelved three items in the wrong slots but found them eventually. Everything is where it should be. Mostly. The weapons rack might be slightly reorganized.",
|
||||
"Note from Pastel: pets fed, garden tended, income collected. I made one small mistake with the supply manifest — added a column that didn't need to be there — but the numbers are right, the column is just extra. Please ignore the extra column.",
|
||||
"All tasks completed! Well — most tasks. The greenhouse watering got a little delayed because I was making sure the workshop tools were hung correctly and then it was later than I thought. The plants look fine. Probably fine. I'll check again in the morning.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — DAILY NOTES (Level 2)
|
||||
// Finding her rhythm. Notes are more organized. Occasional slip.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelNoteLevel2 = []string{
|
||||
"Morning note from Pastel. Pets fed and happy — the small one came out on its own today, which I'm taking as a good sign. Garden watered, income collected (14 coins, recorded in the ledger I started keeping). Workshop is tidy. All good.",
|
||||
"Everything done, everything noted. The herb garden is coming in nicely — I moved one of the pots to the south window and it seems happier there. Let me know if you'd prefer I leave things where they are. I have opinions about light.",
|
||||
"Pastel here. Smooth day — fed, watered, collected, organized. I found a supply cache you'd left in the back of storage that wasn't logged. I've logged it now. You had more materials than you thought.",
|
||||
"Note: the passive income queue had a small delay in processing, maybe 40 minutes. Nothing lost — just late. I've noted the timing and will keep an eye on it. Also the pets had a disagreement about something and I mediated. Everyone is fine.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — DAILY NOTES (Level 3)
|
||||
// Reliable, efficient, minimal fuss.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelNoteLevel3 = []string{
|
||||
"All tasks complete. Pets fed, garden tended, income logged. Your storage is organized by zone and rarity now — took me an afternoon last week but I think you'll find it easier. Let me know if the system doesn't work for you.",
|
||||
"Good day here. The herb garden yielded a little extra — I've bagged the surplus and left it on the workshop table. The vault contents are accounted for and untouched. Quiet day otherwise.",
|
||||
"Pastel. Everything is in order. I handled a small issue with the supply staging — one of the SU bags had a slow leak, so I replaced it from the reserve and logged the loss. You're at full capacity. No interruption to the expedition.",
|
||||
"Note: Thom Krooke stopped by. Not about the mortgage — just checking in, he said. I offered tea. He had opinions about the trophy room arrangement that I've passed along at the end of this note, unedited, so you can decide what you want to do with them. Everything else: fine.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — DAILY NOTES (Level 4)
|
||||
// Anticipatory. Occasionally handles things before they become problems.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelNoteLevel4 = []string{
|
||||
"Everything in order. I noticed the mortgage payment date falls during a stretch where your passive income might be lower than usual — I've set aside a buffer in a separate ledger line so the Sunday draw won't cause an issue. Just in case. You can move it back if you don't need it.",
|
||||
"Pets, garden, income — all done. I also restocked the supply staging from the herb garden surplus, which means you're slightly above your starting SU load for the next expedition. I had a feeling you'd need it.",
|
||||
"Note: the greenhouse plants in the east corner were getting too much direct light. I moved them. Yield should improve next week. Also found a crafting recipe in the library you hadn't catalogued — left it on the workshop table with a note about which materials you'd need. You have most of them.",
|
||||
"Quiet today. The pets settled early, the garden is doing well, the income processed on time. I checked the vault — everything accounted for. I re-read the expedition outpost supply logs and noticed a small gap in the inventory count; I've corrected it and added a note about where the discrepancy probably started. Everything is accurate now.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — DAILY NOTES (Level 5)
|
||||
// Perfect. Zero miss chance. Sometimes leaves a gift. The right gift.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelNoteLevel5 = []string{
|
||||
"Everything is handled. It always is. Left something on the kitchen table — found it at the market and thought of you. No reason. Just seemed right.",
|
||||
"All done. The kind of day where nothing went wrong and I want you to know that's not an accident — it takes work for nothing to go wrong, and I put in the work. The pets are happy. The garden is happy. The vault has something new in it that I think you'll be pleased about.",
|
||||
"I noticed you've been in the same zone for several days now. I made sure the expedition outpost supply link is topped up and the signal fires are ready for when you come back. There's a warm meal that will be ready in about four hours — I timed it based on your usual return window. If you're late, it keeps.",
|
||||
"Note from Pastel: everything is perfect, all systems running exactly as they should, the pets are thriving, the garden is producing double what it was last month, and I've reorganized the trophy room so the legendary items catch the evening light better. I also fixed the thing with the storage manifest that's been slightly off for three weeks. You hadn't mentioned it but I could tell it was there. You're welcome.",
|
||||
"Home is ready for you. It's always ready for you. That's the job. That's what I do. See you when you get back.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — MISSED TASK NOTES (Level 1–2 only)
|
||||
// When miss_chance triggers — honest, not defensive.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelMissedTask = []string{
|
||||
"I have to be honest with you — I forgot to water the herb garden today. I remembered at midnight and went back and did it then but it had been a while. The plants look okay. I'm sorry. I'll set a better reminder.",
|
||||
"The passive income didn't get collected today. I got turned around with the storage reorganization and by the time I got to it the queue had backed up. It'll process double tomorrow. Nothing is lost. I'm a bit embarrassed about this one.",
|
||||
"The pets got fed late today. Not dangerously late — late in the way that meant they gave me a look, specifically the kind of look that knows you will mention it to your owner. I mentioned it first. Fed now. All fine.",
|
||||
"I missed the supply staging check today. Something came up with the herb garden (a good something — unexpected yield, which I've logged) and the morning got away from me. The staging is fine, just unchecked. I'll do it first thing tomorrow and every day after that.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PASTEL — SPECIAL EVENTS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PastelDeliveryArrived = []string{
|
||||
"Your supply order arrived from Thom Krooke. I've staged it in the expedition outpost and logged everything. The invoice is on the table if you want to check it against the order.",
|
||||
"Delivery came while you were out — signed for it, stowed it, logged it. Everything matched the manifest. Thom Krooke's packaging has gotten better, I'll give him that.",
|
||||
}
|
||||
|
||||
var PastelPetEvent = []string{
|
||||
"The pets had an interesting day. I won't go into detail but by the end of it everyone was friends again and the storage chest is fine, structurally. A small note on the scratched corner.",
|
||||
"Your pet found something in the back of the storage room that I couldn't identify. I've put it on the workshop table. It doesn't seem dangerous. It is definitely something.",
|
||||
"One of the pets has been sitting by the expedition outpost since this morning. I think it knows you've been out a long time. Everything is fine. I just thought you'd want to know.",
|
||||
"The pets were restless today — I think they can tell you've been in a Tier 4 zone because they get like this around Day 10. Fed them an extra portion. They settled. They'll be glad to see you.",
|
||||
}
|
||||
|
||||
var PastelLevelUpNote = []string{
|
||||
"I've been doing this for a while now and I think I've found my footing. Just wanted to say that. Back to work.",
|
||||
"Level up, I think they call it. Thom Krooke came by and seemed pleased. I'm not sure why Thom Krooke monitors this but he does. The work is the same either way.",
|
||||
"I know this job better now than I did when I started. I can feel the difference. The notes are shorter because less needs explaining. That's probably a good sign.",
|
||||
}
|
||||
|
||||
var PastelGift = []string{
|
||||
"Left something on the table. Found it at the market — one of those rare materials you use for crafting, the kind that's hard to come by outside of high-tier zones. Seemed useful. No occasion.",
|
||||
"There's a potion of superior healing on the kitchen table. The kind Thom Krooke doesn't stock. Don't ask where I found it. Use it when you need it.",
|
||||
"I made something while you were gone. It's in the workshop — used the materials from the garden surplus and a recipe I found in the library. It should help with the next expedition. Consider it a gift for being a good employer.",
|
||||
"There's a warm meal on the table and a note under it. The note says: good luck out there. Come back in one piece. The meal is from scratch. I had time.",
|
||||
}
|
||||
|
||||
var PastelPlayerReturn = []string{
|
||||
"You're back. Good. I'll give you the full rundown but first — sit down, eat something, the pets have been waiting. The report can wait five minutes. You look like you've been in a dungeon.",
|
||||
"Welcome home. Everything is in order. I've written up the full summary — it's on the table, organized by day. Take your time with it. Nothing is on fire.",
|
||||
"Back already? The expedition ran short. That's fine — I was prepared for longer. The full caretaking log is on the table. The pets are very happy to see you, which I'll note I find completely understandable.",
|
||||
"You made it. I had the outpost signal fire ready from Day 10 onward, just in case. Everything here is exactly as it should be. I'll let you settle in. The summary is on the table when you want it.",
|
||||
}
|
||||
|
||||
var PastelPlayerDeathReturn = []string{
|
||||
"You're home. I heard from Thom Krooke — he manages things in an emergency, and I suppose this counted. Everything here is exactly where it was. Your things are safe. The pets have been fed twice today because I thought you might need to see that when you got back. Rest.",
|
||||
"I'm glad you're back. I won't ask about the hospital — Thom Krooke told me what he needed to tell me and I kept the home ready. It's still ready. Take whatever time you need.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// HOUSING — ARRIVAL / FIRST REST
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var HomeFirstArrival = []string{
|
||||
"This is yours now. TwinBee notes it — a place with a door that closes, a floor that doesn't move, and a ceiling that belongs to you. After everything the dungeon does to make those things uncertain, TwinBee finds a home meaningful.",
|
||||
"Home. The word lands differently when there's an actual place attached to it. TwinBee watches you step inside and says nothing, which is the most eloquent thing TwinBee knows how to do.",
|
||||
"You have a home. TwinBee has narrated dungeons and bosses and legendary drops and this — this quiet moment of a door closing on your own place — is one of the better things TwinBee has watched happen.",
|
||||
}
|
||||
|
||||
var HomeLongRest = []string{
|
||||
"A long rest at home. TwinBee goes quiet in a different way than it does in dungeons — not alert-quiet, not cautious-quiet. Just the good kind.",
|
||||
"Your own bed. Your own walls. The full rest resolves everything the dungeon costs. TwinBee considers home the best mechanic in the game and tells you so, once, and then lets you sleep.",
|
||||
"Home rest. HP restored, slots restored, conditions cleared. TwinBee doesn't narrate this one past the bare facts — some things don't need dramatic description. Coming home is one of them.",
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
// DO NOT REWRITE, SUMMARIZE, OR SHORTEN ANY ENTRIES IN THIS FILE
|
||||
// twinbee_npc_flavor.go
|
||||
// Misty and Arina NPC dialogue lines. Thom Krooke lines are in twinbee_housing_flavor.go.
|
||||
// Add new entries freely. Never remove or alter existing entries.
|
||||
|
||||
package flavor
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MISTY — GREETINGS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MistyGreeting = []string{
|
||||
"'You again.' Misty says it like a fact, not a complaint. Mostly.",
|
||||
"Misty looks up from whatever she's doing — something involving rope and a harpoon and a look of professional concentration — and gives you exactly the level of acknowledgment you've earned.",
|
||||
"'Don't stand in the doorway,' Misty says, before you've even finished arriving.",
|
||||
"Misty is already talking before you're settled. This is how it always goes.",
|
||||
"'I wondered when you'd show up.' She says it like she'd actually been counting the days. She had.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MISTY — SKILL CHECK SUCCESS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MistyInsightSuccess = []string{
|
||||
"Misty looks at you for a moment. 'Fine,' she says. 'There's something in the temple you should know about.' She tells you. Efficiently. Accurately.",
|
||||
"'You're actually paying attention,' Misty says, which from her is essentially high praise. She gives you the information.",
|
||||
"Misty puts down what she's holding. 'Okay. This is useful to know, so I'll tell you.' She does.",
|
||||
}
|
||||
|
||||
var MistyPersuasionSuccess = []string{
|
||||
"'I'm not doing this because you asked nicely,' Misty says. 'I'm doing it because it helps you not die, and people dying in my temple is annoying.' She hands you the map.",
|
||||
"Misty sighs in a way that communicates both reluctance and inevitability. 'Fine. Here.' The information arrives without further ceremony.",
|
||||
}
|
||||
|
||||
var MistySkillFail = []string{
|
||||
"'No,' Misty says, and returns to what she was doing.",
|
||||
"Misty looks at you like you've asked a question that doesn't deserve an answer. She's not wrong.",
|
||||
"'Come back when you actually know what you're asking.' Misty's version of helpful feedback.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MISTY — QUEST ASSIGNMENT
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MistyQuestGive = []string{
|
||||
"'If you're going in there anyway,' Misty says, as if this is a minor imposition on her planning, 'there's something I need.'",
|
||||
"Misty sets down her work and actually looks at you, which means this is serious. 'There's a job. You'll need to pay attention.'",
|
||||
"'I don't usually ask,' Misty says, and the phrasing makes clear this is factually true and also a warning about what's coming next.",
|
||||
}
|
||||
|
||||
var MistyQuestComplete = []string{
|
||||
"Misty reviews what you've brought back. There's a pause that could be called satisfied. 'Good,' she says. Exactly one word. Coming from Misty, it means a lot.",
|
||||
"'You didn't mess it up.' Misty accepts the reward materials and gives you yours without ceremony. 'That was the job. Well done.'",
|
||||
"Misty looks at the completed quest items and then looks at you. Something shifts in her expression — not warm exactly, but warmer. 'You actually did it the right way.' The reward follows.",
|
||||
}
|
||||
|
||||
var MistyQuestFail = []string{
|
||||
"'You didn't finish.' Misty says it without heat, which is somehow worse than heat. 'Come back when you have.'",
|
||||
"Misty registers the incomplete quest with the expression of someone who expected exactly this outcome and had hoped to be wrong.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// MISTY — AFTER EARNING HER RESPECT
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var MistyTrusted = []string{
|
||||
"Misty sees you coming and does something she almost never does — stops what she's doing before you reach her. She's ready to talk. This is respect, Misty-style.",
|
||||
"'You've been doing good work in there,' Misty says, as you arrive. She doesn't look up. She doesn't need to. 'I noticed.'",
|
||||
"Something has changed in how Misty addresses you. Not warmer exactly. More equal. You earned that.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ARINA — GREETINGS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ArinaGreeting = []string{
|
||||
"'Oh! You're here!' Arina says this with the energy of someone who has been looking forward to a thing and is pleased the thing has arrived. The thing is you.",
|
||||
"Arina looks up from a worktable covered in notes, materials, and something faintly glowing, and her face does the thing it does — open, interested, ready to talk very fast.",
|
||||
"'Perfect timing,' Arina says, in the tone of someone for whom most timings are perfect because everything is interesting. 'I was just thinking about—' She stops. 'Actually, what do you need?'",
|
||||
"Arina has three things she's in the middle of and immediately sets all of them down to give you her full attention, which is considerable.",
|
||||
"'You came back!' Arina says, as if there was any question. In her experience there sometimes isn't.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ARINA — ITEM IDENTIFICATION
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ArinaIdentify = []string{
|
||||
"Arina picks up the item with both hands and goes immediately quiet, which is the most alarming thing she does. Then: 'Okay. Okay, this is — this is actually really interesting.' She tells you everything.",
|
||||
"'Can I — I'm not going to touch it, I just—' She touches it. 'Okay so here's what it does.'",
|
||||
"Arina holds the item up to the light, turns it twice, says something under her breath that might be an incantation or just enthusiasm, and then begins a very efficient explanation.",
|
||||
"'Oh I know what this is.' The words land quickly, confidently, correctly. Arina has seen a lot of magic items and she remembers all of them.",
|
||||
"Arina goes still in the specific way she goes still when magic is doing something she finds genuinely surprising. 'That's — huh. Okay. That's new. Let me—' The identification follows, along with three questions she has that you're under no obligation to answer.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ARINA — SKILL CHECK SUCCESS
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ArinaArcanaSuccess = []string{
|
||||
"'Yes! Exactly right — you know what, most people don't catch that.' Arina opens her notes and shows you something that solves the problem neatly.",
|
||||
"Arina's face does the thing where she's genuinely pleased that you got it. 'Okay so since you clearly know what you're doing—' She gives you the recipe.",
|
||||
"'That check was excellent,' Arina says, which from her means the knowledge was real and not a guess. She gives you the full information without making you ask for pieces of it.",
|
||||
}
|
||||
|
||||
var ArinaSkillFail = []string{
|
||||
"'Oh — no, that's not quite—' Arina seems genuinely sorry about this. 'Come back and we'll try again. Or bring the right materials. Or both.'",
|
||||
"Arina makes a small face that isn't unkind. 'Not quite. You're close though! The concept is right, the specifics just need—' She trails off. 'Anyway. Come back.'",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ARINA — CRAFTING
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ArinaCraftStart = []string{
|
||||
"'Okay! I have everything I need, you have everything you brought, let's see what we can make.' Arina's work mode is focused and fast.",
|
||||
"Arina spreads the materials across the table and looks at them the way a musician looks at an instrument — familiarity and anticipation. 'This is the good part,' she says.",
|
||||
"'I've been thinking about this combination for a while actually,' Arina says, and begins immediately.",
|
||||
}
|
||||
|
||||
var ArinaCraftComplete = []string{
|
||||
"Arina presents the finished item with quiet satisfaction — the specific satisfaction of a thing made well. 'There. That's what those materials wanted to be.'",
|
||||
"'Done!' Arina says, and she sounds pleased in the way she sounds when something worked exactly as planned. Which it did. 'Take good care of it.'",
|
||||
"The item is finished and Arina holds it out to you. 'Made right, with the right materials. That's how these things last.' She means it literally and figuratively.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ARINA — QUEST ASSIGNMENT
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var ArinaQuestGive = []string{
|
||||
"'Okay so I have a thing,' Arina says, which is how she starts sentences that are actually requests. 'You don't have to. But if you're going into that zone anyway—'",
|
||||
"'I need a sample,' Arina says. 'Specifically—' She describes it in precise detail. The precision is its own kind of excitement.",
|
||||
"Arina looks at her notes, looks at you, looks at her notes again. 'I think you're the right person to ask about this. Can I ask you about this?'",
|
||||
}
|
||||
|
||||
var ArinaQuestComplete = []string{
|
||||
"Arina sees what you've brought and makes a sound that is entirely undignified and entirely genuine. 'You actually got it. Can I — thank you. This is going to—' She's already analyzing it.",
|
||||
"'This is perfect,' Arina says, and she means it in the exact scientific sense — perfect, the right amount, the right quality. 'The reward is on the table. Thank you.'",
|
||||
"Arina takes the materials and immediately begins making notes, which means she's happy, which means you did it right. The reward is handled efficiently because her hands are busy.",
|
||||
}
|
||||
|
||||
var ArinaFavoriteUnlocked = []string{
|
||||
"Arina puts down her notes. Actually puts them down. 'You've done a lot for this workshop,' she says. 'I want to show you what I'm actually working on.' The advanced recipe list opens.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PETE BOT — BROADCAST LINES
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PeteZoneUnlock = []string{
|
||||
"📣 Pete: {zone_name} is now accessible. Community milestone reached. First expeditions can begin immediately.",
|
||||
"📣 Pete: New zone available — {zone_name} (Tier {tier}, recommended Level {level_min}+). Details via !expedition start {zone_id}.",
|
||||
}
|
||||
|
||||
var PeteTier5Complete = []string{
|
||||
"📣 Pete: {player_name} has completed {zone_name}. Expedition duration: {days} days. Boss defeated. Legendary loot confirmed. TwinBee has noted this one.",
|
||||
"📣 Pete: {zone_name} cleared by {player_name} on Day {day}. The {boss_name} is down. Community achievement recorded.",
|
||||
}
|
||||
|
||||
var PeteStreakMilestone = []string{
|
||||
"📣 Pete: {player_name} is on a {streak}-win arena streak. Current status: {title}. The leaderboard has updated.",
|
||||
"📣 Pete: Arena milestone — {player_name} reaches streak {streak}. Previous record in this community: {record}.",
|
||||
}
|
||||
|
||||
var PeteCommunityBoost = []string{
|
||||
"📣 Pete: Community activity this week has been strong. TwinBee's mood is elevated. Dungeon drop rates and milestone rewards have been adjusted upward for 48 hours.",
|
||||
"📣 Pete: TwinBee is in a good mood. Reasons cited: community engagement, a particularly impressive nat 20, and general satisfaction with how things have been going. Enhanced rewards active through Sunday.",
|
||||
}
|
||||
|
||||
var PeteMaintenance = []string{
|
||||
"📣 Pete: Brief maintenance window incoming — approximately {duration}. Active expeditions are paused and will resume from last checkpoint. Supplies will not deplete during downtime.",
|
||||
"📣 Pete: Maintenance complete. All systems restored. Expedition timers have been adjusted for downtime. Apologies for the interruption.",
|
||||
}
|
||||
|
||||
var PeteExpeditionBulletin = []string{
|
||||
"📣 Pete: Expedition update — {count} active expeditions in progress across {zones}. Longest running: Day {max_day}. TwinBee is busy.",
|
||||
"📣 Pete: Current expedition activity: {count} players in the field. The dungeon is occupied. Good.",
|
||||
}
|
||||
|
||||
var PetePatchNotes = []string{
|
||||
"📣 Pete: Update deployed. Changes: {summary}. Full notes available on request. TwinBee has been briefed.",
|
||||
}
|
||||
|
||||
var PeteMortgageRate = []string{
|
||||
"📣 Pete: Weekly rate update. FRED ARM rate: {rate}%. Effective GogoBee mortgage rate (Thom Krooke margin included): {effective}%. Payments process Sunday.",
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
// DO NOT REWRITE, SUMMARIZE, OR SHORTEN ANY ENTRIES IN THIS FILE
|
||||
// twinbee_resource_flavor.go
|
||||
// TwinBee GM Dialogue — Resource gathering, combat interrupts,
|
||||
// zone-specific loot descriptions, and harvest narration.
|
||||
// Add new entries freely. Never remove or alter existing entries.
|
||||
|
||||
package flavor
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// HARVEST SUCCESS — Generic by Action Type
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var HarvestForageSuccess = []string{
|
||||
"The land gives something up. TwinBee watches you identify it with the quiet satisfaction of someone watching a skill be used correctly.",
|
||||
"There — growing in a place that suggests it knows exactly what it's good for and has been waiting. You found it. TwinBee approves of the finding.",
|
||||
"A Ranger's eye in a non-Ranger would have missed that entirely. TwinBee notes the distinction.",
|
||||
"Like finding the hidden item block in a Mario level — you knew to look, you looked in the right place, and the thing that was always there is now yours.",
|
||||
"The plant comes away cleanly. Good root structure, good potency. TwinBee mentally catalogues it and moves on.",
|
||||
}
|
||||
|
||||
var HarvestMineSuccess = []string{
|
||||
"The stone yields. TwinBee listens to the sound of it — the specific tone of rock giving up something it's been holding for a very long time.",
|
||||
"Solid work. The ore comes out in a piece worth taking. TwinBee checks the vein depth. There's more. There's always more if you're willing to dig.",
|
||||
"Like the mining minigame in Stardew Valley, but with real consequences and no save file. TwinBee watches you extract the material with professional appreciation.",
|
||||
"The wall gives up its contents without drama. TwinBee appreciates materials that cooperate.",
|
||||
"Good strike. Clean extraction. TwinBee notes the weight and the quality simultaneously.",
|
||||
}
|
||||
|
||||
var HarvestScavengeSuccess = []string{
|
||||
"There it is. Among the debris, the decay, the things that were left behind — something worth taking. TwinBee knew it was there. You found it. TwinBee is pleased.",
|
||||
"The room held something after all. TwinBee had estimated 60% odds and updates the estimate to 'correct.'",
|
||||
"Like finding the secret item in a dungeon chest that looked empty — you checked anyway. That's the habit. That's the discipline. TwinBee notes both.",
|
||||
"Scavenged. The word has a bad reputation it doesn't deserve. You found value in the discarded. TwinBee respects that entirely.",
|
||||
"A Rogue's eye in a non-Rogue would have walked past this. TwinBee notes the distinction.",
|
||||
}
|
||||
|
||||
var HarvestEssenceSuccess = []string{
|
||||
"The essence coalesces. TwinBee watches the process with the reverence it deserves — magic condensing from ambient to held is not nothing.",
|
||||
"Drawn out cleanly. The Arcana check held and the essence responds to the knowledge behind it. TwinBee is appropriately impressed.",
|
||||
"Like tapping into a power source in Metroid — you knew the energy was there, you had the tool to reach it, you reached it. The vial fills.",
|
||||
"The room releases something it didn't know it was holding. TwinBee watches the transfer and marks the yield in its ledger.",
|
||||
"Essence harvested. TwinBee notes the quality — above average for this zone, below average for what you'd need to know to appreciate that distinction. TwinBee appreciates it on your behalf.",
|
||||
}
|
||||
|
||||
var HarvestCommuneSuccess = []string{
|
||||
"The spiritual resonance here responds to you. TwinBee observes this with something adjacent to wonder — not everything in a dungeon wants to fight, and this one chose to offer instead.",
|
||||
"A Cleric reaching into the bones of a place and finding something willing to be found. TwinBee has watched this fewer times than it's watched combat and values it proportionally.",
|
||||
"The commune holds. The material comes. TwinBee says nothing and lets the moment be what it is.",
|
||||
"Like finding a save point that also tells you something true about the world. The dungeon has given you something. TwinBee notes the gift.",
|
||||
}
|
||||
|
||||
var HarvestFishSuccess = []string{
|
||||
"The line goes taut and TwinBee straightens up. Whatever's on the end of it, it came from somewhere deep and dark and it's yours now.",
|
||||
"A catch. TwinBee identifies it before you finish pulling it in — the coloring, the depth-marks, the specific opacity of its eyes. 'Good one,' TwinBee says, meaning it.",
|
||||
"Fishing in a dungeon. TwinBee has opinions about fishing in dungeons and all of them are positive. The fish is landed. The opinions remain.",
|
||||
"Like the fishing minigame in every RPG that ever had one — the moment the indicator hits perfect and everything pays off. TwinBee takes quiet delight in this.",
|
||||
"The water gives up its catch with minimal argument. TwinBee respects fish that don't make it personal.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// HARVEST FAILURE — Generic
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var HarvestFail = []string{
|
||||
"Nothing. The node had nothing to offer, or you didn't ask the right way, or both. TwinBee notes this without judgment and suggests trying elsewhere.",
|
||||
"The attempt fails to produce anything useful. TwinBee marks the node and moves on. Some rooms are stingier than others.",
|
||||
"Not everything that looks like a resource is one. TwinBee files this under 'learned' and considers it worth the attempt.",
|
||||
"Empty-handed. TwinBee has seen this before and will see it again. The dungeon doesn't owe you anything. You ask anyway. That's the deal.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// HARVEST INTERRUPT — Combat Triggered
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var HarvestInterrupt = []string{
|
||||
"TwinBee sees it before you do — movement at the edge of the room, something that was waiting for you to be distracted. 'Company,' TwinBee says, which is the politest word for it.",
|
||||
"The harvest is interrupted. You were focused on the node; something was focused on you. TwinBee notes the tactical lesson without rubbing it in.",
|
||||
"Like the enemy ambush that fires when you open the treasure chest — the dungeon watched you commit to the harvest and introduced a complication. TwinBee did warn about this. Once. Earlier.",
|
||||
"Something heard the mining. Sound travels in dungeons. TwinBee has mentioned this. The enemy emerging from the corridor has confirmed it.",
|
||||
"A patrol. Bad timing, or very good timing from their perspective. TwinBee sets aside the harvest log and opens the combat log.",
|
||||
"The forage was going well until it wasn't. TwinBee measures the distance between you and the enemy, between the enemy and the door, and starts calculating options at speed.",
|
||||
"Interrupted. The node is still there. The enemy is also still there, in a more immediate way. TwinBee suggests addressing the more immediate thing first.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// NODE DEPLETED
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var NodeDepleted = []string{
|
||||
"The node is stripped. You've taken everything it had to give. TwinBee marks the location in its mental map as exhausted until the next rest.",
|
||||
"Empty. The resource is gone. TwinBee finds something quietly melancholy about a depleted node and something practical about moving to the next one.",
|
||||
"That's all it had. TwinBee confirms the node at zero and moves on without ceremony.",
|
||||
"Harvested clean. TwinBee notes the room is now resource-dry until you rest and the dungeon replenishes. It will replenish. It always does.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// RICH YIELD
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var RichYield = []string{
|
||||
"A rich vein. TwinBee's assessment upgrades mid-harvest — more than expected, better quality than the zone average. This room was generous. TwinBee marks it.",
|
||||
"The node gives more than it should have. TwinBee notes the anomaly with appreciation and does not question it.",
|
||||
"Like finding the rare item drop that you stopped expecting — the dungeon decided to be kind today, in this specific way, in this specific room. TwinBee takes it.",
|
||||
"Exceptional yield. TwinBee catalogs the bonus material with the efficiency of someone who has been waiting for exactly this and prepared for it anyway.",
|
||||
"More than the DC promised. The dungeon overdelivered. TwinBee notes this is unusual and also completely welcome.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// ZONE-SPECIFIC HARVEST LINES
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var HarvestGoblinWarrens = []string{
|
||||
"The goblins had more than anyone gave them credit for. Crude, yes. Stolen, mostly. But present, and now yours. TwinBee is pragmatic about origins.",
|
||||
"Scavenged from a goblin stash that someone worked hard to hide and harder to accumulate. TwinBee finds a moment of respect for the effort before moving on.",
|
||||
"The warrens are full of things the goblins took from people who'd take them back given the opportunity. TwinBee considers this a form of redistribution.",
|
||||
}
|
||||
|
||||
var HarvestCryptValdris = []string{
|
||||
"Grave goods. TwinBee notes the weight of taking from a burial site and files it under: necessary. The dead have no use for these. You do.",
|
||||
"The crypt gives up its materials with the reluctance of a place that considers itself permanent. TwinBee disagrees with the premise. The materials are harvested.",
|
||||
"Ancient things preserved by darkness and time. TwinBee handles the concept carefully even as you handle the material practically.",
|
||||
}
|
||||
|
||||
var HarvestForestShadows = []string{
|
||||
"The forest gives and the forest takes and right now it is giving, which TwinBee notes as the correct direction for this interaction to go.",
|
||||
"A plant that has no business being this healthy in a corrupted forest. TwinBee considers it either very resilient or very clever. Either way, useful.",
|
||||
"The woods here remember what they were before they went wrong. The resources carry that memory. TwinBee thinks this makes them better materials. TwinBee might be right.",
|
||||
}
|
||||
|
||||
var HarvestSunkenTemple = []string{
|
||||
"The temple held onto this longer than anything else. TwinBee extracts it from the silt and the salt and the particular weight of a place that's been underwater for thirty years.",
|
||||
"Ancient, preserved, and still potent. The deep cold does something to materials that nothing else replicates. TwinBee values the outcome even if it declines to romanticize the process.",
|
||||
"The sea left something behind when it half-abandoned this place. TwinBee retrieves it with appropriate care.",
|
||||
}
|
||||
|
||||
var HarvestHauntedManor = []string{
|
||||
"The manor keeps things. Has always kept things. TwinBee takes this one out of the keeping and into the useful, which is a small act of defiance against the house's whole philosophy.",
|
||||
"Found among the things that have been here since the last person stopped being here. TwinBee notes the provenance without dwelling on it.",
|
||||
"The house watches you take it. TwinBee watches the house watch you. A full triangle of observation, and TwinBee notes: the house blinks first.",
|
||||
}
|
||||
|
||||
var HarvestUnderforge = []string{
|
||||
"The forge yields its material with the grudging respect of something built to produce and still producing, even now, for someone it didn't expect.",
|
||||
"Dwarven craftsmanship even in the raw materials. TwinBee has always believed the quality is in the extraction, not just the finishing. This confirms it.",
|
||||
"Hot, heavy, and exactly what the zone promised. TwinBee marks the vein depth. There is more. The Underforge does not run out of things to give.",
|
||||
}
|
||||
|
||||
var HarvestUnderdark = []string{
|
||||
"The Underdark produces everything the surface does, stranger, in the dark, and with fewer questions about why. TwinBee harvests without asking why.",
|
||||
"Things grow down here that have no equivalent above. TwinBee catalogs the material and the context it came from with equal precision.",
|
||||
"A material that has never seen sunlight and is better for it. TwinBee notes this without irony.",
|
||||
}
|
||||
|
||||
var HarvestFeywild = []string{
|
||||
"The Feywild gives things away. That's the problem — it gives things away and sometimes what it gives isn't what you thought you were taking. TwinBee checks the material twice. It appears to be what it appears to be. TwinBee remains alert.",
|
||||
"Beautiful material from a zone that uses beauty as a weapon. TwinBee takes it carefully, like picking up something that might be watching.",
|
||||
"The fey made this place generous on purpose. TwinBee is not going to complain about the generosity and is not going to stop watching for the catch.",
|
||||
}
|
||||
|
||||
var HarvestDragonsLair = []string{
|
||||
"Plucked from a hoard that has been accumulating since before your civilization named itself. TwinBee notes the historical weight and moves on.",
|
||||
"The kobolds will notice something is missing. They count everything. TwinBee accounts for this and suggests moving with intent.",
|
||||
"Dragon-adjacent materials carry something in them — a residual heat, a quality that doesn't exist anywhere the dragon hasn't been. TwinBee considers this a feature.",
|
||||
}
|
||||
|
||||
var HarvestAbyssPortal = []string{
|
||||
"Harvesting from the Abyss. TwinBee delivers this line flatly because it deserves flat delivery. The material is valuable. The context is permanent.",
|
||||
"Reality left something behind when it tore here. TwinBee takes the fragment and notes: don't linger near the edges of what isn't stable.",
|
||||
"Demon ichor. TwinBee says the words with the efficiency of someone who has moved past the part where the words were alarming.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// FISHING — Zone-Specific Lines
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var FishingForestShadows = []string{
|
||||
"Fishing in a cursed forest stream. TwinBee finds this more peaceful than it has any right to be and refuses to let the shadow-things in the canopy ruin it.",
|
||||
"The stream runs dark but the fish run silver. TwinBee watches the line and says nothing for a while, which is what fishing is for.",
|
||||
"Like the fishing minigame before the hard dungeon in Ocarina of Time. TwinBee takes the moment seriously.",
|
||||
}
|
||||
|
||||
var FishingSunkenTemple = []string{
|
||||
"Fishing in a flooded temple. The fish here have never seen the surface. They don't know what they're missing. TwinBee is uncertain whether to pity them.",
|
||||
"The line drops into water that hasn't moved in thirty years and immediately gets attention. Things down here are hungry. TwinBee watches the tension.",
|
||||
"Deep water fishing in the ruins of something ancient. TwinBee thinks the builders would have found this either sacrilegious or practical. TwinBee lands on practical.",
|
||||
}
|
||||
|
||||
var FishingUnderdark = []string{
|
||||
"The underground river is cold and fast and the fish in it have evolved past needing eyes, which TwinBee finds both efficient and slightly unsettling.",
|
||||
"Fishing in total darkness in a river that doesn't appear on any surface map. TwinBee narrates by sound: the cast, the current, the eventual tension on the line.",
|
||||
"The Eyeless King is in here somewhere. TwinBee doesn't say this out loud but thinks it very clearly. The line goes deep.",
|
||||
}
|
||||
|
||||
var FishingFeywild = []string{
|
||||
"Fey fishing. TwinBee watches the line for signs of time distortion — the way the reflection moves wrong, the way the fish seem to arrive before they bite. The Feywild is like this about everything.",
|
||||
"The stream catches light that shouldn't be here and the fish reflect it from below. TwinBee watches something luminous move toward the hook and tries to stay professional about it.",
|
||||
"Like fishing in a dream. TwinBee means this literally — the mechanics are the same but the rules feel advisory.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// PATROL ENCOUNTER LINES
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var PatrolEncounter = []string{
|
||||
"A patrol. Moving between the cleared rooms with the confidence of something that considers them still theirs. TwinBee disagrees with this assessment and will help you express the disagreement.",
|
||||
"They found you between rooms, which is exactly where patrols are supposed to find you. TwinBee notes the Threat Clock and suggests dispatching this quickly and quietly.",
|
||||
"The patrol isn't looking for a fight — it's doing its job, which happens to involve you being somewhere you aren't supposed to be. TwinBee will help you redefine 'supposed to.'",
|
||||
"Two of them. Moving together. The coordination suggests the zone is at Alert or higher. TwinBee confirms: it is. Fight or fade.",
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// LOOT DROP LINES — Generic
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var LootDropCommon = []string{
|
||||
"They had something on them. TwinBee checks it over. Common rarity — useful in the way that common things are useful, which is often.",
|
||||
"Standard loot. Nothing that rewrites the story, but everything that keeps it going.",
|
||||
"A drop. TwinBee catalogs it efficiently and notes: this is the economy of dungeons. Enemies have things. You take them. The loop continues.",
|
||||
}
|
||||
|
||||
var LootDropUncommon = []string{
|
||||
"Better than expected. TwinBee examines the drop with slightly elevated interest. Uncommon rarity — someone made this with intent.",
|
||||
"An uncommon drop from a common enemy. TwinBee notes the anomaly with satisfaction. The dungeon was generous in this room.",
|
||||
"Uncommon. TwinBee turns it over once and nods. 'Keeper,' TwinBee says, which in TwinBee's vocabulary means: this changes your math.",
|
||||
}
|
||||
|
||||
var LootDropRare = []string{
|
||||
"TwinBee stops. Actually stops. 'That's rare,' TwinBee says, with the specific register of someone who uses the word correctly and uses it seldom.",
|
||||
"A rare drop. TwinBee examines it the way you examine something that doesn't appear often — thoroughly, quietly, with appropriate appreciation.",
|
||||
"The loot table gave you something uncommon and then kept going. Rare rarity. TwinBee files this in the column it reserves for things worth remembering.",
|
||||
}
|
||||
|
||||
var LootDropLegendary = []string{
|
||||
"TwinBee goes very still. The drop sits in the light and TwinBee processes what it is seeing. 'Legendary,' TwinBee says eventually. One word. That's all it needs.",
|
||||
"Legendary rarity. TwinBee has seen a few of these in a long career and each time — each time — there is a moment that is separate from everything else. This is that moment. Pick it up carefully.",
|
||||
"The dungeon produced a legendary item. TwinBee notes the zone, the enemy, the day of the expedition, the Threat Clock value, the precise conditions. Some things deserve to be recorded completely.",
|
||||
}
|
||||
+310
-22
@@ -36,6 +36,7 @@ type AdventurePlugin struct {
|
||||
shopSessions sync.Map // userID string -> *advShopSession
|
||||
hospitalNudges sync.Map // userID string -> time.Time (when to send nudge)
|
||||
craftResults sync.Map // userID string -> []CraftResult (pending craft results for narrative)
|
||||
treasureUndo sync.Map // userID string -> *advTreasureUndoToken (10-min auto-swap reversal)
|
||||
morningHour int
|
||||
summaryHour int
|
||||
}
|
||||
@@ -47,6 +48,19 @@ func (p *AdventurePlugin) advUserLock(userID id.UserID) *sync.Mutex {
|
||||
}
|
||||
|
||||
const advDMResponseWindow = 3 * time.Hour
|
||||
const advTreasureUndoWindow = 10 * time.Minute
|
||||
|
||||
// advTreasureUndoToken tracks a recent auto-swap so the player can undo it
|
||||
// within the window by replying "undo" in DM. Holds the discarded def so
|
||||
// the swap can be reversed exactly. AnnounceTimer is the deferred room
|
||||
// announcement — fired once the undo window closes if the swap stands,
|
||||
// stopped on undo so reversed swaps don't get publicly announced.
|
||||
type advTreasureUndoToken struct {
|
||||
Discarded *AdvTreasureDef
|
||||
Kept *AdvTreasureDef
|
||||
ExpiresAt time.Time
|
||||
AnnounceTimer *time.Timer
|
||||
}
|
||||
|
||||
// advMarkMenuSent records that an actionable adventure menu was DM'd to the user.
|
||||
// Only bare-number DM replies within this window will be treated as adventure choices.
|
||||
@@ -106,6 +120,19 @@ func (p *AdventurePlugin) Commands() []CommandDef {
|
||||
{Name: "adventure", Description: "Daily adventure game — dungeon, mine, forage, or rest", Usage: "!adventure", Category: "Games"},
|
||||
{Name: "arena", Description: "Arena combat — fight through 5 tiers of increasingly deadly monsters", Usage: "!arena", Category: "Games"},
|
||||
{Name: "thom", Description: "Visit Thom Krooke — housing and loans", Usage: "!thom", Category: "Games"},
|
||||
{Name: "setup", Description: "Create or continue your Adv 2.0 character (race, class, stats)", Usage: "!setup", Category: "Games"},
|
||||
{Name: "sheet", Description: "View your Adv 2.0 character sheet", Usage: "!sheet", Category: "Games"},
|
||||
{Name: "abilities", Description: "List your Adv 2.0 class and race abilities", Usage: "!abilities", Category: "Games"},
|
||||
{Name: "respec", Description: "Wipe and rebuild your Adv 2.0 character (5000 euros, 7-day cooldown)", Usage: "!respec", Category: "Games"},
|
||||
{Name: "check", Description: "Roll an Adv 2.0 skill check (d20 + ability modifier vs DC)", Usage: "!check <skill> [dc]", Category: "Games"},
|
||||
{Name: "rest", Description: "Take an Adv 2.0 rest (`short`: 1h cooldown, partial heal — `long`: 24h, full heal, requires housing or inn)", Usage: "!rest short|long", Category: "Games"},
|
||||
{Name: "arm", Description: "Pre-arm an active Adv 2.0 ability for next combat (consumes resource)", Usage: "!arm <ability>", Category: "Games"},
|
||||
{Name: "roll", Description: "Roll dice (NdN+M format, e.g. 2d6+3, d20, 4d6-1)", Usage: "!roll <dice>", Category: "Games"},
|
||||
{Name: "stats", Description: "Show your Adv 2.0 ability scores and modifiers", Usage: "!stats", Category: "Games"},
|
||||
{Name: "level", Description: "Show your Adv 2.0 level and XP progress", Usage: "!level", Category: "Games"},
|
||||
{Name: "cast", Description: "Cast an Adv 2.0 spell (queues for next combat, or resolves out-of-combat)", Usage: "!cast <spell> [--upcast N] [--target @user]", Category: "Games"},
|
||||
{Name: "spells", Description: "List your known spells, prepared spells, and spell slots", Usage: "!spells [learn <spell>]", Category: "Games"},
|
||||
{Name: "prepare", Description: "Cleric: prepare a spell for the day (cap = WIS mod + level)", Usage: "!prepare <spell> | !prepare clear <spell>", Category: "Games"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +203,47 @@ func (p *AdventurePlugin) OnReaction(_ ReactionContext) error { return nil }
|
||||
// ── Message Dispatch ─────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) OnMessage(ctx MessageContext) error {
|
||||
// 0. D&D layer commands (Phase 1 — work in rooms and DMs)
|
||||
if p.IsCommand(ctx.Body, "setup") {
|
||||
return p.handleDnDSetupCmd(ctx, p.GetArgs(ctx.Body, "setup"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "sheet") {
|
||||
return p.handleDnDSheetCmd(ctx)
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "abilities") {
|
||||
return p.handleDnDAbilitiesCmd(ctx)
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "respec") {
|
||||
return p.handleDnDRespecCmd(ctx)
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "check") {
|
||||
return p.handleDnDCheckCmd(ctx, p.GetArgs(ctx.Body, "check"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "rest") {
|
||||
return p.handleDnDRestCmd(ctx, p.GetArgs(ctx.Body, "rest"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "arm") {
|
||||
return p.handleDnDArmCmd(ctx, p.GetArgs(ctx.Body, "arm"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "cast") {
|
||||
return p.handleDnDCastCmd(ctx, p.GetArgs(ctx.Body, "cast"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "spells") {
|
||||
return p.handleDnDSpellsCmd(ctx, p.GetArgs(ctx.Body, "spells"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "prepare") {
|
||||
return p.handleDnDPrepareCmd(ctx, p.GetArgs(ctx.Body, "prepare"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "roll") {
|
||||
return p.handleDnDRollCmd(ctx, p.GetArgs(ctx.Body, "roll"))
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "stats") {
|
||||
return p.handleDnDStatsCmd(ctx)
|
||||
}
|
||||
if p.IsCommand(ctx.Body, "level") {
|
||||
return p.handleDnDLevelCmd(ctx)
|
||||
}
|
||||
|
||||
// 1. Arena commands (work in rooms and DMs)
|
||||
if p.IsCommand(ctx.Body, "bail") {
|
||||
return p.handleArenaBail(ctx)
|
||||
@@ -269,6 +337,10 @@ func (p *AdventurePlugin) dispatchCommand(ctx MessageContext) error {
|
||||
return p.handleBoostCmd(ctx)
|
||||
case lower == "recipes":
|
||||
return p.handleRecipesCmd(ctx)
|
||||
case lower == "mastery":
|
||||
return p.handleMasteryCmd(ctx)
|
||||
case lower == "treasures" || strings.HasPrefix(lower, "treasures "):
|
||||
return p.handleTreasuresCmd(ctx, strings.TrimSpace(strings.TrimPrefix(lower, "treasures")))
|
||||
}
|
||||
|
||||
return p.SendDM(ctx.Sender, "Unknown command. Type `!adventure help` to see available commands.")
|
||||
@@ -289,10 +361,13 @@ const advHelpText = `**Adventure Commands**
|
||||
` + "`!adventure rivals`" + ` — View rival duel records
|
||||
` + "`!adventure babysit`" + ` — Adventurer Babysitting Service
|
||||
` + "`!adventure babysit auto`" + ` — Toggle auto-babysit (protects streaks on missed days)
|
||||
` + "`!adventure babysit focus <skill>`" + ` — Pick the skill auto-babysit trains (mining/fishing/foraging)
|
||||
` + "`!adventure blacksmith`" + ` — Visit the blacksmith (view repair costs)
|
||||
` + "`!adventure repair all`" + ` — Repair all damaged equipment
|
||||
` + "`!adventure repair <slot>`" + ` — Repair a specific slot
|
||||
` + "`!adventure recipes`" + ` — List crafting recipes known at your current Foraging level
|
||||
` + "`!adventure mastery`" + ` — Per-slot equipment mastery progress and active bonus
|
||||
` + "`!adventure treasures`" + ` — List your treasures · ` + "`treasures lock`" + ` to refuse swaps
|
||||
` + "`!coop`" + ` — Co-op dungeons (multi-day party runs). See ` + "`!coop help`" + `.
|
||||
` + "`!hospital`" + ` — Visit St. Guildmore's Memorial Hospital (same-day revival when dead)
|
||||
` + "`!thom`" + ` — Visit Thom Krooke (housing and loans)
|
||||
@@ -414,6 +489,9 @@ func (p *AdventurePlugin) handleShopCmd(ctx MessageContext, args string) error {
|
||||
|
||||
if category == "" {
|
||||
text := luigiShopGreeting(ctx.Sender, equip, balance, showAll, p.chatLevel(ctx.Sender))
|
||||
if disc := p.shopSessionAnnounceDiscount(ctx.Sender); disc != "" {
|
||||
text += "\n\n" + disc
|
||||
}
|
||||
p.pending.Store(string(ctx.Sender), &advPendingInteraction{
|
||||
Type: "shop_category",
|
||||
Data: &advPendingShopCategory{ShowAll: showAll},
|
||||
@@ -559,6 +637,15 @@ func (p *AdventurePlugin) handleDMReply(ctx MessageContext) error {
|
||||
return p.dispatchCommand(ctx)
|
||||
}
|
||||
|
||||
// "undo" reverts a recent treasure auto-swap. Checked ahead of the
|
||||
// pending-interaction block so it doesn't get consumed by an unrelated
|
||||
// pending prompt.
|
||||
if lower == "undo" {
|
||||
if p.tryTreasureUndo(ctx.Sender) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check for pending interaction first (always honored regardless of window)
|
||||
if val, ok := p.pending.Load(string(ctx.Sender)); ok {
|
||||
interaction := val.(*advPendingInteraction)
|
||||
@@ -968,6 +1055,13 @@ func (p *AdventurePlugin) resolveActivity(ctx MessageContext, char *AdventureCha
|
||||
|
||||
// Send resolution DM with closing block
|
||||
text := renderAdvResolutionDM(result, char)
|
||||
if result.CombatLog != nil {
|
||||
// Combat closing narrative — victory or death depending on outcome.
|
||||
text += dndItalicize(dndCombatClosingLine(result.CombatLog.PlayerWon, false))
|
||||
if rollLine := dndRollSummaryLine(*result.CombatLog); rollLine != "" {
|
||||
text += "\n" + rollLine
|
||||
}
|
||||
}
|
||||
if deathReprieved {
|
||||
nextWindow := char.DeathReprieveLast.Add(168 * time.Hour)
|
||||
text += fmt.Sprintf("\n\n⚔️ **Death's Reprieve activated.** Your Sovereign gear absorbed the killing blow. "+
|
||||
@@ -983,6 +1077,9 @@ func (p *AdventurePlugin) resolveActivity(ctx MessageContext, char *AdventureCha
|
||||
if result.CombatLog != nil {
|
||||
phaseMessages := RenderCombatLog(*result.CombatLog, char.DisplayName, loc.Denizens)
|
||||
phaseMessages = p.prependCraftNarrative(ctx.Sender, phaseMessages)
|
||||
if open := dndCombatOpeningLine(); open != "" && len(phaseMessages) > 0 {
|
||||
phaseMessages[0] = "_" + open + "_\n\n" + phaseMessages[0]
|
||||
}
|
||||
done := p.sendCombatMessages(ctx.Sender, phaseMessages, text)
|
||||
|
||||
go func() {
|
||||
@@ -1018,6 +1115,14 @@ func (p *AdventurePlugin) resolveActivity(ctx MessageContext, char *AdventureCha
|
||||
p.checkMasterworkDrop(ctx.Sender, char, equip, loc, result.Outcome)
|
||||
}
|
||||
|
||||
// Equipment mastery — celebrate threshold crossings so the silent
|
||||
// per-slot counter becomes visible to the player.
|
||||
for _, mc := range result.MasteryCrossings {
|
||||
p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"🛠️ **Mastery: %s — %d uses!** Your %s is paying it back: +1%% loot quality from this slot.",
|
||||
mc.ItemName, mc.Threshold, mc.Slot))
|
||||
}
|
||||
|
||||
// If the player still has actions remaining, nudge them
|
||||
if !char.AllActionsUsed(isHol) && (result.Outcome != AdvOutcomeDeath || deathReprieved) {
|
||||
remaining := []string{}
|
||||
@@ -1087,8 +1192,15 @@ func (p *AdventurePlugin) resolveRest(ctx MessageContext, char *AdventureCharact
|
||||
// ── Treasure Drop Check ─────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) checkTreasureDrop(userID id.UserID, char *AdventureCharacter, loc *AdvLocation) {
|
||||
drop := rollAdvTreasureDrop(loc.Tier, userID, p.chatLevel(userID))
|
||||
drop, roll, rate := rollAdvTreasureDropDetailed(loc.Tier, userID, p.chatLevel(userID))
|
||||
if drop == nil {
|
||||
// Near-miss feedback: when the roll was within 2× of the drop rate,
|
||||
// tell the player they almost got it. Treasure rates are 0.15–1.5%
|
||||
// so without this signal the system feels invisible.
|
||||
if rate > 0 && roll < rate*2 {
|
||||
p.SendDM(userID, fmt.Sprintf("🎁 *Treasure: just missed* — rolled %.2f%% against %.2f%% drop chance.",
|
||||
roll*100, rate*100))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1110,24 +1222,143 @@ func (p *AdventurePlugin) checkTreasureDrop(userID id.UserID, char *AdventureCha
|
||||
return
|
||||
}
|
||||
|
||||
// At cap — prompt for discard
|
||||
// At cap — try the auto-swap path before falling back to the manual
|
||||
// discard prompt. The prompt was the wound; most players don't want
|
||||
// agency at the rare moment of finding a treasure, they want the swap.
|
||||
existing, err := advUserTreasures(userID)
|
||||
if err != nil || len(existing) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Set pending interaction
|
||||
p.pending.Store(string(userID), &advPendingInteraction{
|
||||
Type: "treasure_discard",
|
||||
Data: &advPendingTreasureDiscard{
|
||||
NewTreasure: drop.Def,
|
||||
Existing: existing,
|
||||
},
|
||||
ExpiresAt: time.Now().Add(advDMResponseWindow),
|
||||
// Lock honors the player's "I'm done curating" state — refuse the drop
|
||||
// instead of churning their set.
|
||||
if char.TreasuresLocked {
|
||||
p.SendDM(userID, fmt.Sprintf("💎 *Treasure refused* — found **%s** (Tier %d) but your treasures are locked. Unlock with `!adventure treasures unlock` to allow swaps.",
|
||||
drop.Def.Name, drop.Def.Tier))
|
||||
return
|
||||
}
|
||||
|
||||
// Pick the worst replaceable existing treasure as the swap candidate.
|
||||
// Irreplaceable treasures (special_* bonuses) are protected — never
|
||||
// auto-discarded, even by a higher-tier drop.
|
||||
worstIdx := -1
|
||||
var worstRank advTreasureRankKey
|
||||
for i := range existing {
|
||||
ex := existing[i]
|
||||
if advTreasureIrreplaceable(&ex) {
|
||||
continue
|
||||
}
|
||||
r := advTreasureRank(&ex)
|
||||
if worstIdx < 0 || advTreasureRankBetter(worstRank, r) {
|
||||
worstIdx, worstRank = i, r
|
||||
}
|
||||
}
|
||||
|
||||
newRank := advTreasureRank(drop.Def)
|
||||
|
||||
// All existing are irreplaceable — fall back to the manual prompt so
|
||||
// the player consciously chooses what to give up.
|
||||
if worstIdx < 0 {
|
||||
p.pending.Store(string(userID), &advPendingInteraction{
|
||||
Type: "treasure_discard",
|
||||
Data: &advPendingTreasureDiscard{
|
||||
NewTreasure: drop.Def,
|
||||
Existing: existing,
|
||||
},
|
||||
ExpiresAt: time.Now().Add(advDMResponseWindow),
|
||||
})
|
||||
p.SendDM(userID, renderAdvTreasureDiscardPrompt(drop.Def, existing))
|
||||
return
|
||||
}
|
||||
|
||||
// New treasure is irreplaceable but would force out a replaceable —
|
||||
// auto-swap is fine here, the protection rule is about not removing
|
||||
// existing irreplaceables.
|
||||
if !advTreasureRankBetter(newRank, worstRank) {
|
||||
// New is no better than the worst we'd give up. Don't churn —
|
||||
// just tell the player about the find passively.
|
||||
p.SendDM(userID, fmt.Sprintf("💎 *Found %s (Tier %d)* — left behind: your current set ranks higher.",
|
||||
drop.Def.Name, drop.Def.Tier))
|
||||
return
|
||||
}
|
||||
|
||||
// Swap: discard worst, save new, store undo token.
|
||||
discarded := existing[worstIdx]
|
||||
if err := advDiscardTreasure(userID, discarded.Key); err != nil {
|
||||
slog.Error("adventure: failed to discard for auto-swap", "user", userID, "err", err)
|
||||
return
|
||||
}
|
||||
if err := advSaveTreasure(userID, drop.Def); err != nil {
|
||||
slog.Error("adventure: failed to save auto-swapped treasure", "user", userID, "err", err)
|
||||
// Best-effort recovery — restore the discarded one.
|
||||
_ = advSaveTreasure(userID, &discarded)
|
||||
return
|
||||
}
|
||||
|
||||
// High-tier story items earn a public moment even via auto-swap, but
|
||||
// defer the announce until after the undo window so reversed swaps
|
||||
// don't get publicly announced. Capture the data we need on close
|
||||
// over so the timer doesn't reach back into mutable state.
|
||||
announceChar := *char
|
||||
announceDef := *drop.Def
|
||||
announceLoc := *loc
|
||||
announceTimer := time.AfterFunc(advTreasureUndoWindow, func() {
|
||||
// Token is deleted on undo, so only fire when it's still present.
|
||||
// The map entry also gets cleared lazily below by future undo
|
||||
// attempts; firing once based on Timer presence is enough.
|
||||
if _, ok := p.treasureUndo.Load(string(userID)); !ok {
|
||||
return
|
||||
}
|
||||
p.treasureUndo.Delete(string(userID))
|
||||
p.announceTreasureToRoom(&announceChar, &announceDef, &announceLoc)
|
||||
})
|
||||
|
||||
text := renderAdvTreasureDiscardPrompt(drop.Def, existing)
|
||||
p.SendDM(userID, text)
|
||||
p.treasureUndo.Store(string(userID), &advTreasureUndoToken{
|
||||
Discarded: &discarded,
|
||||
Kept: drop.Def,
|
||||
ExpiresAt: time.Now().Add(advTreasureUndoWindow),
|
||||
AnnounceTimer: announceTimer,
|
||||
})
|
||||
|
||||
p.SendDM(userID, fmt.Sprintf(
|
||||
"💎 **Found %s** (Tier %d)\nAuto-swapped for **%s** (Tier %d, lowest in your set).\n_Reply `undo` within %d min to revert, or `!adventure treasures` to review._",
|
||||
drop.Def.Name, drop.Def.Tier,
|
||||
discarded.Name, discarded.Tier,
|
||||
int(advTreasureUndoWindow.Minutes())))
|
||||
}
|
||||
|
||||
// tryTreasureUndo reverses a recent auto-swap. Returns true when an undo
|
||||
// was applied. Stale or missing tokens return false so the caller falls
|
||||
// through to the regular DM dispatch.
|
||||
func (p *AdventurePlugin) tryTreasureUndo(userID id.UserID) bool {
|
||||
val, ok := p.treasureUndo.Load(string(userID))
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
tok := val.(*advTreasureUndoToken)
|
||||
p.treasureUndo.Delete(string(userID))
|
||||
// Cancel the deferred room announcement — a reversed swap shouldn't
|
||||
// produce a public "X recovered Y" line.
|
||||
if tok.AnnounceTimer != nil {
|
||||
tok.AnnounceTimer.Stop()
|
||||
}
|
||||
if time.Now().After(tok.ExpiresAt) {
|
||||
p.SendDM(userID, "⌛ The undo window expired. Your treasure swap stands.")
|
||||
return true
|
||||
}
|
||||
|
||||
// Reverse: discard the kept one, restore the discarded one.
|
||||
if err := advDiscardTreasure(userID, tok.Kept.Key); err != nil {
|
||||
slog.Error("adventure: failed to discard kept on undo", "user", userID, "err", err)
|
||||
return true
|
||||
}
|
||||
if err := advSaveTreasure(userID, tok.Discarded); err != nil {
|
||||
slog.Error("adventure: failed to restore on undo", "user", userID, "err", err)
|
||||
return true
|
||||
}
|
||||
p.SendDM(userID, fmt.Sprintf("↩️ Reverted. Your **%s** is back, **%s** released.",
|
||||
tok.Discarded.Name, tok.Kept.Name))
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) sendTreasureDiscoveryDM(userID id.UserID, char *AdventureCharacter, def *AdvTreasureDef, loc *AdvLocation) {
|
||||
@@ -1146,17 +1377,27 @@ func (p *AdventurePlugin) sendTreasureDiscoveryDM(userID id.UserID, char *Advent
|
||||
|
||||
p.SendDM(userID, text)
|
||||
|
||||
// Room announcement for tier 5 or special items
|
||||
if def.RoomAnnounce != "" {
|
||||
gr := gamesRoom()
|
||||
if gr != "" {
|
||||
announce := advSubstituteFlavor(def.RoomAnnounce, map[string]string{
|
||||
"{name}": char.DisplayName,
|
||||
"{location}": loc.Name,
|
||||
})
|
||||
p.SendMessage(id.RoomID(gr), announce)
|
||||
}
|
||||
p.announceTreasureToRoom(char, def, loc)
|
||||
}
|
||||
|
||||
// announceTreasureToRoom posts the public "X recovered Y from Z" notice for
|
||||
// treasures that carry a RoomAnnounce string (typically tier 5 / story
|
||||
// items). Called from both the normal discovery path and the auto-swap
|
||||
// path so high-tier finds keep their public moment regardless of whether
|
||||
// they arrived under or at the treasure cap.
|
||||
func (p *AdventurePlugin) announceTreasureToRoom(char *AdventureCharacter, def *AdvTreasureDef, loc *AdvLocation) {
|
||||
if def == nil || def.RoomAnnounce == "" {
|
||||
return
|
||||
}
|
||||
gr := gamesRoom()
|
||||
if gr == "" {
|
||||
return
|
||||
}
|
||||
announce := advSubstituteFlavor(def.RoomAnnounce, map[string]string{
|
||||
"{name}": char.DisplayName,
|
||||
"{location}": loc.Name,
|
||||
})
|
||||
p.SendMessage(id.RoomID(gr), announce)
|
||||
}
|
||||
|
||||
// ── Flavor Text Selection ────────────────────────────────────────────────────
|
||||
@@ -1356,6 +1597,53 @@ func (p *AdventurePlugin) handleRecipesCmd(ctx MessageContext) error {
|
||||
return p.SendDM(ctx.Sender, renderRecipesKnown(char.ForagingSkill))
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) handleTreasuresCmd(ctx MessageContext, arg string) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
char, err := loadAdvCharacter(ctx.Sender)
|
||||
if err != nil || char == nil {
|
||||
return p.SendDM(ctx.Sender, "Failed to load your character.")
|
||||
}
|
||||
|
||||
switch arg {
|
||||
case "lock":
|
||||
char.TreasuresLocked = true
|
||||
if err := saveAdvCharacter(char); err != nil {
|
||||
slog.Error("adventure: failed to save treasures_locked", "user", ctx.Sender, "err", err)
|
||||
return p.SendDM(ctx.Sender, "Something went wrong. Try again.")
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "🔒 **Treasures locked.** Drops at cap will be refused — no auto-swap. Unlock with `!adventure treasures unlock`.")
|
||||
case "unlock":
|
||||
char.TreasuresLocked = false
|
||||
if err := saveAdvCharacter(char); err != nil {
|
||||
slog.Error("adventure: failed to save treasures_locked", "user", ctx.Sender, "err", err)
|
||||
return p.SendDM(ctx.Sender, "Something went wrong. Try again.")
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "🔓 **Treasures unlocked.** Higher-tier drops will auto-swap your lowest replaceable treasure (with 10-min undo).")
|
||||
case "":
|
||||
treasures, err := advUserTreasures(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Failed to load your treasures.")
|
||||
}
|
||||
return p.SendDM(ctx.Sender, renderAdvTreasureList(treasures, char.TreasuresLocked))
|
||||
default:
|
||||
return p.SendDM(ctx.Sender, "Usage: `!adventure treasures` (list) · `!adventure treasures lock` · `!adventure treasures unlock`")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) handleMasteryCmd(ctx MessageContext) error {
|
||||
if _, _, err := p.ensureCharacter(ctx.Sender); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Failed to load your character.")
|
||||
}
|
||||
equip, err := loadAdvEquipment(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Failed to load your equipment.")
|
||||
}
|
||||
return p.SendDM(ctx.Sender, renderAdvMasteryView(equip))
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) handleBoostCmd(ctx MessageContext) error {
|
||||
if !p.IsAdmin(ctx.Sender) {
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand/v2"
|
||||
"time"
|
||||
@@ -643,6 +644,139 @@ type AdvActionResult struct {
|
||||
NearDeath bool
|
||||
StreakBonus int
|
||||
CombatLog *CombatResult
|
||||
// MasteryCrossings records equipment slots whose ActionsUsed crossed a
|
||||
// mastery threshold (advMasteryThresholds) on this action. The caller
|
||||
// uses this to DM a celebration so the silent counter becomes visible.
|
||||
MasteryCrossings []AdvMasteryCrossing
|
||||
}
|
||||
|
||||
type AdvMasteryCrossing struct {
|
||||
Slot EquipmentSlot
|
||||
ItemName string
|
||||
Threshold int // 50, 100, or 250
|
||||
}
|
||||
|
||||
// advMasteryThresholds defines the action counts at which equipment mastery
|
||||
// is celebrated. Picked to span an early-game milestone (50), a mid-game
|
||||
// commitment (100), and a hard-to-reach veteran tier (250).
|
||||
var advMasteryThresholds = []int{50, 100, 250}
|
||||
|
||||
// advMasteryTier reports how many mastery thresholds a piece has crossed
|
||||
// (0–3) and the next threshold. nextThreshold is 0 when the piece has
|
||||
// already crossed every threshold.
|
||||
func advMasteryTier(actionsUsed int) (tier, nextThreshold int) {
|
||||
for _, t := range advMasteryThresholds {
|
||||
if actionsUsed >= t {
|
||||
tier++
|
||||
} else {
|
||||
nextThreshold = t
|
||||
break
|
||||
}
|
||||
}
|
||||
return tier, nextThreshold
|
||||
}
|
||||
|
||||
// advMasteryMarker returns the visual tier marker for a piece of equipment.
|
||||
// Empty for sub-50; ✦/✦✦/✦✦✦ at the 50/100/250 thresholds.
|
||||
func advMasteryMarker(actionsUsed int) string {
|
||||
tier, _ := advMasteryTier(actionsUsed)
|
||||
switch tier {
|
||||
case 1:
|
||||
return "✦"
|
||||
case 2:
|
||||
return "✦✦"
|
||||
case 3:
|
||||
return "✦✦✦"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// advSlotRelevantToActivity reports whether using a slot during the given
|
||||
// activity should count toward that slot's mastery. Combat actions exercise
|
||||
// the combat loadout (weapon/armor/helmet/boots); harvest actions exercise
|
||||
// only the tool. This is what makes mastery feel like "you used this
|
||||
// piece" rather than "you played for a while" — without this gate every
|
||||
// slot ticks in lockstep and the per-slot view is meaningless.
|
||||
func advSlotRelevantToActivity(slot EquipmentSlot, activity AdvActivityType) bool {
|
||||
if isCombatActivity(activity) {
|
||||
return slot == SlotWeapon || slot == SlotArmor || slot == SlotHelmet || slot == SlotBoots
|
||||
}
|
||||
if isHarvestActivity(activity) {
|
||||
return slot == SlotTool
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// advMasteryRowSegment formats the `23/50`, `73/100 ✦`, `142/250 ✦✦`, or
|
||||
// `250 ✦✦✦` segment shown inline on each equipment row in the character
|
||||
// sheet so progress is visible at a glance — not just a tier marker that
|
||||
// flips on at 50/100/250 with nothing in between.
|
||||
func advMasteryRowSegment(actionsUsed int) string {
|
||||
if actionsUsed <= 0 {
|
||||
return ""
|
||||
}
|
||||
_, next := advMasteryTier(actionsUsed)
|
||||
marker := advMasteryMarker(actionsUsed)
|
||||
if next == 0 {
|
||||
// At max — there's no "next" threshold to count toward.
|
||||
return fmt.Sprintf("%d %s", actionsUsed, marker)
|
||||
}
|
||||
if marker == "" {
|
||||
return fmt.Sprintf("%d/%d", actionsUsed, next)
|
||||
}
|
||||
return fmt.Sprintf("%d/%d %s", actionsUsed, next, marker)
|
||||
}
|
||||
|
||||
// AdvMasteryRollup summarizes mastery state across all equipped slots so the
|
||||
// character sheet can show one informative aggregate line without a
|
||||
// per-slot block. AnyProgress is true when at least one slot has any
|
||||
// ActionsUsed — used to decide whether to show a "building up" hint when
|
||||
// no thresholds have crossed yet.
|
||||
type AdvMasteryRollup struct {
|
||||
ThresholdsCrossed int // raw count, pre-cap (sum across all slots)
|
||||
MaxedSlots int // slots with all 3 thresholds crossed
|
||||
Bonus float64 // capped %, mirrors advEquipmentMasteryBonus
|
||||
AnyProgress bool
|
||||
}
|
||||
|
||||
func advMasteryRollup(equip map[EquipmentSlot]*AdvEquipment) AdvMasteryRollup {
|
||||
r := AdvMasteryRollup{}
|
||||
for _, eq := range equip {
|
||||
if eq == nil {
|
||||
continue
|
||||
}
|
||||
if eq.ActionsUsed > 0 {
|
||||
r.AnyProgress = true
|
||||
}
|
||||
tier, _ := advMasteryTier(eq.ActionsUsed)
|
||||
r.ThresholdsCrossed += tier
|
||||
if tier == len(advMasteryThresholds) {
|
||||
r.MaxedSlots++
|
||||
}
|
||||
}
|
||||
r.Bonus = advEquipmentMasteryBonus(equip)
|
||||
return r
|
||||
}
|
||||
|
||||
// advEquipmentMasteryBonus returns the loot-quality bonus from accumulated
|
||||
// mastery across all equipped slots. Each crossed threshold grants +1% loot
|
||||
// quality on its slot, capped at +10% total to keep balance reasonable.
|
||||
func advEquipmentMasteryBonus(equip map[EquipmentSlot]*AdvEquipment) float64 {
|
||||
total := 0.0
|
||||
for _, eq := range equip {
|
||||
if eq == nil {
|
||||
continue
|
||||
}
|
||||
for _, t := range advMasteryThresholds {
|
||||
if eq.ActionsUsed >= t {
|
||||
total++
|
||||
}
|
||||
}
|
||||
}
|
||||
if total > 10 {
|
||||
total = 10
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func resolveAdvAction(char *AdventureCharacter, equip map[EquipmentSlot]*AdvEquipment, loc *AdvLocation, bonuses *AdvBonusSummary, inPenaltyZone bool) *AdvActionResult {
|
||||
@@ -651,6 +785,12 @@ func resolveAdvAction(char *AdventureCharacter, equip map[EquipmentSlot]*AdvEqui
|
||||
XPSkill: advXPSkill(loc.Activity),
|
||||
}
|
||||
|
||||
// Apply equipment-mastery loot bonus on a local copy so we don't mutate
|
||||
// the caller's bonuses struct (it's reused across multiple actions).
|
||||
localBonuses := *bonuses
|
||||
localBonuses.LootQuality += advEquipmentMasteryBonus(equip)
|
||||
bonuses = &localBonuses
|
||||
|
||||
probs := calculateAdvProbabilities(char, equip, loc, bonuses, inPenaltyZone)
|
||||
|
||||
// Overlevel penalty — reduces loot and XP for farming low-tier content
|
||||
@@ -718,9 +858,28 @@ func resolveAdvAction(char *AdventureCharacter, equip map[EquipmentSlot]*AdvEqui
|
||||
result.EquipBroken = advCheckBrokenEquipment(equip)
|
||||
}
|
||||
|
||||
// Increment actions_used for equipment mastery
|
||||
for _, eq := range equip {
|
||||
// Increment actions_used for equipment mastery only on slots relevant
|
||||
// to the activity — a foraging trip shouldn't master a sword, and a
|
||||
// dungeon run shouldn't master a pickaxe. Detect threshold crossings
|
||||
// so the caller can DM a celebration.
|
||||
for slot, eq := range equip {
|
||||
if eq == nil {
|
||||
continue
|
||||
}
|
||||
if !advSlotRelevantToActivity(slot, loc.Activity) {
|
||||
continue
|
||||
}
|
||||
before := eq.ActionsUsed
|
||||
eq.ActionsUsed++
|
||||
for _, t := range advMasteryThresholds {
|
||||
if before < t && eq.ActionsUsed >= t {
|
||||
result.MasteryCrossings = append(result.MasteryCrossings, AdvMasteryCrossing{
|
||||
Slot: slot,
|
||||
ItemName: eq.Name,
|
||||
Threshold: t,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -762,9 +921,10 @@ func resolveAdvEmptyOutcome(loc *AdvLocation, _ float64) AdvOutcomeType {
|
||||
// ── Eligible Locations for DM Menu ───────────────────────────────────────────
|
||||
|
||||
type AdvEligibleLocation struct {
|
||||
Location *AdvLocation
|
||||
InPenaltyZone bool
|
||||
DeathPct float64
|
||||
Location *AdvLocation
|
||||
InPenaltyZone bool
|
||||
DeathPct float64
|
||||
ExceptionalPct float64
|
||||
}
|
||||
|
||||
func advEligibleLocations(char *AdventureCharacter, equip map[EquipmentSlot]*AdvEquipment, activity AdvActivityType, bonuses *AdvBonusSummary) []AdvEligibleLocation {
|
||||
@@ -777,9 +937,10 @@ func advEligibleLocations(char *AdventureCharacter, equip map[EquipmentSlot]*Adv
|
||||
}
|
||||
probs := calculateAdvProbabilities(char, equip, &loc, bonuses, penalty)
|
||||
eligible = append(eligible, AdvEligibleLocation{
|
||||
Location: &loc,
|
||||
InPenaltyZone: penalty,
|
||||
DeathPct: probs.DeathPct,
|
||||
Location: &loc,
|
||||
InPenaltyZone: penalty,
|
||||
DeathPct: probs.DeathPct,
|
||||
ExceptionalPct: probs.ExceptionalPct,
|
||||
})
|
||||
}
|
||||
return eligible
|
||||
|
||||
@@ -319,7 +319,16 @@ func (p *AdventurePlugin) resolveArenaSurvival(ctx MessageContext, run *ArenaRun
|
||||
// Render combat log as phased messages + final outcome
|
||||
phaseMessages := RenderCombatLogArena(result, char.DisplayName, monster.Name)
|
||||
phaseMessages = p.prependCraftNarrative(ctx.Sender, phaseMessages)
|
||||
if open := dndCombatOpeningLine(); open != "" && len(phaseMessages) > 0 {
|
||||
phaseMessages[0] = "_" + open + "_\n\n" + phaseMessages[0]
|
||||
}
|
||||
finalMessage := renderArenaCombatFinalMessage(result, monster, reward, battleXP, run.Round)
|
||||
// Boss = T5 final round. Use BossDeath flavor for that fight's win.
|
||||
isBoss := run.Tier == 5
|
||||
finalMessage += dndItalicize(dndCombatClosingLine(true, isBoss))
|
||||
if rollLine := dndRollSummaryLine(result); rollLine != "" {
|
||||
finalMessage += "\n" + rollLine
|
||||
}
|
||||
|
||||
// Suppress the "(at risk)" line on the tier-completing round — those earnings
|
||||
// are about to be locked in by the tier-complete branch below, so labelling
|
||||
@@ -413,6 +422,9 @@ func (p *AdventurePlugin) resolveArenaDeath(ctx MessageContext, run *ArenaRun, c
|
||||
lostEarnings := run.Earnings + run.TierEarnings
|
||||
|
||||
phaseMessages := RenderCombatLogArena(result, char.DisplayName, monster.Name)
|
||||
if open := dndCombatOpeningLine(); open != "" && len(phaseMessages) > 0 {
|
||||
phaseMessages[0] = "_" + open + "_\n\n" + phaseMessages[0]
|
||||
}
|
||||
|
||||
dt := transitionDeath(DeathTransitionParams{
|
||||
Char: char,
|
||||
@@ -442,6 +454,10 @@ func (p *AdventurePlugin) resolveArenaDeath(ctx MessageContext, run *ArenaRun, c
|
||||
upsertArenaStats(run.UserID, 0, true, run.Tier)
|
||||
|
||||
finalMsg := renderArenaCombatFinalMessage(result, monster, 0, arenaParticipationXP, run.Round)
|
||||
finalMsg += dndItalicize(dndCombatClosingLine(false, false))
|
||||
if rollLine := dndRollSummaryLine(result); rollLine != "" {
|
||||
finalMsg += "\n" + rollLine
|
||||
}
|
||||
if dt.PetRecovered {
|
||||
finalMsg += fmt.Sprintf("\n\nYour pet dragged you out of the arena. Death timer reduced. All session earnings forfeited.")
|
||||
} else {
|
||||
|
||||
@@ -74,16 +74,57 @@ func (p *AdventurePlugin) handleBabysitCmd(ctx MessageContext, args string) erro
|
||||
return p.handleBabysitPurchase(ctx, 30)
|
||||
case lower == "auto":
|
||||
return p.handleBabysitAutoToggle(ctx)
|
||||
case strings.HasPrefix(lower, "focus"):
|
||||
return p.handleBabysitFocus(ctx, strings.TrimSpace(strings.TrimPrefix(lower, "focus")))
|
||||
default:
|
||||
return p.SendDM(ctx.Sender, "🍼 **Adventurer Babysitting Service**\n\n"+
|
||||
"`!adventure babysit week` — 7 days of service\n"+
|
||||
"`!adventure babysit month` — 30 days of service\n"+
|
||||
"`!adventure babysit auto` — toggle auto-babysit on missed days\n"+
|
||||
"`!adventure babysit focus <mining|fishing|foraging>` — pick the skill auto-babysit trains\n"+
|
||||
"`!adventure babysit status` — check service status\n"+
|
||||
"`!adventure babysit cancel` — cancel early (no refund)")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) handleBabysitFocus(ctx MessageContext, arg string) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
char, err := loadAdvCharacter(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "No adventurer found. Type `!adventure` to create one.")
|
||||
}
|
||||
|
||||
switch arg {
|
||||
case "":
|
||||
current := char.AutoBabysitFocus
|
||||
if current == "" {
|
||||
current = "weakest skill (default)"
|
||||
}
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"🎯 **Auto-babysit focus:** %s\n\nSet with `!adventure babysit focus <mining|fishing|foraging>`. Use `!adventure babysit focus clear` to revert to the weakest-skill default.",
|
||||
current))
|
||||
case "clear", "default", "weakest", "off":
|
||||
char.AutoBabysitFocus = ""
|
||||
case "mining", "fishing", "foraging":
|
||||
char.AutoBabysitFocus = arg
|
||||
default:
|
||||
return p.SendDM(ctx.Sender, "Pick one of `mining`, `fishing`, `foraging`, or `clear`.")
|
||||
}
|
||||
|
||||
if err := saveAdvCharacter(char); err != nil {
|
||||
slog.Error("babysit: failed to save focus", "user", ctx.Sender, "err", err)
|
||||
return p.SendDM(ctx.Sender, "Something went wrong. Try again.")
|
||||
}
|
||||
|
||||
if char.AutoBabysitFocus == "" {
|
||||
return p.SendDM(ctx.Sender, "🎯 Auto-babysit focus cleared. The babysitter will train your weakest skill.")
|
||||
}
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("🎯 Auto-babysit focus set to **%s**. The babysitter will train this on missed days.", char.AutoBabysitFocus))
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) handleBabysitAutoToggle(ctx MessageContext) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
@@ -348,13 +389,24 @@ func (p *AdventurePlugin) runBabysitAction(char *AdventureCharacter, equip map[E
|
||||
return int(result.TotalLootValue), result.XPGained, items
|
||||
}
|
||||
|
||||
// AutoBabysitDayResult summarizes one day of auto-babysit work, surfaced in
|
||||
// the morning DM so the babysitter feels like a companion that did
|
||||
// something rather than a silent insurance product.
|
||||
type AutoBabysitDayResult struct {
|
||||
Skill string
|
||||
Gold int
|
||||
XP int
|
||||
Items []string
|
||||
Highlight bool // true if the day produced an unusually large single haul or multiple item finds
|
||||
}
|
||||
|
||||
// runAutoBabysitDay runs a single day of babysit actions for auto-babysit.
|
||||
// Called by the scheduler when a player with auto-babysit enabled misses a day.
|
||||
func (p *AdventurePlugin) runAutoBabysitDay(char *AdventureCharacter) {
|
||||
func (p *AdventurePlugin) runAutoBabysitDay(char *AdventureCharacter) AutoBabysitDayResult {
|
||||
equip, err := loadAdvEquipment(char.UserID)
|
||||
if err != nil {
|
||||
slog.Error("auto-babysit: failed to load equipment", "user", char.UserID, "err", err)
|
||||
return
|
||||
return AutoBabysitDayResult{}
|
||||
}
|
||||
|
||||
isHol, _ := isHolidayToday()
|
||||
@@ -364,17 +416,29 @@ func (p *AdventurePlugin) runAutoBabysitDay(char *AdventureCharacter) {
|
||||
}
|
||||
|
||||
bonuses := &AdvBonusSummary{}
|
||||
skill := babysitWeakestSkill(char)
|
||||
// Honor a player-set focus if it's a valid harvest skill; otherwise
|
||||
// fall back to the weakest-skill default.
|
||||
skill := char.AutoBabysitFocus
|
||||
switch skill {
|
||||
case "mining", "fishing", "foraging":
|
||||
// player preference
|
||||
default:
|
||||
skill = babysitWeakestSkill(char)
|
||||
}
|
||||
activity := skillToActivity(skill)
|
||||
|
||||
var totalGold int
|
||||
var totalXP int
|
||||
var allItems []string
|
||||
bestSingleHaul := 0
|
||||
for char.HarvestActionsUsed < harvestMax {
|
||||
gold, xp, items := p.runBabysitAction(char, equip, activity, bonuses)
|
||||
totalGold += gold
|
||||
totalXP += xp
|
||||
allItems = append(allItems, items...)
|
||||
if gold > bestSingleHaul {
|
||||
bestSingleHaul = gold
|
||||
}
|
||||
char.HarvestActionsUsed++
|
||||
}
|
||||
|
||||
@@ -387,6 +451,14 @@ func (p *AdventurePlugin) runAutoBabysitDay(char *AdventureCharacter) {
|
||||
}
|
||||
logBabysitActivity(char.UserID, string(activity), "auto_babysit_daily",
|
||||
totalGold, totalXP, itemsJSON)
|
||||
|
||||
return AutoBabysitDayResult{
|
||||
Skill: skill,
|
||||
Gold: totalGold,
|
||||
XP: totalXP,
|
||||
Items: allItems,
|
||||
Highlight: bestSingleHaul >= 200 || len(allItems) >= 2,
|
||||
}
|
||||
}
|
||||
|
||||
// ── Expiry Check ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -94,6 +94,8 @@ type AdventureCharacter struct {
|
||||
PetLevel10Date string
|
||||
PetMorningDefense bool
|
||||
AutoBabysit bool
|
||||
AutoBabysitFocus string // mining|fishing|foraging — preferred skill for auto-babysit; "" defaults to weakest
|
||||
TreasuresLocked bool // when true, treasure drops at cap are refused instead of auto-swapping
|
||||
StreakDecayed bool
|
||||
CraftsSucceeded int
|
||||
DeathSource string // "adventure" | "arena" | "" (legacy/unknown — treated as adventure)
|
||||
@@ -378,7 +380,17 @@ func xpToNextLevel(level int) int {
|
||||
|
||||
// checkAdvLevelUp checks if a character leveled up in the given skill and applies it.
|
||||
// Returns whether a level-up occurred and the new level.
|
||||
//
|
||||
// Combat is special-cased: once a player has confirmed a D&D character,
|
||||
// combat_level freezes. dnd_level (driven by dnd_xp via grantDnDXP) is
|
||||
// canonical going forward. Combat XP still accrues into combat_xp for
|
||||
// historical display, but never causes combat_level to advance.
|
||||
// Skill levels (mining/foraging/fishing) are unaffected and continue to
|
||||
// progress on their own track per v1.1 §4.
|
||||
func checkAdvLevelUp(char *AdventureCharacter, skill string) (bool, int) {
|
||||
if skill == "combat" && HasCompletedSetup(char.UserID) {
|
||||
return false, char.CombatLevel
|
||||
}
|
||||
var xp *int
|
||||
var level *int
|
||||
switch skill {
|
||||
@@ -426,7 +438,7 @@ func loadAdvCharacter(userID id.UserID) (*AdventureCharacter, error) {
|
||||
|
||||
var houseFrozen, houseAutopay int
|
||||
var petChasedAway, petReactivated, petArrived, thomAnimalLine, petSupplyUnlocked, petMorningDef int
|
||||
var autoBabysit, streakDecayed int
|
||||
var autoBabysit, streakDecayed, treasuresLocked int
|
||||
|
||||
err := d.QueryRow(`
|
||||
SELECT user_id, display_name,
|
||||
@@ -453,7 +465,7 @@ func loadAdvCharacter(userID id.UserID) (*AdventureCharacter, error) {
|
||||
misty_encounter_count, misty_donated_count,
|
||||
thom_animal_line_fired, pet_supply_shop_unlocked, pet_level10_date,
|
||||
pet_morning_defense, auto_babysit, streak_decayed, crafts_succeeded,
|
||||
death_source, death_location
|
||||
death_source, death_location, auto_babysit_focus, treasures_locked
|
||||
FROM adventure_characters WHERE user_id = ?`, string(userID)).Scan(
|
||||
&c.UserID, &c.DisplayName,
|
||||
&c.CombatLevel, &c.MiningSkill, &c.ForagingSkill, &c.FishingSkill,
|
||||
@@ -479,7 +491,7 @@ func loadAdvCharacter(userID id.UserID) (*AdventureCharacter, error) {
|
||||
&c.MistyEncounterCount, &c.MistyDonatedCount,
|
||||
&thomAnimalLine, &petSupplyUnlocked, &c.PetLevel10Date,
|
||||
&petMorningDef, &autoBabysit, &streakDecayed, &c.CraftsSucceeded,
|
||||
&c.DeathSource, &c.DeathLocation,
|
||||
&c.DeathSource, &c.DeathLocation, &c.AutoBabysitFocus, &treasuresLocked,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -491,6 +503,7 @@ func loadAdvCharacter(userID id.UserID) (*AdventureCharacter, error) {
|
||||
c.BabysitActive = babysitAct == 1
|
||||
c.PetMorningDefense = petMorningDef == 1
|
||||
c.AutoBabysit = autoBabysit == 1
|
||||
c.TreasuresLocked = treasuresLocked == 1
|
||||
c.StreakDecayed = streakDecayed == 1
|
||||
if deadUntil.Valid {
|
||||
c.DeadUntil = &deadUntil.Time
|
||||
@@ -650,7 +663,9 @@ func saveAdvCharacter(char *AdventureCharacter) error {
|
||||
streak_decayed = ?,
|
||||
crafts_succeeded = ?,
|
||||
death_source = ?,
|
||||
death_location = ?
|
||||
death_location = ?,
|
||||
auto_babysit_focus = ?,
|
||||
treasures_locked = ?
|
||||
WHERE user_id = ?`,
|
||||
char.DisplayName, char.CombatLevel, char.MiningSkill, char.ForagingSkill, char.FishingSkill,
|
||||
char.CombatXP, char.MiningXP, char.ForagingXP, char.FishingXP,
|
||||
@@ -678,11 +693,20 @@ func saveAdvCharacter(char *AdventureCharacter) error {
|
||||
streakDecayed,
|
||||
char.CraftsSucceeded,
|
||||
char.DeathSource, char.DeathLocation,
|
||||
char.AutoBabysitFocus,
|
||||
boolToInt(char.TreasuresLocked),
|
||||
string(char.UserID),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func boolToInt(b bool) int {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func loadAdvEquipment(userID id.UserID) (map[EquipmentSlot]*AdvEquipment, error) {
|
||||
d := db.Get()
|
||||
rows, err := d.Query(`
|
||||
@@ -809,7 +833,7 @@ func loadAllAdvCharacters() ([]AdventureCharacter, error) {
|
||||
misty_encounter_count, misty_donated_count,
|
||||
thom_animal_line_fired, pet_supply_shop_unlocked, pet_level10_date,
|
||||
pet_morning_defense, auto_babysit, streak_decayed, crafts_succeeded,
|
||||
death_source, death_location
|
||||
death_source, death_location, auto_babysit_focus, treasures_locked
|
||||
FROM adventure_characters`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -824,7 +848,7 @@ func loadAllAdvCharacters() ([]AdventureCharacter, error) {
|
||||
var mistyLastSeen, arinaLastSeen, mistyBuffExp, mistyDebuffExp, arinaBuffExp sql.NullTime
|
||||
var houseFrozen, houseAutopay int
|
||||
var petChasedAway, petReactivated, petArrived, thomAnimalLine, petSupplyUnlocked, petMorningDef int
|
||||
var autoBabysit, streakDecayed int
|
||||
var autoBabysit, streakDecayed, treasuresLocked int
|
||||
if err := rows.Scan(
|
||||
&c.UserID, &c.DisplayName,
|
||||
&c.CombatLevel, &c.MiningSkill, &c.ForagingSkill, &c.FishingSkill,
|
||||
@@ -850,7 +874,7 @@ func loadAllAdvCharacters() ([]AdventureCharacter, error) {
|
||||
&c.MistyEncounterCount, &c.MistyDonatedCount,
|
||||
&thomAnimalLine, &petSupplyUnlocked, &c.PetLevel10Date,
|
||||
&petMorningDef, &autoBabysit, &streakDecayed, &c.CraftsSucceeded,
|
||||
&c.DeathSource, &c.DeathLocation,
|
||||
&c.DeathSource, &c.DeathLocation, &c.AutoBabysitFocus, &treasuresLocked,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -861,6 +885,7 @@ func loadAllAdvCharacters() ([]AdventureCharacter, error) {
|
||||
c.BabysitActive = babysitAct == 1
|
||||
c.PetMorningDefense = petMorningDef == 1
|
||||
c.AutoBabysit = autoBabysit == 1
|
||||
c.TreasuresLocked = treasuresLocked == 1
|
||||
c.StreakDecayed = streakDecayed == 1
|
||||
c.HouseLoanFrozen = houseFrozen == 1
|
||||
c.HouseAutopay = houseAutopay == 1
|
||||
|
||||
@@ -28,6 +28,17 @@ var babysitDiaperLines = []string{
|
||||
"The diapers. They happened. They were handled. Moving on.",
|
||||
}
|
||||
|
||||
// babysitHighlightLines fire on auto-babysit days when the haul was unusually
|
||||
// good — making the babysitter feel like a companion rather than a silent
|
||||
// insurance product. Each line takes one %s slot for the focused skill name.
|
||||
var babysitHighlightLines = []string{
|
||||
"The babysitter says your kid was a natural at %s today. They want it noted.",
|
||||
"Solid day on the %s circuit, apparently. The babysitter looked smug about it.",
|
||||
"Whatever the babysitter did with your %s gear — it worked. The numbers don't lie.",
|
||||
"The babysitter handed in a %s haul and said nothing. The smug silence said plenty.",
|
||||
"Your kid is, against the odds, getting alarmingly good at %s under TwinBee's care.",
|
||||
}
|
||||
|
||||
// pickBabysitFlavor returns a random entry from the given pool.
|
||||
func pickBabysitFlavor(pool []string) string {
|
||||
if len(pool) == 0 {
|
||||
|
||||
@@ -529,51 +529,38 @@ var RespawnDM = []string{
|
||||
}
|
||||
|
||||
var IdleShameDM = []string{
|
||||
"{name}, you didn't leave the house today.\n\n" +
|
||||
"Your adventurer sat in their hovel, stared at the wall,\n" +
|
||||
"and achieved absolutely nothing. No loot. No XP. No death,\n" +
|
||||
"which is honestly the nicest thing that can be said about today.\n\n" +
|
||||
"Tomorrow's choices arrive at 08:00 UTC.\n" +
|
||||
"Please, for the love of everything, try to be brave.",
|
||||
"{name}, hey. Didn't see you out there today.\n\n" +
|
||||
"TwinBee swung by the hovel — door was shut, no answer.\n" +
|
||||
"Hope you're alright. The dungeon will keep. The mine will keep.\n" +
|
||||
"They've been there a while; they're patient.\n\n" +
|
||||
"Tomorrow: 08:00 UTC. We'll be ready when you are.",
|
||||
|
||||
"No action today, {name}.\n\n" +
|
||||
"The morning DM was sent. The morning DM was not answered.\n" +
|
||||
"The dungeon was there. The mine was there. The forest was there.\n" +
|
||||
"You were also there, presumably, somewhere, not responding.\n\n" +
|
||||
"TwinBee noticed. The daily summary has noted your absence.\n" +
|
||||
"Tomorrow: 08:00 UTC. The options will be there. Please be there too.",
|
||||
"Quiet day for you, {name}.\n\n" +
|
||||
"The morning DM went out and didn't come back. That happens.\n" +
|
||||
"Real life sometimes shows up uninvited and stays for dinner.\n" +
|
||||
"TwinBee picked up a little extra in the field — covered for you.\n\n" +
|
||||
"Tomorrow morning the choices reset. Drop by when you can.",
|
||||
|
||||
"{name}. You rested today.\n\n" +
|
||||
"'Rested' is the word being used. It is the charitable word.\n" +
|
||||
"The uncharitable word is 'nothing.' You did nothing.\n" +
|
||||
"The dungeons are still there. The mines are still there.\n" +
|
||||
"The foraging areas are still there. Your XP is still where you left it.\n\n" +
|
||||
"08:00 UTC tomorrow. An adventure awaits.\n" +
|
||||
"The adventure has been waiting since you ignored it this morning.",
|
||||
"{name}, no sign of you in the field today.\n\n" +
|
||||
"The forest is still there. So's the mine. So's that one rusted sword\n" +
|
||||
"you keep meaning to replace. Nothing important moved.\n\n" +
|
||||
"08:00 UTC tomorrow — fresh menu, same patient TwinBee.",
|
||||
|
||||
"Today passed without you, {name}.\n\n" +
|
||||
"TwinBee went to a dungeon. The dungeon was real.\n" +
|
||||
"Your share of TwinBee's haul was distributed to people who showed up.\n" +
|
||||
"You did not show up. You did not get a share.\n" +
|
||||
"TwinBee noticed. TwinBee says nothing.\n" +
|
||||
"TwinBee's silence is louder than most things.\n\n" +
|
||||
"Tomorrow: 08:00 UTC. Show up.",
|
||||
"Missed you out there, {name}.\n\n" +
|
||||
"TwinBee went on a haul today and saved a corner of the splits for you,\n" +
|
||||
"then ate it on principle when you didn't show. (Sorry. House rule.)\n" +
|
||||
"Nothing's lost that can't be earned back.\n\n" +
|
||||
"Tomorrow: 08:00 UTC. The dungeons are warm.",
|
||||
|
||||
"A day of rest, {name}. Unearned, but rest.\n\n" +
|
||||
"The hovel is comfortable. The wall is familiar.\n" +
|
||||
"Nothing in the hovel tried to kill you, which is the one advantage the hovel has.\n" +
|
||||
"The hovel also paid you nothing and taught you nothing and advanced nothing.\n" +
|
||||
"The hovel is comfortable and useless. So was today.\n\n" +
|
||||
"Tomorrow is 08:00 UTC. The choices will be new ones.\n" +
|
||||
"Make one of them. Any of them. Please.",
|
||||
"A quiet day, {name}. Those happen.\n\n" +
|
||||
"You weren't on the trail. The trail didn't fall apart without you.\n" +
|
||||
"It'll be there tomorrow, and the day after, and the one after that.\n\n" +
|
||||
"08:00 UTC. Whenever you're back, we pick up where we left off.",
|
||||
|
||||
"Where were you today, {name}?\n\n" +
|
||||
"The bot sent the DM. The DM was delivered.\n" +
|
||||
"The DM sat there, unread or unresponded-to, while your adventurer\n" +
|
||||
"sat in the hovel and the day happened without them.\n" +
|
||||
"XP: not gained. Loot: not found. Death: at least avoided.\n\n" +
|
||||
"Low bar. You cleared the low bar by doing nothing.\n" +
|
||||
"Tomorrow: 08:00 UTC. Clear a higher bar.",
|
||||
"{name}. Hope you had a good rest day.\n\n" +
|
||||
"TwinBee held down the fort. Nothing dramatic, nothing lost —\n" +
|
||||
"the world declined to end on your behalf, which feels generous.\n\n" +
|
||||
"When you're ready, the morning DM hits at 08:00 UTC. No rush.",
|
||||
}
|
||||
|
||||
var OnboardingDM = []string{
|
||||
|
||||
@@ -0,0 +1,466 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// ── Equipment Mastery ──────────────────────────────────────────────────────
|
||||
|
||||
func TestAdvEquipmentMasteryBonus(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
used map[EquipmentSlot]int
|
||||
want float64
|
||||
}{
|
||||
{"empty equip", nil, 0},
|
||||
{"all sub-50", map[EquipmentSlot]int{SlotWeapon: 49, SlotArmor: 1}, 0},
|
||||
{"one slot crossed first threshold", map[EquipmentSlot]int{SlotWeapon: 50}, 1},
|
||||
{"one slot at all three thresholds", map[EquipmentSlot]int{SlotWeapon: 250}, 3},
|
||||
{"mixed: 100 + 50", map[EquipmentSlot]int{SlotWeapon: 100, SlotArmor: 50}, 3},
|
||||
{"all 5 slots maxed = 15 raw, capped at 10", map[EquipmentSlot]int{
|
||||
SlotWeapon: 999, SlotArmor: 999, SlotHelmet: 999, SlotBoots: 999, SlotTool: 999,
|
||||
}, 10},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
equip := map[EquipmentSlot]*AdvEquipment{}
|
||||
for slot, used := range tc.used {
|
||||
equip[slot] = &AdvEquipment{ActionsUsed: used}
|
||||
}
|
||||
got := advEquipmentMasteryBonus(equip)
|
||||
if got != tc.want {
|
||||
t.Errorf("got %.1f, want %.1f", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdvSlotRelevantToActivity(t *testing.T) {
|
||||
cases := []struct {
|
||||
slot EquipmentSlot
|
||||
activity AdvActivityType
|
||||
want bool
|
||||
}{
|
||||
// Combat exercises the combat loadout.
|
||||
{SlotWeapon, AdvActivityDungeon, true},
|
||||
{SlotArmor, AdvActivityDungeon, true},
|
||||
{SlotHelmet, AdvActivityDungeon, true},
|
||||
{SlotBoots, AdvActivityDungeon, true},
|
||||
{SlotTool, AdvActivityDungeon, false}, // a dungeon shouldn't master a pickaxe
|
||||
|
||||
// Each harvest activity exercises only the tool.
|
||||
{SlotTool, AdvActivityMining, true},
|
||||
{SlotTool, AdvActivityForaging, true},
|
||||
{SlotTool, AdvActivityFishing, true},
|
||||
{SlotWeapon, AdvActivityMining, false}, // foraging shouldn't master a sword
|
||||
{SlotArmor, AdvActivityForaging, false},
|
||||
{SlotHelmet, AdvActivityFishing, false},
|
||||
{SlotBoots, AdvActivityMining, false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(fmt.Sprintf("%s_%s", tc.slot, tc.activity), func(t *testing.T) {
|
||||
if got := advSlotRelevantToActivity(tc.slot, tc.activity); got != tc.want {
|
||||
t.Errorf("got %v, want %v", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveAdvAction_MasteryOnlyCountsRelevantSlots(t *testing.T) {
|
||||
// A foraging action should bump tool but leave weapon/armor/helmet/boots
|
||||
// untouched. The reverse for combat.
|
||||
char := &AdventureCharacter{
|
||||
CombatLevel: 5, ForagingSkill: 5, MiningSkill: 5, FishingSkill: 5,
|
||||
}
|
||||
bonuses := &AdvBonusSummary{}
|
||||
|
||||
t.Run("foraging only bumps tool", func(t *testing.T) {
|
||||
loc := &AdvLocation{Name: "T", Tier: 1, Activity: AdvActivityForaging,
|
||||
MinLevel: 1, BaseDeathPct: 1, EmptyPct: 50}
|
||||
equip := map[EquipmentSlot]*AdvEquipment{
|
||||
SlotWeapon: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotArmor: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotHelmet: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotBoots: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotTool: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
}
|
||||
resolveAdvAction(char, equip, loc, bonuses, false)
|
||||
if equip[SlotTool].ActionsUsed != 11 {
|
||||
t.Errorf("tool should have advanced 10→11, got %d", equip[SlotTool].ActionsUsed)
|
||||
}
|
||||
for _, slot := range []EquipmentSlot{SlotWeapon, SlotArmor, SlotHelmet, SlotBoots} {
|
||||
if equip[slot].ActionsUsed != 10 {
|
||||
t.Errorf("%s should be unchanged at 10, got %d", slot, equip[slot].ActionsUsed)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("combat only bumps combat slots", func(t *testing.T) {
|
||||
loc := &AdvLocation{Name: "T", Tier: 1, Activity: AdvActivityDungeon,
|
||||
MinLevel: 1, BaseDeathPct: 1, EmptyPct: 50}
|
||||
equip := map[EquipmentSlot]*AdvEquipment{
|
||||
SlotWeapon: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotArmor: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotHelmet: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotBoots: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
SlotTool: {Tier: 1, Condition: 100, ActionsUsed: 10},
|
||||
}
|
||||
resolveAdvAction(char, equip, loc, bonuses, false)
|
||||
for _, slot := range []EquipmentSlot{SlotWeapon, SlotArmor, SlotHelmet, SlotBoots} {
|
||||
if equip[slot].ActionsUsed != 11 {
|
||||
t.Errorf("%s should have advanced 10→11, got %d", slot, equip[slot].ActionsUsed)
|
||||
}
|
||||
}
|
||||
if equip[SlotTool].ActionsUsed != 10 {
|
||||
t.Errorf("tool should be unchanged at 10, got %d", equip[SlotTool].ActionsUsed)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestResolveAdvAction_MasteryCrossingFiresOnceAtBoundary(t *testing.T) {
|
||||
// Action 49→50 should report a single crossing at threshold 50.
|
||||
// Action 50→51 should report none (idempotent past the boundary).
|
||||
loc := &AdvLocation{
|
||||
Name: "Test", Tier: 1, Activity: AdvActivityForaging,
|
||||
MinLevel: 1, MinEquipTier: 0, BaseDeathPct: 1, EmptyPct: 50,
|
||||
}
|
||||
char := &AdventureCharacter{
|
||||
CombatLevel: 5, ForagingSkill: 5, MiningSkill: 5, FishingSkill: 5,
|
||||
}
|
||||
bonuses := &AdvBonusSummary{}
|
||||
|
||||
mkEquip := func(used int) map[EquipmentSlot]*AdvEquipment {
|
||||
return map[EquipmentSlot]*AdvEquipment{
|
||||
SlotTool: {Tier: 1, Condition: 100, ActionsUsed: used},
|
||||
}
|
||||
}
|
||||
|
||||
res1 := resolveAdvAction(char, mkEquip(49), loc, bonuses, false)
|
||||
if got := len(res1.MasteryCrossings); got != 1 {
|
||||
t.Fatalf("49→50: expected 1 crossing, got %d", got)
|
||||
}
|
||||
if res1.MasteryCrossings[0].Threshold != 50 {
|
||||
t.Errorf("expected threshold 50, got %d", res1.MasteryCrossings[0].Threshold)
|
||||
}
|
||||
|
||||
res2 := resolveAdvAction(char, mkEquip(50), loc, bonuses, false)
|
||||
if got := len(res2.MasteryCrossings); got != 0 {
|
||||
t.Errorf("50→51: expected 0 crossings, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdvMasteryRowSegment(t *testing.T) {
|
||||
cases := []struct {
|
||||
used int
|
||||
want string
|
||||
}{
|
||||
{0, ""},
|
||||
{1, "1/50"},
|
||||
{49, "49/50"},
|
||||
{50, "50/100 ✦"},
|
||||
{99, "99/100 ✦"},
|
||||
{100, "100/250 ✦✦"},
|
||||
{249, "249/250 ✦✦"},
|
||||
{250, "250 ✦✦✦"},
|
||||
{500, "500 ✦✦✦"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(fmt.Sprintf("used=%d", tc.used), func(t *testing.T) {
|
||||
if got := advMasteryRowSegment(tc.used); got != tc.want {
|
||||
t.Errorf("got %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdvMasteryRollup(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
used map[EquipmentSlot]int
|
||||
wantCrossed int
|
||||
wantMaxed int
|
||||
wantBonus float64
|
||||
wantAnyProgress bool
|
||||
}{
|
||||
{"empty", nil, 0, 0, 0, false},
|
||||
{"sub-50 only", map[EquipmentSlot]int{SlotWeapon: 30}, 0, 0, 0, true},
|
||||
{"one slot 1 threshold", map[EquipmentSlot]int{SlotWeapon: 50}, 1, 0, 1, true},
|
||||
{"one slot maxed", map[EquipmentSlot]int{SlotWeapon: 250}, 3, 1, 3, true},
|
||||
{"two slots, 5 thresholds", map[EquipmentSlot]int{SlotWeapon: 100, SlotArmor: 250}, 5, 1, 5, true},
|
||||
{"all maxed = 15 raw, capped at 10", map[EquipmentSlot]int{
|
||||
SlotWeapon: 999, SlotArmor: 999, SlotHelmet: 999, SlotBoots: 999, SlotTool: 999,
|
||||
}, 15, 5, 10, true},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
equip := map[EquipmentSlot]*AdvEquipment{}
|
||||
for slot, used := range tc.used {
|
||||
equip[slot] = &AdvEquipment{ActionsUsed: used}
|
||||
}
|
||||
got := advMasteryRollup(equip)
|
||||
if got.ThresholdsCrossed != tc.wantCrossed {
|
||||
t.Errorf("ThresholdsCrossed: got %d, want %d", got.ThresholdsCrossed, tc.wantCrossed)
|
||||
}
|
||||
if got.MaxedSlots != tc.wantMaxed {
|
||||
t.Errorf("MaxedSlots: got %d, want %d", got.MaxedSlots, tc.wantMaxed)
|
||||
}
|
||||
if got.Bonus != tc.wantBonus {
|
||||
t.Errorf("Bonus: got %.1f, want %.1f", got.Bonus, tc.wantBonus)
|
||||
}
|
||||
if got.AnyProgress != tc.wantAnyProgress {
|
||||
t.Errorf("AnyProgress: got %v, want %v", got.AnyProgress, tc.wantAnyProgress)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderAdvMasteryAggregate(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
used map[EquipmentSlot]int
|
||||
wantEmpty bool
|
||||
wantSubstring []string
|
||||
wantNot []string
|
||||
}{
|
||||
{"no progress → empty", nil, true, nil, nil},
|
||||
{"sub-threshold progress → building up", map[EquipmentSlot]int{SlotWeapon: 30},
|
||||
false, []string{"building up", "first threshold at 50"}, []string{"+0%", "loot quality"}},
|
||||
{"one threshold crossed → singular threshold", map[EquipmentSlot]int{SlotWeapon: 50},
|
||||
false, []string{"+1% loot quality", "1 threshold crossed"}, []string{"thresholds", "maxed", "cap reached"}},
|
||||
{"three thresholds, no maxed → plural threshold no maxed", map[EquipmentSlot]int{SlotWeapon: 100, SlotArmor: 50},
|
||||
false, []string{"+3% loot quality", "3 thresholds crossed"}, []string{"maxed", "cap reached"}},
|
||||
{"one maxed + extras → mention maxed slot", map[EquipmentSlot]int{SlotWeapon: 250, SlotArmor: 50},
|
||||
false, []string{"+4% loot quality", "4 thresholds crossed", "1 slot maxed"}, []string{"cap reached", "slots maxed"}},
|
||||
{"capped → flag cap reached", map[EquipmentSlot]int{
|
||||
SlotWeapon: 250, SlotArmor: 250, SlotHelmet: 250, SlotBoots: 250, SlotTool: 250,
|
||||
}, false, []string{"+10% loot quality", "15 thresholds crossed", "5 slots maxed", "cap reached"}, nil},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
equip := map[EquipmentSlot]*AdvEquipment{}
|
||||
for slot, used := range tc.used {
|
||||
equip[slot] = &AdvEquipment{ActionsUsed: used}
|
||||
}
|
||||
got := renderAdvMasteryAggregate(equip)
|
||||
if tc.wantEmpty {
|
||||
if got != "" {
|
||||
t.Fatalf("expected empty, got %q", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
if got == "" {
|
||||
t.Fatalf("expected non-empty, got empty")
|
||||
}
|
||||
for _, s := range tc.wantSubstring {
|
||||
if !strings.Contains(got, s) {
|
||||
t.Errorf("expected to contain %q, got %q", s, got)
|
||||
}
|
||||
}
|
||||
for _, s := range tc.wantNot {
|
||||
if strings.Contains(got, s) {
|
||||
t.Errorf("should not contain %q, got %q", s, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ── Treasure Rank Ordering ─────────────────────────────────────────────────
|
||||
|
||||
func TestAdvTreasureRank_Ordering(t *testing.T) {
|
||||
t5 := &AdvTreasureDef{Key: "a", Tier: 5, Bonuses: []advTreasureBonusDef{{Type: "all_skills", Value: 5}}}
|
||||
t3multi := &AdvTreasureDef{Key: "b", Tier: 3, Bonuses: []advTreasureBonusDef{
|
||||
{Type: "combat_level", Value: 1}, {Type: "death_chance", Value: -1},
|
||||
}}
|
||||
t3single := &AdvTreasureDef{Key: "c", Tier: 3, Bonuses: []advTreasureBonusDef{{Type: "loot_quality", Value: 5}}}
|
||||
t3same := &AdvTreasureDef{Key: "d", Tier: 3, Bonuses: []advTreasureBonusDef{{Type: "loot_quality", Value: 5}}}
|
||||
|
||||
if !advTreasureRankBetter(advTreasureRank(t5), advTreasureRank(t3multi)) {
|
||||
t.Error("T5 should beat T3 regardless of bonus count")
|
||||
}
|
||||
if !advTreasureRankBetter(advTreasureRank(t3multi), advTreasureRank(t3single)) {
|
||||
t.Error("equal tier: more bonuses should win")
|
||||
}
|
||||
if advTreasureRankBetter(advTreasureRank(t3single), advTreasureRank(t3same)) {
|
||||
t.Error("equal tier and bonus count: should NOT be strictly better (no churn)")
|
||||
}
|
||||
if advTreasureRankBetter(advTreasureRank(t3same), advTreasureRank(t3single)) {
|
||||
t.Error("equal tier and bonus count, reversed: also not strictly better")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdvTreasureIrreplaceable(t *testing.T) {
|
||||
special := &AdvTreasureDef{Bonuses: []advTreasureBonusDef{{Type: "special_respawn_halve", Value: 1}}}
|
||||
mixed := &AdvTreasureDef{Bonuses: []advTreasureBonusDef{
|
||||
{Type: "all_skills", Value: 5}, {Type: "special_monthly_death_bypass", Value: 1},
|
||||
}}
|
||||
regular := &AdvTreasureDef{Bonuses: []advTreasureBonusDef{{Type: "loot_quality", Value: 10}}}
|
||||
none := &AdvTreasureDef{}
|
||||
|
||||
if !advTreasureIrreplaceable(special) {
|
||||
t.Error("special_* bonus should mark irreplaceable")
|
||||
}
|
||||
if !advTreasureIrreplaceable(mixed) {
|
||||
t.Error("any special_* among bonuses should mark irreplaceable")
|
||||
}
|
||||
if advTreasureIrreplaceable(regular) {
|
||||
t.Error("regular bonuses should not be irreplaceable")
|
||||
}
|
||||
if advTreasureIrreplaceable(none) {
|
||||
t.Error("zero bonuses is not irreplaceable")
|
||||
}
|
||||
if advTreasureIrreplaceable(nil) {
|
||||
t.Error("nil should not be irreplaceable")
|
||||
}
|
||||
}
|
||||
|
||||
// ── Crafting Teaser Boundaries ─────────────────────────────────────────────
|
||||
|
||||
func TestRenderCraftingTeaser_BracketBoundaries(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
foraging int
|
||||
craftsSucceeded int
|
||||
wantEmpty bool
|
||||
wantContainsAny []string // any of these (OR)
|
||||
wantNotContains []string
|
||||
}{
|
||||
{"foraging 6 — out of pre-window", 6, 0, true, nil, nil},
|
||||
{"foraging 7 — pre-unlock with 3 levels left, plural", 7, 0, false, []string{"3 Foraging level"}, []string{"unlocks in 1 ", "unlocks in 0"}},
|
||||
{"foraging 9 — pre-unlock with 1 level, singular", 9, 0, false, []string{"1 Foraging level"}, []string{"levels"}},
|
||||
{"foraging 10, no crafts yet — unlocked nudge", 10, 0, false, []string{"Crafting is unlocked"}, []string{"unlocks in"}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
char := &AdventureCharacter{
|
||||
ForagingSkill: tc.foraging,
|
||||
CraftsSucceeded: tc.craftsSucceeded,
|
||||
}
|
||||
got := renderCraftingTeaser(char)
|
||||
if tc.wantEmpty {
|
||||
if got != "" {
|
||||
t.Errorf("expected empty, got %q", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
if got == "" {
|
||||
t.Fatalf("expected non-empty teaser, got empty")
|
||||
}
|
||||
for _, s := range tc.wantContainsAny {
|
||||
if strings.Contains(got, s) {
|
||||
goto matched
|
||||
}
|
||||
}
|
||||
t.Errorf("expected any of %v, got %q", tc.wantContainsAny, got)
|
||||
matched:
|
||||
for _, bad := range tc.wantNotContains {
|
||||
if strings.Contains(got, bad) {
|
||||
t.Errorf("output should not contain %q, got %q", bad, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCraftingReminderWeekday_Spread(t *testing.T) {
|
||||
// Across many synthetic users in the same week, the per-player weekday
|
||||
// should land on most weekdays (uniform-ish hash). Asserting "≥ 4 of 7"
|
||||
// is a loose sanity check that catches a constant or pathological hash.
|
||||
now := time.Date(2026, 5, 4, 12, 0, 0, 0, time.UTC)
|
||||
hits := map[int]bool{}
|
||||
for i := 0; i < 100; i++ {
|
||||
uid := id.UserID(strings.Repeat("a", i+1) + "@test:local")
|
||||
hits[craftingReminderWeekday(uid, now)] = true
|
||||
}
|
||||
if len(hits) < 5 {
|
||||
t.Errorf("expected weekday spread across most days, only hit %d distinct: %v", len(hits), hits)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCraftingReminderWeekday_StableWithinWeek(t *testing.T) {
|
||||
uid := id.UserID("@stable:test")
|
||||
mon := time.Date(2026, 5, 4, 0, 0, 0, 0, time.UTC) // Monday
|
||||
sun := time.Date(2026, 5, 10, 23, 0, 0, 0, time.UTC) // Sunday same ISO week
|
||||
if craftingReminderWeekday(uid, mon) != craftingReminderWeekday(uid, sun) {
|
||||
t.Error("weekday should be stable within an ISO week")
|
||||
}
|
||||
// Following ISO week — should differ for at least *some* users; not
|
||||
// guaranteed for every user but we test the rotation property exists.
|
||||
nextWeek := time.Date(2026, 5, 11, 0, 0, 0, 0, time.UTC)
|
||||
differs := 0
|
||||
for i := 0; i < 50; i++ {
|
||||
u := id.UserID(strings.Repeat("u", i+1) + "@x")
|
||||
if craftingReminderWeekday(u, mon) != craftingReminderWeekday(u, nextWeek) {
|
||||
differs++
|
||||
}
|
||||
}
|
||||
if differs == 0 {
|
||||
t.Error("expected the per-week hash to rotate at least some users between weeks")
|
||||
}
|
||||
}
|
||||
|
||||
// ── Co-op Teaser Leader Skip ───────────────────────────────────────────────
|
||||
|
||||
func TestPickCoopTeaserCandidate_SkipsLeader(t *testing.T) {
|
||||
me := id.UserID("@me:test")
|
||||
other := id.UserID("@other:test")
|
||||
|
||||
myRun := &CoopRun{ID: 1, Tier: 1, LeaderID: me}
|
||||
theirRunMatch := &CoopRun{ID: 2, Tier: 1, LeaderID: other}
|
||||
theirRunStretch := &CoopRun{ID: 3, Tier: 5, LeaderID: other}
|
||||
|
||||
char := &AdventureCharacter{UserID: me, CombatLevel: 10}
|
||||
|
||||
// Player leads run 1, qualifies for run 2 (T1 minLevel 5), under-level for run 3 (T5 minLevel 40).
|
||||
match, stretch := pickCoopTeaserCandidate([]*CoopRun{myRun, theirRunMatch, theirRunStretch}, char)
|
||||
if match == nil || match.ID != 2 {
|
||||
t.Errorf("expected match=run 2, got %v", match)
|
||||
}
|
||||
if stretch == nil || stretch.ID != 3 {
|
||||
t.Errorf("expected stretch=run 3, got %v", stretch)
|
||||
}
|
||||
|
||||
// Only own run open: nothing to surface.
|
||||
match, stretch = pickCoopTeaserCandidate([]*CoopRun{myRun}, char)
|
||||
if match != nil || stretch != nil {
|
||||
t.Errorf("expected both nil when only own run open; got match=%v stretch=%v", match, stretch)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Location Risk/Reward Numbers ───────────────────────────────────────────
|
||||
|
||||
func TestCalculateAdvProbabilities_RiskReward_NormalizesAcrossConfigs(t *testing.T) {
|
||||
// Risk/reward render line depends on these probabilities. Lock in that
|
||||
// they normalize to 100 across a few realistic configurations beyond
|
||||
// the existing single-config sum test.
|
||||
cases := []struct {
|
||||
name string
|
||||
char *AdventureCharacter
|
||||
loc *AdvLocation
|
||||
}{
|
||||
{"low-tier with low skill", &AdventureCharacter{ForagingSkill: 3},
|
||||
&AdvLocation{Activity: AdvActivityForaging, Tier: 1, BaseDeathPct: 5, EmptyPct: 30}},
|
||||
{"high-tier with high skill", &AdventureCharacter{ForagingSkill: 30},
|
||||
&AdvLocation{Activity: AdvActivityForaging, Tier: 4, BaseDeathPct: 25, EmptyPct: 20}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
equip := map[EquipmentSlot]*AdvEquipment{
|
||||
SlotTool: {Tier: 3, Condition: 100},
|
||||
}
|
||||
probs := calculateAdvProbabilities(tc.char, equip, tc.loc, &AdvBonusSummary{}, false)
|
||||
total := probs.DeathPct + probs.EmptyPct + probs.SuccessPct + probs.ExceptionalPct
|
||||
if total < 99.99 || total > 100.01 {
|
||||
t.Errorf("probabilities should sum to 100, got %.2f (%+v)", total, probs)
|
||||
}
|
||||
if probs.DeathPct < 0 || probs.ExceptionalPct < 0 {
|
||||
t.Errorf("negative probability: %+v", probs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"gogobee/internal/flavor"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
@@ -134,12 +135,15 @@ func (p *AdventurePlugin) npcFireEncounter(userID id.UserID, npc string) {
|
||||
case "misty":
|
||||
char.MistyLastSeen = &now
|
||||
char.MistyEncounterCount++
|
||||
opening = mistyOpenings[rand.IntN(len(mistyOpenings))]
|
||||
// Pool union: legacy mistyOpenings + D&D MistyGreeting flavor.
|
||||
mistyPool := dndMistyGreetingPool()
|
||||
opening = mistyPool[rand.IntN(len(mistyPool))]
|
||||
prompt = fmt.Sprintf("👤 A woman approaches you.\n\n_%s_\n\n"+
|
||||
"Reply `yes` to give €%d, or `no` to walk away.", opening, mistyCost)
|
||||
case "arina":
|
||||
char.ArinaLastSeen = &now
|
||||
opening = arinaOpenings[rand.IntN(len(arinaOpenings))]
|
||||
arinaPool := dndArinaGreetingPool()
|
||||
opening = arinaPool[rand.IntN(len(arinaPool))]
|
||||
prompt = fmt.Sprintf("💎 A woman in expensive clothing stops you.\n\n_%s_\n\n"+
|
||||
"Reply `yes` to pay €%d, or `no` to decline.", opening, arinaCost)
|
||||
}
|
||||
@@ -223,6 +227,9 @@ func (p *AdventurePlugin) resolveMisty(ctx MessageContext, char *AdventureCharac
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "You reach for your gold but there isn't enough. She sees this. She doesn't say anything.\n\n_"+mistyDeclineLine+"_")
|
||||
}
|
||||
// D&D Insight check — passing refunds the donation. Renders flavor on
|
||||
// either outcome (success or fail) when a check was attempted.
|
||||
insightCheck := dndNPCInsightRefund(ctx.Sender, p.euro, mistyCost)
|
||||
char.MistyBuffExpires = expires
|
||||
char.MistyDonatedCount++
|
||||
|
||||
@@ -241,6 +248,20 @@ func (p *AdventurePlugin) resolveMisty(ctx MessageContext, char *AdventureCharac
|
||||
reply += "\n\n_" + hint + "_"
|
||||
}
|
||||
|
||||
// Flavor for the D&D check outcome (when applicable).
|
||||
if insightCheck.Attempted {
|
||||
if insightCheck.Succeeded {
|
||||
if line := flavor.Pick(flavor.MistyInsightSuccess); line != "" {
|
||||
reply += "\n\n_" + line + "_"
|
||||
}
|
||||
reply += "\n\n_(Insight DC 12 passed — donation refunded.)_"
|
||||
} else {
|
||||
if line := flavor.Pick(flavor.MistySkillFail); line != "" {
|
||||
reply += "\n\n_" + line + "_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("_%s_", reply))
|
||||
}
|
||||
|
||||
@@ -264,13 +285,28 @@ func (p *AdventurePlugin) resolveArina(ctx MessageContext, char *AdventureCharac
|
||||
reply := arinaDeclineLines[rand.IntN(len(arinaDeclineLines))]
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("You can't afford it. She noticed before you did.\n\n_%s_", reply))
|
||||
}
|
||||
// D&D Arcana check — flavor for either outcome when a check was attempted.
|
||||
arcanaCheck := dndNPCArcanaRefund(ctx.Sender, p.euro, arinaCost)
|
||||
char.ArinaBuffExpires = expires
|
||||
if err := saveAdvCharacter(char); err != nil {
|
||||
slog.Error("npc: failed to save arina buff", "user", ctx.Sender, "err", err)
|
||||
}
|
||||
extra := ""
|
||||
if arcanaCheck.Attempted {
|
||||
if arcanaCheck.Succeeded {
|
||||
if line := flavor.Pick(flavor.ArinaArcanaSuccess); line != "" {
|
||||
extra = "\n\n_" + line + "_"
|
||||
}
|
||||
extra += "\n\n_(Arcana DC 14 passed — investment refunded.)_"
|
||||
} else {
|
||||
if line := flavor.Pick(flavor.ArinaSkillFail); line != "" {
|
||||
extra = "\n\n_" + line + "_"
|
||||
}
|
||||
}
|
||||
}
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"_She snatches the money from you, almost rudely, then looks at you expectantly._\n\n\"%s\"\n\n_She walks away just as quickly as she came._",
|
||||
arinaAcceptLine))
|
||||
"_She snatches the money from you, almost rudely, then looks at you expectantly._\n\n\"%s\"\n\n_She walks away just as quickly as she came._%s",
|
||||
arinaAcceptLine, extra))
|
||||
}
|
||||
|
||||
// Declined — no mechanical effect, just insults
|
||||
|
||||
@@ -2,6 +2,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"math/rand/v2"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -131,22 +132,29 @@ func renderAdvCharacterSheet(char *AdventureCharacter, equip map[EquipmentSlot]*
|
||||
eqScore := advEquipmentScore(equip)
|
||||
for _, slot := range allSlots {
|
||||
eq := equip[slot]
|
||||
if eq == nil {
|
||||
continue
|
||||
}
|
||||
marker := ""
|
||||
if eq.Masterwork {
|
||||
marker = " ⭐"
|
||||
} else if eq.ArenaTier > 0 {
|
||||
marker = " ⚔️"
|
||||
}
|
||||
// Mastery segment is appended as a third inline field after
|
||||
// condition only when there's progress — keeps rows tight for
|
||||
// freshly-equipped gear and grows with use.
|
||||
mastery := ""
|
||||
if eq != nil && eq.ActionsUsed >= 20 {
|
||||
mastery = " ✦"
|
||||
}
|
||||
if eq != nil {
|
||||
marker := ""
|
||||
if eq.Masterwork {
|
||||
marker = " ⭐"
|
||||
} else if eq.ArenaTier > 0 {
|
||||
marker = " ⚔️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" %s %s: %s%s (Tier %d | %d%% condition%s)\n",
|
||||
slotEmoji(slot), slotTitle(slot), eq.Name, marker, eq.Tier, eq.Condition, mastery))
|
||||
if seg := advMasteryRowSegment(eq.ActionsUsed); seg != "" {
|
||||
mastery = " | " + seg
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" %s %s: %s%s (Tier %d | %d%% cond%s)\n",
|
||||
slotEmoji(slot), slotTitle(slot), eq.Name, marker, eq.Tier, eq.Condition, mastery))
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" Equipment Score: %.1f\n", eqScore))
|
||||
if line := renderAdvMasteryAggregate(equip); line != "" {
|
||||
sb.WriteString(" " + line + "\n")
|
||||
}
|
||||
|
||||
// Treasures
|
||||
if len(treasures) > 0 {
|
||||
@@ -157,15 +165,8 @@ func renderAdvCharacterSheet(char *AdventureCharacter, equip map[EquipmentSlot]*
|
||||
continue
|
||||
}
|
||||
seen[t.TreasureKey] = true
|
||||
// Find def for inventory desc
|
||||
for tier, defs := range advAllTreasures {
|
||||
_ = tier
|
||||
for _, def := range defs {
|
||||
if def.Key == t.TreasureKey {
|
||||
sb.WriteString(fmt.Sprintf(" %s\n", def.InventoryDesc))
|
||||
break
|
||||
}
|
||||
}
|
||||
if def := lookupAdvTreasureDef(t.TreasureKey); def != nil {
|
||||
sb.WriteString(fmt.Sprintf(" %s\n", def.InventoryDesc))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,6 +235,138 @@ func renderAdvCharacterSheet(char *AdventureCharacter, equip map[EquipmentSlot]*
|
||||
|
||||
// ── Morning DM ───────────────────────────────────────────────────────────────
|
||||
|
||||
// renderCoopTeaser surfaces an open co-op run the player could join, so the
|
||||
// system isn't a footnote in help text. Returns "" when there's nothing to
|
||||
// surface (no open runs, or the player is already locked into one). When
|
||||
// runs exist that the player is under-levelled for, we still hint at them
|
||||
// as a stretch goal — joining as a liability is a real choice.
|
||||
func renderCoopTeaser(char *AdventureCharacter) string {
|
||||
runs, err := loadOpenCoopRuns()
|
||||
if err != nil || len(runs) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
pick, stretch := pickCoopTeaserCandidate(runs, char)
|
||||
tag := ""
|
||||
if pick == nil {
|
||||
pick = stretch
|
||||
tag = " *(below recommended level — would join as liability)*"
|
||||
}
|
||||
if pick == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
leaderName := string(pick.LeaderID)
|
||||
if c, err := loadAdvCharacter(pick.LeaderID); err == nil && c != nil && c.DisplayName != "" {
|
||||
leaderName = c.DisplayName
|
||||
}
|
||||
def := coopTierTable[pick.Tier]
|
||||
return fmt.Sprintf("🛡️ **Open Co-op #%d** — Tier %d (%s) led by %s · `!coop join %d`%s",
|
||||
pick.ID, pick.Tier, def.difficulty, leaderName, pick.ID, tag)
|
||||
}
|
||||
|
||||
// pickCoopTeaserCandidate scans the open coop runs and returns up to two
|
||||
// picks: a primary (where the player meets the level gate) and a stretch
|
||||
// (any other run, joined as a liability). Skips runs the player already
|
||||
// leads. Pure function — testable without DB.
|
||||
func pickCoopTeaserCandidate(runs []*CoopRun, char *AdventureCharacter) (match, stretch *CoopRun) {
|
||||
for _, r := range runs {
|
||||
if r.LeaderID == char.UserID {
|
||||
continue
|
||||
}
|
||||
def := coopTierTable[r.Tier]
|
||||
if char.CombatLevel >= def.minLevel && match == nil {
|
||||
match = r
|
||||
} else if stretch == nil {
|
||||
stretch = r
|
||||
}
|
||||
}
|
||||
return match, stretch
|
||||
}
|
||||
|
||||
// renderCraftingTeaser surfaces the crafting system before and just after
|
||||
// the Foraging-10 auto-unlock, so it doesn't stay invisible to players who
|
||||
// never type !adventure recipes. Returns "" when the teaser shouldn't fire
|
||||
// today (out of pre-unlock window, or already deep into post-unlock).
|
||||
func renderCraftingTeaser(char *AdventureCharacter) string {
|
||||
const unlock = 10
|
||||
if char.ForagingSkill < unlock {
|
||||
// Pre-unlock teaser: only when within 3 levels.
|
||||
if char.ForagingSkill < unlock-3 {
|
||||
return ""
|
||||
}
|
||||
levelsToGo := unlock - char.ForagingSkill
|
||||
return fmt.Sprintf("🧪 **Crafting unlocks in %d Foraging level%s** — auto-craft consumables from gathered ingredients (Berry Poultice, Herb Salve, etc.).",
|
||||
levelsToGo, plural(levelsToGo))
|
||||
}
|
||||
|
||||
// Post-unlock: nudge when no successful crafts yet (gentle), or once a
|
||||
// week (loose periodicity via day-of-year %).
|
||||
if char.CraftsSucceeded == 0 {
|
||||
return "🧪 **Crafting is unlocked.** Gather a couple of matching ingredients and TwinBee will auto-craft consumables — try `!adventure recipes` to see what your level supports."
|
||||
}
|
||||
// Per-player weekly reminder: hash UserID + ISO week to pick a stable
|
||||
// weekday for this player. Spreads the cohort across the week instead
|
||||
// of all firing on the same global day.
|
||||
if int(time.Now().UTC().Weekday()) == craftingReminderWeekday(char.UserID, time.Now().UTC()) {
|
||||
return "🧪 *Crafting reminder* — `!adventure recipes` shows what's available at Foraging Lv." + fmt.Sprintf("%d.", char.ForagingSkill)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// craftingReminderWeekday picks the day-of-week (0=Sunday..6=Saturday) on
|
||||
// which a given player gets the weekly crafting nudge during the given
|
||||
// week. Stable within an ISO week (predictable, not annoying), rotates
|
||||
// across weeks (not always the same day long-term).
|
||||
func craftingReminderWeekday(userID id.UserID, now time.Time) int {
|
||||
year, week := now.ISOWeek()
|
||||
h := fnv.New32a()
|
||||
fmt.Fprintf(h, "%s|%d|%d", string(userID), year, week)
|
||||
return int(h.Sum32() % 7)
|
||||
}
|
||||
|
||||
func plural(n int) string {
|
||||
if n == 1 {
|
||||
return ""
|
||||
}
|
||||
return "s"
|
||||
}
|
||||
|
||||
// renderRivalNudge surfaces a pending rival challenge in the morning DM so
|
||||
// players who missed or ignored the dramatic challenge DM see a reminder
|
||||
// before it expires. Returns "" if there's no pending challenge against
|
||||
// this player.
|
||||
func renderRivalNudge(char *AdventureCharacter) string {
|
||||
c := pendingRivalChallengeForChallenged(char.UserID)
|
||||
if c == nil {
|
||||
return ""
|
||||
}
|
||||
hours := int(time.Until(c.ExpiresAt).Hours())
|
||||
if hours < 1 {
|
||||
hours = 1 // floor — "<1h" feels worse than "1h"
|
||||
}
|
||||
rivalName := string(c.ChallengerID)
|
||||
if rc, err := loadAdvCharacter(c.ChallengerID); err == nil && rc != nil && rc.DisplayName != "" {
|
||||
rivalName = rc.DisplayName
|
||||
}
|
||||
return fmt.Sprintf("⚔️ **Rival challenge open** — %s, round %d/3, €%d on the line · expires in %dh · reply **rock**, **paper**, or **scissors**",
|
||||
rivalName, c.Round, c.Stake, hours)
|
||||
}
|
||||
|
||||
// writeAdvLocationLines renders the eligible-location bullets shown in the
|
||||
// morning DM. Each line surfaces both the downside (death %) and upside
|
||||
// (exceptional %) so the menu teaches risk/reward, not just risk.
|
||||
func writeAdvLocationLines(sb *strings.Builder, locs []AdvEligibleLocation) {
|
||||
for _, el := range locs {
|
||||
warn := ""
|
||||
if el.InPenaltyZone {
|
||||
warn = " ⚠️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" • %s (Tier %d, ~%.0f%% death · ~%.0f%% exceptional%s)\n",
|
||||
el.Location.Name, el.Location.Tier, el.DeathPct, el.ExceptionalPct, warn))
|
||||
}
|
||||
}
|
||||
|
||||
func renderAdvMorningDM(char *AdventureCharacter, equip map[EquipmentSlot]*AdvEquipment, balance float64, bonuses *AdvBonusSummary, holidayName string) string {
|
||||
var sb strings.Builder
|
||||
|
||||
@@ -303,51 +436,45 @@ func renderAdvMorningDM(char *AdventureCharacter, equip map[EquipmentSlot]*AdvEq
|
||||
coopRun.ID, coopRun.CurrentDay, coopRun.TotalDays, harvestLeft, harvestMax))
|
||||
} else {
|
||||
sb.WriteString(fmt.Sprintf("📋 **Actions:** %d/%d combat · %d/%d harvest\n\n", combatLeft, combatMax, harvestLeft, harvestMax))
|
||||
|
||||
// Co-op teaser — show open runs the player could join.
|
||||
if line := renderCoopTeaser(char); line != "" {
|
||||
sb.WriteString(line)
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
// Rival nudge — a pending challenge waits for action.
|
||||
if line := renderRivalNudge(char); line != "" {
|
||||
sb.WriteString(line)
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
// Crafting teaser — surface the system when it's near unlock or post-unlock.
|
||||
if line := renderCraftingTeaser(char); line != "" {
|
||||
sb.WriteString(line)
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
// Location choices
|
||||
if inCoop {
|
||||
sb.WriteString(fmt.Sprintf("**1️⃣ Dungeon:** _(off in the Co-op, no solo combat — `!coop status` for run state)_\n"))
|
||||
sb.WriteString("**1️⃣ Dungeon:** _(off in the Co-op, no solo combat — `!coop status` for run state)_\n")
|
||||
} else if char.CanDoCombat(isHol) {
|
||||
sb.WriteString("**1️⃣ Dungeon:**\n")
|
||||
for _, el := range advEligibleLocations(char, equip, AdvActivityDungeon, bonuses) {
|
||||
warn := ""
|
||||
if el.InPenaltyZone {
|
||||
warn = " ⚠️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" • %s (Tier %d, ~%.0f%% death%s)\n", el.Location.Name, el.Location.Tier, el.DeathPct, warn))
|
||||
}
|
||||
writeAdvLocationLines(&sb, advEligibleLocations(char, equip, AdvActivityDungeon, bonuses))
|
||||
} else {
|
||||
sb.WriteString("**1️⃣ Dungeon:** _(no combat actions remaining)_\n")
|
||||
}
|
||||
|
||||
if char.CanDoHarvest(isHol) {
|
||||
sb.WriteString("**2️⃣ Mine:**\n")
|
||||
for _, el := range advEligibleLocations(char, equip, AdvActivityMining, bonuses) {
|
||||
warn := ""
|
||||
if el.InPenaltyZone {
|
||||
warn = " ⚠️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" • %s (Tier %d, ~%.0f%% death%s)\n", el.Location.Name, el.Location.Tier, el.DeathPct, warn))
|
||||
}
|
||||
writeAdvLocationLines(&sb, advEligibleLocations(char, equip, AdvActivityMining, bonuses))
|
||||
|
||||
sb.WriteString("**3️⃣ Forage:**\n")
|
||||
for _, el := range advEligibleLocations(char, equip, AdvActivityForaging, bonuses) {
|
||||
warn := ""
|
||||
if el.InPenaltyZone {
|
||||
warn = " ⚠️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" • %s (Tier %d, ~%.0f%% death%s)\n", el.Location.Name, el.Location.Tier, el.DeathPct, warn))
|
||||
}
|
||||
writeAdvLocationLines(&sb, advEligibleLocations(char, equip, AdvActivityForaging, bonuses))
|
||||
|
||||
sb.WriteString("**4️⃣ Fish:**\n")
|
||||
for _, el := range advEligibleLocations(char, equip, AdvActivityFishing, bonuses) {
|
||||
warn := ""
|
||||
if el.InPenaltyZone {
|
||||
warn = " ⚠️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" • %s (Tier %d, ~%.0f%% death%s)\n", el.Location.Name, el.Location.Tier, el.DeathPct, warn))
|
||||
}
|
||||
writeAdvLocationLines(&sb, advEligibleLocations(char, equip, AdvActivityFishing, bonuses))
|
||||
} else {
|
||||
sb.WriteString("**2️⃣ Mine:** _(no harvest actions remaining)_\n")
|
||||
sb.WriteString("**3️⃣ Forage:** _(no harvest actions remaining)_\n")
|
||||
@@ -505,6 +632,183 @@ func renderAdvRespawnDM(char *AdventureCharacter) string {
|
||||
})
|
||||
}
|
||||
|
||||
// ── Treasure List ───────────────────────────────────────────────────────────
|
||||
|
||||
// lookupAdvTreasureDef returns the canonical definition for a treasure key,
|
||||
// or nil if unknown. Walks the tiered table; cheap because the total count
|
||||
// is small.
|
||||
func lookupAdvTreasureDef(key string) *AdvTreasureDef {
|
||||
for _, defs := range advAllTreasures {
|
||||
for i := range defs {
|
||||
if defs[i].Key == key {
|
||||
d := defs[i]
|
||||
return &d
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// renderAdvTreasureList renders the standalone treasure listing for
|
||||
// `!adventure treasures`. Shows each treasure, marks irreplaceable ones,
|
||||
// and surfaces the lock state so players know whether new drops will
|
||||
// auto-swap or be refused.
|
||||
func renderAdvTreasureList(treasures []AdvTreasureDef, locked bool) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("💎 **Your Treasures**")
|
||||
if locked {
|
||||
sb.WriteString(" 🔒 _(locked — drops at cap refused)_")
|
||||
}
|
||||
sb.WriteString("\n\n")
|
||||
|
||||
if len(treasures) == 0 {
|
||||
sb.WriteString("_No treasures yet. Higher-tier locations have higher drop rates._")
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
for _, t := range treasures {
|
||||
t := t
|
||||
marker := ""
|
||||
if advTreasureIrreplaceable(&t) {
|
||||
marker = " 🛡️"
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" • Tier %d · %s%s\n _%s_\n", t.Tier, t.Name, marker, t.InventoryDesc))
|
||||
}
|
||||
|
||||
if locked {
|
||||
sb.WriteString("\n_Unlock with `!adventure treasures unlock` to allow higher-tier auto-swaps._")
|
||||
} else {
|
||||
sb.WriteString("\n_Higher-tier drops auto-swap your lowest replaceable treasure (10-min undo). 🛡️ = irreplaceable, never auto-discarded._\n_Lock with `!adventure treasures lock` to refuse drops at cap._")
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// renderAdvMasteryAggregate produces the one-line summary shown under the
|
||||
// equipment block on the character sheet. Three states:
|
||||
// - Bonus active: shows percent, threshold count, cap-reached when at +10%.
|
||||
// - No bonus but some progress: hints that a threshold is approaching.
|
||||
// - No progress: empty (don't bloat sheets for new players).
|
||||
func renderAdvMasteryAggregate(equip map[EquipmentSlot]*AdvEquipment) string {
|
||||
r := advMasteryRollup(equip)
|
||||
if !r.AnyProgress {
|
||||
return ""
|
||||
}
|
||||
if r.Bonus > 0 {
|
||||
base := fmt.Sprintf("🎯 Mastery: +%.0f%% loot quality · %d threshold%s crossed",
|
||||
r.Bonus, r.ThresholdsCrossed, plural(r.ThresholdsCrossed))
|
||||
if r.MaxedSlots > 0 {
|
||||
base += fmt.Sprintf(" · %d slot%s maxed", r.MaxedSlots, plural(r.MaxedSlots))
|
||||
}
|
||||
// Cap is +10%; the raw count keeps rising past it. Flag when the
|
||||
// player is paying threshold tax for nothing.
|
||||
if r.Bonus >= 10 {
|
||||
base += " (cap reached)"
|
||||
}
|
||||
base += " · `!adventure mastery`"
|
||||
return base
|
||||
}
|
||||
// Some progress, no thresholds crossed yet — surface the next gate.
|
||||
return "🎯 Mastery: building up — first threshold at 50 actions/slot · `!adventure mastery`"
|
||||
}
|
||||
|
||||
// ── Equipment Mastery View ──────────────────────────────────────────────────
|
||||
|
||||
// renderAdvMasteryView renders a per-slot mastery readout: progress bar,
|
||||
// tier marker, and next threshold so players can see "where am I" between
|
||||
// the discrete celebration DMs that fire at threshold crossings.
|
||||
func renderAdvMasteryView(equip map[EquipmentSlot]*AdvEquipment) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("🎯 **Equipment Mastery**\n\n")
|
||||
|
||||
any := false
|
||||
for _, slot := range allSlots {
|
||||
eq := equip[slot]
|
||||
if eq == nil {
|
||||
sb.WriteString(fmt.Sprintf(" %s %s — _empty_\n", slotEmoji(slot), slotTitle(slot)))
|
||||
continue
|
||||
}
|
||||
any = true
|
||||
tier, next := advMasteryTier(eq.ActionsUsed)
|
||||
marker := advMasteryMarker(eq.ActionsUsed)
|
||||
if marker == "" {
|
||||
marker = "·"
|
||||
}
|
||||
|
||||
// Bar against the next threshold (or against 250 when at max so the
|
||||
// bar visually maxes out rather than disappearing).
|
||||
var barTotal int
|
||||
if next > 0 {
|
||||
barTotal = next
|
||||
} else {
|
||||
barTotal = advMasteryThresholds[len(advMasteryThresholds)-1]
|
||||
}
|
||||
bar := masteryBar(eq.ActionsUsed, barTotal)
|
||||
_ = tier
|
||||
|
||||
if next > 0 {
|
||||
sb.WriteString(fmt.Sprintf(" %s %s · %s · %d/%d %s %s\n",
|
||||
slotEmoji(slot), slotTitle(slot), eq.Name, eq.ActionsUsed, next, bar, marker))
|
||||
} else {
|
||||
sb.WriteString(fmt.Sprintf(" %s %s · %s · %d (max) %s %s\n",
|
||||
slotEmoji(slot), slotTitle(slot), eq.Name, eq.ActionsUsed, bar, marker))
|
||||
}
|
||||
}
|
||||
|
||||
bonus := advEquipmentMasteryBonus(equip)
|
||||
sb.WriteString("\n")
|
||||
if !any {
|
||||
sb.WriteString("_No equipment yet — gear up first._")
|
||||
return sb.String()
|
||||
}
|
||||
if bonus > 0 {
|
||||
sb.WriteString(fmt.Sprintf("**Active mastery bonus: +%.0f%% loot quality** (cap +10%%)\n", bonus))
|
||||
} else {
|
||||
sb.WriteString("_No mastery bonus yet — first threshold at 50 actions per slot._\n")
|
||||
}
|
||||
sb.WriteString("Thresholds: 50 ✦ · 100 ✦✦ · 250 ✦✦✦. Each crossed threshold per slot adds +1% loot quality.")
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// masteryBar builds a 10-cell progress bar for the mastery view.
|
||||
func masteryBar(value, total int) string {
|
||||
if total <= 0 {
|
||||
return "▱▱▱▱▱▱▱▱▱▱"
|
||||
}
|
||||
filled := value * 10 / total
|
||||
if filled > 10 {
|
||||
filled = 10
|
||||
}
|
||||
if filled < 0 {
|
||||
filled = 0
|
||||
}
|
||||
return strings.Repeat("▰", filled) + strings.Repeat("▱", 10-filled)
|
||||
}
|
||||
|
||||
// ── Auto-Babysit DM ─────────────────────────────────────────────────────────
|
||||
|
||||
// renderAutoBabysitDM builds the morning notification when auto-babysit
|
||||
// covered an idle day. Surfaces what the babysitter actually accomplished
|
||||
// (skill focus, gold/XP, items) plus a flavor highlight on lucky days, so
|
||||
// the system feels like an active companion instead of a silent debit.
|
||||
func renderAutoBabysitDM(daily int, streak int, res AutoBabysitDayResult) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(fmt.Sprintf("🍼 **Auto-babysit activated** — €%d deducted. Your streak is safe at %d days.\n", daily, streak))
|
||||
if res.Skill != "" {
|
||||
sb.WriteString(fmt.Sprintf("Focus: %s · €%d earned · %d XP", res.Skill, res.Gold, res.XP))
|
||||
if len(res.Items) > 0 {
|
||||
sb.WriteString(fmt.Sprintf(" · items: %s", strings.Join(res.Items, ", ")))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
if res.Highlight && res.Skill != "" {
|
||||
line := pickBabysitFlavor(babysitHighlightLines)
|
||||
if line != "" {
|
||||
sb.WriteString("\n_" + fmt.Sprintf(line, res.Skill) + "_")
|
||||
}
|
||||
}
|
||||
return strings.TrimRight(sb.String(), "\n")
|
||||
}
|
||||
|
||||
// ── Idle Shame DM ────────────────────────────────────────────────────────────
|
||||
|
||||
func renderAdvIdleShameDM(char *AdventureCharacter) string {
|
||||
|
||||
@@ -247,6 +247,28 @@ func lastRivalChallengeTime() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
// pendingRivalChallengeForChallenged returns the active challenge where the
|
||||
// given user is the challenged party (i.e. the side that needs to act).
|
||||
// Returns nil if no challenge is pending or the user is only on the
|
||||
// auto-resolved challenger side.
|
||||
func pendingRivalChallengeForChallenged(userID id.UserID) *advRivalChallenge {
|
||||
d := db.Get()
|
||||
c := &advRivalChallenge{}
|
||||
err := d.QueryRow(`
|
||||
SELECT challenge_id, challenger_id, challenged_id, stake,
|
||||
round, player_score, rival_score, expires_at, created_at
|
||||
FROM adventure_rival_challenges
|
||||
WHERE challenged_id = ? AND expires_at > CURRENT_TIMESTAMP
|
||||
ORDER BY created_at DESC LIMIT 1`, string(userID)).Scan(
|
||||
&c.ChallengeID, &c.ChallengerID, &c.ChallengedID, &c.Stake,
|
||||
&c.Round, &c.PlayerScore, &c.RivalScore, &c.ExpiresAt, &c.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func hasActiveChallenge(userID id.UserID) bool {
|
||||
d := db.Get()
|
||||
var count int
|
||||
|
||||
@@ -334,25 +334,49 @@ func (p *AdventurePlugin) midnightReset() error {
|
||||
}
|
||||
|
||||
today := time.Now().UTC().Format("2006-01-02")
|
||||
yesterday := time.Now().UTC().Add(-24 * time.Hour).Format("2006-01-02")
|
||||
|
||||
coopMembers, err := activeCoopMemberSet()
|
||||
if err != nil {
|
||||
slog.Error("adventure: failed to load active coop members", "err", err)
|
||||
coopMembers = map[string]bool{}
|
||||
}
|
||||
|
||||
dmsSent := 0
|
||||
for _, char := range chars {
|
||||
// Active co-op members can't take manual actions (combat is locked
|
||||
// to the coop run, harvest is optional). Their participation
|
||||
// auto-resolves daily, so credit them with a streak day and skip
|
||||
// idle/babysit logic — otherwise the lockCoopCombatActions sentinel
|
||||
// (combat_actions_used = 99) trips HasActedToday and falls through
|
||||
// to the streak-reset branch.
|
||||
if coopMembers[string(char.UserID)] {
|
||||
char.CurrentStreak++
|
||||
if char.CurrentStreak > char.BestStreak {
|
||||
char.BestStreak = char.CurrentStreak
|
||||
}
|
||||
char.LastActionDate = today
|
||||
_ = saveAdvCharacter(&char)
|
||||
continue
|
||||
}
|
||||
|
||||
if !char.HasActedToday() {
|
||||
// If the player died today or yesterday, they couldn't act — no shame,
|
||||
// no streak reset. This covers both currently-dead players and players
|
||||
// who were just revived at midnight (Alive already flipped to true by
|
||||
// the reminder loop before midnightReset runs).
|
||||
if char.LastDeathDate == today ||
|
||||
char.LastDeathDate == time.Now().UTC().Add(-24*time.Hour).Format("2006-01-02") {
|
||||
if char.LastDeathDate == today || char.LastDeathDate == yesterday {
|
||||
continue
|
||||
}
|
||||
|
||||
// Auto-babysit: if enabled, alive, and affordable, run a single babysit day instead of losing streak
|
||||
autoBabysitShortfall := int64(0)
|
||||
if char.AutoBabysit && char.Alive && !char.BabysitActive {
|
||||
daily := babysitDailyCost(char.CombatLevel)
|
||||
if p.euro.GetBalance(char.UserID) >= float64(daily) {
|
||||
bal := p.euro.GetBalance(char.UserID)
|
||||
if bal >= float64(daily) {
|
||||
if p.euro.Debit(char.UserID, float64(daily), "auto_babysit") {
|
||||
p.runAutoBabysitDay(&char)
|
||||
res := p.runAutoBabysitDay(&char)
|
||||
if char.CurrentStreak > 0 {
|
||||
char.CurrentStreak++
|
||||
if char.CurrentStreak > char.BestStreak {
|
||||
@@ -371,9 +395,11 @@ func (p *AdventurePlugin) midnightReset() error {
|
||||
time.Sleep(time.Duration(1000+rand.IntN(2000)) * time.Millisecond)
|
||||
}
|
||||
dmsSent++
|
||||
p.SendDM(char.UserID, fmt.Sprintf("🍼 **Auto-babysit activated** — €%d deducted. Your streak is safe at %d days.", daily, char.CurrentStreak))
|
||||
p.SendDM(char.UserID, renderAutoBabysitDM(daily, char.CurrentStreak, res))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
autoBabysitShortfall = int64(float64(daily) - bal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,6 +411,9 @@ func (p *AdventurePlugin) midnightReset() error {
|
||||
|
||||
// Idle shame DM
|
||||
text := renderAdvIdleShameDM(&char)
|
||||
if autoBabysitShortfall > 0 {
|
||||
text += fmt.Sprintf("\n\n💸 Auto-babysit was on but couldn't cover today (€%d short). Top up the wallet and TwinBee can step in next time.", autoBabysitShortfall)
|
||||
}
|
||||
if char.CurrentStreak > 0 {
|
||||
oldStreak := char.CurrentStreak
|
||||
char.CurrentStreak /= 2
|
||||
@@ -400,7 +429,6 @@ func (p *AdventurePlugin) midnightReset() error {
|
||||
}
|
||||
} else {
|
||||
// Update streak — LastActionDate was set at action time
|
||||
yesterday := time.Now().UTC().Add(-24 * time.Hour).Format("2006-01-02")
|
||||
if char.LastActionDate == yesterday || char.LastActionDate == today {
|
||||
char.CurrentStreak++
|
||||
} else {
|
||||
|
||||
@@ -61,8 +61,17 @@ type advPendingShopConfirm struct {
|
||||
type advShopSession struct {
|
||||
StartedAt time.Time
|
||||
ItemsBought int
|
||||
// Persuasion discount: 0.10 if the player passed Persuasion DC 15 on
|
||||
// session start, else 0. Applied to all purchases this session.
|
||||
// Expires `dndPersuasionDiscountTTL` after StartedAt — players can't
|
||||
// hold a discount session open indefinitely.
|
||||
PersuasionDiscount float64
|
||||
}
|
||||
|
||||
// dndPersuasionDiscountTTL — how long after shop entry the Persuasion
|
||||
// discount remains valid. After this, prices return to full.
|
||||
const dndPersuasionDiscountTTL = 30 * time.Minute
|
||||
|
||||
func (p *AdventurePlugin) shopSessionGet(userID id.UserID) *advShopSession {
|
||||
if val, ok := p.shopSessions.Load(string(userID)); ok {
|
||||
return val.(*advShopSession)
|
||||
@@ -72,12 +81,45 @@ func (p *AdventurePlugin) shopSessionGet(userID id.UserID) *advShopSession {
|
||||
|
||||
func (p *AdventurePlugin) shopSessionStart(userID id.UserID) {
|
||||
if p.shopSessionGet(userID) == nil {
|
||||
discount := 0.0
|
||||
if dndNPCPersuasionDiscount(userID) {
|
||||
discount = 0.10
|
||||
}
|
||||
p.shopSessions.Store(string(userID), &advShopSession{
|
||||
StartedAt: time.Now(),
|
||||
StartedAt: time.Now(),
|
||||
PersuasionDiscount: discount,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// shopSessionPriceFactor returns the multiplier to apply to shop prices for
|
||||
// the given user's current session. 1.0 normally, 0.9 if Persuasion passed.
|
||||
// The discount expires after dndPersuasionDiscountTTL to prevent indefinite
|
||||
// session-holding (audit fix G).
|
||||
func (p *AdventurePlugin) shopSessionPriceFactor(userID id.UserID) float64 {
|
||||
sess := p.shopSessionGet(userID)
|
||||
if sess == nil {
|
||||
return 1.0
|
||||
}
|
||||
if sess.PersuasionDiscount > 0 && time.Since(sess.StartedAt) > dndPersuasionDiscountTTL {
|
||||
return 1.0
|
||||
}
|
||||
return 1.0 - sess.PersuasionDiscount
|
||||
}
|
||||
|
||||
// shopSessionAnnounceDiscount returns flavor text to surface a passed
|
||||
// Persuasion check, or empty string if none/expired.
|
||||
func (p *AdventurePlugin) shopSessionAnnounceDiscount(userID id.UserID) string {
|
||||
sess := p.shopSessionGet(userID)
|
||||
if sess == nil || sess.PersuasionDiscount <= 0 {
|
||||
return ""
|
||||
}
|
||||
if time.Since(sess.StartedAt) > dndPersuasionDiscountTTL {
|
||||
return ""
|
||||
}
|
||||
return "_(Persuasion DC 15 passed — 10% discount applied; expires 30 minutes after shop entry.)_"
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) shopSessionBump(userID id.UserID) {
|
||||
sess := p.shopSessionGet(userID)
|
||||
if sess != nil {
|
||||
@@ -486,19 +528,22 @@ func (p *AdventurePlugin) resolveShopConfirm(ctx MessageContext, interaction *ad
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("Your **%s** (Masterwork ⭐) is better than that T%d shop item.", current.Name, def.Tier))
|
||||
}
|
||||
|
||||
// Persuasion-discounted price.
|
||||
price := def.Price * p.shopSessionPriceFactor(ctx.Sender)
|
||||
|
||||
// Affordability.
|
||||
if balance < def.Price {
|
||||
if balance < price {
|
||||
flavor, _ := advPickFlavor(luigiInsufficientFunds, ctx.Sender, "luigi_broke")
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("*%s*\n\nYou have €%.0f. %s costs €%.0f.", flavor, balance, def.Name, def.Price))
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("*%s*\n\nYou have €%.0f. %s costs €%.0f.", flavor, balance, def.Name, price))
|
||||
}
|
||||
|
||||
// Debit.
|
||||
if !p.euro.Debit(ctx.Sender, def.Price, "adventure_shop_"+string(data.Slot)) {
|
||||
if !p.euro.Debit(ctx.Sender, price, "adventure_shop_"+string(data.Slot)) {
|
||||
return p.SendDM(ctx.Sender, "Transaction failed. The economy is having a moment.")
|
||||
}
|
||||
|
||||
// Community contribution: 5% of purchase price.
|
||||
if potCut := int(def.Price * 0.05); potCut > 0 {
|
||||
if potCut := int(price * 0.05); potCut > 0 {
|
||||
communityPotAdd(potCut)
|
||||
trackTaxPaid(ctx.Sender, potCut)
|
||||
}
|
||||
@@ -693,18 +738,19 @@ func (p *AdventurePlugin) advBuyEquipment(userID id.UserID, slot EquipmentSlot,
|
||||
current.Name, current.Tier, def.Tier)
|
||||
}
|
||||
|
||||
price := def.Price * p.shopSessionPriceFactor(userID)
|
||||
balance := p.euro.GetBalance(userID)
|
||||
if balance < def.Price {
|
||||
if balance < price {
|
||||
flavor, _ := advPickFlavor(luigiInsufficientFunds, userID, "luigi_broke")
|
||||
return fmt.Sprintf("*%s*\n\nYou have €%.0f. %s costs €%.0f.", flavor, balance, def.Name, def.Price)
|
||||
return fmt.Sprintf("*%s*\n\nYou have €%.0f. %s costs €%.0f.", flavor, balance, def.Name, price)
|
||||
}
|
||||
|
||||
if !p.euro.Debit(userID, def.Price, "adventure_shop_"+string(slot)) {
|
||||
if !p.euro.Debit(userID, price, "adventure_shop_"+string(slot)) {
|
||||
return "Transaction failed. The economy is having a moment."
|
||||
}
|
||||
|
||||
// Community contribution: 5% of purchase price.
|
||||
if potCut := int(def.Price * 0.05); potCut > 0 {
|
||||
if potCut := int(price * 0.05); potCut > 0 {
|
||||
communityPotAdd(potCut)
|
||||
trackTaxPaid(userID, potCut)
|
||||
}
|
||||
@@ -975,15 +1021,16 @@ func (p *AdventurePlugin) resolveShopSupplyChoice(ctx MessageContext, interactio
|
||||
return p.SendDM(ctx.Sender, "I don't have that. Reply with an item name from the list, or `back` to return.")
|
||||
}
|
||||
|
||||
consumablePrice := float64(match.Price) * p.shopSessionPriceFactor(ctx.Sender)
|
||||
balance := p.euro.GetBalance(ctx.Sender)
|
||||
if balance < float64(match.Price) {
|
||||
if balance < consumablePrice {
|
||||
p.pending.Store(string(ctx.Sender), interaction)
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("You need €%d for %s but only have €%.0f.", match.Price, match.Name, balance))
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("You need €%.0f for %s but only have €%.0f.", consumablePrice, match.Name, balance))
|
||||
}
|
||||
|
||||
// Purchase the consumable
|
||||
p.euro.Debit(ctx.Sender, float64(match.Price), "shop_consumable")
|
||||
if potCut := int(math.Round(float64(match.Price) * 0.05)); potCut > 0 {
|
||||
p.euro.Debit(ctx.Sender, consumablePrice, "shop_consumable")
|
||||
if potCut := int(math.Round(consumablePrice * 0.05)); potCut > 0 {
|
||||
communityPotAdd(potCut)
|
||||
trackTaxPaid(ctx.Sender, potCut)
|
||||
}
|
||||
@@ -998,6 +1045,6 @@ func (p *AdventurePlugin) resolveShopSupplyChoice(ctx MessageContext, interactio
|
||||
// Stay in supplies view for more purchases
|
||||
p.pending.Store(string(ctx.Sender), interaction)
|
||||
newBalance := p.euro.GetBalance(ctx.Sender)
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("Purchased **%s** for €%d. Added to inventory.\n💰 Balance: €%.0f\n\nReply with another item name or `back` to return.",
|
||||
match.Name, match.Price, newBalance))
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("Purchased **%s** for €%.0f. Added to inventory.\n💰 Balance: €%.0f\n\nReply with another item name or `back` to return.",
|
||||
match.Name, consumablePrice, newBalance))
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
"strings"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
@@ -241,20 +242,25 @@ var advAllTreasures = map[int][]AdvTreasureDef{
|
||||
|
||||
// ── Treasure Drop Logic ──────────────────────────────────────────────────────
|
||||
|
||||
func rollAdvTreasureDrop(tier int, userID id.UserID, chatLevel int) *AdvTreasureDrop {
|
||||
rate, ok := advTreasureDropRates[tier]
|
||||
// rollAdvTreasureDropDetailed returns the drop (or nil) plus the random roll
|
||||
// and the effective drop rate, so callers can surface near-miss feedback
|
||||
// ("rolled 1.8% vs 1.5% chance — just missed"). Players never see treasure
|
||||
// math otherwise, which makes rare drops feel mythical.
|
||||
func rollAdvTreasureDropDetailed(tier int, userID id.UserID, chatLevel int) (drop *AdvTreasureDrop, roll, rate float64) {
|
||||
r, ok := advTreasureDropRates[tier]
|
||||
if !ok {
|
||||
return nil
|
||||
return nil, 0, 0
|
||||
}
|
||||
rate += chatLevelRareBonus(chatLevel)
|
||||
rate = r + chatLevelRareBonus(chatLevel)
|
||||
roll = rand.Float64()
|
||||
|
||||
if rand.Float64() >= rate {
|
||||
return nil
|
||||
if roll >= rate {
|
||||
return nil, roll, rate
|
||||
}
|
||||
|
||||
pool, ok := advAllTreasures[tier]
|
||||
if !ok || len(pool) == 0 {
|
||||
return nil
|
||||
return nil, roll, rate
|
||||
}
|
||||
|
||||
// Pick random treasure
|
||||
@@ -267,11 +273,68 @@ func rollAdvTreasureDrop(tier int, userID id.UserID, chatLevel int) *AdvTreasure
|
||||
def = &pool[rand.IntN(len(pool))]
|
||||
owns, err = advUserOwnsTreasure(userID, def.Key)
|
||||
if err != nil || owns {
|
||||
return nil // both rolls duplicated
|
||||
return nil, roll, rate // both rolls duplicated
|
||||
}
|
||||
}
|
||||
|
||||
return &AdvTreasureDrop{Def: def}
|
||||
return &AdvTreasureDrop{Def: def}, roll, rate
|
||||
}
|
||||
|
||||
// rollAdvTreasureDrop is the legacy single-return variant used by call sites
|
||||
// that don't surface near-miss feedback (auto-babysit, twinbee shares).
|
||||
func rollAdvTreasureDrop(tier int, userID id.UserID, chatLevel int) *AdvTreasureDrop {
|
||||
d, _, _ := rollAdvTreasureDropDetailed(tier, userID, chatLevel)
|
||||
return d
|
||||
}
|
||||
|
||||
// ── Treasure Comparison ─────────────────────────────────────────────────────
|
||||
|
||||
// advTreasureIrreplaceable reports whether a treasure carries a bonus type
|
||||
// that can't be replicated by another drop (e.g. monthly death bypass).
|
||||
// Such treasures are excluded from auto-swap and fall back to the manual
|
||||
// discard prompt so the player consciously chooses to give one up.
|
||||
func advTreasureIrreplaceable(def *AdvTreasureDef) bool {
|
||||
if def == nil {
|
||||
return false
|
||||
}
|
||||
for _, b := range def.Bonuses {
|
||||
if strings.HasPrefix(b.Type, "special_") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// advTreasureRank produces a comparable triple (tier, bonusCount, key) for
|
||||
// auto-swap decisions. Bonuses are heterogeneous and there's no honest
|
||||
// scalar comparator — we use tier first, then bonus count as a tiebreaker,
|
||||
// then the deterministic key so equal-rank ties prefer the existing item
|
||||
// (no churn). Higher tuple = better treasure.
|
||||
type advTreasureRankKey struct {
|
||||
Tier int
|
||||
BonusCount int
|
||||
Key string
|
||||
}
|
||||
|
||||
func advTreasureRank(def *AdvTreasureDef) advTreasureRankKey {
|
||||
if def == nil {
|
||||
return advTreasureRankKey{}
|
||||
}
|
||||
return advTreasureRankKey{Tier: def.Tier, BonusCount: len(def.Bonuses), Key: def.Key}
|
||||
}
|
||||
|
||||
// advTreasureRankBetter reports whether a is strictly better than b.
|
||||
// Equal-rank returns false (caller treats this as "keep existing").
|
||||
func advTreasureRankBetter(a, b advTreasureRankKey) bool {
|
||||
if a.Tier != b.Tier {
|
||||
return a.Tier > b.Tier
|
||||
}
|
||||
if a.BonusCount != b.BonusCount {
|
||||
return a.BonusCount > b.BonusCount
|
||||
}
|
||||
// Deterministic but neutral tiebreak — different keys aren't "better"
|
||||
// than each other, so equal Tier+BonusCount means no swap.
|
||||
return false
|
||||
}
|
||||
|
||||
// ── Treasure DB Operations ───────────────────────────────────────────────────
|
||||
|
||||
@@ -29,6 +29,27 @@ func (p *AdventurePlugin) runArenaCombat(
|
||||
// Load consumables from inventory and auto-select
|
||||
consumables := p.loadConsumableInventory(userID)
|
||||
enemyStats, _ := DeriveArenaMonsterStats(monster)
|
||||
|
||||
// All combat is D&D. If the player has no sheet yet (or only a draft),
|
||||
// auto-migrate them to a sensible inferred character before fighting.
|
||||
dndChar, freshMigrate, err := ensureDnDCharacterForCombat(userID, char)
|
||||
if err != nil {
|
||||
slog.Error("dnd: ensureDnDCharacterForCombat (arena) failed", "user", userID, "err", err)
|
||||
return CombatResult{}, 0
|
||||
}
|
||||
if freshMigrate {
|
||||
p.maybeSendDnDOnboarding(userID, char, dndChar)
|
||||
}
|
||||
applyDnDPlayerLayer(&playerStats, dndChar)
|
||||
applyDnDEquipmentLayer(&playerStats, dndChar, equip)
|
||||
applyDnDHPScaling(&playerStats, dndChar)
|
||||
applyClassPassives(&playerStats, &playerMods, dndChar)
|
||||
applyRacePassives(&playerStats, &playerMods, dndChar)
|
||||
if firedName, fired := applyArmedAbility(dndChar, &playerMods); fired {
|
||||
slog.Info("dnd: armed ability fired", "user", userID, "ability", firedName)
|
||||
}
|
||||
applyDnDArenaMonsterLayer(&enemyStats, monster.ThreatLevel)
|
||||
|
||||
selected := SelectConsumables(consumables, playerStats, enemyStats, arenaRound, arenaTier)
|
||||
ApplyConsumableMods(&playerStats, &playerMods, selected)
|
||||
|
||||
@@ -66,6 +87,14 @@ func (p *AdventurePlugin) runArenaCombat(
|
||||
|
||||
p.grantCombatAchievements(userID, result)
|
||||
|
||||
persistDnDHPAfterCombat(userID, result.PlayerStartHP, result.PlayerEndHP)
|
||||
|
||||
if xp := arenaCombatXP(result, monster.ThreatLevel); xp > 0 {
|
||||
if _, err := p.grantDnDXP(userID, xp); err != nil {
|
||||
slog.Error("dnd: grantDnDXP arena", "user", userID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
return result, condRepair
|
||||
}
|
||||
|
||||
@@ -124,6 +153,26 @@ func (p *AdventurePlugin) runDungeonCombat(
|
||||
// Load consumables from inventory and auto-select
|
||||
consumables := p.loadConsumableInventory(userID)
|
||||
enemyStats, enemyMods := DeriveDungeonMonsterStats(loc)
|
||||
|
||||
// All combat is D&D. Auto-migrate if needed.
|
||||
dndChar, freshMigrate, err := ensureDnDCharacterForCombat(userID, char)
|
||||
if err != nil {
|
||||
slog.Error("dnd: ensureDnDCharacterForCombat (dungeon) failed", "user", userID, "err", err)
|
||||
return CombatResult{}
|
||||
}
|
||||
if freshMigrate {
|
||||
p.maybeSendDnDOnboarding(userID, char, dndChar)
|
||||
}
|
||||
applyDnDPlayerLayer(&playerStats, dndChar)
|
||||
applyDnDEquipmentLayer(&playerStats, dndChar, equip)
|
||||
applyDnDHPScaling(&playerStats, dndChar)
|
||||
applyClassPassives(&playerStats, &playerMods, dndChar)
|
||||
applyRacePassives(&playerStats, &playerMods, dndChar)
|
||||
if firedName, fired := applyArmedAbility(dndChar, &playerMods); fired {
|
||||
slog.Info("dnd: armed ability fired", "user", userID, "ability", firedName)
|
||||
}
|
||||
applyDnDDungeonMonsterLayer(&enemyStats, loc.Tier)
|
||||
|
||||
selected := SelectConsumables(consumables, playerStats, enemyStats, 0, loc.Tier)
|
||||
ApplyConsumableMods(&playerStats, &playerMods, selected)
|
||||
|
||||
@@ -163,6 +212,15 @@ func (p *AdventurePlugin) runDungeonCombat(
|
||||
|
||||
p.grantCombatAchievements(userID, result)
|
||||
|
||||
persistDnDHPAfterCombat(userID, result.PlayerStartHP, result.PlayerEndHP)
|
||||
|
||||
if xp := dungeonCombatXP(result, loc.Tier); xp > 0 {
|
||||
if _, err := p.grantDnDXP(userID, xp); err != nil {
|
||||
slog.Error("dnd: grantDnDXP dungeon", "user", userID, "err", err)
|
||||
}
|
||||
}
|
||||
_ = dndChar
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,23 @@ type CombatStats struct {
|
||||
Attack int
|
||||
Defense int
|
||||
Speed int
|
||||
CritRate float64
|
||||
DodgeRate float64
|
||||
BlockRate float64
|
||||
CritRate float64 // legacy; superseded by nat-20 crits but still consumed by autoCrit logic & equipment scaling.
|
||||
DodgeRate float64 // legacy; no longer queried by hit resolution but still computed for narrative scaling.
|
||||
BlockRate float64 // still used to halve damage on a successful hit.
|
||||
|
||||
// D&D layer. AC and AttackBonus drive d20-vs-AC hit resolution.
|
||||
// Set via dnd_combat.go's applyDnDPlayerLayer / applyDnDArenaMonsterLayer / applyDnDDungeonMonsterLayer.
|
||||
AC int
|
||||
AttackBonus int
|
||||
|
||||
// Phase 8 — equipment-driven damage. When Weapon is non-nil, the d20
|
||||
// attack path rolls weapon damage dice + AbilityModForDamage instead of
|
||||
// the legacy calcDamage penetration formula. When nil, legacy math
|
||||
// applies (used by monsters and any combatant without a D&D weapon).
|
||||
Weapon *WeaponProfile
|
||||
AbilityModForDamage int
|
||||
WeaponProficient bool // false → -4 attack penalty (appendix §8 implementation note)
|
||||
TwoHandedMode bool // true + versatile weapon → use larger versatile die
|
||||
}
|
||||
|
||||
type CombatModifiers struct {
|
||||
@@ -33,6 +47,11 @@ type CombatModifiers struct {
|
||||
ReflectNext float64 // consumable: fraction of next hit reflected
|
||||
AutoCritFirst bool // consumable: first player hit is auto-crit
|
||||
FlatDmgStart int // consumable: flat damage to enemy pre-combat
|
||||
|
||||
// D&D race passives (Phase 3 — race traits with combat hooks).
|
||||
LuckyReroll bool // Halfling: reroll the first nat 1 of the fight
|
||||
RageReady bool // Orc: when HP first drops <50%, next attack deals +50% damage
|
||||
PoisonResist bool // Dwarf: poison tick damage halved
|
||||
}
|
||||
|
||||
type Combatant struct {
|
||||
@@ -61,6 +80,10 @@ type CombatEvent struct {
|
||||
PlayerHP int
|
||||
EnemyHP int
|
||||
Desc string // optional flavor (item name, ability name)
|
||||
// D&D layer fields. Set only on events from the d20-vs-AC resolution path.
|
||||
// Roll is the raw d20 (1..20); RollAgainst is the target AC.
|
||||
Roll int
|
||||
RollAgainst int
|
||||
}
|
||||
|
||||
type CombatResult struct {
|
||||
@@ -127,6 +150,11 @@ type combatState struct {
|
||||
// Sovereign reprieve
|
||||
deathSaveUsed bool
|
||||
|
||||
// D&D race-passive state
|
||||
luckyUsed bool // Halfling Lucky reroll consumed
|
||||
raged bool // Orc Rage already triggered this fight
|
||||
pendingRageAttack bool // next player attack gets +50% damage
|
||||
|
||||
round int
|
||||
events []CombatEvent
|
||||
}
|
||||
@@ -353,6 +381,9 @@ func simulateRound(st *combatState, player, enemy *Combatant, phase *CombatPhase
|
||||
|
||||
// ── Attack Resolution ────────────────────────────────────────────────────────
|
||||
|
||||
// resolvePlayerAttack — d20 + AttackBonus vs enemy AC.
|
||||
// Nat 20 = auto-hit + crit. Nat 1 = auto-miss tagged "fumble".
|
||||
// Block (on hit) halves damage. autoCrit consumable forces a crit on hit.
|
||||
func resolvePlayerAttack(st *combatState, player, enemy *Combatant, phase *CombatPhase, result *CombatResult) bool {
|
||||
phaseName := phase.Name
|
||||
|
||||
@@ -366,44 +397,98 @@ func resolvePlayerAttack(st *combatState, player, enemy *Combatant, phase *Comba
|
||||
return false
|
||||
}
|
||||
|
||||
// Enemy dodge
|
||||
enemyDodge := enemy.Stats.DodgeRate * phase.SpeedWeight
|
||||
if enemyDodge > 0 && rand.Float64() < enemyDodge {
|
||||
// Orc Rage: trigger on the first attack after dropping below 50% HP.
|
||||
// Use HP*2 < MaxHP rather than HP < MaxHP/2 so the threshold is exact
|
||||
// regardless of MaxHP parity (avoids per-character drift on odd MaxHP).
|
||||
if player.Mods.RageReady && !st.raged && st.playerHP > 0 &&
|
||||
st.playerHP*2 < player.Stats.MaxHP {
|
||||
st.raged = true
|
||||
st.pendingRageAttack = true
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "player", Action: "rage",
|
||||
PlayerHP: st.playerHP, EnemyHP: st.enemyHP, Desc: "Orc Rage",
|
||||
})
|
||||
}
|
||||
|
||||
roll := 1 + rand.IntN(20)
|
||||
// Halfling Lucky: reroll the first nat 1 of the fight.
|
||||
if roll == 1 && player.Mods.LuckyReroll && !st.luckyUsed {
|
||||
st.luckyUsed = true
|
||||
newRoll := 1 + rand.IntN(20)
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "player", Action: "lucky_reroll",
|
||||
PlayerHP: st.playerHP, EnemyHP: st.enemyHP,
|
||||
Roll: newRoll, RollAgainst: enemy.Stats.AC, Desc: "Halfling Lucky",
|
||||
})
|
||||
roll = newRoll
|
||||
}
|
||||
isFumble := roll == 1
|
||||
isNat20 := roll == 20
|
||||
// Class proficiency penalty (appendix §8): -4 attack with a non-proficient weapon.
|
||||
attackBonus := player.Stats.AttackBonus
|
||||
if player.Stats.Weapon != nil && !player.Stats.WeaponProficient {
|
||||
attackBonus -= 4
|
||||
}
|
||||
total := roll + attackBonus
|
||||
|
||||
if isFumble || (!isNat20 && total < enemy.Stats.AC) {
|
||||
desc := ""
|
||||
if isFumble {
|
||||
desc = "fumble"
|
||||
}
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "player", Action: "miss",
|
||||
PlayerHP: st.playerHP, EnemyHP: st.enemyHP,
|
||||
Roll: roll, RollAgainst: enemy.Stats.AC, Desc: desc,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
// Calculate damage
|
||||
dmg := calcDamage(player.Stats.Attack, phase.AttackWeight, player.Mods.DamageBonus,
|
||||
enemy.Stats.Defense, phase.DefenseWeight, enemy.Mods.DamageReduct)
|
||||
// Damage roll: weapon dice path (Phase 8) or legacy penetration formula.
|
||||
var dmg int
|
||||
if player.Stats.Weapon != nil {
|
||||
// Unproficient wielders don't add their ability mod to damage.
|
||||
mod := player.Stats.AbilityModForDamage
|
||||
if !player.Stats.WeaponProficient {
|
||||
mod = 0
|
||||
}
|
||||
total, _ := rollWeaponDamage(player.Stats.Weapon, mod, player.Stats.TwoHandedMode)
|
||||
dmg = total
|
||||
// Class damage bonus / streak bonus / etc. layered on top via DamageBonus.
|
||||
if player.Mods.DamageBonus > 0 {
|
||||
dmg = int(float64(dmg) * (1 + player.Mods.DamageBonus))
|
||||
}
|
||||
// Apply enemy damage reduction (consumables, sets) the same way calcDamage does.
|
||||
if enemy.Mods.DamageReduct > 0 && enemy.Mods.DamageReduct != 1.0 {
|
||||
dmg = int(float64(dmg) * enemy.Mods.DamageReduct)
|
||||
}
|
||||
} else {
|
||||
dmg = calcDamage(player.Stats.Attack, phase.AttackWeight, player.Mods.DamageBonus,
|
||||
enemy.Stats.Defense, phase.DefenseWeight, enemy.Mods.DamageReduct)
|
||||
}
|
||||
|
||||
// Block: half damage
|
||||
blocked := enemy.Stats.BlockRate > 0 && rand.Float64() < enemy.Stats.BlockRate
|
||||
if blocked {
|
||||
dmg = max(1, dmg/2)
|
||||
}
|
||||
|
||||
// Crit check
|
||||
critRate := player.Stats.CritRate
|
||||
if phaseName == "Decisive" {
|
||||
critRate *= 2
|
||||
}
|
||||
isCrit := false
|
||||
isCrit := isNat20
|
||||
if st.autoCrit {
|
||||
isCrit = true
|
||||
st.autoCrit = false
|
||||
dmg *= 2
|
||||
} else if critRate > 0 && rand.Float64() < critRate {
|
||||
isCrit = true
|
||||
}
|
||||
if isCrit {
|
||||
// Crit: double damage. (5e rolls extra dice; we double total to
|
||||
// match the engine's pre-Phase-8 crit semantics.)
|
||||
dmg *= 2
|
||||
}
|
||||
|
||||
// Orc Rage: +50% damage on this attack, then consume.
|
||||
if st.pendingRageAttack {
|
||||
dmg = int(float64(dmg) * 1.5)
|
||||
st.pendingRageAttack = false
|
||||
}
|
||||
dmg = max(1, dmg)
|
||||
|
||||
// Cleave handling for enemy is in resolveEnemyAttack
|
||||
action := "hit"
|
||||
if isCrit {
|
||||
action = "crit"
|
||||
@@ -415,20 +500,21 @@ func resolvePlayerAttack(st *combatState, player, enemy *Combatant, phase *Comba
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "player", Action: action,
|
||||
Damage: dmg, PlayerHP: st.playerHP, EnemyHP: st.enemyHP,
|
||||
Roll: roll, RollAgainst: enemy.Stats.AC,
|
||||
})
|
||||
|
||||
return st.enemyHP <= 0
|
||||
}
|
||||
|
||||
// resolveEnemyAttack — enemy rolls d20 + AttackBonus vs player AC.
|
||||
// Pet whiff and spore-cloud miss preempt the roll. Ward absorbs a hit fully.
|
||||
// Block halves damage. Reflect bounces a fraction back. Death save fires if HP hits 0.
|
||||
func resolveEnemyAttack(st *combatState, player, enemy *Combatant, phase *CombatPhase, result *CombatResult, petWhiff, petDeflect, sporeMiss bool) bool {
|
||||
phaseName := phase.Name
|
||||
|
||||
// Spore cloud round consumed when enemy attacks (even if whiffed/missed)
|
||||
if st.sporeRounds > 0 {
|
||||
st.sporeRounds--
|
||||
}
|
||||
|
||||
// Pet whiff → guaranteed miss
|
||||
if petWhiff {
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "pet", Action: "pet_whiff",
|
||||
@@ -437,7 +523,6 @@ func resolveEnemyAttack(st *combatState, player, enemy *Combatant, phase *Combat
|
||||
return false
|
||||
}
|
||||
|
||||
// Spore cloud miss
|
||||
if sporeMiss {
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "consumable", Action: "spore_miss",
|
||||
@@ -446,17 +531,24 @@ func resolveEnemyAttack(st *combatState, player, enemy *Combatant, phase *Combat
|
||||
return false
|
||||
}
|
||||
|
||||
// Player dodge
|
||||
playerDodge := player.Stats.DodgeRate * phase.SpeedWeight
|
||||
if playerDodge > 0 && rand.Float64() < playerDodge {
|
||||
roll := 1 + rand.IntN(20)
|
||||
isFumble := roll == 1
|
||||
isNat20 := roll == 20
|
||||
total := roll + enemy.Stats.AttackBonus
|
||||
|
||||
if isFumble || (!isNat20 && total < player.Stats.AC) {
|
||||
desc := ""
|
||||
if isFumble {
|
||||
desc = "fumble"
|
||||
}
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "enemy", Action: "miss",
|
||||
PlayerHP: st.playerHP, EnemyHP: st.enemyHP,
|
||||
Roll: roll, RollAgainst: player.Stats.AC, Desc: desc,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
// Ward: absorb full hit
|
||||
if st.wardCharges > 0 {
|
||||
st.wardCharges--
|
||||
st.events = append(st.events, CombatEvent{
|
||||
@@ -473,25 +565,17 @@ func resolveEnemyAttack(st *combatState, player, enemy *Combatant, phase *Combat
|
||||
dmg := calcDamage(int(float64(enemy.Stats.Attack)*atkMult), phase.AttackWeight, enemy.Mods.DamageBonus,
|
||||
playerDefense(player, st), phase.DefenseWeight, player.Mods.DamageReduct)
|
||||
|
||||
// Player block
|
||||
blocked := player.Stats.BlockRate > 0 && rand.Float64() < player.Stats.BlockRate
|
||||
if blocked {
|
||||
dmg = max(1, dmg/2)
|
||||
}
|
||||
|
||||
// Crit
|
||||
critRate := enemy.Stats.CritRate
|
||||
if phaseName == "Decisive" {
|
||||
critRate *= 2
|
||||
}
|
||||
isCrit := critRate > 0 && rand.Float64() < critRate
|
||||
isCrit := isNat20
|
||||
if isCrit {
|
||||
dmg *= 2
|
||||
}
|
||||
|
||||
dmg = max(1, dmg)
|
||||
|
||||
// Pet deflect: halve damage
|
||||
if petDeflect {
|
||||
dmg = max(1, dmg/2)
|
||||
st.events = append(st.events, CombatEvent{
|
||||
@@ -511,9 +595,9 @@ func resolveEnemyAttack(st *combatState, player, enemy *Combatant, phase *Combat
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "enemy", Action: action,
|
||||
Damage: dmg, PlayerHP: st.playerHP, EnemyHP: st.enemyHP,
|
||||
Roll: roll, RollAgainst: player.Stats.AC,
|
||||
})
|
||||
|
||||
// Reflect: bounce portion back (after player takes the hit)
|
||||
if st.reflectFrac > 0 {
|
||||
reflected := max(1, int(float64(dmg)*st.reflectFrac))
|
||||
st.reflectFrac = 0
|
||||
@@ -554,6 +638,9 @@ func applyAbility(st *combatState, player, enemy *Combatant, phase *CombatPhase,
|
||||
case "poison":
|
||||
st.poisonTicks = 2
|
||||
st.poisonDmg = 3 + rand.IntN(3)
|
||||
if player.Mods.PoisonResist {
|
||||
st.poisonDmg = max(1, st.poisonDmg/2)
|
||||
}
|
||||
st.events = append(st.events, CombatEvent{
|
||||
Round: st.round, Phase: phaseName, Actor: "enemy", Action: "poison",
|
||||
Desc: ab.Name, PlayerHP: st.playerHP, EnemyHP: st.enemyHP,
|
||||
|
||||
@@ -192,6 +192,31 @@ func unlockCoopCombatActionsForRun(runID int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// activeCoopMemberSet returns the set of user IDs currently locked into an
|
||||
// active co-op run. The midnight reset uses this to skip the streak/babysit
|
||||
// logic for those players — their co-op participation auto-resolves daily,
|
||||
// so they should not be treated as idle even though they take no manual
|
||||
// actions.
|
||||
func activeCoopMemberSet() (map[string]bool, error) {
|
||||
d := db.Get()
|
||||
rows, err := d.Query(`SELECT m.user_id FROM coop_dungeon_members m
|
||||
JOIN coop_dungeon_runs r ON r.id = m.run_id
|
||||
WHERE r.status = 'active'`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
out := map[string]bool{}
|
||||
for rows.Next() {
|
||||
var u string
|
||||
if err := rows.Scan(&u); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out[u] = true
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func lockCoopCombatActions() error {
|
||||
d := db.Get()
|
||||
_, err := d.Exec(`UPDATE adventure_characters
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 1 of the D&D integration layer. See gogobee_dnd_design_doc_v1.1.md.
|
||||
//
|
||||
// This file defines the additive D&D character layer that sits alongside
|
||||
// adventure_characters. A player without a dnd_character row continues to
|
||||
// use the legacy adventure system unchanged.
|
||||
|
||||
// ── Race / Class ─────────────────────────────────────────────────────────────
|
||||
|
||||
type DnDRace string
|
||||
type DnDClass string
|
||||
|
||||
const (
|
||||
RaceHuman DnDRace = "human"
|
||||
RaceElf DnDRace = "elf"
|
||||
RaceDwarf DnDRace = "dwarf"
|
||||
RaceHalfling DnDRace = "halfling"
|
||||
RaceOrc DnDRace = "orc"
|
||||
RaceTiefling DnDRace = "tiefling"
|
||||
RaceHalfElf DnDRace = "half_elf"
|
||||
|
||||
ClassFighter DnDClass = "fighter"
|
||||
ClassRogue DnDClass = "rogue"
|
||||
ClassMage DnDClass = "mage"
|
||||
ClassCleric DnDClass = "cleric"
|
||||
ClassRanger DnDClass = "ranger"
|
||||
)
|
||||
|
||||
type DnDRaceInfo struct {
|
||||
Key DnDRace
|
||||
Display string
|
||||
// Stat modifiers applied at setup-confirm time. STR/DEX/CON/INT/WIS/CHA.
|
||||
// Human's "+1 to any" is not yet implemented in Phase 1 — Human gets +0
|
||||
// across the board and we'll add the floating bonus in a later phase.
|
||||
Mods [6]int
|
||||
Passive string
|
||||
}
|
||||
|
||||
type DnDClassInfo struct {
|
||||
Key DnDClass
|
||||
Display string
|
||||
HPDie int // d10 → 10, d8 → 8, d6 → 6
|
||||
HPAvg int // per-level average after L1 (roundup of die/2 + 1)
|
||||
PrimaryA string // primary stat for narrative (not mechanical in Phase 1)
|
||||
PrimaryB string
|
||||
}
|
||||
|
||||
var dndRaces = []DnDRaceInfo{
|
||||
{RaceHuman, "Human", [6]int{0, 0, 0, 0, 0, 0}, "Versatile (floating +1 bonus deferred to Phase 2)"},
|
||||
{RaceElf, "Elf", [6]int{0, 2, -1, 1, 1, 0}, "Darkvision; immune to sleep effects"},
|
||||
{RaceDwarf, "Dwarf", [6]int{1, -1, 2, 0, 1, -1}, "Poison resistance; bonus vs. underground enemies"},
|
||||
{RaceHalfling, "Halfling", [6]int{0, 2, 0, 0, 1, 0}, "Lucky: once per combat, reroll a natural 1"},
|
||||
{RaceOrc, "Orc", [6]int{3, -1, 2, -1, -1, -1}, "Rage: once per combat, +50% damage for one turn"},
|
||||
{RaceTiefling, "Tiefling", [6]int{0, 1, 0, 1, 0, 2}, "Fire resistance; bonus on CHA checks"},
|
||||
{RaceHalfElf, "Half-Elf", [6]int{0, 1, 0, 1, 0, 2}, "Two bonus skill proficiencies"},
|
||||
}
|
||||
|
||||
var dndClasses = []DnDClassInfo{
|
||||
{ClassFighter, "Fighter", 10, 6, "STR", "CON"},
|
||||
{ClassRogue, "Rogue", 8, 5, "DEX", "INT"},
|
||||
{ClassMage, "Mage", 6, 4, "INT", "WIS"},
|
||||
{ClassCleric, "Cleric", 8, 5, "WIS", "CHA"},
|
||||
{ClassRanger, "Ranger", 8, 5, "DEX", "WIS"},
|
||||
}
|
||||
|
||||
func raceInfo(r DnDRace) (DnDRaceInfo, bool) {
|
||||
for _, ri := range dndRaces {
|
||||
if ri.Key == r {
|
||||
return ri, true
|
||||
}
|
||||
}
|
||||
return DnDRaceInfo{}, false
|
||||
}
|
||||
|
||||
func classInfo(c DnDClass) (DnDClassInfo, bool) {
|
||||
for _, ci := range dndClasses {
|
||||
if ci.Key == c {
|
||||
return ci, true
|
||||
}
|
||||
}
|
||||
return DnDClassInfo{}, false
|
||||
}
|
||||
|
||||
// ── Stat math ────────────────────────────────────────────────────────────────
|
||||
|
||||
// StandardArray is the set of values a player assigns at !setup stats.
|
||||
var standardArray = [6]int{15, 14, 13, 12, 10, 8}
|
||||
|
||||
// abilityModifier implements the standard D&D modifier formula:
|
||||
// floor((score - 10) / 2). Works for negative-going scores (Go's integer
|
||||
// division rounds toward zero, so we shift by 10 first via score-10
|
||||
// arithmetic; for the legal score range 1..30 this matches floor exactly).
|
||||
func abilityModifier(score int) int {
|
||||
diff := score - 10
|
||||
if diff >= 0 || diff%2 == 0 {
|
||||
return diff / 2
|
||||
}
|
||||
// negative odd → step toward -inf
|
||||
return diff/2 - 1
|
||||
}
|
||||
|
||||
// computeMaxHP — D&D5e style. L1: full HP die + CON mod (min 1).
|
||||
// Per level after: average HP die (roundup of die/2 + 1) + CON mod.
|
||||
func computeMaxHP(class DnDClass, conMod, level int) int {
|
||||
ci, ok := classInfo(class)
|
||||
if !ok {
|
||||
return 1
|
||||
}
|
||||
hp := ci.HPDie + conMod
|
||||
if hp < 1 {
|
||||
hp = 1
|
||||
}
|
||||
for i := 2; i <= level; i++ {
|
||||
gain := ci.HPAvg + conMod
|
||||
if gain < 1 {
|
||||
gain = 1
|
||||
}
|
||||
hp += gain
|
||||
}
|
||||
return hp
|
||||
}
|
||||
|
||||
// computeAC — Phase 1 baseline. Equipment-derived AC arrives in Phase 4
|
||||
// (per design doc §7.3 slot mapping). For now: 10 + DEX modifier, with a
|
||||
// small class armor floor reflecting starting proficiency.
|
||||
func computeAC(class DnDClass, dexMod int) int {
|
||||
floor := 0
|
||||
switch class {
|
||||
case ClassFighter:
|
||||
floor = 6 // medium-armor baseline
|
||||
case ClassCleric, ClassRanger:
|
||||
floor = 3
|
||||
case ClassRogue:
|
||||
floor = 1
|
||||
}
|
||||
return 10 + dexMod + floor
|
||||
}
|
||||
|
||||
// ── DnDCharacter struct + repository ─────────────────────────────────────────
|
||||
|
||||
type DnDCharacter struct {
|
||||
UserID id.UserID
|
||||
Race DnDRace
|
||||
Class DnDClass
|
||||
Level int
|
||||
XP int
|
||||
STR, DEX, CON int
|
||||
INT, WIS, CHA int
|
||||
HPCurrent int
|
||||
HPMax int
|
||||
TempHP int
|
||||
ArmorClass int
|
||||
PendingSetup bool
|
||||
AutoMigrated bool
|
||||
OnboardingSent bool
|
||||
ArmedAbility string
|
||||
// Phase 9 — spell layer.
|
||||
// PendingCast: JSON blob describing the queued spell to fire on next
|
||||
// one-shot combat (empty string = nothing queued). Set by !cast for
|
||||
// damage/control/buff spells; cleared after combat resolution.
|
||||
// ConcentrationSpell: id of the currently-active concentration spell
|
||||
// (empty = nothing active). ConcentrationExpiresAt is the wall-clock
|
||||
// expiry; nil for indefinite. Casting another concentration spell
|
||||
// supersedes whatever's here.
|
||||
PendingCast string
|
||||
ConcentrationSpell string
|
||||
ConcentrationExpiresAt *time.Time
|
||||
LastRespecAt *time.Time
|
||||
LastShortRestAt *time.Time
|
||||
LastLongRestAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Modifiers returns the six ability modifiers in STR/DEX/CON/INT/WIS/CHA order.
|
||||
func (c *DnDCharacter) Modifiers() [6]int {
|
||||
return [6]int{
|
||||
abilityModifier(c.STR),
|
||||
abilityModifier(c.DEX),
|
||||
abilityModifier(c.CON),
|
||||
abilityModifier(c.INT),
|
||||
abilityModifier(c.WIS),
|
||||
abilityModifier(c.CHA),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadDnDCharacter returns the player's D&D row, or (nil, nil) if absent.
|
||||
// Absent means the player has not run !setup at all.
|
||||
func LoadDnDCharacter(userID id.UserID) (*DnDCharacter, error) {
|
||||
row := db.Get().QueryRow(`
|
||||
SELECT user_id, race, class, dnd_level, dnd_xp,
|
||||
str_score, dex_score, con_score, int_score, wis_score, cha_score,
|
||||
hp_current, hp_max, temp_hp, armor_class,
|
||||
pending_setup, auto_migrated, onboarding_sent, armed_ability,
|
||||
pending_cast, concentration_spell, concentration_expires_at,
|
||||
last_respec_at, last_short_rest_at, last_long_rest_at,
|
||||
created_at, updated_at
|
||||
FROM dnd_character WHERE user_id = ?`, string(userID))
|
||||
c := &DnDCharacter{}
|
||||
var pending, autoMig, onboard int
|
||||
var raceStr, classStr string
|
||||
var uidStr string
|
||||
err := row.Scan(&uidStr, &raceStr, &classStr, &c.Level, &c.XP,
|
||||
&c.STR, &c.DEX, &c.CON, &c.INT, &c.WIS, &c.CHA,
|
||||
&c.HPCurrent, &c.HPMax, &c.TempHP, &c.ArmorClass,
|
||||
&pending, &autoMig, &onboard, &c.ArmedAbility,
|
||||
&c.PendingCast, &c.ConcentrationSpell, &c.ConcentrationExpiresAt,
|
||||
&c.LastRespecAt, &c.LastShortRestAt, &c.LastLongRestAt,
|
||||
&c.CreatedAt, &c.UpdatedAt)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load dnd_character: %w", err)
|
||||
}
|
||||
c.UserID = id.UserID(uidStr)
|
||||
c.Race = DnDRace(raceStr)
|
||||
c.Class = DnDClass(classStr)
|
||||
c.PendingSetup = pending == 1
|
||||
c.AutoMigrated = autoMig == 1
|
||||
c.OnboardingSent = onboard == 1
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// SaveDnDCharacter upserts the row.
|
||||
func SaveDnDCharacter(c *DnDCharacter) error {
|
||||
pending := 0
|
||||
if c.PendingSetup {
|
||||
pending = 1
|
||||
}
|
||||
autoMig := 0
|
||||
if c.AutoMigrated {
|
||||
autoMig = 1
|
||||
}
|
||||
onboard := 0
|
||||
if c.OnboardingSent {
|
||||
onboard = 1
|
||||
}
|
||||
_, err := db.Get().Exec(`
|
||||
INSERT INTO dnd_character (user_id, race, class, dnd_level, dnd_xp,
|
||||
str_score, dex_score, con_score, int_score, wis_score, cha_score,
|
||||
hp_current, hp_max, temp_hp, armor_class,
|
||||
pending_setup, auto_migrated, onboarding_sent, armed_ability,
|
||||
pending_cast, concentration_spell, concentration_expires_at,
|
||||
last_respec_at, last_short_rest_at, last_long_rest_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(user_id) DO UPDATE SET
|
||||
race=excluded.race, class=excluded.class,
|
||||
dnd_level=excluded.dnd_level, dnd_xp=excluded.dnd_xp,
|
||||
str_score=excluded.str_score, dex_score=excluded.dex_score,
|
||||
con_score=excluded.con_score, int_score=excluded.int_score,
|
||||
wis_score=excluded.wis_score, cha_score=excluded.cha_score,
|
||||
hp_current=excluded.hp_current, hp_max=excluded.hp_max,
|
||||
temp_hp=excluded.temp_hp, armor_class=excluded.armor_class,
|
||||
pending_setup=excluded.pending_setup,
|
||||
auto_migrated=excluded.auto_migrated,
|
||||
onboarding_sent=excluded.onboarding_sent,
|
||||
armed_ability=excluded.armed_ability,
|
||||
pending_cast=excluded.pending_cast,
|
||||
concentration_spell=excluded.concentration_spell,
|
||||
concentration_expires_at=excluded.concentration_expires_at,
|
||||
last_respec_at=excluded.last_respec_at,
|
||||
last_short_rest_at=excluded.last_short_rest_at,
|
||||
last_long_rest_at=excluded.last_long_rest_at,
|
||||
updated_at=CURRENT_TIMESTAMP`,
|
||||
string(c.UserID), string(c.Race), string(c.Class), c.Level, c.XP,
|
||||
c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA,
|
||||
c.HPCurrent, c.HPMax, c.TempHP, c.ArmorClass,
|
||||
pending, autoMig, onboard, c.ArmedAbility,
|
||||
c.PendingCast, c.ConcentrationSpell, c.ConcentrationExpiresAt,
|
||||
c.LastRespecAt, c.LastShortRestAt, c.LastLongRestAt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("save dnd_character: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// HasCompletedSetup returns true if the player has a confirmed D&D character.
|
||||
// Returns false for both "no row" and "row with pending_setup=1".
|
||||
func HasCompletedSetup(userID id.UserID) bool {
|
||||
var pending int
|
||||
err := db.Get().QueryRow(
|
||||
`SELECT pending_setup FROM dnd_character WHERE user_id = ?`,
|
||||
string(userID),
|
||||
).Scan(&pending)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return pending == 0
|
||||
}
|
||||
|
||||
// dndLevelFromCombatLevel maps the legacy combat_level onto the D&D level
|
||||
// scale. Empirical: legacy levels reach 50+, but the D&D progression curve
|
||||
// is specced through L20. We compress 5:1 — five legacy levels of grinding
|
||||
// roughly equals one D&D level — and clamp into [1, 20].
|
||||
//
|
||||
// Examples: legacy 0-4 → 1, 5-9 → 1, 10 → 2, 20 → 4, 49 → 9, 100+ → 20.
|
||||
//
|
||||
// Used by !setup confirm and by ensureDnDCharacterForCombat (auto-migration)
|
||||
// to seed the initial D&D level. After migration, dnd_level advances on its
|
||||
// own via XP earned in combat (see dnd_xp.go).
|
||||
func dndLevelFromCombatLevel(combatLevel int) int {
|
||||
lvl := combatLevel / 5
|
||||
if lvl < 1 {
|
||||
lvl = 1
|
||||
}
|
||||
if lvl > dndMaxLevel {
|
||||
lvl = dndMaxLevel
|
||||
}
|
||||
return lvl
|
||||
}
|
||||
|
||||
// applyRaceMods adds the race's ability modifiers to a base score block.
|
||||
func applyRaceMods(race DnDRace, scores [6]int) [6]int {
|
||||
ri, ok := raceInfo(race)
|
||||
if !ok {
|
||||
return scores
|
||||
}
|
||||
for i := 0; i < 6; i++ {
|
||||
scores[i] += ri.Mods[i]
|
||||
}
|
||||
return scores
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 6 — active abilities via pre-arm model.
|
||||
//
|
||||
// The combat engine is one-shot, so player-activated abilities use a pre-arm
|
||||
// pattern: !arm <ability> reserves it (consumes one resource immediately)
|
||||
// and the next combat auto-fires it via existing CombatModifiers fields.
|
||||
// The armed flag is cleared on combat completion regardless of outcome.
|
||||
//
|
||||
// Resources refresh on long rest (Phase 6 simplification — short-rest classes
|
||||
// also use long-rest refresh until we split short/long resource pools).
|
||||
|
||||
// ── Ability definitions ──────────────────────────────────────────────────────
|
||||
|
||||
type DnDAbility struct {
|
||||
ID string
|
||||
Name string
|
||||
Class DnDClass
|
||||
Resource string // "stamina", "spell_slot", "favor", etc.
|
||||
Description string
|
||||
// Effect — applied to mods at combat start when armed
|
||||
Apply func(c *DnDCharacter, mods *CombatModifiers)
|
||||
}
|
||||
|
||||
var dndActiveAbilities = map[string]DnDAbility{
|
||||
"second_wind": {
|
||||
ID: "second_wind",
|
||||
Name: "Second Wind",
|
||||
Class: ClassFighter,
|
||||
Resource: "stamina",
|
||||
Description: "Restore HP at low health: 1d10 + level (consumes 1 stamina).",
|
||||
Apply: func(c *DnDCharacter, mods *CombatModifiers) {
|
||||
// HealItem fires once when player drops below 50% HP.
|
||||
// Avg of 1d10 + level: 5.5 + level.
|
||||
mods.HealItem += 5 + c.Level
|
||||
},
|
||||
},
|
||||
"magic_missile": {
|
||||
ID: "magic_missile",
|
||||
Name: "Magic Missile",
|
||||
Class: ClassMage,
|
||||
Resource: "spell_slot",
|
||||
Description: "Three darts strike unerringly at the start of combat: 3 × (1d4+1) force damage.",
|
||||
Apply: func(c *DnDCharacter, mods *CombatModifiers) {
|
||||
// 3 darts × avg 3.5 = ~10. Auto-hit pre-combat damage.
|
||||
mods.FlatDmgStart += 9 + abilityModifier(c.INT)
|
||||
},
|
||||
},
|
||||
"healing_word": {
|
||||
ID: "healing_word",
|
||||
Name: "Healing Word",
|
||||
Class: ClassCleric,
|
||||
Resource: "favor",
|
||||
Description: "Restore 1d4 + WIS HP at low health (consumes 1 divine favor).",
|
||||
Apply: func(c *DnDCharacter, mods *CombatModifiers) {
|
||||
mods.HealItem += 3 + abilityModifier(c.WIS)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func parseAbility(s string) (DnDAbility, bool) {
|
||||
s = strings.ToLower(strings.TrimSpace(strings.ReplaceAll(s, " ", "_")))
|
||||
s = strings.ReplaceAll(s, "-", "_")
|
||||
if a, ok := dndActiveAbilities[s]; ok {
|
||||
return a, true
|
||||
}
|
||||
for _, a := range dndActiveAbilities {
|
||||
if strings.EqualFold(a.Name, s) {
|
||||
return a, true
|
||||
}
|
||||
}
|
||||
return DnDAbility{}, false
|
||||
}
|
||||
|
||||
// classActiveAbilities returns the active abilities a class can know.
|
||||
func classActiveAbilities(class DnDClass) []DnDAbility {
|
||||
var out []DnDAbility
|
||||
for _, a := range dndActiveAbilities {
|
||||
if a.Class == class {
|
||||
out = append(out, a)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ── Resource pool ────────────────────────────────────────────────────────────
|
||||
|
||||
// classResourceMax returns (resource_type, max_value) for a class.
|
||||
// Phase 6: each class has one active resource pool.
|
||||
func classResourceMax(class DnDClass) (string, int) {
|
||||
switch class {
|
||||
case ClassFighter:
|
||||
return "stamina", 3
|
||||
case ClassRogue:
|
||||
return "focus", 2
|
||||
case ClassMage:
|
||||
return "spell_slot", 1
|
||||
case ClassCleric:
|
||||
return "favor", 3
|
||||
case ClassRanger:
|
||||
return "focus", 2
|
||||
}
|
||||
return "", 0
|
||||
}
|
||||
|
||||
// initResources writes a fresh resource row for the class. Idempotent —
|
||||
// won't overwrite an existing pool. Called on !setup confirm and on
|
||||
// auto-migration.
|
||||
func initResources(userID id.UserID, class DnDClass) error {
|
||||
resType, max := classResourceMax(class)
|
||||
if resType == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := db.Get().Exec(`
|
||||
INSERT OR IGNORE INTO dnd_resources (user_id, resource_type, current_value, max_value)
|
||||
VALUES (?, ?, ?, ?)`,
|
||||
string(userID), resType, max, max)
|
||||
return err
|
||||
}
|
||||
|
||||
// getResource returns (current, max). Returns (0, 0, true) if no row exists.
|
||||
func getResource(userID id.UserID, resType string) (int, int, error) {
|
||||
var cur, max int
|
||||
err := db.Get().QueryRow(
|
||||
`SELECT current_value, max_value FROM dnd_resources
|
||||
WHERE user_id = ? AND resource_type = ?`,
|
||||
string(userID), resType,
|
||||
).Scan(&cur, &max)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
return cur, max, err
|
||||
}
|
||||
|
||||
// spendResource decrements current_value if at least amount is available.
|
||||
// Returns true on success.
|
||||
func spendResource(userID id.UserID, resType string, amount int) (bool, error) {
|
||||
res, err := db.Get().Exec(`
|
||||
UPDATE dnd_resources
|
||||
SET current_value = current_value - ?,
|
||||
last_reset_at = last_reset_at -- no-op, keep timestamp
|
||||
WHERE user_id = ? AND resource_type = ?
|
||||
AND current_value >= ?`,
|
||||
amount, string(userID), resType, amount)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
// refreshAllResources sets current_value = max_value for every resource of a user.
|
||||
// Called on long rest.
|
||||
func refreshAllResources(userID id.UserID) error {
|
||||
_, err := db.Get().Exec(`
|
||||
UPDATE dnd_resources SET current_value = max_value, last_reset_at = CURRENT_TIMESTAMP
|
||||
WHERE user_id = ?`,
|
||||
string(userID))
|
||||
return err
|
||||
}
|
||||
|
||||
// ── !arm command ─────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDArmCmd(ctx MessageContext, args string) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
args = strings.TrimSpace(args)
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character.")
|
||||
}
|
||||
|
||||
if args == "" || strings.ToLower(args) == "list" {
|
||||
return p.SendDM(ctx.Sender, renderArmList(c))
|
||||
}
|
||||
if strings.ToLower(args) == "clear" {
|
||||
c.ArmedAbility = ""
|
||||
_ = SaveDnDCharacter(c)
|
||||
return p.SendDM(ctx.Sender, "Disarmed. Resource is not refunded.")
|
||||
}
|
||||
|
||||
ab, ok := parseAbility(args)
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender, "Unknown ability. Run `!arm` to see your options.")
|
||||
}
|
||||
if ab.Class != c.Class {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s is a %s ability — your class is %s.", ab.Name, titleClass(ab.Class), titleClass(c.Class)))
|
||||
}
|
||||
|
||||
if c.ArmedAbility != "" {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"You already have **%s** armed. Run `!arm clear` to disarm first.",
|
||||
displayAbility(c.ArmedAbility)))
|
||||
}
|
||||
|
||||
cur, _, err := getResource(ctx.Sender, ab.Resource)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load resources.")
|
||||
}
|
||||
if cur < 1 {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"No %s remaining. Take a long rest to refresh.", ab.Resource))
|
||||
}
|
||||
|
||||
// Audit fix C: save the armed-ability flag FIRST. If save fails, no
|
||||
// resource was spent. If save succeeds and spend fails (rare — single
|
||||
// writer SQLite makes it nearly impossible after a successful save in
|
||||
// the same connection), revert the armed flag.
|
||||
c.ArmedAbility = ab.ID
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't save armed state: "+err.Error())
|
||||
}
|
||||
|
||||
ok, err = spendResource(ctx.Sender, ab.Resource, 1)
|
||||
if err != nil || !ok {
|
||||
// Roll back the armed flag.
|
||||
c.ArmedAbility = ""
|
||||
if rerr := SaveDnDCharacter(c); rerr != nil {
|
||||
slog.Error("dnd: failed to revert armed flag after spend failure",
|
||||
"user", ctx.Sender, "err", rerr)
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "Couldn't spend resource — armed state reverted.")
|
||||
}
|
||||
|
||||
curAfter, max, _ := getResource(ctx.Sender, ab.Resource)
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"⚡ **%s** armed for next combat. (%s: %d/%d remaining)",
|
||||
ab.Name, ab.Resource, curAfter, max))
|
||||
}
|
||||
|
||||
func renderArmList(c *DnDCharacter) string {
|
||||
abilities := classActiveAbilities(c.Class)
|
||||
var b strings.Builder
|
||||
b.WriteString("**Active Abilities** (pre-arm via `!arm <name>`)\n\n")
|
||||
|
||||
if len(abilities) == 0 {
|
||||
b.WriteString("_No active abilities for your class yet._\n")
|
||||
} else {
|
||||
resType, _ := classResourceMax(c.Class)
|
||||
cur, max, _ := getResource(c.UserID, resType)
|
||||
b.WriteString(fmt.Sprintf("Resource: **%s** %d/%d\n\n", resType, cur, max))
|
||||
for _, a := range abilities {
|
||||
b.WriteString(fmt.Sprintf(" • **%s** (1 %s) — %s\n", a.Name, a.Resource, a.Description))
|
||||
}
|
||||
}
|
||||
if c.ArmedAbility != "" {
|
||||
b.WriteString(fmt.Sprintf("\n_Currently armed: **%s** (will fire on next combat)_\n", displayAbility(c.ArmedAbility)))
|
||||
}
|
||||
b.WriteString("\nResources refresh on long rest.")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func displayAbility(id string) string {
|
||||
if a, ok := dndActiveAbilities[id]; ok {
|
||||
return a.Name
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// ── Combat hook ──────────────────────────────────────────────────────────────
|
||||
|
||||
// applyArmedAbility checks for a pre-armed ability on the character and
|
||||
// applies its effect to the player's CombatModifiers, then clears the armed
|
||||
// flag. Called from combat_bridge.go before SimulateCombat.
|
||||
func applyArmedAbility(c *DnDCharacter, mods *CombatModifiers) (string, bool) {
|
||||
if c == nil || c.ArmedAbility == "" {
|
||||
return "", false
|
||||
}
|
||||
ab, ok := dndActiveAbilities[c.ArmedAbility]
|
||||
if !ok {
|
||||
c.ArmedAbility = ""
|
||||
_ = SaveDnDCharacter(c)
|
||||
return "", false
|
||||
}
|
||||
ab.Apply(c, mods)
|
||||
firedName := ab.Name
|
||||
c.ArmedAbility = ""
|
||||
_ = SaveDnDCharacter(c)
|
||||
return firedName, true
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func setupAbilitiesTestDB(t *testing.T) {
|
||||
t.Helper()
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
}
|
||||
|
||||
func TestActiveAbilityCatalogue(t *testing.T) {
|
||||
required := map[string]DnDClass{
|
||||
"second_wind": ClassFighter,
|
||||
"magic_missile": ClassMage,
|
||||
"healing_word": ClassCleric,
|
||||
}
|
||||
for id, class := range required {
|
||||
ab, ok := dndActiveAbilities[id]
|
||||
if !ok {
|
||||
t.Errorf("missing active ability: %s", id)
|
||||
continue
|
||||
}
|
||||
if ab.Class != class {
|
||||
t.Errorf("%s class = %s, want %s", id, ab.Class, class)
|
||||
}
|
||||
if ab.Apply == nil {
|
||||
t.Errorf("%s has nil Apply func", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAbility(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
id string
|
||||
ok bool
|
||||
}{
|
||||
{"second_wind", "second_wind", true},
|
||||
{"second wind", "second_wind", true},
|
||||
{"second-wind", "second_wind", true},
|
||||
{"Second Wind", "second_wind", true},
|
||||
{"magic_missile", "magic_missile", true},
|
||||
{"frostbolt", "", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
ab, ok := parseAbility(c.in)
|
||||
if ok != c.ok {
|
||||
t.Errorf("parseAbility(%q) ok = %v, want %v", c.in, ok, c.ok)
|
||||
}
|
||||
if ok && ab.ID != c.id {
|
||||
t.Errorf("parseAbility(%q) id = %q, want %q", c.in, ab.ID, c.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassResourceMax(t *testing.T) {
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
typ string
|
||||
max int
|
||||
}{
|
||||
{ClassFighter, "stamina", 3},
|
||||
{ClassRogue, "focus", 2},
|
||||
{ClassMage, "spell_slot", 1},
|
||||
{ClassCleric, "favor", 3},
|
||||
{ClassRanger, "focus", 2},
|
||||
}
|
||||
for _, c := range cases {
|
||||
typ, max := classResourceMax(c.class)
|
||||
if typ != c.typ || max != c.max {
|
||||
t.Errorf("%s: got (%s, %d), want (%s, %d)", c.class, typ, max, c.typ, c.max)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitResources_Idempotent(t *testing.T) {
|
||||
setupAbilitiesTestDB(t)
|
||||
uid := id.UserID("@init_res:example")
|
||||
|
||||
if err := initResources(uid, ClassFighter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cur, max, _ := getResource(uid, "stamina")
|
||||
if cur != 3 || max != 3 {
|
||||
t.Errorf("post-init: cur=%d max=%d, want 3/3", cur, max)
|
||||
}
|
||||
|
||||
// Second call should not bump.
|
||||
if err := initResources(uid, ClassFighter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cur2, _, _ := getResource(uid, "stamina")
|
||||
if cur2 != cur {
|
||||
t.Errorf("init not idempotent: cur went %d → %d", cur, cur2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpendAndRefreshResource(t *testing.T) {
|
||||
setupAbilitiesTestDB(t)
|
||||
uid := id.UserID("@spend_test:example")
|
||||
if err := initResources(uid, ClassFighter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
ok, err := spendResource(uid, "stamina", 1)
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("spend %d failed: ok=%v err=%v", i, ok, err)
|
||||
}
|
||||
}
|
||||
// 4th spend should fail (drained).
|
||||
ok, _ := spendResource(uid, "stamina", 1)
|
||||
if ok {
|
||||
t.Error("4th spend succeeded; should drain at 0")
|
||||
}
|
||||
|
||||
if err := refreshAllResources(uid); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cur, max, _ := getResource(uid, "stamina")
|
||||
if cur != max || cur != 3 {
|
||||
t.Errorf("post-refresh: cur=%d max=%d, want 3/3", cur, max)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyArmedAbility_FighterSecondWind(t *testing.T) {
|
||||
setupAbilitiesTestDB(t)
|
||||
uid := id.UserID("@arm_fighter:example")
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 5,
|
||||
STR: 16, DEX: 12, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
ArmedAbility: "second_wind",
|
||||
}
|
||||
c.HPMax = computeMaxHP(c.Class, abilityModifier(c.CON), c.Level)
|
||||
c.HPCurrent = c.HPMax
|
||||
c.ArmorClass = computeAC(c.Class, abilityModifier(c.DEX))
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mods := CombatModifiers{}
|
||||
name, fired := applyArmedAbility(c, &mods)
|
||||
if !fired {
|
||||
t.Fatal("ability did not fire")
|
||||
}
|
||||
if name != "Second Wind" {
|
||||
t.Errorf("name = %q, want Second Wind", name)
|
||||
}
|
||||
wantHeal := 5 + c.Level // 5 + 5 = 10
|
||||
if mods.HealItem != wantHeal {
|
||||
t.Errorf("HealItem = %d, want %d", mods.HealItem, wantHeal)
|
||||
}
|
||||
|
||||
// Armed flag cleared, persisted.
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.ArmedAbility != "" {
|
||||
t.Errorf("ArmedAbility not cleared: %q", got.ArmedAbility)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyArmedAbility_MageMagicMissile(t *testing.T) {
|
||||
setupAbilitiesTestDB(t)
|
||||
uid := id.UserID("@arm_mage:example")
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Class: ClassMage, Race: RaceHuman, Level: 1,
|
||||
INT: 14, ArmedAbility: "magic_missile", HPMax: 10, HPCurrent: 10,
|
||||
}
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mods := CombatModifiers{}
|
||||
_, fired := applyArmedAbility(c, &mods)
|
||||
if !fired {
|
||||
t.Fatal("magic missile did not fire")
|
||||
}
|
||||
wantDmg := 9 + abilityModifier(c.INT) // 9 + 2 = 11
|
||||
if mods.FlatDmgStart != wantDmg {
|
||||
t.Errorf("FlatDmgStart = %d, want %d", mods.FlatDmgStart, wantDmg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyArmedAbility_NoArm(t *testing.T) {
|
||||
c := &DnDCharacter{Class: ClassFighter, ArmedAbility: ""}
|
||||
mods := CombatModifiers{}
|
||||
_, fired := applyArmedAbility(c, &mods)
|
||||
if fired {
|
||||
t.Error("fired with no armed ability")
|
||||
}
|
||||
}
|
||||
|
||||
// TestArmCommand_FullFlow integrates !arm via the handler: spends resource,
|
||||
// sets armed_ability, surfaces in combat, clears.
|
||||
func TestArmCommand_FullFlow(t *testing.T) {
|
||||
setupAbilitiesTestDB(t)
|
||||
uid := id.UserID("@arm_flow:example")
|
||||
|
||||
if err := createAdvCharacter(uid, "arm_flow"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 3,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
}
|
||||
c.HPMax = computeMaxHP(c.Class, abilityModifier(c.CON), c.Level)
|
||||
c.HPCurrent = c.HPMax
|
||||
c.ArmorClass = computeAC(c.Class, abilityModifier(c.DEX))
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := initResources(uid, c.Class); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDArmCmd(MessageContext{Sender: uid}, "second_wind"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.ArmedAbility != "second_wind" {
|
||||
t.Errorf("ArmedAbility = %q, want second_wind", got.ArmedAbility)
|
||||
}
|
||||
cur, max, _ := getResource(uid, "stamina")
|
||||
if cur != 2 || max != 3 {
|
||||
t.Errorf("stamina = %d/%d, want 2/3", cur, max)
|
||||
}
|
||||
|
||||
// Trying to arm again with one already armed should fail (without
|
||||
// changing state).
|
||||
if err := p.handleDnDArmCmd(MessageContext{Sender: uid}, "second_wind"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got2, _ := LoadDnDCharacter(uid)
|
||||
if got2.ArmedAbility != "second_wind" {
|
||||
t.Errorf("double-arm changed state: %q", got2.ArmedAbility)
|
||||
}
|
||||
cur2, _, _ := getResource(uid, "stamina")
|
||||
if cur2 != 2 {
|
||||
t.Errorf("double-arm spent extra resource: cur=%d", cur2)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func setupAuditTestDB(t *testing.T) {
|
||||
t.Helper()
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
}
|
||||
|
||||
// ── Fix D: Orc Rage threshold parity ────────────────────────────────────────
|
||||
|
||||
// TestOrcRage_ThresholdExact: with HP*2 < MaxHP, the threshold is exactly 50%
|
||||
// regardless of MaxHP parity.
|
||||
func TestOrcRage_ThresholdExact(t *testing.T) {
|
||||
cases := []struct {
|
||||
hp, maxHP int
|
||||
shouldFire bool
|
||||
}{
|
||||
{50, 100, false}, // exactly 50% — does NOT fire (strict <)
|
||||
{49, 100, true}, // just under
|
||||
{8, 16, false}, // exactly 50% even MaxHP
|
||||
{7, 16, true},
|
||||
{8, 15, true}, // 8/15 = 53% — under former threshold of MaxHP/2=7. New: 8*2=16, 16<15 false. Hmm.
|
||||
}
|
||||
// Re-derive: HP*2 < MaxHP. So 8*2=16 < 15? No. Doesn't fire. That means at MaxHP=15, threshold trips at HP*2 < 15, i.e. HP < 7.5, i.e. HP ≤ 7.
|
||||
// Old behavior used HP < MaxHP/2 = HP < 7 (integer div). So fired at HP < 7, i.e., HP ≤ 6. Different by one.
|
||||
// Pick cases that distinguish.
|
||||
cases = []struct {
|
||||
hp, maxHP int
|
||||
shouldFire bool
|
||||
}{
|
||||
{50, 100, false},
|
||||
{49, 100, true},
|
||||
{8, 16, false},
|
||||
{7, 16, true},
|
||||
{6, 15, true}, // 6*2=12 < 15 ✓
|
||||
{7, 15, true}, // 7*2=14 < 15 ✓ (old code's MaxHP/2=7 would have NOT fired at HP=7)
|
||||
{8, 15, false}, // 8*2=16, not < 15
|
||||
}
|
||||
for _, c := range cases {
|
||||
// Direct unit-check via the predicate the engine uses.
|
||||
fired := c.hp*2 < c.maxHP
|
||||
if fired != c.shouldFire {
|
||||
t.Errorf("hp=%d maxHP=%d: predicate=%v, want %v", c.hp, c.maxHP, fired, c.shouldFire)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fix E: respec wipes resource pool ───────────────────────────────────────
|
||||
|
||||
func TestRespec_WipesOldResources(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@respec_resources:example")
|
||||
|
||||
// Set up a Fighter with stamina pool.
|
||||
if err := createAdvCharacter(uid, "respec_test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 3,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
HPMax: 30, HPCurrent: 30, ArmorClass: 16,
|
||||
}
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := initResources(uid, ClassFighter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Spend some stamina so the pool isn't at max.
|
||||
spendResource(uid, "stamina", 1)
|
||||
|
||||
// Fund their account so respec can debit.
|
||||
euro := &EuroPlugin{}
|
||||
euro.ensureBalance(uid)
|
||||
euro.Credit(uid, 10000, "test")
|
||||
|
||||
p := &AdventurePlugin{euro: euro}
|
||||
if err := p.handleDnDRespecCmd(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Old stamina row should be gone.
|
||||
cur, max, _ := getResource(uid, "stamina")
|
||||
if cur != 0 || max != 0 {
|
||||
t.Errorf("post-respec stamina: cur=%d max=%d, want 0/0 (row deleted)", cur, max)
|
||||
}
|
||||
|
||||
// dnd_character should be in pending_setup state, no class/race.
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got == nil || !got.PendingSetup || got.Class != "" || got.Race != "" {
|
||||
t.Errorf("post-respec sheet: %+v", got)
|
||||
}
|
||||
// Euros debited.
|
||||
if euro.GetBalance(uid) > 5001 {
|
||||
t.Errorf("euros not debited: balance %.0f, expected ~5000", euro.GetBalance(uid))
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fix B: respec save-then-debit preserves euros on save failure ───────────
|
||||
|
||||
// We can't easily simulate a save failure mid-test without dependency
|
||||
// injection. Instead, verify the *insufficient-balance* path: a player with
|
||||
// no euros should get the error WITHOUT any state mutation.
|
||||
func TestRespec_InsufficientFundsLeavesStateIntact(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@respec_broke:example")
|
||||
if err := createAdvCharacter(uid, "broke"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceElf, Class: ClassMage, Level: 4,
|
||||
STR: 8, DEX: 16, CON: 10, INT: 17, WIS: 13, CHA: 12,
|
||||
HPMax: 22, HPCurrent: 22, ArmorClass: 13,
|
||||
}
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := initResources(uid, ClassMage); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
euro := &EuroPlugin{}
|
||||
// Don't credit — balance stays 0.
|
||||
p := &AdventurePlugin{euro: euro}
|
||||
if err := p.handleDnDRespecCmd(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// State must be intact.
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.Class != ClassMage || got.Race != RaceElf || got.PendingSetup {
|
||||
t.Errorf("insufficient-funds respec mutated state: %+v", got)
|
||||
}
|
||||
// Mage's spell_slot pool should still be there.
|
||||
cur, max, _ := getResource(uid, "spell_slot")
|
||||
if max != 1 {
|
||||
t.Errorf("spell_slot pool wiped on insufficient-funds respec: cur=%d max=%d", cur, max)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fix C: arm save-then-spend; on spend failure, armed flag reverts ────────
|
||||
|
||||
// Hard to force spendResource to fail without DI; verify the happy path
|
||||
// still works (resource decrements once, armed_ability set).
|
||||
func TestArm_SaveThenSpend_HappyPath(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@arm_order:example")
|
||||
if err := createAdvCharacter(uid, "arm_order"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 3,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
HPMax: 30, HPCurrent: 30, ArmorClass: 16,
|
||||
}
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := initResources(uid, ClassFighter); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDArmCmd(MessageContext{Sender: uid}, "second_wind"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.ArmedAbility != "second_wind" {
|
||||
t.Errorf("ArmedAbility = %q, want second_wind", got.ArmedAbility)
|
||||
}
|
||||
cur, _, _ := getResource(uid, "stamina")
|
||||
if cur != 2 {
|
||||
t.Errorf("stamina = %d, want 2 (3 - 1)", cur)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fix F: onboarding sent exactly once across draft cancel/rebuild ────────
|
||||
|
||||
func TestOnboarding_PersistsAcrossRespec(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@onboard_persist:example")
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 3,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
HPMax: 30, HPCurrent: 30, ArmorClass: 16,
|
||||
OnboardingSent: true, // already received DM
|
||||
}
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if !got.OnboardingSent {
|
||||
t.Fatal("OnboardingSent didn't round-trip")
|
||||
}
|
||||
|
||||
// maybeSendDnDOnboarding must NOT re-send.
|
||||
p := &AdventurePlugin{}
|
||||
advChar := &AdventureCharacter{UserID: uid, CombatLevel: 20}
|
||||
p.maybeSendDnDOnboarding(uid, advChar, got)
|
||||
|
||||
// Flag must remain set; no error.
|
||||
got2, _ := LoadDnDCharacter(uid)
|
||||
if !got2.OnboardingSent {
|
||||
t.Error("OnboardingSent flag flipped off")
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fix G: Persuasion shop discount expires after 30 minutes ────────────────
|
||||
|
||||
func TestPersuasionDiscount_ExpiresAfterTTL(t *testing.T) {
|
||||
p := &AdventurePlugin{}
|
||||
uid := id.UserID("@disc_expire:example")
|
||||
// Start a session with a discount applied, but with StartedAt in the past.
|
||||
pastTime := time.Now().Add(-31 * time.Minute)
|
||||
p.shopSessions.Store(string(uid), &advShopSession{
|
||||
StartedAt: pastTime,
|
||||
PersuasionDiscount: 0.10,
|
||||
})
|
||||
factor := p.shopSessionPriceFactor(uid)
|
||||
if factor != 1.0 {
|
||||
t.Errorf("expired session: factor = %v, want 1.0", factor)
|
||||
}
|
||||
// Announce should also return empty.
|
||||
if got := p.shopSessionAnnounceDiscount(uid); got != "" {
|
||||
t.Errorf("expired session announce = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPersuasionDiscount_ActiveWithinTTL(t *testing.T) {
|
||||
p := &AdventurePlugin{}
|
||||
uid := id.UserID("@disc_active:example")
|
||||
p.shopSessions.Store(string(uid), &advShopSession{
|
||||
StartedAt: time.Now(),
|
||||
PersuasionDiscount: 0.10,
|
||||
})
|
||||
factor := p.shopSessionPriceFactor(uid)
|
||||
if factor != 0.90 {
|
||||
t.Errorf("active session: factor = %v, want 0.9", factor)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fix I: HP scaling clamp ─────────────────────────────────────────────────
|
||||
|
||||
// ── Onboarding gap: !setup-first path and wrapper for non-combat handlers ──
|
||||
|
||||
// TestEnsureCharForDnDCmd_FreshMigrate — the wrapper used by !check, !stats,
|
||||
// !level, !rest, !arm should auto-migrate AND record OnboardingSent=true
|
||||
// for legacy players.
|
||||
func TestEnsureCharForDnDCmd_FreshMigrate(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@wrapper_legacy:example")
|
||||
if err := createAdvCharacter(uid, "wrapper_legacy"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
advChar, _ := loadAdvCharacter(uid)
|
||||
advChar.CombatLevel = 25 // legacy player
|
||||
if err := saveAdvCharacter(advChar); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Plugin without Matrix client — maybeSendDnDOnboarding short-circuits.
|
||||
// We only verify that the wrapper produces a character; the DM-side
|
||||
// short-circuit means OnboardingSent stays false until a real send fires.
|
||||
p := &AdventurePlugin{}
|
||||
c, err := p.ensureCharForDnDCmd(uid, advChar)
|
||||
if err != nil || c == nil {
|
||||
t.Fatalf("ensureCharForDnDCmd: %v / nil=%v", err, c == nil)
|
||||
}
|
||||
if c.PendingSetup {
|
||||
t.Error("auto-migrated char should not be pending_setup")
|
||||
}
|
||||
if !c.AutoMigrated {
|
||||
t.Error("auto-migrated flag not set")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetupStatus_LegacyWelcomeStubsRow — when a legacy player runs `!setup`
|
||||
// for the first time, we save a stub draft with OnboardingSent persisted so
|
||||
// future paths don't re-fire the welcome.
|
||||
//
|
||||
// SendDM no-ops in tests (nil Client), so OnboardingSent stays 0 on the
|
||||
// stub. The behavior we verify: a stub row gets saved on first !setup, and
|
||||
// it's flagged PendingSetup=1 so loadOrInitDraft will continue the flow.
|
||||
func TestSetupStatus_StubRowSaved(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@setup_first:example")
|
||||
if err := createAdvCharacter(uid, "setup_first"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
advChar, _ := loadAdvCharacter(uid)
|
||||
advChar.CombatLevel = 30
|
||||
saveAdvCharacter(advChar)
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.dndSetupStatus(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Stub row should now exist.
|
||||
got, err := LoadDnDCharacter(uid)
|
||||
if err != nil || got == nil {
|
||||
t.Fatalf("expected stub row after !setup; got err=%v", err)
|
||||
}
|
||||
if !got.PendingSetup {
|
||||
t.Error("stub row should be pending_setup=1")
|
||||
}
|
||||
if got.Race != "" || got.Class != "" {
|
||||
t.Errorf("stub row should have empty race/class; got race=%q class=%q",
|
||||
got.Race, got.Class)
|
||||
}
|
||||
// Level on the stub must be the computed mapping (not the default 1)
|
||||
// so the onboarding DM reports the correct projected level.
|
||||
wantLevel := dndLevelFromCombatLevel(30) // 30/5 = 6
|
||||
if got.Level != wantLevel {
|
||||
t.Errorf("stub level = %d, want %d (combat_level=30 → /5)", got.Level, wantLevel)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetupStatus_BrandNewPlayerNoStub — combat_level < 2 means brand-new
|
||||
// player. The !setup flow must NOT save a stub or fire onboarding.
|
||||
func TestSetupStatus_BrandNewPlayerNoStub(t *testing.T) {
|
||||
setupAuditTestDB(t)
|
||||
uid := id.UserID("@setup_new:example")
|
||||
if err := createAdvCharacter(uid, "setup_new"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// CombatLevel stays at default (1).
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.dndSetupStatus(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// No row should exist — brand-new player flow doesn't pre-create.
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got != nil {
|
||||
t.Errorf("brand-new player got a stub row: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDHPScaling_NeverExceedsOriginalMax(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 100}
|
||||
c := &DnDCharacter{HPMax: 50, HPCurrent: 100} // pathological: 200% — shouldn't happen but be safe
|
||||
applyDnDHPScaling(&stats, c)
|
||||
if stats.MaxHP > 100 {
|
||||
t.Errorf("clamp failed: MaxHP scaled to %d, original was 100", stats.MaxHP)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package plugin
|
||||
|
||||
// Phase 7 — D&D starter bestiary.
|
||||
//
|
||||
// These are named monster definitions ready to slot into encounter content.
|
||||
// Phase 7 ships them as data only — wiring them into specific dungeons or
|
||||
// arena rounds is a future content task. The combat engine consumes them
|
||||
// via the existing DnDMonsterTemplate→CombatStats path (see toCombatStats).
|
||||
|
||||
// DnDMonsterTemplate is the bestiary record for a named creature. Mirrors
|
||||
// v1.0 §8.1's stat block schema, simplified to the subset combat actually
|
||||
// uses (HP, AC, attack, speed, ability proc, special tags).
|
||||
type DnDMonsterTemplate struct {
|
||||
ID string
|
||||
Name string
|
||||
CR float32 // challenge rating (display only for now)
|
||||
HP int
|
||||
AC int
|
||||
Attack int // engine's "Attack" stat (raw damage value)
|
||||
AttackBonus int // d20 to-hit bonus
|
||||
Speed int
|
||||
BlockRate float64
|
||||
Ability *MonsterAbility
|
||||
XPValue int
|
||||
Notes string
|
||||
}
|
||||
|
||||
// dndBestiary is the canonical lookup. Keyed by ID.
|
||||
var dndBestiary = map[string]DnDMonsterTemplate{
|
||||
"goblin": {
|
||||
ID: "goblin", Name: "Goblin",
|
||||
CR: 0.25, HP: 7, AC: 13, Attack: 6, AttackBonus: 4, Speed: 14,
|
||||
BlockRate: 0.05,
|
||||
Ability: &MonsterAbility{Name: "Nimble Escape", Phase: "any", ProcChance: 0.20, Effect: "stun"},
|
||||
XPValue: 30,
|
||||
Notes: "Fast and skittish. Escapes pin attempts; will retreat if obviously outmatched.",
|
||||
},
|
||||
"skeleton": {
|
||||
ID: "skeleton", Name: "Skeleton",
|
||||
CR: 0.25, HP: 13, AC: 13, Attack: 8, AttackBonus: 4, Speed: 10,
|
||||
BlockRate: 0.10,
|
||||
// Skeletons are immune to poison; we'd model that with a future
|
||||
// CombatModifiers.PoisonImmunity flag. For Phase 7, no ability.
|
||||
XPValue: 50,
|
||||
Notes: "Bone-and-rust. Resistant to slashing weapons; vulnerable to bludgeoning.",
|
||||
},
|
||||
"orc_grunt": {
|
||||
ID: "orc_grunt", Name: "Orc Grunt",
|
||||
CR: 0.5, HP: 15, AC: 13, Attack: 10, AttackBonus: 5, Speed: 11,
|
||||
BlockRate: 0.05,
|
||||
Ability: &MonsterAbility{Name: "Aggressive", Phase: "opening", ProcChance: 0.30, Effect: "enrage"},
|
||||
XPValue: 100,
|
||||
Notes: "Charges. Bonus damage on its first hit if it goes first.",
|
||||
},
|
||||
"troll": {
|
||||
ID: "troll", Name: "Troll",
|
||||
CR: 5, HP: 84, AC: 15, Attack: 22, AttackBonus: 7, Speed: 8,
|
||||
BlockRate: 0.10,
|
||||
Ability: &MonsterAbility{Name: "Regeneration", Phase: "any", ProcChance: 0.50, Effect: "lifesteal"},
|
||||
XPValue: 1800,
|
||||
Notes: "Regenerates each round unless burned or acid-burned. Fire/acid damage stops the regen.",
|
||||
},
|
||||
"wyvern": {
|
||||
ID: "wyvern", Name: "Wyvern",
|
||||
CR: 6, HP: 110, AC: 13, Attack: 28, AttackBonus: 7, Speed: 16,
|
||||
BlockRate: 0.05,
|
||||
Ability: &MonsterAbility{Name: "Poison Sting", Phase: "decisive", ProcChance: 0.60, Effect: "poison"},
|
||||
XPValue: 2300,
|
||||
Notes: "Aerial; opens with dive attack. Tail sting injects poison (CON DC 15 in tabletop).",
|
||||
},
|
||||
"ancient_dragon": {
|
||||
ID: "ancient_dragon", Name: "Ancient Dragon",
|
||||
CR: 20, HP: 367, AC: 22, Attack: 65, AttackBonus: 14, Speed: 18,
|
||||
BlockRate: 0.15,
|
||||
Ability: &MonsterAbility{Name: "Frightful Presence", Phase: "opening", ProcChance: 0.80, Effect: "stun"},
|
||||
XPValue: 25000,
|
||||
Notes: "Legendary. Breath weapon (cleave-equivalent), frightful presence on opening, regenerates between phases. Tabletop equivalent has legendary actions; the engine approximates with elevated stats.",
|
||||
},
|
||||
}
|
||||
|
||||
// dndBestiaryByCR returns templates whose CR is at or below the given cap.
|
||||
// Useful for procedurally selecting a monster appropriate to player level.
|
||||
func dndBestiaryByCR(maxCR float32) []DnDMonsterTemplate {
|
||||
var out []DnDMonsterTemplate
|
||||
for _, m := range dndBestiary {
|
||||
if m.CR <= maxCR {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// toCombatStats converts a bestiary entry into the engine's CombatStats +
|
||||
// CombatModifiers shape. Future encounter content can use this to spawn
|
||||
// named monsters in the existing combat pipeline.
|
||||
func (m DnDMonsterTemplate) toCombatStats() (CombatStats, CombatModifiers) {
|
||||
stats := CombatStats{
|
||||
MaxHP: m.HP,
|
||||
Attack: m.Attack,
|
||||
Defense: 0,
|
||||
Speed: m.Speed,
|
||||
BlockRate: m.BlockRate,
|
||||
AC: m.AC,
|
||||
AttackBonus: m.AttackBonus,
|
||||
}
|
||||
mods := CombatModifiers{DamageReduct: 1.0}
|
||||
return stats, mods
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package plugin
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBestiaryAllWellFormed(t *testing.T) {
|
||||
if len(dndBestiary) == 0 {
|
||||
t.Fatal("dndBestiary empty")
|
||||
}
|
||||
for id, m := range dndBestiary {
|
||||
if m.ID != id {
|
||||
t.Errorf("%s: ID mismatch (%s)", id, m.ID)
|
||||
}
|
||||
if m.Name == "" {
|
||||
t.Errorf("%s: empty Name", id)
|
||||
}
|
||||
if m.HP < 1 {
|
||||
t.Errorf("%s: HP=%d", id, m.HP)
|
||||
}
|
||||
if m.AC < 10 {
|
||||
t.Errorf("%s: AC=%d (want ≥ 10)", id, m.AC)
|
||||
}
|
||||
if m.Attack < 1 {
|
||||
t.Errorf("%s: Attack=%d", id, m.Attack)
|
||||
}
|
||||
if m.XPValue < 0 {
|
||||
t.Errorf("%s: XPValue=%d", id, m.XPValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBestiaryByCR(t *testing.T) {
|
||||
low := dndBestiaryByCR(1.0)
|
||||
for _, m := range low {
|
||||
if m.CR > 1.0 {
|
||||
t.Errorf("CR filter leaked: %s CR=%v", m.Name, m.CR)
|
||||
}
|
||||
}
|
||||
high := dndBestiaryByCR(20.0)
|
||||
if len(high) != len(dndBestiary) {
|
||||
t.Errorf("CR≤20 filter returned %d, want all %d", len(high), len(dndBestiary))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBestiaryToCombatStats(t *testing.T) {
|
||||
dragon := dndBestiary["ancient_dragon"]
|
||||
stats, mods := dragon.toCombatStats()
|
||||
if stats.MaxHP != 367 {
|
||||
t.Errorf("dragon HP = %d, want 367", stats.MaxHP)
|
||||
}
|
||||
if stats.AC != 22 {
|
||||
t.Errorf("dragon AC = %d, want 22", stats.AC)
|
||||
}
|
||||
if stats.AttackBonus != 14 {
|
||||
t.Errorf("dragon AttackBonus = %d, want 14", stats.AttackBonus)
|
||||
}
|
||||
if mods.DamageReduct != 1.0 {
|
||||
t.Errorf("DamageReduct = %v, want 1.0", mods.DamageReduct)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBestiaryStarterMonsters(t *testing.T) {
|
||||
// Section 8.2 of v1.0 lists 6 starter monsters; verify all present.
|
||||
wantIDs := []string{"goblin", "skeleton", "orc_grunt", "troll", "wyvern", "ancient_dragon"}
|
||||
for _, id := range wantIDs {
|
||||
if _, ok := dndBestiary[id]; !ok {
|
||||
t.Errorf("starter bestiary missing: %s", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,648 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 9 SP2 — !cast / !spells / !prepare commands and out-of-combat
|
||||
// resolution. Combat-time resolution of pending_cast lives in dnd_combat.go
|
||||
// (SP3).
|
||||
//
|
||||
// Casting model:
|
||||
// - Cantrips: no slot cost. Damage cantrips queue as pending_cast for
|
||||
// next combat. Utility cantrips (Mending, Message, Minor Illusion,
|
||||
// Guidance) resolve immediately with a flavorful response.
|
||||
// - Leveled spells: consume a slot at cast time (audit-style save-then-
|
||||
// debit). DAMAGE_*, CONTROL, BUFF_SELF/ALLY queue as pending_cast.
|
||||
// HEAL and UTILITY resolve immediately.
|
||||
// - Reaction spells (Shield, Counterspell, Absorb Elements) refuse with
|
||||
// a "Phase 11" note — they require the boss turn-based engine.
|
||||
//
|
||||
// Cross-player targeting (--target @user) is deliberately deferred. SP2
|
||||
// supports self-target only. Heals on self work; ally buffs queue with the
|
||||
// caster as the target until SP3 wires up the multi-player resolution.
|
||||
|
||||
// PendingCast is the shape stored in dnd_character.pending_cast (JSON blob).
|
||||
// Keep this minimal — the combat layer resolves the actual numbers on fire.
|
||||
type PendingCast struct {
|
||||
SpellID string `json:"spell"`
|
||||
SlotLevel int `json:"slot"` // 0 for cantrips
|
||||
Target string `json:"target,omitempty"`
|
||||
}
|
||||
|
||||
func encodePendingCast(p PendingCast) string {
|
||||
b, _ := json.Marshal(p)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func decodePendingCast(s string) (PendingCast, bool) {
|
||||
if s == "" {
|
||||
return PendingCast{}, false
|
||||
}
|
||||
var p PendingCast
|
||||
if err := json.Unmarshal([]byte(s), &p); err != nil {
|
||||
return PendingCast{}, false
|
||||
}
|
||||
if p.SpellID == "" {
|
||||
return PendingCast{}, false
|
||||
}
|
||||
return p, true
|
||||
}
|
||||
|
||||
// ── !cast command ────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDCastCmd(ctx MessageContext, args string) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
args = strings.TrimSpace(args)
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your Adv 2.0 sheet.")
|
||||
}
|
||||
if !classIsCaster(c.Class) {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s isn't a caster class. `!cast` is for Mage, Cleric, and Ranger.",
|
||||
titleClass(c.Class)))
|
||||
}
|
||||
|
||||
if args == "" {
|
||||
return p.SendDM(ctx.Sender, renderCastHelp(c))
|
||||
}
|
||||
|
||||
// Parse: --drop is a special form ("!cast --drop" or "!cast drop").
|
||||
lower := strings.ToLower(args)
|
||||
if lower == "--drop" || lower == "drop" {
|
||||
return p.dndCastDrop(ctx, c)
|
||||
}
|
||||
|
||||
// Parse spell name + optional --upcast N.
|
||||
tokens := strings.Fields(args)
|
||||
upcast := 0
|
||||
var spellTokens []string
|
||||
for i := 0; i < len(tokens); i++ {
|
||||
switch tokens[i] {
|
||||
case "--upcast":
|
||||
if i+1 < len(tokens) {
|
||||
n, err := strconv.Atoi(tokens[i+1])
|
||||
if err == nil {
|
||||
upcast = n
|
||||
}
|
||||
i++
|
||||
}
|
||||
case "--target":
|
||||
// Reserved for SP3 — accept and ignore for now.
|
||||
if i+1 < len(tokens) {
|
||||
i++
|
||||
}
|
||||
default:
|
||||
spellTokens = append(spellTokens, tokens[i])
|
||||
}
|
||||
}
|
||||
if len(spellTokens) == 0 {
|
||||
return p.SendDM(ctx.Sender, "Usage: `!cast <spell> [--upcast N]`. Run `!spells` to list options.")
|
||||
}
|
||||
spell, ok := parseSpell(strings.Join(spellTokens, " "))
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"Unknown spell %q. Run `!spells` to list what you know.", strings.Join(spellTokens, " ")))
|
||||
}
|
||||
|
||||
// Class gate.
|
||||
classOK := false
|
||||
for _, cl := range spell.Classes {
|
||||
if cl == c.Class {
|
||||
classOK = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !classOK {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s is not on the %s spell list.", spell.Name, titleClass(c.Class)))
|
||||
}
|
||||
|
||||
// Reaction spells deferred.
|
||||
if spell.Effect == EffectReaction {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s is a reaction spell — those land in Phase 11 alongside turn-based boss combat.", spell.Name))
|
||||
}
|
||||
|
||||
// Known + prepared check.
|
||||
known, prepared, err := playerKnowsSpell(ctx.Sender, spell.ID)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't check your spell list.")
|
||||
}
|
||||
if !known {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"You don't know %s yet.", spell.Name))
|
||||
}
|
||||
if !prepared {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s isn't prepared today. Run `!prepare %s` first.", spell.Name, spell.ID))
|
||||
}
|
||||
|
||||
// Determine slot level.
|
||||
slotLevel := spell.Level
|
||||
if upcast > slotLevel && spell.Level > 0 {
|
||||
slotLevel = upcast
|
||||
}
|
||||
if slotLevel < 0 || slotLevel > 5 {
|
||||
return p.SendDM(ctx.Sender, "Slot level out of range (1–5).")
|
||||
}
|
||||
|
||||
// Concentration conflict: if spell needs concentration and player has
|
||||
// another active, warn (we'll supersede on the actual cast).
|
||||
supersedes := ""
|
||||
if spell.Concentration {
|
||||
if active := concentrationActive(c); active != "" && active != spell.ID {
|
||||
supersedes = active
|
||||
}
|
||||
}
|
||||
|
||||
// Material cost (Revivify, Raise Dead).
|
||||
if spell.MaterialCost > 0 {
|
||||
if p.euro == nil || !p.euro.Debit(ctx.Sender, float64(spell.MaterialCost), "dnd_spell_component") {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s needs a %d-coin diamond component you can't afford.", spell.Name, spell.MaterialCost))
|
||||
}
|
||||
}
|
||||
|
||||
// Slot consumption (cantrips skip).
|
||||
if spell.Level > 0 {
|
||||
ok, err := consumeSpellSlot(ctx.Sender, slotLevel)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't consume slot: "+err.Error())
|
||||
}
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"No L%d slot available. %s", slotLevel, renderSlotsBrief(ctx.Sender)))
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve. Audit pattern: for queueing effects, save state BEFORE we
|
||||
// would otherwise consider the action committed. The slot is already
|
||||
// debited above; if SaveDnDCharacter fails we refund.
|
||||
switch spell.Effect {
|
||||
case EffectSpellHeal:
|
||||
return p.resolveHealOutOfCombat(ctx, c, spell, slotLevel)
|
||||
case EffectUtility:
|
||||
return p.resolveUtility(ctx, c, spell, slotLevel)
|
||||
default:
|
||||
// DAMAGE_*, CONTROL, BUFF_SELF/ALLY → queue for next combat.
|
||||
return p.queuePendingCast(ctx, c, spell, slotLevel, supersedes)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Out-of-combat: HEAL ──────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) resolveHealOutOfCombat(ctx MessageContext, c *DnDCharacter, spell SpellDefinition, slotLevel int) error {
|
||||
dice, faces, _ := parseDamageDice(spell.DamageDice)
|
||||
if dice == 0 {
|
||||
dice, faces = 1, 8 // safety fallback
|
||||
}
|
||||
// Upcast scales healing. Most heal spells are "+1d8 per slot above 1st".
|
||||
extra := slotLevel - spell.Level
|
||||
if extra < 0 {
|
||||
extra = 0
|
||||
}
|
||||
totalDice := dice + extra
|
||||
heal := 0
|
||||
for i := 0; i < totalDice; i++ {
|
||||
heal += 1 + rand.IntN(faces)
|
||||
}
|
||||
heal += abilityModifier(c.WIS)
|
||||
|
||||
before := c.HPCurrent
|
||||
c.HPCurrent = min(c.HPMax, c.HPCurrent+heal)
|
||||
delta := c.HPCurrent - before
|
||||
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
// Refund the slot.
|
||||
if spell.Level > 0 {
|
||||
_ = refundSpellSlot(ctx.Sender, slotLevel)
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "Couldn't apply heal: "+err.Error())
|
||||
}
|
||||
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"🩹 **%s** — restored %d HP (%d → %d / %d). %s",
|
||||
spell.Name, delta, before, c.HPCurrent, c.HPMax,
|
||||
renderSlotsBrief(ctx.Sender)))
|
||||
}
|
||||
|
||||
// ── Out-of-combat: UTILITY ──────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) resolveUtility(ctx MessageContext, c *DnDCharacter, spell SpellDefinition, slotLevel int) error {
|
||||
// Most utility spells are pure narrative — they produce a flavor line
|
||||
// and a confirmation. A few (Mage Armor, Hunter's Mark, etc.) are
|
||||
// concentration buffs that fire as pending_cast in combat. Those are
|
||||
// classified as BUFF_* in the registry, not UTILITY, so we don't see
|
||||
// them here. Concentration UTILITY spells (Detect Magic, Beast Sense)
|
||||
// merely set the concentration flag; combat doesn't care.
|
||||
supersedes := ""
|
||||
if spell.Concentration {
|
||||
supersedes = setConcentration(c, spell.ID, utilityConcentrationDuration(spell))
|
||||
}
|
||||
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
if spell.Level > 0 {
|
||||
_ = refundSpellSlot(ctx.Sender, slotLevel)
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "Couldn't save state: "+err.Error())
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("✨ **%s** — %s", spell.Name, spell.Description)
|
||||
if supersedes != "" {
|
||||
msg += fmt.Sprintf("\n_(Concentration shifts: %s ended.)_", displaySpellName(supersedes))
|
||||
}
|
||||
if spell.Level > 0 {
|
||||
msg += "\n" + renderSlotsBrief(ctx.Sender)
|
||||
}
|
||||
return p.SendDM(ctx.Sender, msg)
|
||||
}
|
||||
|
||||
func utilityConcentrationDuration(spell SpellDefinition) time.Duration {
|
||||
// Phase 9 keeps durations narrative — anything that lasts past a long
|
||||
// rest is reset by long rest anyway. Use a generous default.
|
||||
switch spell.ID {
|
||||
case "detect_magic", "beast_sense":
|
||||
return 10 * time.Minute
|
||||
}
|
||||
return 1 * time.Hour
|
||||
}
|
||||
|
||||
// ── Queue for next combat ───────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) queuePendingCast(ctx MessageContext, c *DnDCharacter, spell SpellDefinition, slotLevel int, supersedes string) error {
|
||||
if c.PendingCast != "" {
|
||||
// Refund the slot we just consumed.
|
||||
if spell.Level > 0 {
|
||||
_ = refundSpellSlot(ctx.Sender, slotLevel)
|
||||
}
|
||||
prev, _ := decodePendingCast(c.PendingCast)
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"You already have **%s** queued. Cast `!cast --drop` to clear it first.",
|
||||
displaySpellName(prev.SpellID)))
|
||||
}
|
||||
|
||||
pc := PendingCast{SpellID: spell.ID, SlotLevel: slotLevel}
|
||||
c.PendingCast = encodePendingCast(pc)
|
||||
if spell.Concentration {
|
||||
setConcentration(c, spell.ID, 1*time.Hour)
|
||||
}
|
||||
|
||||
// Audit pattern (Fix C): save-then-the-rest. Slot already debited; on
|
||||
// save failure, refund slot and concentration.
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
if spell.Level > 0 {
|
||||
_ = refundSpellSlot(ctx.Sender, slotLevel)
|
||||
}
|
||||
c.ConcentrationSpell = ""
|
||||
c.ConcentrationExpiresAt = nil
|
||||
return p.SendDM(ctx.Sender, "Couldn't queue spell: "+err.Error())
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("✨ **%s** queued for next combat.", spell.Name)
|
||||
if slotLevel > spell.Level {
|
||||
msg += fmt.Sprintf(" _(upcast to L%d)_", slotLevel)
|
||||
}
|
||||
if supersedes != "" {
|
||||
msg += fmt.Sprintf("\n_(Concentration shifts: %s ended.)_", displaySpellName(supersedes))
|
||||
}
|
||||
if spell.Level > 0 {
|
||||
msg += "\n" + renderSlotsBrief(ctx.Sender)
|
||||
}
|
||||
return p.SendDM(ctx.Sender, msg)
|
||||
}
|
||||
|
||||
// ── !cast --drop ─────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) dndCastDrop(ctx MessageContext, c *DnDCharacter) error {
|
||||
if c.PendingCast == "" && c.ConcentrationSpell == "" {
|
||||
return p.SendDM(ctx.Sender, "Nothing queued and no concentration active.")
|
||||
}
|
||||
|
||||
// Refund the queued slot (if any) — voluntary drop is the player's
|
||||
// choice; restore the slot rather than forfeit it.
|
||||
if pc, ok := decodePendingCast(c.PendingCast); ok && pc.SlotLevel > 0 {
|
||||
_ = refundSpellSlot(ctx.Sender, pc.SlotLevel)
|
||||
}
|
||||
|
||||
dropped := []string{}
|
||||
if pc, ok := decodePendingCast(c.PendingCast); ok {
|
||||
dropped = append(dropped, displaySpellName(pc.SpellID)+" (queued)")
|
||||
}
|
||||
if c.ConcentrationSpell != "" {
|
||||
dropped = append(dropped, displaySpellName(c.ConcentrationSpell)+" (concentration)")
|
||||
}
|
||||
|
||||
c.PendingCast = ""
|
||||
c.ConcentrationSpell = ""
|
||||
c.ConcentrationExpiresAt = nil
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't drop: "+err.Error())
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "Dropped: "+strings.Join(dropped, ", ")+".")
|
||||
}
|
||||
|
||||
// ── !spells command ─────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDSpellsCmd(ctx MessageContext, args string) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your Adv 2.0 sheet.")
|
||||
}
|
||||
if !classIsCaster(c.Class) {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"%s isn't a caster class.", titleClass(c.Class)))
|
||||
}
|
||||
|
||||
args = strings.TrimSpace(args)
|
||||
if strings.HasPrefix(strings.ToLower(args), "learn ") {
|
||||
return p.handleSpellsLearn(ctx, c, strings.TrimSpace(args[6:]))
|
||||
}
|
||||
|
||||
return p.SendDM(ctx.Sender, renderSpellsList(c))
|
||||
}
|
||||
|
||||
func renderSpellsList(c *DnDCharacter) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("**Spellbook — %s L%d**\n\n",
|
||||
titleClass(c.Class), c.Level))
|
||||
|
||||
known, _ := listKnownSpells(c.UserID)
|
||||
if len(known) == 0 {
|
||||
b.WriteString("_No spells known. Run `!spells learn <name>` to add one._\n")
|
||||
} else {
|
||||
// Group by spell level.
|
||||
byLevel := map[int][]knownSpellRow{}
|
||||
for _, k := range known {
|
||||
s, ok := lookupSpell(k.SpellID)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
byLevel[s.Level] = append(byLevel[s.Level], k)
|
||||
}
|
||||
levels := []int{}
|
||||
for lvl := range byLevel {
|
||||
levels = append(levels, lvl)
|
||||
}
|
||||
sort.Ints(levels)
|
||||
for _, lvl := range levels {
|
||||
label := fmt.Sprintf("L%d", lvl)
|
||||
if lvl == 0 {
|
||||
label = "Cantrip"
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("__%s__\n", label))
|
||||
for _, k := range byLevel[lvl] {
|
||||
s, _ := lookupSpell(k.SpellID)
|
||||
prepStr := ""
|
||||
if c.Class == ClassCleric && s.Level > 0 {
|
||||
if k.Prepared {
|
||||
prepStr = " ✅"
|
||||
} else {
|
||||
prepStr = " ⬜"
|
||||
}
|
||||
}
|
||||
b.WriteString(fmt.Sprintf(" • **%s**%s — %s\n", s.Name, prepStr, s.Description))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slots, _ := getSpellSlots(c.UserID)
|
||||
b.WriteString("\n**Slots:** " + renderSlotLine(slots) + "\n")
|
||||
b.WriteString(fmt.Sprintf("**Spell DC:** %d **Spell Atk:** +%d\n",
|
||||
spellSaveDC(c), spellAttackBonus(c)))
|
||||
|
||||
if pc, ok := decodePendingCast(c.PendingCast); ok {
|
||||
b.WriteString(fmt.Sprintf("\n_Queued: **%s**", displaySpellName(pc.SpellID)))
|
||||
if pc.SlotLevel > 0 {
|
||||
b.WriteString(fmt.Sprintf(" (L%d slot)", pc.SlotLevel))
|
||||
}
|
||||
b.WriteString(" — fires next combat._\n")
|
||||
}
|
||||
if c.ConcentrationSpell != "" && concentrationActive(c) != "" {
|
||||
b.WriteString(fmt.Sprintf("_Concentrating on **%s**._\n",
|
||||
displaySpellName(c.ConcentrationSpell)))
|
||||
}
|
||||
b.WriteString("\nSlots refresh on long rest.")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// ── !spells learn (Mage spellbook) ───────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleSpellsLearn(ctx MessageContext, c *DnDCharacter, raw string) error {
|
||||
if c.Class != ClassMage {
|
||||
return p.SendDM(ctx.Sender, "`!spells learn` is for Mage. Cleric uses `!prepare`; Ranger spells are auto-known.")
|
||||
}
|
||||
if raw == "" {
|
||||
return p.SendDM(ctx.Sender, "Usage: `!spells learn <spell name>`")
|
||||
}
|
||||
spell, ok := parseSpell(raw)
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("Unknown spell %q.", raw))
|
||||
}
|
||||
classOK := false
|
||||
for _, cl := range spell.Classes {
|
||||
if cl == ClassMage {
|
||||
classOK = true
|
||||
}
|
||||
}
|
||||
if !classOK {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("%s isn't on the Mage spell list.", spell.Name))
|
||||
}
|
||||
if spell.Level > highestAvailableSlot(ClassMage, c.Level) && spell.Level > 0 {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"L%d spells require Mage level %d+.", spell.Level, requiredMageLevelFor(spell.Level)))
|
||||
}
|
||||
known, _, err := playerKnowsSpell(ctx.Sender, spell.ID)
|
||||
if err == nil && known {
|
||||
return p.SendDM(ctx.Sender, "You already know "+spell.Name+".")
|
||||
}
|
||||
if err := addKnownSpell(ctx.Sender, spell.ID, "class", true); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't learn: "+err.Error())
|
||||
}
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("📖 Learned **%s**.", spell.Name))
|
||||
}
|
||||
|
||||
func requiredMageLevelFor(slotLevel int) int {
|
||||
switch slotLevel {
|
||||
case 1:
|
||||
return 1
|
||||
case 2:
|
||||
return 3
|
||||
case 3:
|
||||
return 5
|
||||
case 4:
|
||||
return 7
|
||||
case 5:
|
||||
return 9
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
// ── !prepare command (Cleric stub — full SP4) ───────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDPrepareCmd(ctx MessageContext, args string) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your Adv 2.0 sheet.")
|
||||
}
|
||||
if c.Class != ClassCleric {
|
||||
return p.SendDM(ctx.Sender, "`!prepare` is for Cleric. Mage uses `!spells learn`; Ranger spells are auto-known.")
|
||||
}
|
||||
args = strings.TrimSpace(args)
|
||||
if args == "" {
|
||||
return p.SendDM(ctx.Sender, renderClericPrepStatus(c))
|
||||
}
|
||||
|
||||
clear := false
|
||||
if strings.HasPrefix(strings.ToLower(args), "clear ") {
|
||||
clear = true
|
||||
args = strings.TrimSpace(args[6:])
|
||||
}
|
||||
|
||||
spell, ok := parseSpell(args)
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("Unknown spell %q.", args))
|
||||
}
|
||||
if spell.Level == 0 {
|
||||
return p.SendDM(ctx.Sender, "Cantrips are always prepared.")
|
||||
}
|
||||
known, _, err := playerKnowsSpell(ctx.Sender, spell.ID)
|
||||
if err != nil || !known {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("%s isn't on your known list.", spell.Name))
|
||||
}
|
||||
|
||||
if clear {
|
||||
if err := setSpellPrepared(ctx.Sender, spell.ID, false); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't unprepare: "+err.Error())
|
||||
}
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("Unprepared **%s**.", spell.Name))
|
||||
}
|
||||
|
||||
// Cap = WIS mod + Cleric level. Cantrips don't count.
|
||||
cap := abilityModifier(c.WIS) + c.Level
|
||||
if cap < 1 {
|
||||
cap = 1
|
||||
}
|
||||
rows, _ := listKnownSpells(ctx.Sender)
|
||||
prepCount := 0
|
||||
for _, r := range rows {
|
||||
s, ok := lookupSpell(r.SpellID)
|
||||
if !ok || s.Level == 0 {
|
||||
continue
|
||||
}
|
||||
if r.Prepared && r.SpellID != spell.ID {
|
||||
prepCount++
|
||||
}
|
||||
}
|
||||
if prepCount+1 > cap {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"Prep cap is %d. Unprepare a spell first: `!prepare clear <name>`.", cap))
|
||||
}
|
||||
if err := setSpellPrepared(ctx.Sender, spell.ID, true); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't prepare: "+err.Error())
|
||||
}
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("📖 Prepared **%s** (%d/%d).",
|
||||
spell.Name, prepCount+1, cap))
|
||||
}
|
||||
|
||||
func renderClericPrepStatus(c *DnDCharacter) string {
|
||||
cap := abilityModifier(c.WIS) + c.Level
|
||||
if cap < 1 {
|
||||
cap = 1
|
||||
}
|
||||
rows, _ := listKnownSpells(c.UserID)
|
||||
prepCount := 0
|
||||
for _, r := range rows {
|
||||
s, ok := lookupSpell(r.SpellID)
|
||||
if !ok || s.Level == 0 {
|
||||
continue
|
||||
}
|
||||
if r.Prepared {
|
||||
prepCount++
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("**Prepared spells:** %d/%d. Run `!prepare <spell>` to add, `!prepare clear <spell>` to remove. Long rest re-opens choices.",
|
||||
prepCount, cap)
|
||||
}
|
||||
|
||||
// ── helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func renderCastHelp(c *DnDCharacter) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("**Cast a spell**\n\n")
|
||||
b.WriteString("Usage: `!cast <spell> [--upcast N]`\n")
|
||||
b.WriteString(" `!cast --drop` to clear queued/concentration.\n\n")
|
||||
b.WriteString("Run `!spells` for your full list.\n\n")
|
||||
if pc, ok := decodePendingCast(c.PendingCast); ok {
|
||||
b.WriteString(fmt.Sprintf("_Currently queued: **%s**._\n", displaySpellName(pc.SpellID)))
|
||||
}
|
||||
if c.ConcentrationSpell != "" && concentrationActive(c) != "" {
|
||||
b.WriteString(fmt.Sprintf("_Concentrating on **%s**._\n",
|
||||
displaySpellName(c.ConcentrationSpell)))
|
||||
}
|
||||
b.WriteString("\n" + renderSlotsBrief(c.UserID))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func renderSlotsBrief(userID id.UserID) string {
|
||||
slots, err := getSpellSlots(userID)
|
||||
if err != nil {
|
||||
slog.Warn("dnd: getSpellSlots", "user", userID, "err", err)
|
||||
}
|
||||
return "**Slots:** " + renderSlotLine(slots)
|
||||
}
|
||||
|
||||
// parseDamageDice extracts (count, faces, flatBonus) from "3d6", "1d8",
|
||||
// "3d4+3" style strings. Returns (0,0,0) on failure.
|
||||
func parseDamageDice(s string) (int, int, int) {
|
||||
s = strings.TrimSpace(strings.ToLower(s))
|
||||
if s == "" {
|
||||
return 0, 0, 0
|
||||
}
|
||||
// Optional flat bonus: split on +.
|
||||
flat := 0
|
||||
if i := strings.Index(s, "+"); i > 0 {
|
||||
f, err := strconv.Atoi(strings.TrimSpace(s[i+1:]))
|
||||
if err == nil {
|
||||
flat = f
|
||||
}
|
||||
s = strings.TrimSpace(s[:i])
|
||||
}
|
||||
i := strings.Index(s, "d")
|
||||
if i <= 0 {
|
||||
return 0, 0, flat
|
||||
}
|
||||
count, err := strconv.Atoi(s[:i])
|
||||
if err != nil {
|
||||
return 0, 0, flat
|
||||
}
|
||||
faces, err := strconv.Atoi(s[i+1:])
|
||||
if err != nil {
|
||||
return 0, 0, flat
|
||||
}
|
||||
return count, faces, flat
|
||||
}
|
||||
@@ -0,0 +1,489 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 2 — D&D combat layer hookup.
|
||||
//
|
||||
// Phase 2 strategy: keep legacy HP/damage/dodge-rate scaling intact. The D&D
|
||||
// layer adds AC + d20-vs-AC hit resolution on top. This preserves the
|
||||
// existing balance while making combat read as D&D for opted-in players.
|
||||
//
|
||||
// HP rescaling and condition-system overhaul are deferred to later phases.
|
||||
|
||||
// ── Tunable constants ────────────────────────────────────────────────────────
|
||||
|
||||
// Class-derived "weapon proficiency" bonus baked into AttackBonus.
|
||||
// Fighter is a martial class; Mage uses spell-attack baseline.
|
||||
var dndClassWeaponBonus = map[DnDClass]int{
|
||||
ClassFighter: 2,
|
||||
ClassRanger: 1,
|
||||
ClassRogue: 1,
|
||||
ClassCleric: 0,
|
||||
ClassMage: 0,
|
||||
}
|
||||
|
||||
// Monster AC formulas. Tuned so a typical L1 player (+5 attack bonus) hits
|
||||
// roughly 70-80% at low tiers and 50-60% at high tiers. Adjust after live
|
||||
// data lands.
|
||||
const (
|
||||
dndArenaACBase = 10
|
||||
dndArenaACPerThreat = 0.25 // ThreatLevel 0..30 → AC bump 0..7
|
||||
dndDungeonACBase = 9
|
||||
// Dungeon AC scales linearly with tier: T1=10, T5=14
|
||||
)
|
||||
|
||||
// Monster attack bonus. Counters player AC growth. T1 monster +5, T5 +9.
|
||||
const (
|
||||
dndArenaAtkBase = 4
|
||||
dndArenaAtkPerThreat = 0.30
|
||||
dndDungeonAtkBase = 4
|
||||
// T1 dungeon +5, T5 +9
|
||||
)
|
||||
|
||||
// ── Player layer ─────────────────────────────────────────────────────────────
|
||||
|
||||
// proficiencyBonus implements ceil(level/4) + 1, matching D&D5e (L1-4 = +2,
|
||||
// L5-8 = +3, L9-12 = +4, ...).
|
||||
func proficiencyBonus(level int) int {
|
||||
if level < 1 {
|
||||
level = 1
|
||||
}
|
||||
return (level-1)/4 + 2
|
||||
}
|
||||
|
||||
// classAttackStatMod returns the ability modifier the class uses for its
|
||||
// primary attack roll. Fighters use STR (melee), Rogue/Ranger use DEX, Mage
|
||||
// uses INT (spell attack), Cleric uses WIS.
|
||||
func classAttackStatMod(c *DnDCharacter) int {
|
||||
switch c.Class {
|
||||
case ClassFighter:
|
||||
return abilityModifier(c.STR)
|
||||
case ClassRogue, ClassRanger:
|
||||
return abilityModifier(c.DEX)
|
||||
case ClassMage:
|
||||
return abilityModifier(c.INT)
|
||||
case ClassCleric:
|
||||
return abilityModifier(c.WIS)
|
||||
}
|
||||
return abilityModifier(c.STR)
|
||||
}
|
||||
|
||||
// dndPlayerAttackBonus = primary stat mod + proficiency + class weapon bonus.
|
||||
func dndPlayerAttackBonus(c *DnDCharacter) int {
|
||||
return classAttackStatMod(c) + proficiencyBonus(c.Level) + dndClassWeaponBonus[c.Class]
|
||||
}
|
||||
|
||||
// applyDnDPlayerLayer sets AC and AttackBonus on a stat block from the
|
||||
// player's D&D character. Called after DerivePlayerStats has populated
|
||||
// HP/Attack/Defense/etc. Phase 8: also wires equipped weapon/armor profiles
|
||||
// into CombatStats so the d20 attack path uses real weapon dice and AC
|
||||
// computation per gogobee_equipment_appendix.md.
|
||||
func applyDnDPlayerLayer(stats *CombatStats, c *DnDCharacter) {
|
||||
stats.AC = c.ArmorClass
|
||||
stats.AttackBonus = dndPlayerAttackBonus(c)
|
||||
}
|
||||
|
||||
// applyDnDEquipmentLayer populates the Phase 8 equipment-driven fields on
|
||||
// CombatStats from synthesized profiles of the player's legacy gear. Also
|
||||
// overrides stats.AC with the equipment-derived computation when an armor
|
||||
// or shield is equipped.
|
||||
//
|
||||
// `equip` is the legacy adventure_equipment map; the synthesizer infers a
|
||||
// D&D weapon/armor profile from slot+tier+name without requiring a loot
|
||||
// migration. Helmets, boots, and non-shield tools have no D&D profile yet
|
||||
// and don't affect this layer.
|
||||
func applyDnDEquipmentLayer(stats *CombatStats, c *DnDCharacter, equip map[EquipmentSlot]*AdvEquipment) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
// Weapon synthesis.
|
||||
weapon := synthesizeWeaponProfile(equip[SlotWeapon])
|
||||
if weapon != nil {
|
||||
stats.Weapon = weapon
|
||||
// Pick STR vs DEX modifier per finesse rule and class default.
|
||||
stats.AbilityModForDamage = pickWeaponAbilityMod(weapon, c)
|
||||
stats.WeaponProficient = dndClassWeaponProficiency(c.Class, weapon)
|
||||
// Magic bonus on the weapon also stacks onto AttackBonus.
|
||||
stats.AttackBonus += weapon.MagicBonus
|
||||
// Two-handed when the weapon has the property AND no shield is held.
|
||||
hasShield := synthesizeShield(equip[SlotTool]) != nil
|
||||
if weapon.HasProperty(PropTwoHanded) || (weapon.HasProperty(PropVersatile) && !hasShield) {
|
||||
stats.TwoHandedMode = true
|
||||
}
|
||||
}
|
||||
|
||||
// Armor + shield → AC override per appendix.
|
||||
armor := synthesizeArmorProfile(equip[SlotArmor])
|
||||
shield := synthesizeShield(equip[SlotTool])
|
||||
// Two-handed weapons forbid shields per appendix §5.4.
|
||||
if weapon != nil && weapon.HasProperty(PropTwoHanded) {
|
||||
shield = nil
|
||||
}
|
||||
dexMod := abilityModifier(c.DEX)
|
||||
// Heavy armor STR-requirement penalty: -2 to DEX-based rolls if STR < req.
|
||||
// In our model, AC is the prominent DEX-derived value; honoring this
|
||||
// strictly would penalize attack rolls (DEX-attacking finesse/ranged) too.
|
||||
// For the AC computation we just clamp the dex bonus to 0 anyway when
|
||||
// armor is heavy (MaxDEXBonus=0), so the STR check has no AC effect —
|
||||
// it would only matter to attack rolls. Skip the penalty for now;
|
||||
// document it as a future refinement.
|
||||
if armor != nil || shield != nil {
|
||||
stats.AC = computeArmorAC(armor, shield, dexMod)
|
||||
}
|
||||
}
|
||||
|
||||
// pickWeaponAbilityMod returns the ability modifier added to weapon damage:
|
||||
// STR for melee unless the weapon is finesse/ranged and DEX is higher (then DEX).
|
||||
func pickWeaponAbilityMod(w *WeaponProfile, c *DnDCharacter) int {
|
||||
str, dex := abilityModifier(c.STR), abilityModifier(c.DEX)
|
||||
switch w.Category {
|
||||
case WeaponCatSimpleRanged, WeaponCatMartialRanged:
|
||||
return dex
|
||||
}
|
||||
// Melee: finesse picks the better of STR/DEX.
|
||||
if w.HasProperty(PropFinesse) {
|
||||
if dex > str {
|
||||
return dex
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
// ── Monster layer ────────────────────────────────────────────────────────────
|
||||
|
||||
func applyDnDArenaMonsterLayer(stats *CombatStats, threatLevel int) {
|
||||
stats.AC = dndArenaACBase + int(float64(threatLevel)*dndArenaACPerThreat)
|
||||
stats.AttackBonus = dndArenaAtkBase + int(float64(threatLevel)*dndArenaAtkPerThreat)
|
||||
}
|
||||
|
||||
func applyDnDDungeonMonsterLayer(stats *CombatStats, tier int) {
|
||||
stats.AC = dndDungeonACBase + tier
|
||||
stats.AttackBonus = dndDungeonAtkBase + tier
|
||||
}
|
||||
|
||||
// ── Auto-migration on first combat ───────────────────────────────────────────
|
||||
|
||||
// classStatPriority returns the standard-array values {15,14,13,12,10,8}
|
||||
// assigned to STR/DEX/CON/INT/WIS/CHA in the order the class cares about.
|
||||
// Used by ensureDnDCharacterForCombat — players can rebuild later via !setup
|
||||
// (which is allowed without respec cooldown when auto_migrated=1).
|
||||
func classStatPriority(class DnDClass) [6]int {
|
||||
// Returned array is in STR, DEX, CON, INT, WIS, CHA order.
|
||||
switch class {
|
||||
case ClassFighter:
|
||||
return [6]int{15, 13, 14, 8, 12, 10} // STR, CON, DEX prioritized
|
||||
case ClassRogue:
|
||||
return [6]int{8, 15, 13, 14, 10, 12} // DEX, INT, CON
|
||||
case ClassMage:
|
||||
return [6]int{8, 12, 13, 15, 14, 10} // INT, WIS, CON
|
||||
case ClassCleric:
|
||||
return [6]int{12, 10, 13, 8, 15, 14} // WIS, CHA, CON
|
||||
case ClassRanger:
|
||||
return [6]int{12, 15, 13, 10, 14, 8} // DEX, WIS, CON
|
||||
}
|
||||
return [6]int{15, 14, 13, 12, 10, 8} // fallback: martial-ish
|
||||
}
|
||||
|
||||
// ensureCharForDnDCmd is the helper non-combat D&D command handlers should
|
||||
// use when they want auto-migration semantics PLUS the legacy-player
|
||||
// onboarding DM. Combat paths in combat_bridge.go use ensureDnDCharacterForCombat
|
||||
// directly because they already control the freshMigrate hook.
|
||||
func (p *AdventurePlugin) ensureCharForDnDCmd(userID id.UserID, char *AdventureCharacter) (*DnDCharacter, error) {
|
||||
c, fresh, err := ensureDnDCharacterForCombat(userID, char)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fresh {
|
||||
p.maybeSendDnDOnboarding(userID, char, c)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// ensureDnDCharacterForCombat returns a usable D&D character for combat. If
|
||||
// the player already has a confirmed sheet, it's returned. Otherwise an
|
||||
// auto-migrated character is created using:
|
||||
//
|
||||
// - Race/class inferred from archetypes (Human Fighter fallback)
|
||||
// - Class-tuned standard array assignment
|
||||
// - Racial modifiers applied
|
||||
// - dnd_level seeded from the legacy combat_level
|
||||
// - HP/AC computed from class + ability scores + level
|
||||
//
|
||||
// auto_migrated=1 is set on the row so !setup can freely overwrite it
|
||||
// without consuming the !respec cooldown.
|
||||
//
|
||||
// Returns (character, freshlyMigrated, err). freshlyMigrated is true only
|
||||
// on the first call that creates the row — used by callers to fire the
|
||||
// one-shot onboarding DM for legacy players.
|
||||
func ensureDnDCharacterForCombat(userID id.UserID, char *AdventureCharacter) (*DnDCharacter, bool, error) {
|
||||
existing, err := LoadDnDCharacter(userID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if existing != nil && !existing.PendingSetup {
|
||||
return existing, false, nil
|
||||
}
|
||||
// existing == nil OR pending_setup=1. In the pending case we leave the
|
||||
// player's draft alone and overlay a temporary auto-migrated working
|
||||
// character — the draft survives untouched in the DB, but the fight
|
||||
// they're trying to start gets a usable sheet *for this fight only*.
|
||||
// (We don't write — pending_setup=1 stays so they can finish !setup.)
|
||||
if existing != nil && existing.PendingSetup {
|
||||
return autoBuildCharacter(userID, char), false, nil
|
||||
}
|
||||
|
||||
// Fresh auto-migration. Build, save, return.
|
||||
c := autoBuildCharacter(userID, char)
|
||||
c.AutoMigrated = true
|
||||
c.PendingSetup = false
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
_ = initResources(userID, c.Class)
|
||||
// Phase 9: caster auto-migrants get a starter spell list + slot pool so
|
||||
// !cast/!spells work the moment they land. Idempotent.
|
||||
_ = ensureSpellsForCharacter(c)
|
||||
slog.Info("dnd: auto-migrated character", "user", userID,
|
||||
"race", c.Race, "class", c.Class, "level", c.Level)
|
||||
return c, true, nil
|
||||
}
|
||||
|
||||
// autoBuildCharacter constructs a complete DnDCharacter from archetype
|
||||
// inference + the player's adventure state. Does not save.
|
||||
func autoBuildCharacter(userID id.UserID, char *AdventureCharacter) *DnDCharacter {
|
||||
sug := inferDnDFromArchetypes(userID)
|
||||
scores := classStatPriority(sug.Class)
|
||||
scores = applyRaceMods(sug.Race, scores)
|
||||
|
||||
level := 1
|
||||
if char != nil {
|
||||
level = dndLevelFromCombatLevel(char.CombatLevel)
|
||||
}
|
||||
|
||||
c := &DnDCharacter{
|
||||
UserID: userID,
|
||||
Race: sug.Race,
|
||||
Class: sug.Class,
|
||||
Level: level,
|
||||
STR: scores[0], DEX: scores[1], CON: scores[2],
|
||||
INT: scores[3], WIS: scores[4], CHA: scores[5],
|
||||
PendingSetup: false,
|
||||
AutoMigrated: true,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
conMod := abilityModifier(c.CON)
|
||||
dexMod := abilityModifier(c.DEX)
|
||||
c.HPMax = computeMaxHP(c.Class, conMod, c.Level)
|
||||
c.HPCurrent = c.HPMax
|
||||
c.ArmorClass = computeAC(c.Class, dexMod)
|
||||
return c
|
||||
}
|
||||
|
||||
// ── Roll summary line ────────────────────────────────────────────────────────
|
||||
|
||||
// dndRollSummaryLine scans a CombatResult's events for d20 rolls and returns
|
||||
// a one-liner summarizing the player's accuracy. Returns "" if no D&D rolls
|
||||
// are present (legacy combat, or a fight that resolved on consumables alone).
|
||||
//
|
||||
// Format: "🎲 d20 — 5/8 hit (2 crits, 1 fumble). Best: nat 20."
|
||||
//
|
||||
// Surfaced post-combat by arena and dungeon callers; keeps the d20 system
|
||||
// visible without modifying combat_narrative.go's flavor pools.
|
||||
func dndRollSummaryLine(result CombatResult) string {
|
||||
hits, misses, crits, fumbles := 0, 0, 0, 0
|
||||
bestRoll, bestSeen := 0, false
|
||||
for _, ev := range result.Events {
|
||||
if ev.Actor != "player" || ev.Roll == 0 {
|
||||
continue
|
||||
}
|
||||
switch ev.Action {
|
||||
case "hit", "block":
|
||||
hits++
|
||||
case "crit":
|
||||
hits++
|
||||
crits++
|
||||
case "miss":
|
||||
misses++
|
||||
if ev.Desc == "fumble" {
|
||||
fumbles++
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if !bestSeen || ev.Roll > bestRoll {
|
||||
bestRoll = ev.Roll
|
||||
bestSeen = true
|
||||
}
|
||||
}
|
||||
total := hits + misses
|
||||
if total == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b []byte
|
||||
b = append(b, []byte("🎲 d20 — ")...)
|
||||
b = appendInt(b, hits)
|
||||
b = append(b, '/')
|
||||
b = appendInt(b, total)
|
||||
b = append(b, []byte(" hit")...)
|
||||
|
||||
notes := []string{}
|
||||
if crits > 0 {
|
||||
notes = append(notes, formatN(crits, "crit"))
|
||||
}
|
||||
if fumbles > 0 {
|
||||
notes = append(notes, formatN(fumbles, "fumble"))
|
||||
}
|
||||
if len(notes) > 0 {
|
||||
b = append(b, []byte(" (")...)
|
||||
for i, n := range notes {
|
||||
if i > 0 {
|
||||
b = append(b, []byte(", ")...)
|
||||
}
|
||||
b = append(b, []byte(n)...)
|
||||
}
|
||||
b = append(b, ')')
|
||||
}
|
||||
if bestSeen {
|
||||
b = append(b, []byte(". Best: ")...)
|
||||
if bestRoll == 20 {
|
||||
b = append(b, []byte("nat 20!")...)
|
||||
} else {
|
||||
b = appendInt(b, bestRoll)
|
||||
b = append(b, '.')
|
||||
}
|
||||
} else {
|
||||
b = append(b, '.')
|
||||
}
|
||||
// Append narrative for nat 20 / nat 1 occurrences. One line per fight
|
||||
// regardless of how many rolled — avoids spam.
|
||||
sawNat20, sawNat1 := bestRoll == 20, fumbles > 0
|
||||
if sawNat20 {
|
||||
if line := dndNat20Line(); line != "" {
|
||||
b = append(b, []byte("\n_")...)
|
||||
b = append(b, []byte(line)...)
|
||||
b = append(b, '_')
|
||||
}
|
||||
}
|
||||
if sawNat1 && !sawNat20 {
|
||||
if line := dndNat1Line(); line != "" {
|
||||
b = append(b, []byte("\n_")...)
|
||||
b = append(b, []byte(line)...)
|
||||
b = append(b, '_')
|
||||
}
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func appendInt(b []byte, n int) []byte {
|
||||
if n == 0 {
|
||||
return append(b, '0')
|
||||
}
|
||||
if n < 0 {
|
||||
b = append(b, '-')
|
||||
n = -n
|
||||
}
|
||||
digits := []byte{}
|
||||
for n > 0 {
|
||||
digits = append([]byte{byte('0' + n%10)}, digits...)
|
||||
n /= 10
|
||||
}
|
||||
return append(b, digits...)
|
||||
}
|
||||
|
||||
func formatN(n int, word string) string {
|
||||
if n == 1 {
|
||||
return "1 " + word
|
||||
}
|
||||
out := []byte{}
|
||||
out = appendInt(out, n)
|
||||
out = append(out, ' ')
|
||||
out = append(out, []byte(word+"s")...)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// ── Combat HP scaling (rest teeth) ───────────────────────────────────────────
|
||||
|
||||
// dndWoundFloor — when scaling combat MaxHP from sheet HP%, never reduce
|
||||
// below this fraction of the legacy max. Prevents one-shot deaths when the
|
||||
// sheet is at 0 HP.
|
||||
const dndWoundFloor = 0.25
|
||||
|
||||
// applyDnDHPScaling scales playerStats.MaxHP based on the player's current
|
||||
// dnd_character HP fraction. A fully-rested player fights at full legacy HP;
|
||||
// a wounded player fights at reduced HP, with a floor at dndWoundFloor.
|
||||
//
|
||||
// This is what makes !rest mechanically meaningful — without it, the rest
|
||||
// system is purely cosmetic.
|
||||
func applyDnDHPScaling(stats *CombatStats, c *DnDCharacter) {
|
||||
if c == nil || c.HPMax <= 0 {
|
||||
return
|
||||
}
|
||||
pct := float64(c.HPCurrent) / float64(c.HPMax)
|
||||
if pct >= 1.0 {
|
||||
return
|
||||
}
|
||||
if pct < dndWoundFloor {
|
||||
pct = dndWoundFloor
|
||||
}
|
||||
scaled := int(float64(stats.MaxHP) * pct)
|
||||
if scaled < 1 {
|
||||
scaled = 1
|
||||
}
|
||||
// Defensive: pct is clamped above to [floor, 1.0], so scaled should
|
||||
// always be ≤ original MaxHP. Belt-and-suspenders in case the floor
|
||||
// or pct math drifts in a future refactor.
|
||||
if scaled > stats.MaxHP {
|
||||
scaled = stats.MaxHP
|
||||
}
|
||||
stats.MaxHP = scaled
|
||||
}
|
||||
|
||||
// ── HP persistence ───────────────────────────────────────────────────────────
|
||||
|
||||
// persistDnDHPAfterCombat updates dnd_character.hp_current to reflect wounds
|
||||
// from a fight, scaled to the D&D HP scale (since combat uses legacy HP).
|
||||
//
|
||||
// We compute the % of legacy HP the player ended with and apply the same %
|
||||
// to dnd_character.hp_max. This keeps the player's "displayed health" in
|
||||
// the sheet honest even though the combat engine itself uses legacy HP.
|
||||
//
|
||||
// No-op if the player has no dnd_character row or hasn't completed setup.
|
||||
func persistDnDHPAfterCombat(userID id.UserID, legacyStartHP, legacyEndHP int) {
|
||||
c, err := LoadDnDCharacter(userID)
|
||||
if err != nil || c == nil || c.PendingSetup {
|
||||
return
|
||||
}
|
||||
if legacyStartHP <= 0 || c.HPMax <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
pct := float64(legacyEndHP) / float64(legacyStartHP)
|
||||
if pct < 0 {
|
||||
pct = 0
|
||||
} else if pct > 1 {
|
||||
pct = 1
|
||||
}
|
||||
|
||||
newHP := int(float64(c.HPMax) * pct)
|
||||
if newHP < 0 {
|
||||
newHP = 0
|
||||
}
|
||||
if newHP > c.HPMax {
|
||||
newHP = c.HPMax
|
||||
}
|
||||
|
||||
if _, err := db.Get().Exec(
|
||||
`UPDATE dnd_character SET hp_current = ?, updated_at = CURRENT_TIMESTAMP WHERE user_id = ?`,
|
||||
newHP, string(userID),
|
||||
); err != nil {
|
||||
slog.Error("dnd: persist hp after combat", "user", userID, "err", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProficiencyBonus(t *testing.T) {
|
||||
cases := []struct{ level, want int }{
|
||||
{1, 2}, {2, 2}, {3, 2}, {4, 2},
|
||||
{5, 3}, {6, 3}, {7, 3}, {8, 3},
|
||||
{9, 4}, {12, 4},
|
||||
{13, 5}, {16, 5},
|
||||
{17, 6}, {20, 6},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := proficiencyBonus(c.level); got != c.want {
|
||||
t.Errorf("proficiencyBonus(%d) = %d, want %d", c.level, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassAttackStatMod(t *testing.T) {
|
||||
c := &DnDCharacter{STR: 16, DEX: 12, CON: 14, INT: 10, WIS: 8, CHA: 18}
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
want int
|
||||
}{
|
||||
{ClassFighter, 3}, // STR 16 → +3
|
||||
{ClassRogue, 1}, // DEX 12 → +1
|
||||
{ClassRanger, 1},
|
||||
{ClassMage, 0}, // INT 10 → 0
|
||||
{ClassCleric, -1}, // WIS 8 → -1
|
||||
}
|
||||
for _, tc := range cases {
|
||||
c.Class = tc.class
|
||||
if got := classAttackStatMod(c); got != tc.want {
|
||||
t.Errorf("classAttackStatMod(%s, STR=%d/DEX=%d/INT=%d/WIS=%d) = %d, want %d",
|
||||
tc.class, c.STR, c.DEX, c.INT, c.WIS, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDPlayerAttackBonus(t *testing.T) {
|
||||
// L1 Fighter, STR 17 (+3 mod), prof 2, weapon bonus 2 → +7
|
||||
fighter := &DnDCharacter{Class: ClassFighter, Level: 1, STR: 17}
|
||||
if got := dndPlayerAttackBonus(fighter); got != 7 {
|
||||
t.Errorf("L1 Fighter STR17 attack bonus = %d, want 7", got)
|
||||
}
|
||||
// L5 Mage, INT 16 (+3), prof 3, no weapon bonus → +6
|
||||
mage := &DnDCharacter{Class: ClassMage, Level: 5, INT: 16}
|
||||
if got := dndPlayerAttackBonus(mage); got != 6 {
|
||||
t.Errorf("L5 Mage INT16 attack bonus = %d, want 6", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDPlayerLayer(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 50, Attack: 10, Defense: 5}
|
||||
c := &DnDCharacter{Class: ClassFighter, Level: 1, STR: 17, ArmorClass: 16}
|
||||
applyDnDPlayerLayer(&stats, c)
|
||||
if stats.AC != 16 {
|
||||
t.Errorf("AC = %d, want 16", stats.AC)
|
||||
}
|
||||
if stats.AttackBonus != 7 {
|
||||
t.Errorf("AttackBonus = %d, want 7", stats.AttackBonus)
|
||||
}
|
||||
// HP/Attack scaling fields unchanged
|
||||
if stats.MaxHP != 50 || stats.Attack != 10 {
|
||||
t.Errorf("non-D&D fields mutated: %+v", stats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDArenaMonsterLayer(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 100, Attack: 20}
|
||||
applyDnDArenaMonsterLayer(&stats, 12)
|
||||
// AC base 10 + 12*0.25 = 13
|
||||
if stats.AC != 13 {
|
||||
t.Errorf("AC = %d, want 13", stats.AC)
|
||||
}
|
||||
// Atk base 4 + 12*0.30 = 7 (int trunc)
|
||||
if stats.AttackBonus != 7 {
|
||||
t.Errorf("AttackBonus = %d, want 7", stats.AttackBonus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassStatPriority(t *testing.T) {
|
||||
// Each class's array must contain {15,14,13,12,10,8} exactly once.
|
||||
want := standardArray
|
||||
for _, class := range []DnDClass{ClassFighter, ClassRogue, ClassMage, ClassCleric, ClassRanger} {
|
||||
got := classStatPriority(class)
|
||||
if !isStandardArray(got) {
|
||||
t.Errorf("classStatPriority(%s) = %v, not a permutation of %v", class, got, want)
|
||||
}
|
||||
}
|
||||
// Fighter: STR (idx 0) is the highest stat.
|
||||
f := classStatPriority(ClassFighter)
|
||||
if f[0] != 15 {
|
||||
t.Errorf("Fighter STR = %d, want 15 (primary stat)", f[0])
|
||||
}
|
||||
// Mage: INT (idx 3) is the highest stat.
|
||||
m := classStatPriority(ClassMage)
|
||||
if m[3] != 15 {
|
||||
t.Errorf("Mage INT = %d, want 15 (primary stat)", m[3])
|
||||
}
|
||||
// Cleric: WIS (idx 4) is the highest stat.
|
||||
c := classStatPriority(ClassCleric)
|
||||
if c[4] != 15 {
|
||||
t.Errorf("Cleric WIS = %d, want 15 (primary stat)", c[4])
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDDungeonMonsterLayer(t *testing.T) {
|
||||
stats := CombatStats{}
|
||||
applyDnDDungeonMonsterLayer(&stats, 1)
|
||||
if stats.AC != 10 || stats.AttackBonus != 5 {
|
||||
t.Errorf("T1 monster: AC=%d Atk=%d, want AC=10 Atk=5", stats.AC, stats.AttackBonus)
|
||||
}
|
||||
stats = CombatStats{}
|
||||
applyDnDDungeonMonsterLayer(&stats, 5)
|
||||
if stats.AC != 14 || stats.AttackBonus != 9 {
|
||||
t.Errorf("T5 monster: AC=%d Atk=%d, want AC=14 Atk=9", stats.AC, stats.AttackBonus)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSimulateCombat_RollsAppear: every attack event in a normal fight should
|
||||
// carry a d20 Roll in [1,20] and a RollAgainst (target AC).
|
||||
func TestSimulateCombat_RollsAppear(t *testing.T) {
|
||||
player := Combatant{
|
||||
Name: "P", IsPlayer: true,
|
||||
Stats: CombatStats{
|
||||
MaxHP: 50, Attack: 15, Defense: 5, Speed: 8,
|
||||
AC: 14, AttackBonus: 5,
|
||||
},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
enemy := Combatant{
|
||||
Name: "E",
|
||||
Stats: CombatStats{
|
||||
MaxHP: 30, Attack: 10, Defense: 3, Speed: 5,
|
||||
AC: 12, AttackBonus: 4,
|
||||
},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
result := SimulateCombat(player, enemy, defaultCombatPhases)
|
||||
attackEvents := 0
|
||||
for _, ev := range result.Events {
|
||||
if ev.Actor != "player" && ev.Actor != "enemy" {
|
||||
continue
|
||||
}
|
||||
if ev.Action != "hit" && ev.Action != "miss" && ev.Action != "crit" && ev.Action != "block" {
|
||||
continue
|
||||
}
|
||||
attackEvents++
|
||||
if ev.Roll < 1 || ev.Roll > 20 {
|
||||
t.Errorf("roll out of range: %+v", ev)
|
||||
}
|
||||
if ev.RollAgainst <= 0 {
|
||||
t.Errorf("RollAgainst should be set: %+v", ev)
|
||||
}
|
||||
}
|
||||
if attackEvents == 0 {
|
||||
t.Error("no attack events produced")
|
||||
}
|
||||
}
|
||||
|
||||
// TestD20HitRate_PlayerDominant: player +10 attack vs AC 11 should hit ~95%
|
||||
// (any roll 2+ hits, plus nat 20). Run many trials for statistical bound.
|
||||
func TestD20HitRate_PlayerDominant(t *testing.T) {
|
||||
hits, total := 0, 2000
|
||||
for i := 0; i < total; i++ {
|
||||
// Single-round simulation: large player HP/attack, high attack bonus,
|
||||
// monster low HP/AC. Count hit/crit events from "player".
|
||||
player := Combatant{
|
||||
IsPlayer: true,
|
||||
Stats: CombatStats{MaxHP: 1000, Attack: 1, Defense: 0, Speed: 100, AC: 99, AttackBonus: 10},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
enemy := Combatant{
|
||||
Stats: CombatStats{MaxHP: 100000, Attack: 0, Defense: 0, Speed: 1, AC: 11, AttackBonus: 0},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
// Run only one phase / one round to isolate first-attack hit rate.
|
||||
phases := []CombatPhase{{Name: "Test", Rounds: 1, AttackWeight: 1.0, DefenseWeight: 1.0, SpeedWeight: 1.0}}
|
||||
result := SimulateCombat(player, enemy, phases)
|
||||
for _, ev := range result.Events {
|
||||
if ev.Actor == "player" && (ev.Action == "hit" || ev.Action == "crit") {
|
||||
hits++
|
||||
break
|
||||
}
|
||||
if ev.Actor == "player" && ev.Action == "miss" {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
rate := float64(hits) / float64(total)
|
||||
// Expected: roll >=1 always (1=fumble miss, 2-20 hit). Nat 20 also hits. So 19/20 = 95%.
|
||||
if rate < 0.92 || rate > 0.98 {
|
||||
t.Errorf("player-dominant hit rate = %.3f, want ~0.95", rate)
|
||||
}
|
||||
}
|
||||
|
||||
// TestD20FumbleAndCrit: nat 1 always misses, nat 20 always crits. Sample
|
||||
// many rolls and confirm at least one of each occurs over many rounds.
|
||||
func TestD20FumbleAndCrit(t *testing.T) {
|
||||
sawFumble, sawCrit := false, false
|
||||
player := Combatant{
|
||||
IsPlayer: true,
|
||||
Stats: CombatStats{MaxHP: 100000, Attack: 5, Defense: 0, Speed: 50, AC: 10, AttackBonus: 5},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
enemy := Combatant{
|
||||
Stats: CombatStats{MaxHP: 100000, Attack: 1, Defense: 0, Speed: 50, AC: 13, AttackBonus: 0},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
phases := []CombatPhase{{Name: "Long", Rounds: 200, AttackWeight: 1.0, DefenseWeight: 1.0, SpeedWeight: 1.0}}
|
||||
result := SimulateCombat(player, enemy, phases)
|
||||
for _, ev := range result.Events {
|
||||
if ev.Actor != "player" {
|
||||
continue
|
||||
}
|
||||
if ev.Action == "miss" && ev.Desc == "fumble" {
|
||||
sawFumble = true
|
||||
}
|
||||
if ev.Action == "crit" && ev.Roll == 20 {
|
||||
sawCrit = true
|
||||
}
|
||||
}
|
||||
if !sawFumble {
|
||||
t.Error("never observed a fumble (nat 1) over 200 rounds")
|
||||
}
|
||||
if !sawCrit {
|
||||
t.Error("never observed a nat-20 crit over 200 rounds")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package plugin
|
||||
|
||||
// Phase 4 — D&D equipment view.
|
||||
//
|
||||
// Strategy per v1.1 §7.3: legacy adventure_equipment is the source of truth
|
||||
// for what a player has equipped. The D&D layer maps the 5-slot legacy
|
||||
// scheme onto the 10-slot D&D scheme at read time. No migration writes
|
||||
// happen. The five new slots (legs, hands, ring_1, ring_2, amulet) are
|
||||
// reserved for future drops and stay empty for now.
|
||||
|
||||
// DnDSlot is the canonical D&D equipment slot. legacy adventure_equipment
|
||||
// stores items under EquipmentSlot (weapon/armor/helmet/boots/tool); we
|
||||
// map those into D&D slots in mapLegacySlot.
|
||||
type DnDSlot string
|
||||
|
||||
const (
|
||||
DnDSlotHead DnDSlot = "head"
|
||||
DnDSlotChest DnDSlot = "chest"
|
||||
DnDSlotLegs DnDSlot = "legs"
|
||||
DnDSlotHands DnDSlot = "hands"
|
||||
DnDSlotFeet DnDSlot = "feet"
|
||||
DnDSlotMainHand DnDSlot = "main_hand"
|
||||
DnDSlotOffHand DnDSlot = "off_hand"
|
||||
DnDSlotRing1 DnDSlot = "ring_1"
|
||||
DnDSlotRing2 DnDSlot = "ring_2"
|
||||
DnDSlotAmulet DnDSlot = "amulet"
|
||||
)
|
||||
|
||||
// dndSlotOrder controls display order for !sheet.
|
||||
var dndSlotOrder = []DnDSlot{
|
||||
DnDSlotHead, DnDSlotChest, DnDSlotLegs, DnDSlotHands, DnDSlotFeet,
|
||||
DnDSlotMainHand, DnDSlotOffHand,
|
||||
DnDSlotRing1, DnDSlotRing2, DnDSlotAmulet,
|
||||
}
|
||||
|
||||
// mapLegacySlot translates a legacy EquipmentSlot into the D&D slot it
|
||||
// occupies in the new view. The legacy `tool` slot is mapped to off_hand
|
||||
// since tools (pickaxes, fishing rods, etc.) function as off-hand items.
|
||||
func mapLegacySlot(s EquipmentSlot) DnDSlot {
|
||||
switch s {
|
||||
case SlotWeapon:
|
||||
return DnDSlotMainHand
|
||||
case SlotArmor:
|
||||
return DnDSlotChest
|
||||
case SlotHelmet:
|
||||
return DnDSlotHead
|
||||
case SlotBoots:
|
||||
return DnDSlotFeet
|
||||
case SlotTool:
|
||||
return DnDSlotOffHand
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ── Rarity inference ─────────────────────────────────────────────────────────
|
||||
|
||||
// DnDRarity tags an item for D&D-style display. Inferred from the legacy
|
||||
// tier + masterwork flag. New drops with explicit dnd_rarity (Phase 4+
|
||||
// loot generation) skip this inference.
|
||||
type DnDRarity string
|
||||
|
||||
const (
|
||||
RarityCommon DnDRarity = "Common"
|
||||
RarityUncommon DnDRarity = "Uncommon"
|
||||
RarityRare DnDRarity = "Rare"
|
||||
RarityEpic DnDRarity = "Epic"
|
||||
RarityLegendary DnDRarity = "Legendary"
|
||||
)
|
||||
|
||||
// rarityIcon — leading symbol for !sheet rendering (color stand-ins for
|
||||
// terminals that don't render emoji color squares well).
|
||||
func rarityIcon(r DnDRarity) string {
|
||||
switch r {
|
||||
case RarityCommon:
|
||||
return "⬜"
|
||||
case RarityUncommon:
|
||||
return "🟩"
|
||||
case RarityRare:
|
||||
return "🟦"
|
||||
case RarityEpic:
|
||||
return "🟪"
|
||||
case RarityLegendary:
|
||||
return "🟧"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// inferRarity maps legacy gear (tier + masterwork + arena_set) to a D&D
|
||||
// rarity tier. Used at read time when dnd_rarity is empty.
|
||||
func inferRarity(tier int, masterwork bool, arenaTier int) DnDRarity {
|
||||
if masterwork {
|
||||
// Masterwork is the legacy version of "this gear is special" —
|
||||
// always treat as at least Rare to match its mechanical weight.
|
||||
if tier >= 5 {
|
||||
return RarityEpic
|
||||
}
|
||||
return RarityRare
|
||||
}
|
||||
if arenaTier > 0 {
|
||||
// Arena set gear: rarity scales with arena tier.
|
||||
switch arenaTier {
|
||||
case 1, 2:
|
||||
return RarityUncommon
|
||||
case 3:
|
||||
return RarityRare
|
||||
case 4:
|
||||
return RarityEpic
|
||||
default:
|
||||
return RarityLegendary
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case tier <= 2:
|
||||
return RarityCommon
|
||||
case tier <= 4:
|
||||
return RarityUncommon
|
||||
case tier <= 6:
|
||||
return RarityRare
|
||||
case tier <= 8:
|
||||
return RarityEpic
|
||||
default:
|
||||
return RarityLegendary
|
||||
}
|
||||
}
|
||||
|
||||
// equipmentRarity returns the rarity to display for an AdvEquipment row.
|
||||
// Honors any explicit dnd_rarity on the row (Phase 4+ loot drops);
|
||||
// otherwise falls back to inferRarity.
|
||||
func equipmentRarity(eq *AdvEquipment) DnDRarity {
|
||||
if eq == nil {
|
||||
return RarityCommon
|
||||
}
|
||||
return inferRarity(eq.Tier, eq.Masterwork, eq.ArenaTier)
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Phase 8 — equipment profile registry per gogobee_equipment_appendix.md.
|
||||
//
|
||||
// Catalogs every weapon and armor entry from the appendix as data tables,
|
||||
// plus a synthesis layer that maps legacy AdvEquipment rows (which only
|
||||
// know slot + tier + name) onto a sensible D&D profile. This gives us
|
||||
// real weapon damage dice and armor AC computation in combat without
|
||||
// requiring a loot-side rewrite.
|
||||
|
||||
// ── Weapon profiles ──────────────────────────────────────────────────────────
|
||||
|
||||
// WeaponCategory groups weapons for class-proficiency lookup.
|
||||
type WeaponCategory int
|
||||
|
||||
const (
|
||||
WeaponCatSimpleMelee WeaponCategory = iota
|
||||
WeaponCatSimpleRanged
|
||||
WeaponCatMartialMelee
|
||||
WeaponCatMartialRanged
|
||||
)
|
||||
|
||||
// WeaponProperty enumerates the weapon properties from appendix §1.
|
||||
type WeaponProperty string
|
||||
|
||||
const (
|
||||
PropFinesse WeaponProperty = "finesse"
|
||||
PropLight WeaponProperty = "light"
|
||||
PropHeavy WeaponProperty = "heavy"
|
||||
PropTwoHanded WeaponProperty = "two_handed"
|
||||
PropVersatile WeaponProperty = "versatile"
|
||||
PropThrown WeaponProperty = "thrown"
|
||||
PropAmmunition WeaponProperty = "ammunition"
|
||||
PropLoading WeaponProperty = "loading"
|
||||
PropReach WeaponProperty = "reach"
|
||||
)
|
||||
|
||||
// WeaponProfile mirrors the spec's struct. DamageDie is parsed from "1d8",
|
||||
// "2d6", "1d10" etc. into Count/Sides on construction.
|
||||
type WeaponProfile struct {
|
||||
ID string
|
||||
Name string
|
||||
Category WeaponCategory
|
||||
DamageCount int // dice count
|
||||
DamageSides int // die sides
|
||||
DamageType string // slashing, piercing, bludgeoning
|
||||
Properties []WeaponProperty
|
||||
VersaCount int // versatile two-handed dice (0 if not versatile)
|
||||
VersaSides int
|
||||
MagicBonus int // 0 for mundane
|
||||
MagicProp string // empty for mundane
|
||||
NamedItem bool // true for §7.2 named magic weapons
|
||||
}
|
||||
|
||||
// HasProperty reports whether the weapon has the given property.
|
||||
func (w *WeaponProfile) HasProperty(p WeaponProperty) bool {
|
||||
for _, q := range w.Properties {
|
||||
if q == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// dndWeaponRegistry — every weapon from appendix §2 and §3.
|
||||
var dndWeaponRegistry = []WeaponProfile{
|
||||
// §2.1 Simple Melee
|
||||
{ID: "wpn_club", Name: "Club", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 4, DamageType: "bludgeoning", Properties: []WeaponProperty{PropLight}},
|
||||
{ID: "wpn_dagger", Name: "Dagger", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 4, DamageType: "piercing", Properties: []WeaponProperty{PropFinesse, PropLight, PropThrown}},
|
||||
{ID: "wpn_greatclub", Name: "Greatclub", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 8, DamageType: "bludgeoning", Properties: []WeaponProperty{PropTwoHanded}},
|
||||
{ID: "wpn_handaxe", Name: "Handaxe", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 6, DamageType: "slashing", Properties: []WeaponProperty{PropLight, PropThrown}},
|
||||
{ID: "wpn_javelin", Name: "Javelin", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 6, DamageType: "piercing", Properties: []WeaponProperty{PropThrown}},
|
||||
{ID: "wpn_light_hammer", Name: "Light Hammer", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 4, DamageType: "bludgeoning", Properties: []WeaponProperty{PropLight, PropThrown}},
|
||||
{ID: "wpn_mace", Name: "Mace", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 6, DamageType: "bludgeoning"},
|
||||
{ID: "wpn_quarterstaff", Name: "Quarterstaff", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 6, DamageType: "bludgeoning", Properties: []WeaponProperty{PropVersatile}, VersaCount: 1, VersaSides: 8},
|
||||
{ID: "wpn_sickle", Name: "Sickle", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 4, DamageType: "slashing", Properties: []WeaponProperty{PropLight}},
|
||||
{ID: "wpn_spear", Name: "Spear", Category: WeaponCatSimpleMelee, DamageCount: 1, DamageSides: 6, DamageType: "piercing", Properties: []WeaponProperty{PropThrown, PropVersatile}, VersaCount: 1, VersaSides: 8},
|
||||
|
||||
// §2.2 Simple Ranged
|
||||
{ID: "wpn_crossbow_light", Name: "Light Crossbow", Category: WeaponCatSimpleRanged, DamageCount: 1, DamageSides: 8, DamageType: "piercing", Properties: []WeaponProperty{PropAmmunition, PropLoading, PropTwoHanded}},
|
||||
{ID: "wpn_dart", Name: "Dart", Category: WeaponCatSimpleRanged, DamageCount: 1, DamageSides: 4, DamageType: "piercing", Properties: []WeaponProperty{PropFinesse, PropThrown}},
|
||||
{ID: "wpn_shortbow", Name: "Shortbow", Category: WeaponCatSimpleRanged, DamageCount: 1, DamageSides: 6, DamageType: "piercing", Properties: []WeaponProperty{PropAmmunition, PropTwoHanded}},
|
||||
{ID: "wpn_sling", Name: "Sling", Category: WeaponCatSimpleRanged, DamageCount: 1, DamageSides: 4, DamageType: "bludgeoning", Properties: []WeaponProperty{PropAmmunition}},
|
||||
|
||||
// §3.1 Martial Melee
|
||||
{ID: "wpn_battleaxe", Name: "Battleaxe", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "slashing", Properties: []WeaponProperty{PropVersatile}, VersaCount: 1, VersaSides: 10},
|
||||
{ID: "wpn_flail", Name: "Flail", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "bludgeoning"},
|
||||
{ID: "wpn_glaive", Name: "Glaive", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 10, DamageType: "slashing", Properties: []WeaponProperty{PropHeavy, PropReach, PropTwoHanded}},
|
||||
{ID: "wpn_greataxe", Name: "Greataxe", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 12, DamageType: "slashing", Properties: []WeaponProperty{PropHeavy, PropTwoHanded}},
|
||||
{ID: "wpn_greatsword", Name: "Greatsword", Category: WeaponCatMartialMelee, DamageCount: 2, DamageSides: 6, DamageType: "slashing", Properties: []WeaponProperty{PropHeavy, PropTwoHanded}},
|
||||
{ID: "wpn_halberd", Name: "Halberd", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 10, DamageType: "slashing", Properties: []WeaponProperty{PropHeavy, PropReach, PropTwoHanded}},
|
||||
{ID: "wpn_lance", Name: "Lance", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 12, DamageType: "piercing", Properties: []WeaponProperty{PropReach}},
|
||||
{ID: "wpn_longsword", Name: "Longsword", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "slashing", Properties: []WeaponProperty{PropVersatile}, VersaCount: 1, VersaSides: 10},
|
||||
{ID: "wpn_maul", Name: "Maul", Category: WeaponCatMartialMelee, DamageCount: 2, DamageSides: 6, DamageType: "bludgeoning", Properties: []WeaponProperty{PropHeavy, PropTwoHanded}},
|
||||
{ID: "wpn_morningstar", Name: "Morningstar", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "piercing"},
|
||||
{ID: "wpn_pike", Name: "Pike", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 10, DamageType: "piercing", Properties: []WeaponProperty{PropHeavy, PropReach, PropTwoHanded}},
|
||||
{ID: "wpn_rapier", Name: "Rapier", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "piercing", Properties: []WeaponProperty{PropFinesse}},
|
||||
{ID: "wpn_scimitar", Name: "Scimitar", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 6, DamageType: "slashing", Properties: []WeaponProperty{PropFinesse, PropLight}},
|
||||
{ID: "wpn_shortsword", Name: "Shortsword", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 6, DamageType: "piercing", Properties: []WeaponProperty{PropFinesse, PropLight}},
|
||||
{ID: "wpn_trident", Name: "Trident", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 6, DamageType: "piercing", Properties: []WeaponProperty{PropThrown, PropVersatile}, VersaCount: 1, VersaSides: 8},
|
||||
{ID: "wpn_war_pick", Name: "War Pick", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "piercing"},
|
||||
{ID: "wpn_warhammer", Name: "Warhammer", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 8, DamageType: "bludgeoning", Properties: []WeaponProperty{PropVersatile}, VersaCount: 1, VersaSides: 10},
|
||||
{ID: "wpn_whip", Name: "Whip", Category: WeaponCatMartialMelee, DamageCount: 1, DamageSides: 4, DamageType: "slashing", Properties: []WeaponProperty{PropFinesse, PropReach}},
|
||||
|
||||
// §3.2 Martial Ranged
|
||||
{ID: "wpn_crossbow_hand", Name: "Hand Crossbow", Category: WeaponCatMartialRanged, DamageCount: 1, DamageSides: 6, DamageType: "piercing", Properties: []WeaponProperty{PropAmmunition, PropLight, PropLoading}},
|
||||
{ID: "wpn_crossbow_heavy", Name: "Heavy Crossbow", Category: WeaponCatMartialRanged, DamageCount: 1, DamageSides: 10, DamageType: "piercing", Properties: []WeaponProperty{PropAmmunition, PropHeavy, PropLoading, PropTwoHanded}},
|
||||
{ID: "wpn_longbow", Name: "Longbow", Category: WeaponCatMartialRanged, DamageCount: 1, DamageSides: 8, DamageType: "piercing", Properties: []WeaponProperty{PropAmmunition, PropHeavy, PropTwoHanded}},
|
||||
}
|
||||
|
||||
// weaponByID returns the WeaponProfile for an ID, or nil.
|
||||
func weaponByID(id string) *WeaponProfile {
|
||||
for i := range dndWeaponRegistry {
|
||||
if dndWeaponRegistry[i].ID == id {
|
||||
return &dndWeaponRegistry[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ── Armor profiles ───────────────────────────────────────────────────────────
|
||||
|
||||
// ArmorType identifies the proficiency category an armor falls under.
|
||||
type ArmorType int
|
||||
|
||||
const (
|
||||
ArmorTypeLight ArmorType = iota
|
||||
ArmorTypeMedium
|
||||
ArmorTypeHeavy
|
||||
ArmorTypeShield
|
||||
)
|
||||
|
||||
// ArmorProfile is the spec's struct. MaxDEXBonus convention:
|
||||
// -1 = unlimited (light armor takes full DEX mod)
|
||||
// 2 = medium (cap at +2)
|
||||
// 0 = heavy (no DEX bonus)
|
||||
// 0 for shields (shields don't add DEX)
|
||||
type ArmorProfile struct {
|
||||
ID string
|
||||
Name string
|
||||
Type ArmorType
|
||||
BaseAC int // 0 for shields (shields use ShieldBonus)
|
||||
ShieldBonus int // +2 base for shields, 0 for armor
|
||||
MaxDEXBonus int
|
||||
STRRequire int
|
||||
StealthDisad bool
|
||||
MagicBonus int
|
||||
MagicProp string
|
||||
}
|
||||
|
||||
var dndArmorRegistry = []ArmorProfile{
|
||||
// §5.1 Light
|
||||
{ID: "arm_padded", Name: "Padded", Type: ArmorTypeLight, BaseAC: 11, MaxDEXBonus: -1, StealthDisad: true},
|
||||
{ID: "arm_leather", Name: "Leather", Type: ArmorTypeLight, BaseAC: 11, MaxDEXBonus: -1},
|
||||
{ID: "arm_studded", Name: "Studded Leather", Type: ArmorTypeLight, BaseAC: 12, MaxDEXBonus: -1},
|
||||
// §5.2 Medium
|
||||
{ID: "arm_hide", Name: "Hide", Type: ArmorTypeMedium, BaseAC: 12, MaxDEXBonus: 2},
|
||||
{ID: "arm_chain_shirt", Name: "Chain Shirt", Type: ArmorTypeMedium, BaseAC: 13, MaxDEXBonus: 2},
|
||||
{ID: "arm_scale_mail", Name: "Scale Mail", Type: ArmorTypeMedium, BaseAC: 14, MaxDEXBonus: 2, StealthDisad: true},
|
||||
{ID: "arm_breastplate", Name: "Breastplate", Type: ArmorTypeMedium, BaseAC: 14, MaxDEXBonus: 2},
|
||||
{ID: "arm_half_plate", Name: "Half Plate", Type: ArmorTypeMedium, BaseAC: 15, MaxDEXBonus: 2, StealthDisad: true},
|
||||
// §5.3 Heavy
|
||||
{ID: "arm_ring_mail", Name: "Ring Mail", Type: ArmorTypeHeavy, BaseAC: 14, MaxDEXBonus: 0, StealthDisad: true},
|
||||
{ID: "arm_chain_mail", Name: "Chain Mail", Type: ArmorTypeHeavy, BaseAC: 16, MaxDEXBonus: 0, STRRequire: 13, StealthDisad: true},
|
||||
{ID: "arm_splint", Name: "Splint", Type: ArmorTypeHeavy, BaseAC: 17, MaxDEXBonus: 0, STRRequire: 15, StealthDisad: true},
|
||||
{ID: "arm_plate", Name: "Plate", Type: ArmorTypeHeavy, BaseAC: 18, MaxDEXBonus: 0, STRRequire: 15, StealthDisad: true},
|
||||
// §5.4 Shield
|
||||
{ID: "arm_shield", Name: "Shield", Type: ArmorTypeShield, BaseAC: 0, ShieldBonus: 2, MaxDEXBonus: 0},
|
||||
}
|
||||
|
||||
func armorByID(id string) *ArmorProfile {
|
||||
for i := range dndArmorRegistry {
|
||||
if dndArmorRegistry[i].ID == id {
|
||||
return &dndArmorRegistry[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ── Class proficiency matrix (appendix §9) ──────────────────────────────────
|
||||
|
||||
// dndClassWeaponProficiency reports whether a class is proficient with a
|
||||
// weapon. Rogue's restricted martial list (Shortsword, Rapier, Scimitar,
|
||||
// Longsword, Hand crossbow) is hard-coded.
|
||||
func dndClassWeaponProficiency(class DnDClass, w *WeaponProfile) bool {
|
||||
if w == nil {
|
||||
return true
|
||||
}
|
||||
// All classes are proficient with simple weapons.
|
||||
if w.Category == WeaponCatSimpleMelee || w.Category == WeaponCatSimpleRanged {
|
||||
return true
|
||||
}
|
||||
switch class {
|
||||
case ClassFighter, ClassRanger:
|
||||
return true // proficient with all martial
|
||||
case ClassRogue:
|
||||
// Restricted martial list per appendix §9.
|
||||
switch w.ID {
|
||||
case "wpn_shortsword", "wpn_rapier", "wpn_scimitar", "wpn_longsword", "wpn_crossbow_hand":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
case ClassMage, ClassCleric:
|
||||
// Mage: daggers + staves only. Cleric: simple only. Both already
|
||||
// covered by the simple-weapon early-exit. Here we're in martial.
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// dndClassArmorProficiency returns whether the class is proficient with the
|
||||
// given armor type. Per appendix §9 + main design doc §3.2.
|
||||
func dndClassArmorProficiency(class DnDClass, a *ArmorProfile) bool {
|
||||
if a == nil {
|
||||
return true
|
||||
}
|
||||
switch class {
|
||||
case ClassFighter:
|
||||
return true // Fighter wears anything
|
||||
case ClassRanger, ClassCleric:
|
||||
return a.Type == ArmorTypeLight || a.Type == ArmorTypeMedium || a.Type == ArmorTypeShield
|
||||
case ClassRogue:
|
||||
return a.Type == ArmorTypeLight
|
||||
case ClassMage:
|
||||
return false // Mage proficient with no armor
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ── Damage dice rolling ─────────────────────────────────────────────────────
|
||||
|
||||
// rollWeaponDamage rolls the weapon's damage dice and adds the ability mod
|
||||
// + magic bonus. If twoHanded is true and the weapon is versatile, rolls
|
||||
// the larger versatile die instead. Returns the unmodified dice total too
|
||||
// for the crit doubling math.
|
||||
func rollWeaponDamage(w *WeaponProfile, abilityMod int, twoHanded bool) (total, dice int) {
|
||||
count, sides := w.DamageCount, w.DamageSides
|
||||
if twoHanded && w.HasProperty(PropVersatile) && w.VersaCount > 0 {
|
||||
count, sides = w.VersaCount, w.VersaSides
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
dice += 1 + rand.IntN(sides)
|
||||
}
|
||||
total = dice + abilityMod + w.MagicBonus
|
||||
if total < 1 {
|
||||
total = 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// avgWeaponDamage returns the expected (mean) damage for a weapon given the
|
||||
// ability mod. Used by tests and balance checks. Versatile two-handed mode
|
||||
// not considered here — tests pick the form they want.
|
||||
func avgWeaponDamage(w *WeaponProfile, abilityMod int) float64 {
|
||||
count, sides := float64(w.DamageCount), float64(w.DamageSides)
|
||||
avg := count*(sides+1)/2 + float64(abilityMod) + float64(w.MagicBonus)
|
||||
if avg < 1 {
|
||||
avg = 1
|
||||
}
|
||||
return avg
|
||||
}
|
||||
|
||||
// ── AC computation per appendix ──────────────────────────────────────────────
|
||||
|
||||
// computeArmorAC implements the appendix's ComputeAC helper. Returns the
|
||||
// total AC; set armor=nil for unarmored, shield=nil for no shield.
|
||||
func computeArmorAC(armor, shield *ArmorProfile, dexMod int) int {
|
||||
base := 10
|
||||
dexApplied := dexMod
|
||||
magicBonus := 0
|
||||
if armor != nil {
|
||||
base = armor.BaseAC
|
||||
magicBonus = armor.MagicBonus
|
||||
switch armor.MaxDEXBonus {
|
||||
case -1:
|
||||
dexApplied = dexMod
|
||||
case 2:
|
||||
if dexMod > 2 {
|
||||
dexApplied = 2
|
||||
} else {
|
||||
dexApplied = dexMod
|
||||
}
|
||||
case 0:
|
||||
dexApplied = 0
|
||||
}
|
||||
}
|
||||
shieldBonus := 0
|
||||
if shield != nil {
|
||||
shieldBonus = shield.ShieldBonus + shield.MagicBonus
|
||||
}
|
||||
return base + dexApplied + magicBonus + shieldBonus
|
||||
}
|
||||
|
||||
// ── Legacy gear synthesis ────────────────────────────────────────────────────
|
||||
//
|
||||
// Existing AdvEquipment rows have name, tier, slot, masterwork, arena_tier
|
||||
// — but no D&D weapon ID. We synthesize a sensible profile from these fields
|
||||
// so combat gets real weapon dice and armor AC without a loot rewrite.
|
||||
//
|
||||
// Legacy → D&D mapping per slot:
|
||||
// Weapon:
|
||||
// Tier 1 → Club / Dagger by name keyword
|
||||
// Tier 2 → Mace / Quarterstaff
|
||||
// Tier 3 → Longsword (versatile)
|
||||
// Tier 4 → Battleaxe (versatile, two-handed mode)
|
||||
// Tier 5 → Greatsword (2d6)
|
||||
// Tier 6+ → Greatsword + magic_bonus = (tier - 5)
|
||||
// Armor:
|
||||
// Tier 1 → Padded
|
||||
// Tier 2 → Leather
|
||||
// Tier 3 → Chain Shirt (medium)
|
||||
// Tier 4 → Scale Mail (medium)
|
||||
// Tier 5 → Half Plate (medium)
|
||||
// Tier 6+ → Plate (heavy) + magic_bonus = (tier - 5)
|
||||
// Tool slot may include shields by name; otherwise no AC contribution.
|
||||
//
|
||||
// This is intentionally generous — we want existing high-tier players to
|
||||
// see a damage upgrade, not a downgrade, on the rebrand to D&D dice.
|
||||
|
||||
// synthesizeWeaponProfile inspects a legacy AdvEquipment row and returns a
|
||||
// best-fit WeaponProfile. Returns nil if the slot isn't a weapon.
|
||||
func synthesizeWeaponProfile(eq *AdvEquipment) *WeaponProfile {
|
||||
if eq == nil || eq.Slot != SlotWeapon {
|
||||
return nil
|
||||
}
|
||||
tier := eq.Tier
|
||||
if eq.Masterwork && tier < 5 {
|
||||
tier = 5 // Masterwork promotes to top-tier base
|
||||
}
|
||||
nameLower := strings.ToLower(eq.Name)
|
||||
|
||||
var base *WeaponProfile
|
||||
switch {
|
||||
case tier <= 1:
|
||||
if strings.Contains(nameLower, "dagger") || strings.Contains(nameLower, "knife") {
|
||||
base = weaponByID("wpn_dagger")
|
||||
} else {
|
||||
base = weaponByID("wpn_club")
|
||||
}
|
||||
case tier == 2:
|
||||
if strings.Contains(nameLower, "staff") || strings.Contains(nameLower, "wand") {
|
||||
base = weaponByID("wpn_quarterstaff")
|
||||
} else if strings.Contains(nameLower, "axe") {
|
||||
base = weaponByID("wpn_handaxe")
|
||||
} else {
|
||||
base = weaponByID("wpn_mace")
|
||||
}
|
||||
case tier == 3:
|
||||
if strings.Contains(nameLower, "bow") {
|
||||
base = weaponByID("wpn_shortbow")
|
||||
} else if strings.Contains(nameLower, "axe") {
|
||||
base = weaponByID("wpn_battleaxe")
|
||||
} else {
|
||||
base = weaponByID("wpn_longsword")
|
||||
}
|
||||
case tier == 4:
|
||||
if strings.Contains(nameLower, "bow") {
|
||||
base = weaponByID("wpn_longbow")
|
||||
} else if strings.Contains(nameLower, "axe") {
|
||||
base = weaponByID("wpn_battleaxe")
|
||||
} else if strings.Contains(nameLower, "hammer") {
|
||||
base = weaponByID("wpn_warhammer")
|
||||
} else {
|
||||
base = weaponByID("wpn_longsword")
|
||||
}
|
||||
default: // tier 5+
|
||||
if strings.Contains(nameLower, "bow") {
|
||||
base = weaponByID("wpn_longbow")
|
||||
} else if strings.Contains(nameLower, "axe") {
|
||||
base = weaponByID("wpn_greataxe")
|
||||
} else if strings.Contains(nameLower, "hammer") || strings.Contains(nameLower, "maul") {
|
||||
base = weaponByID("wpn_maul")
|
||||
} else {
|
||||
base = weaponByID("wpn_greatsword")
|
||||
}
|
||||
}
|
||||
if base == nil {
|
||||
// Should never happen — registry has all the IDs above. Fallback club.
|
||||
base = weaponByID("wpn_club")
|
||||
}
|
||||
// Copy so we can mutate magic bonus without polluting the registry.
|
||||
out := *base
|
||||
if eq.Tier > 5 {
|
||||
out.MagicBonus = eq.Tier - 5 // T6 = +1, T7 = +2, T8 = +3
|
||||
if out.MagicBonus > 3 {
|
||||
out.MagicBonus = 3
|
||||
}
|
||||
}
|
||||
if eq.Masterwork && out.MagicBonus < 1 {
|
||||
out.MagicBonus = 1
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
// synthesizeArmorProfile inspects a legacy AdvEquipment row and returns a
|
||||
// best-fit ArmorProfile for the chest (armor) slot. Returns nil for other slots.
|
||||
func synthesizeArmorProfile(eq *AdvEquipment) *ArmorProfile {
|
||||
if eq == nil || eq.Slot != SlotArmor {
|
||||
return nil
|
||||
}
|
||||
tier := eq.Tier
|
||||
if eq.Masterwork && tier < 5 {
|
||||
tier = 5
|
||||
}
|
||||
var base *ArmorProfile
|
||||
switch {
|
||||
case tier <= 1:
|
||||
base = armorByID("arm_padded")
|
||||
case tier == 2:
|
||||
base = armorByID("arm_leather")
|
||||
case tier == 3:
|
||||
base = armorByID("arm_chain_shirt")
|
||||
case tier == 4:
|
||||
base = armorByID("arm_scale_mail")
|
||||
case tier == 5:
|
||||
base = armorByID("arm_half_plate")
|
||||
default:
|
||||
base = armorByID("arm_plate")
|
||||
}
|
||||
if base == nil {
|
||||
base = armorByID("arm_padded")
|
||||
}
|
||||
out := *base
|
||||
if eq.Tier > 5 {
|
||||
out.MagicBonus = eq.Tier - 5
|
||||
if out.MagicBonus > 3 {
|
||||
out.MagicBonus = 3
|
||||
}
|
||||
}
|
||||
if eq.Masterwork && out.MagicBonus < 1 {
|
||||
out.MagicBonus = 1
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
// synthesizeShield — tool slot can hold shields when name matches.
|
||||
// Returns nil if the equipped tool isn't a shield.
|
||||
func synthesizeShield(eq *AdvEquipment) *ArmorProfile {
|
||||
if eq == nil || eq.Slot != SlotTool {
|
||||
return nil
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(eq.Name), "shield") {
|
||||
return nil
|
||||
}
|
||||
base := armorByID("arm_shield")
|
||||
if base == nil {
|
||||
return nil
|
||||
}
|
||||
out := *base
|
||||
if eq.Tier > 5 {
|
||||
out.MagicBonus = eq.Tier - 5
|
||||
if out.MagicBonus > 3 {
|
||||
out.MagicBonus = 3
|
||||
}
|
||||
}
|
||||
if eq.Masterwork && out.MagicBonus < 1 {
|
||||
out.MagicBonus = 1
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
// ── Misc helpers ────────────────────────────────────────────────────────────
|
||||
|
||||
// parseDamageDie parses strings like "1d8" or "2d6" into (count, sides).
|
||||
// Used by tests; the registry above pre-parses these at compile time.
|
||||
func parseDamageDie(s string) (count, sides int, ok bool) {
|
||||
parts := strings.SplitN(strings.ToLower(strings.TrimSpace(s)), "d", 2)
|
||||
if len(parts) != 2 {
|
||||
return 0, 0, false
|
||||
}
|
||||
count, err := strconv.Atoi(parts[0])
|
||||
if err != nil || count < 1 {
|
||||
return 0, 0, false
|
||||
}
|
||||
sides, err = strconv.Atoi(parts[1])
|
||||
if err != nil || sides < 2 {
|
||||
return 0, 0, false
|
||||
}
|
||||
return count, sides, true
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// ── Damage die parser ──────────────────────────────────────────────────────
|
||||
|
||||
func TestParseDamageDie(t *testing.T) {
|
||||
cases := []struct {
|
||||
s string
|
||||
count, sides int
|
||||
ok bool
|
||||
}{
|
||||
{"1d8", 1, 8, true},
|
||||
{"2d6", 2, 6, true},
|
||||
{"1D10", 1, 10, true},
|
||||
{" 1d12 ", 1, 12, true},
|
||||
{"d8", 0, 0, false}, // no count
|
||||
{"1d", 0, 0, false}, // no sides
|
||||
{"1d1", 0, 0, false}, // sides < 2
|
||||
{"banana", 0, 0, false},
|
||||
{"", 0, 0, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
count, sides, ok := parseDamageDie(c.s)
|
||||
if ok != c.ok || count != c.count || sides != c.sides {
|
||||
t.Errorf("parseDamageDie(%q) = (%d,%d,%v); want (%d,%d,%v)",
|
||||
c.s, count, sides, ok, c.count, c.sides, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Registry coverage ──────────────────────────────────────────────────────
|
||||
|
||||
func TestWeaponRegistryComplete(t *testing.T) {
|
||||
// Spot-check that key weapons from appendix §2 + §3 are present and
|
||||
// have the right damage dice. If any of these fail, the registry has
|
||||
// drifted from the appendix.
|
||||
cases := map[string]struct {
|
||||
count, sides int
|
||||
dmgType string
|
||||
}{
|
||||
"wpn_dagger": {1, 4, "piercing"},
|
||||
"wpn_longsword": {1, 8, "slashing"},
|
||||
"wpn_greatsword": {2, 6, "slashing"},
|
||||
"wpn_greataxe": {1, 12, "slashing"},
|
||||
"wpn_maul": {2, 6, "bludgeoning"},
|
||||
"wpn_quarterstaff": {1, 6, "bludgeoning"},
|
||||
"wpn_shortbow": {1, 6, "piercing"},
|
||||
"wpn_longbow": {1, 8, "piercing"},
|
||||
"wpn_crossbow_heavy": {1, 10, "piercing"},
|
||||
}
|
||||
for id, want := range cases {
|
||||
w := weaponByID(id)
|
||||
if w == nil {
|
||||
t.Errorf("missing weapon %s", id)
|
||||
continue
|
||||
}
|
||||
if w.DamageCount != want.count || w.DamageSides != want.sides {
|
||||
t.Errorf("%s damage = %dd%d, want %dd%d", id, w.DamageCount, w.DamageSides, want.count, want.sides)
|
||||
}
|
||||
if w.DamageType != want.dmgType {
|
||||
t.Errorf("%s damage type = %s, want %s", id, w.DamageType, want.dmgType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersatileWeaponsHaveLargerDie(t *testing.T) {
|
||||
for _, id := range []string{"wpn_quarterstaff", "wpn_spear", "wpn_battleaxe", "wpn_longsword", "wpn_warhammer", "wpn_trident"} {
|
||||
w := weaponByID(id)
|
||||
if w == nil {
|
||||
t.Errorf("missing %s", id)
|
||||
continue
|
||||
}
|
||||
if !w.HasProperty(PropVersatile) {
|
||||
t.Errorf("%s should be versatile", id)
|
||||
}
|
||||
if w.VersaSides <= w.DamageSides {
|
||||
t.Errorf("%s versa die (%dd%d) not larger than one-handed (%dd%d)",
|
||||
id, w.VersaCount, w.VersaSides, w.DamageCount, w.DamageSides)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArmorRegistryAppendixValues(t *testing.T) {
|
||||
// Direct values from appendix §5.
|
||||
cases := map[string]struct {
|
||||
baseAC int
|
||||
armorType ArmorType
|
||||
maxDexBonus int
|
||||
strReq int
|
||||
stealth bool
|
||||
}{
|
||||
"arm_padded": {11, ArmorTypeLight, -1, 0, true},
|
||||
"arm_leather": {11, ArmorTypeLight, -1, 0, false},
|
||||
"arm_studded": {12, ArmorTypeLight, -1, 0, false},
|
||||
"arm_chain_shirt": {13, ArmorTypeMedium, 2, 0, false},
|
||||
"arm_scale_mail": {14, ArmorTypeMedium, 2, 0, true},
|
||||
"arm_breastplate": {14, ArmorTypeMedium, 2, 0, false},
|
||||
"arm_half_plate": {15, ArmorTypeMedium, 2, 0, true},
|
||||
"arm_chain_mail": {16, ArmorTypeHeavy, 0, 13, true},
|
||||
"arm_splint": {17, ArmorTypeHeavy, 0, 15, true},
|
||||
"arm_plate": {18, ArmorTypeHeavy, 0, 15, true},
|
||||
}
|
||||
for id, want := range cases {
|
||||
a := armorByID(id)
|
||||
if a == nil {
|
||||
t.Errorf("missing %s", id)
|
||||
continue
|
||||
}
|
||||
if a.BaseAC != want.baseAC || a.Type != want.armorType ||
|
||||
a.MaxDEXBonus != want.maxDexBonus || a.STRRequire != want.strReq ||
|
||||
a.StealthDisad != want.stealth {
|
||||
t.Errorf("%s mismatch: got base=%d type=%d dex=%d str=%d stealth=%v; want %+v",
|
||||
id, a.BaseAC, a.Type, a.MaxDEXBonus, a.STRRequire, a.StealthDisad, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── ComputeAC math ──────────────────────────────────────────────────────────
|
||||
|
||||
func TestComputeArmorAC_Unarmored(t *testing.T) {
|
||||
// Unarmored, DEX +3 → 13
|
||||
if got := computeArmorAC(nil, nil, 3); got != 13 {
|
||||
t.Errorf("unarmored DEX+3 AC = %d, want 13", got)
|
||||
}
|
||||
// Unarmored + shield, DEX +0 → 12
|
||||
if got := computeArmorAC(nil, armorByID("arm_shield"), 0); got != 12 {
|
||||
t.Errorf("unarmored + shield DEX+0 AC = %d, want 12", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeArmorAC_Light(t *testing.T) {
|
||||
leather := armorByID("arm_leather")
|
||||
// Leather (11) + DEX +4 → 15
|
||||
if got := computeArmorAC(leather, nil, 4); got != 15 {
|
||||
t.Errorf("leather DEX+4 AC = %d, want 15", got)
|
||||
}
|
||||
// Studded (12) + DEX +5 → 17 (light has no cap)
|
||||
if got := computeArmorAC(armorByID("arm_studded"), nil, 5); got != 17 {
|
||||
t.Errorf("studded DEX+5 AC = %d, want 17", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeArmorAC_MediumCapped(t *testing.T) {
|
||||
// Half plate (15) + DEX +4 → 17 (capped at +2)
|
||||
if got := computeArmorAC(armorByID("arm_half_plate"), nil, 4); got != 17 {
|
||||
t.Errorf("half plate DEX+4 AC = %d, want 17 (cap)", got)
|
||||
}
|
||||
// Chain shirt (13) + DEX +1 → 14 (under cap)
|
||||
if got := computeArmorAC(armorByID("arm_chain_shirt"), nil, 1); got != 14 {
|
||||
t.Errorf("chain shirt DEX+1 AC = %d, want 14", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeArmorAC_HeavyIgnoresDex(t *testing.T) {
|
||||
// Plate (18) + DEX +5 → 18 (no DEX)
|
||||
if got := computeArmorAC(armorByID("arm_plate"), nil, 5); got != 18 {
|
||||
t.Errorf("plate DEX+5 AC = %d, want 18 (no DEX)", got)
|
||||
}
|
||||
// Chain mail (16) + shield + DEX -1 → 18
|
||||
if got := computeArmorAC(armorByID("arm_chain_mail"), armorByID("arm_shield"), -1); got != 18 {
|
||||
t.Errorf("chain mail + shield AC = %d, want 18", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeArmorAC_MagicBonus(t *testing.T) {
|
||||
plate := *armorByID("arm_plate")
|
||||
plate.MagicBonus = 2
|
||||
// +2 plate (18 + 2) → 20
|
||||
if got := computeArmorAC(&plate, nil, 0); got != 20 {
|
||||
t.Errorf("+2 plate AC = %d, want 20", got)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Weapon damage rolls ─────────────────────────────────────────────────────
|
||||
|
||||
func TestRollWeaponDamage_Bounds(t *testing.T) {
|
||||
greatsword := weaponByID("wpn_greatsword") // 2d6
|
||||
for i := 0; i < 1000; i++ {
|
||||
total, dice := rollWeaponDamage(greatsword, 3, false)
|
||||
if dice < 2 || dice > 12 {
|
||||
t.Fatalf("greatsword dice out of [2,12]: %d", dice)
|
||||
}
|
||||
if total != dice+3 {
|
||||
t.Fatalf("total %d != dice %d + mod 3", total, dice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollWeaponDamage_VersatileTwoHanded(t *testing.T) {
|
||||
longsword := weaponByID("wpn_longsword") // 1d8 / 1d10
|
||||
// One-handed
|
||||
for i := 0; i < 100; i++ {
|
||||
_, dice := rollWeaponDamage(longsword, 0, false)
|
||||
if dice < 1 || dice > 8 {
|
||||
t.Errorf("longsword 1H dice = %d, want [1,8]", dice)
|
||||
}
|
||||
}
|
||||
// Two-handed (versatile)
|
||||
for i := 0; i < 100; i++ {
|
||||
_, dice := rollWeaponDamage(longsword, 0, true)
|
||||
if dice < 1 || dice > 10 {
|
||||
t.Errorf("longsword 2H dice = %d, want [1,10]", dice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollWeaponDamage_FloorAt1(t *testing.T) {
|
||||
// Pathological: 1d4 with -10 mod always rolls 1+(-10) = negative, floored to 1.
|
||||
dagger := weaponByID("wpn_dagger")
|
||||
for i := 0; i < 100; i++ {
|
||||
total, _ := rollWeaponDamage(dagger, -10, false)
|
||||
if total < 1 {
|
||||
t.Errorf("damage floor violated: %d", total)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAvgWeaponDamage(t *testing.T) {
|
||||
// 1d8 + 0 mean = 4.5
|
||||
got := avgWeaponDamage(weaponByID("wpn_longsword"), 0)
|
||||
if got != 4.5 {
|
||||
t.Errorf("longsword avg = %v, want 4.5", got)
|
||||
}
|
||||
// 2d6 + 3 mean = 7 + 3 = 10
|
||||
got = avgWeaponDamage(weaponByID("wpn_greatsword"), 3)
|
||||
if got != 10.0 {
|
||||
t.Errorf("greatsword+3 avg = %v, want 10", got)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Class proficiency ──────────────────────────────────────────────────────
|
||||
|
||||
func TestClassWeaponProficiency(t *testing.T) {
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
wpnID string
|
||||
want bool
|
||||
}{
|
||||
// Simple weapons: everyone proficient
|
||||
{ClassMage, "wpn_dagger", true},
|
||||
{ClassCleric, "wpn_mace", true},
|
||||
{ClassRogue, "wpn_quarterstaff", true},
|
||||
// Martial: Fighter/Ranger always
|
||||
{ClassFighter, "wpn_greatsword", true},
|
||||
{ClassRanger, "wpn_longbow", true},
|
||||
// Mage/Cleric: NOT proficient with martial
|
||||
{ClassMage, "wpn_longsword", false},
|
||||
{ClassCleric, "wpn_greatsword", false},
|
||||
// Rogue: restricted martial list
|
||||
{ClassRogue, "wpn_shortsword", true},
|
||||
{ClassRogue, "wpn_rapier", true},
|
||||
{ClassRogue, "wpn_longsword", true},
|
||||
{ClassRogue, "wpn_crossbow_hand", true},
|
||||
{ClassRogue, "wpn_greatsword", false},
|
||||
{ClassRogue, "wpn_warhammer", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
w := weaponByID(c.wpnID)
|
||||
if got := dndClassWeaponProficiency(c.class, w); got != c.want {
|
||||
t.Errorf("class=%s wpn=%s = %v, want %v", c.class, c.wpnID, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassArmorProficiency(t *testing.T) {
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
armorID string
|
||||
want bool
|
||||
}{
|
||||
{ClassFighter, "arm_plate", true},
|
||||
{ClassFighter, "arm_leather", true},
|
||||
{ClassFighter, "arm_shield", true},
|
||||
{ClassRanger, "arm_chain_shirt", true}, // medium
|
||||
{ClassRanger, "arm_plate", false}, // heavy
|
||||
{ClassCleric, "arm_chain_shirt", true},
|
||||
{ClassCleric, "arm_plate", false},
|
||||
{ClassCleric, "arm_shield", true},
|
||||
{ClassRogue, "arm_leather", true},
|
||||
{ClassRogue, "arm_chain_shirt", false}, // medium
|
||||
{ClassRogue, "arm_shield", false},
|
||||
{ClassMage, "arm_leather", false},
|
||||
{ClassMage, "arm_shield", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
a := armorByID(c.armorID)
|
||||
if got := dndClassArmorProficiency(c.class, a); got != c.want {
|
||||
t.Errorf("class=%s armor=%s = %v, want %v", c.class, c.armorID, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Legacy synthesis ───────────────────────────────────────────────────────
|
||||
|
||||
func TestSynthesizeWeaponProfile_TierMapping(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
tier int
|
||||
wantBase string
|
||||
}{
|
||||
{"Iron Club", 1, "wpn_club"},
|
||||
{"Wooden Dagger", 1, "wpn_dagger"},
|
||||
{"Steel Mace", 2, "wpn_mace"},
|
||||
{"Apprentice Staff", 2, "wpn_quarterstaff"},
|
||||
{"Iron Sword", 3, "wpn_longsword"},
|
||||
{"Hunter's Bow", 3, "wpn_shortbow"},
|
||||
{"Knight's Sword", 4, "wpn_longsword"},
|
||||
{"Greatsword", 5, "wpn_greatsword"},
|
||||
{"Battleaxe", 5, "wpn_greataxe"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
eq := &AdvEquipment{Slot: SlotWeapon, Tier: c.tier, Name: c.name}
|
||||
w := synthesizeWeaponProfile(eq)
|
||||
if w == nil {
|
||||
t.Errorf("%s tier %d: synthesize returned nil", c.name, c.tier)
|
||||
continue
|
||||
}
|
||||
base := weaponByID(c.wantBase)
|
||||
if w.DamageCount != base.DamageCount || w.DamageSides != base.DamageSides {
|
||||
t.Errorf("%s tier %d: synthesized %dd%d, expected %dd%d (%s)",
|
||||
c.name, c.tier, w.DamageCount, w.DamageSides,
|
||||
base.DamageCount, base.DamageSides, c.wantBase)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynthesizeWeaponProfile_HighTierMagicBonus(t *testing.T) {
|
||||
eq := &AdvEquipment{Slot: SlotWeapon, Tier: 7, Name: "Legendary Sword"}
|
||||
w := synthesizeWeaponProfile(eq)
|
||||
if w == nil {
|
||||
t.Fatal("synthesize returned nil")
|
||||
}
|
||||
if w.MagicBonus != 2 { // tier 7 - 5 = +2
|
||||
t.Errorf("tier 7 magic bonus = %d, want 2", w.MagicBonus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynthesizeWeaponProfile_MasterworkPromotes(t *testing.T) {
|
||||
eq := &AdvEquipment{Slot: SlotWeapon, Tier: 2, Name: "Sword", Masterwork: true}
|
||||
w := synthesizeWeaponProfile(eq)
|
||||
if w.DamageSides < 6 {
|
||||
t.Errorf("masterwork promoted should be at least tier-5 base (1d8/2d6); got %dd%d",
|
||||
w.DamageCount, w.DamageSides)
|
||||
}
|
||||
if w.MagicBonus < 1 {
|
||||
t.Errorf("masterwork should grant +1 minimum, got +%d", w.MagicBonus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynthesizeWeaponProfile_NonWeaponSlotReturnsNil(t *testing.T) {
|
||||
eq := &AdvEquipment{Slot: SlotArmor, Tier: 3, Name: "Plate"}
|
||||
if got := synthesizeWeaponProfile(eq); got != nil {
|
||||
t.Errorf("non-weapon slot should return nil, got %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynthesizeArmorProfile_TierMapping(t *testing.T) {
|
||||
cases := []struct {
|
||||
tier int
|
||||
wantBaseAC int
|
||||
wantType ArmorType
|
||||
}{
|
||||
{1, 11, ArmorTypeLight}, // Padded
|
||||
{2, 11, ArmorTypeLight}, // Leather
|
||||
{3, 13, ArmorTypeMedium}, // Chain Shirt
|
||||
{4, 14, ArmorTypeMedium}, // Scale Mail
|
||||
{5, 15, ArmorTypeMedium}, // Half Plate
|
||||
{6, 18, ArmorTypeHeavy}, // Plate
|
||||
}
|
||||
for _, c := range cases {
|
||||
eq := &AdvEquipment{Slot: SlotArmor, Tier: c.tier, Name: "Armor"}
|
||||
a := synthesizeArmorProfile(eq)
|
||||
if a == nil {
|
||||
t.Errorf("tier %d: synth returned nil", c.tier)
|
||||
continue
|
||||
}
|
||||
if a.BaseAC != c.wantBaseAC || a.Type != c.wantType {
|
||||
t.Errorf("tier %d: got AC=%d type=%d, want AC=%d type=%d",
|
||||
c.tier, a.BaseAC, a.Type, c.wantBaseAC, c.wantType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynthesizeShield_NameMatch(t *testing.T) {
|
||||
cases := []struct {
|
||||
slot EquipmentSlot
|
||||
name string
|
||||
want bool
|
||||
}{
|
||||
{SlotTool, "Iron Shield", true},
|
||||
{SlotTool, "Tower Shield", true},
|
||||
{SlotTool, "Pickaxe", false},
|
||||
{SlotTool, "", false},
|
||||
{SlotWeapon, "Shield", false}, // wrong slot
|
||||
}
|
||||
for _, c := range cases {
|
||||
eq := &AdvEquipment{Slot: c.slot, Name: c.name, Tier: 3}
|
||||
got := synthesizeShield(eq) != nil
|
||||
if got != c.want {
|
||||
t.Errorf("slot=%s name=%q: shield=%v, want %v", c.slot, c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── pickWeaponAbilityMod ────────────────────────────────────────────────────
|
||||
|
||||
func TestPickWeaponAbilityMod(t *testing.T) {
|
||||
c := &DnDCharacter{STR: 16, DEX: 14, CON: 13, INT: 8, WIS: 10, CHA: 12}
|
||||
// STR mod = +3, DEX mod = +2.
|
||||
cases := []struct {
|
||||
wpnID string
|
||||
want int
|
||||
}{
|
||||
{"wpn_greatsword", 3}, // melee non-finesse → STR
|
||||
{"wpn_longsword", 3},
|
||||
{"wpn_dagger", 3}, // finesse melee, but STR > DEX, picks STR
|
||||
{"wpn_longbow", 2}, // ranged → DEX
|
||||
{"wpn_shortbow", 2},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := pickWeaponAbilityMod(weaponByID(tc.wpnID), c)
|
||||
if got != tc.want {
|
||||
t.Errorf("%s: ability mod = %d, want %d", tc.wpnID, got, tc.want)
|
||||
}
|
||||
}
|
||||
|
||||
// Now with DEX > STR: finesse should pick DEX.
|
||||
c2 := &DnDCharacter{STR: 10, DEX: 18, CON: 14}
|
||||
if got := pickWeaponAbilityMod(weaponByID("wpn_dagger"), c2); got != 4 {
|
||||
t.Errorf("DEX-favored finesse: got %d, want 4 (DEX +4)", got)
|
||||
}
|
||||
if got := pickWeaponAbilityMod(weaponByID("wpn_greatsword"), c2); got != 0 {
|
||||
t.Errorf("non-finesse with DEX>STR: got %d, want 0 (STR +0)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// ── End-to-end: applyDnDEquipmentLayer ─────────────────────────────────────
|
||||
|
||||
func TestApplyDnDEquipmentLayer_FighterFullKit(t *testing.T) {
|
||||
c := &DnDCharacter{
|
||||
Race: RaceHuman, Class: ClassFighter, Level: 5,
|
||||
STR: 18, DEX: 14, CON: 16, INT: 10, WIS: 12, CHA: 8,
|
||||
ArmorClass: 10, // base
|
||||
}
|
||||
equip := map[EquipmentSlot]*AdvEquipment{
|
||||
SlotWeapon: {Slot: SlotWeapon, Tier: 5, Name: "Greatsword"},
|
||||
SlotArmor: {Slot: SlotArmor, Tier: 6, Name: "Plate"},
|
||||
}
|
||||
stats := CombatStats{}
|
||||
applyDnDPlayerLayer(&stats, c)
|
||||
applyDnDEquipmentLayer(&stats, c, equip)
|
||||
|
||||
if stats.Weapon == nil {
|
||||
t.Fatal("weapon not set")
|
||||
}
|
||||
if stats.Weapon.DamageCount != 1 || stats.Weapon.DamageSides != 12 {
|
||||
// Greatsword name + tier 5 → wpn_greataxe (1d12) per synth name match
|
||||
// (greatsword name routes through "axe" branch? No, "greatsword" doesn't
|
||||
// contain "axe". Let me check: tier 5 default else branch → wpn_greatsword (2d6).
|
||||
// Adjust test if synthesis differs.
|
||||
if !(stats.Weapon.DamageCount == 2 && stats.Weapon.DamageSides == 6) {
|
||||
t.Errorf("greatsword tier 5 weapon = %dd%d, expected 2d6 or 1d12",
|
||||
stats.Weapon.DamageCount, stats.Weapon.DamageSides)
|
||||
}
|
||||
}
|
||||
if !stats.WeaponProficient {
|
||||
t.Error("Fighter should be proficient with synthesized weapon")
|
||||
}
|
||||
// Plate (tier 6) → +1 plate, AC = 18+1 = 19, no DEX, no shield
|
||||
if stats.AC != 19 {
|
||||
t.Errorf("Fighter+plate+1 AC = %d, want 19", stats.AC)
|
||||
}
|
||||
// Two-handed mode: greatsword has TwoHanded property (no shield).
|
||||
// Greatsword's properties include Heavy + TwoHanded — TwoHandedMode set.
|
||||
if !stats.TwoHandedMode {
|
||||
t.Error("expected TwoHandedMode for greatsword without shield")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDEquipmentLayer_MageWithMartialWeapon(t *testing.T) {
|
||||
// Mage equips a longsword → not proficient, -4 attack penalty path.
|
||||
c := &DnDCharacter{
|
||||
Class: ClassMage, Level: 1, STR: 8, DEX: 14, CON: 12, INT: 16, WIS: 13, CHA: 10,
|
||||
ArmorClass: 10,
|
||||
}
|
||||
equip := map[EquipmentSlot]*AdvEquipment{
|
||||
SlotWeapon: {Slot: SlotWeapon, Tier: 3, Name: "Longsword"},
|
||||
}
|
||||
stats := CombatStats{}
|
||||
applyDnDPlayerLayer(&stats, c)
|
||||
applyDnDEquipmentLayer(&stats, c, equip)
|
||||
if stats.Weapon == nil {
|
||||
t.Fatal("weapon nil")
|
||||
}
|
||||
if stats.WeaponProficient {
|
||||
t.Error("Mage should NOT be proficient with longsword")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package plugin
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMapLegacySlot(t *testing.T) {
|
||||
cases := []struct {
|
||||
legacy EquipmentSlot
|
||||
want DnDSlot
|
||||
}{
|
||||
{SlotWeapon, DnDSlotMainHand},
|
||||
{SlotArmor, DnDSlotChest},
|
||||
{SlotHelmet, DnDSlotHead},
|
||||
{SlotBoots, DnDSlotFeet},
|
||||
{SlotTool, DnDSlotOffHand},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := mapLegacySlot(c.legacy); got != c.want {
|
||||
t.Errorf("mapLegacySlot(%s) = %s, want %s", c.legacy, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferRarity(t *testing.T) {
|
||||
cases := []struct {
|
||||
tier int
|
||||
masterwork bool
|
||||
arenaTier int
|
||||
want DnDRarity
|
||||
}{
|
||||
{1, false, 0, RarityCommon},
|
||||
{2, false, 0, RarityCommon},
|
||||
{3, false, 0, RarityUncommon},
|
||||
{4, false, 0, RarityUncommon},
|
||||
{5, false, 0, RarityRare},
|
||||
{6, false, 0, RarityRare},
|
||||
{7, false, 0, RarityEpic},
|
||||
{9, false, 0, RarityLegendary},
|
||||
// Masterwork bumps to Rare/Epic
|
||||
{2, true, 0, RarityRare},
|
||||
{6, true, 0, RarityEpic},
|
||||
// Arena set
|
||||
{3, false, 1, RarityUncommon},
|
||||
{3, false, 3, RarityRare},
|
||||
{3, false, 4, RarityEpic},
|
||||
{3, false, 5, RarityLegendary},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := inferRarity(c.tier, c.masterwork, c.arenaTier)
|
||||
if got != c.want {
|
||||
t.Errorf("inferRarity(t=%d mw=%v arena=%d) = %s, want %s",
|
||||
c.tier, c.masterwork, c.arenaTier, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRarityIcon(t *testing.T) {
|
||||
for _, r := range []DnDRarity{RarityCommon, RarityUncommon, RarityRare, RarityEpic, RarityLegendary} {
|
||||
if rarityIcon(r) == "" {
|
||||
t.Errorf("rarityIcon(%s) returned empty string", r)
|
||||
}
|
||||
}
|
||||
if rarityIcon("Bogus") != "" {
|
||||
t.Error("rarityIcon for unknown rarity should be empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEquipmentRarity_NilSafety(t *testing.T) {
|
||||
if got := equipmentRarity(nil); got != RarityCommon {
|
||||
t.Errorf("equipmentRarity(nil) = %s, want Common", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDSlotOrderComplete(t *testing.T) {
|
||||
// Every D&D slot is in the order list exactly once.
|
||||
seen := map[DnDSlot]bool{}
|
||||
for _, s := range dndSlotOrder {
|
||||
if seen[s] {
|
||||
t.Errorf("dndSlotOrder has duplicate %s", s)
|
||||
}
|
||||
seen[s] = true
|
||||
}
|
||||
expected := []DnDSlot{
|
||||
DnDSlotHead, DnDSlotChest, DnDSlotLegs, DnDSlotHands, DnDSlotFeet,
|
||||
DnDSlotMainHand, DnDSlotOffHand,
|
||||
DnDSlotRing1, DnDSlotRing2, DnDSlotAmulet,
|
||||
}
|
||||
if len(seen) != len(expected) {
|
||||
t.Errorf("dndSlotOrder size = %d, want %d", len(seen), len(expected))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gogobee/internal/flavor"
|
||||
)
|
||||
|
||||
// D&D-layer flavor wire-in. Helpers here pull from the protected pools in
|
||||
// internal/flavor and are called at the relevant integration points
|
||||
// (combat outputs, level-up DM, rest commands, NPC encounters, loot drops).
|
||||
//
|
||||
// Each helper returns "" when the corresponding pool is empty so callers can
|
||||
// safely embed the result without conditional-noise everywhere.
|
||||
|
||||
// ── Combat narrative ─────────────────────────────────────────────────────────
|
||||
|
||||
// dndCombatOpeningLine returns a single CombatStart pool line for use at
|
||||
// the top of a fight's combat-log render. Caller decides where to inject it
|
||||
// (typically prepended to the first phase message).
|
||||
func dndCombatOpeningLine() string {
|
||||
return flavor.Pick(flavor.CombatStart)
|
||||
}
|
||||
|
||||
// dndCombatClosingLine returns a single line appropriate for the fight's
|
||||
// end state: CombatVictory on a non-boss win, BossDeath on a boss kill,
|
||||
// PlayerDeath on a loss.
|
||||
func dndCombatClosingLine(playerWon, isBoss bool) string {
|
||||
switch {
|
||||
case playerWon && isBoss:
|
||||
return flavor.Pick(flavor.BossDeath)
|
||||
case playerWon:
|
||||
return flavor.Pick(flavor.CombatVictory)
|
||||
default:
|
||||
return flavor.Pick(flavor.PlayerDeath)
|
||||
}
|
||||
}
|
||||
|
||||
// dndZoneCompleteLine fires on dungeon completion (only on victorious clear).
|
||||
func dndZoneCompleteLine() string {
|
||||
return flavor.Pick(flavor.ZoneComplete)
|
||||
}
|
||||
|
||||
// dndNat20Line / dndNat1Line — appended to the fight's roll summary when
|
||||
// at least one nat 20 / nat 1 was rolled by the player. A single line per
|
||||
// fight (not per roll) to avoid spam.
|
||||
func dndNat20Line() string {
|
||||
return flavor.Pick(flavor.Nat20)
|
||||
}
|
||||
|
||||
func dndNat1Line() string {
|
||||
return flavor.Pick(flavor.Nat1)
|
||||
}
|
||||
|
||||
// ── Level-up + items ────────────────────────────────────────────────────────
|
||||
|
||||
// dndLevelUpFlavorLine — random LevelUp pool entry for the level-up DM.
|
||||
func dndLevelUpFlavorLine() string {
|
||||
return flavor.Pick(flavor.LevelUp)
|
||||
}
|
||||
|
||||
// dndItemFoundLine — used when loot drops in dungeon resolution.
|
||||
func dndItemFoundLine() string {
|
||||
return flavor.Pick(flavor.ItemFound)
|
||||
}
|
||||
|
||||
// ── Rest ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
// dndRestShortFlavorLine — for !rest short.
|
||||
func dndRestShortFlavorLine() string {
|
||||
return flavor.Pick(flavor.RestShort)
|
||||
}
|
||||
|
||||
// dndRestLongFlavorLine — for !rest long. The HomeLongRest pool is
|
||||
// preferred when the player is at home; falls back to generic RestLong.
|
||||
func dndRestLongFlavorLine(atHome bool) string {
|
||||
if atHome {
|
||||
if line := flavor.Pick(flavor.HomeLongRest); line != "" {
|
||||
return line
|
||||
}
|
||||
}
|
||||
return flavor.Pick(flavor.RestLong)
|
||||
}
|
||||
|
||||
// ── NPC greetings ───────────────────────────────────────────────────────────
|
||||
//
|
||||
// The NPC encounter system already has legacy `mistyOpenings` and
|
||||
// `arinaOpenings` slices used for prompt openings. We don't replace those —
|
||||
// we union them with the new D&D-flavored greetings so players see ~2x
|
||||
// variety in the openings. Helpers below return the combined pool.
|
||||
|
||||
// dndMistyGreetingPool returns the union of legacy and D&D pools for Misty.
|
||||
// Used by the encounter-fire path to vary opening lines.
|
||||
func dndMistyGreetingPool() []string {
|
||||
combined := make([]string, 0, len(flavor.MistyGreeting)+len(mistyOpenings))
|
||||
combined = append(combined, flavor.MistyGreeting...)
|
||||
combined = append(combined, mistyOpenings...)
|
||||
return combined
|
||||
}
|
||||
|
||||
func dndArinaGreetingPool() []string {
|
||||
combined := make([]string, 0, len(flavor.ArinaGreeting)+len(arinaOpenings))
|
||||
combined = append(combined, flavor.ArinaGreeting...)
|
||||
combined = append(combined, arinaOpenings...)
|
||||
return combined
|
||||
}
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
// dndItalicize wraps a non-empty line in markdown italics with leading
|
||||
// blank line so callers can append narrative cleanly.
|
||||
func dndItalicize(line string) string {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
return ""
|
||||
}
|
||||
return "\n\n_" + line + "_"
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gogobee/internal/flavor"
|
||||
)
|
||||
|
||||
// TestDnDFlavorPoolsNonEmpty: every pool we wired into the D&D layer must
|
||||
// have at least one entry. Catches accidental deletions in the protected
|
||||
// flavor files that would silently produce empty narrative.
|
||||
func TestDnDFlavorPoolsNonEmpty(t *testing.T) {
|
||||
pools := map[string][]string{
|
||||
"CombatStart": flavor.CombatStart,
|
||||
"CombatVictory": flavor.CombatVictory,
|
||||
"BossDeath": flavor.BossDeath,
|
||||
"PlayerDeath": flavor.PlayerDeath,
|
||||
"ZoneComplete": flavor.ZoneComplete,
|
||||
"Nat20": flavor.Nat20,
|
||||
"Nat1": flavor.Nat1,
|
||||
"LevelUp": flavor.LevelUp,
|
||||
"ItemFound": flavor.ItemFound,
|
||||
"RestShort": flavor.RestShort,
|
||||
"RestLong": flavor.RestLong,
|
||||
"HomeLongRest": flavor.HomeLongRest,
|
||||
"MistyGreeting": flavor.MistyGreeting,
|
||||
"MistyInsightSuccess": flavor.MistyInsightSuccess,
|
||||
"MistySkillFail": flavor.MistySkillFail,
|
||||
"ArinaGreeting": flavor.ArinaGreeting,
|
||||
"ArinaArcanaSuccess": flavor.ArinaArcanaSuccess,
|
||||
"ArinaSkillFail": flavor.ArinaSkillFail,
|
||||
"ExpeditionStart": flavor.ExpeditionStart,
|
||||
}
|
||||
for name, pool := range pools {
|
||||
if len(pool) == 0 {
|
||||
t.Errorf("flavor pool %s is empty — protected file deletion?", name)
|
||||
}
|
||||
for i, s := range pool {
|
||||
if s == "" {
|
||||
t.Errorf("flavor.%s[%d] is empty string", name, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDnDFlavorHelpersReturnNonEmpty: every helper must produce a non-empty
|
||||
// string when its underlying pool has entries.
|
||||
func TestDnDFlavorHelpersReturnNonEmpty(t *testing.T) {
|
||||
cases := map[string]func() string{
|
||||
"dndCombatOpeningLine": dndCombatOpeningLine,
|
||||
"dndZoneCompleteLine": dndZoneCompleteLine,
|
||||
"dndNat20Line": dndNat20Line,
|
||||
"dndNat1Line": dndNat1Line,
|
||||
"dndLevelUpFlavorLine": dndLevelUpFlavorLine,
|
||||
"dndItemFoundLine": dndItemFoundLine,
|
||||
"dndRestShortFlavorLine": dndRestShortFlavorLine,
|
||||
"dndCombatClosingLine_Win": func() string { return dndCombatClosingLine(true, false) },
|
||||
"dndCombatClosingLine_Boss": func() string { return dndCombatClosingLine(true, true) },
|
||||
"dndCombatClosingLine_Death": func() string { return dndCombatClosingLine(false, false) },
|
||||
"dndRestLongFlavorLine_Home": func() string { return dndRestLongFlavorLine(true) },
|
||||
"dndRestLongFlavorLine_Inn": func() string { return dndRestLongFlavorLine(false) },
|
||||
}
|
||||
for name, fn := range cases {
|
||||
// Run several times — flavor pulls a random pool member, so a single
|
||||
// call can flake if the pool happens to have an empty string. The
|
||||
// pool-non-empty test above guards against that, but be belt-and-suspenders.
|
||||
for i := 0; i < 10; i++ {
|
||||
if got := fn(); got == "" {
|
||||
t.Errorf("%s returned empty (call #%d)", name, i)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDnDGreetingPoolUnion: combined Misty/Arina greeting pools include both
|
||||
// legacy openings and the D&D-flavored entries.
|
||||
func TestDnDGreetingPoolUnion(t *testing.T) {
|
||||
mistyPool := dndMistyGreetingPool()
|
||||
if len(mistyPool) != len(flavor.MistyGreeting)+len(mistyOpenings) {
|
||||
t.Errorf("Misty pool union size = %d; expected %d (flavor %d + legacy %d)",
|
||||
len(mistyPool), len(flavor.MistyGreeting)+len(mistyOpenings),
|
||||
len(flavor.MistyGreeting), len(mistyOpenings))
|
||||
}
|
||||
arinaPool := dndArinaGreetingPool()
|
||||
if len(arinaPool) != len(flavor.ArinaGreeting)+len(arinaOpenings) {
|
||||
t.Errorf("Arina pool union size = %d; expected %d", len(arinaPool),
|
||||
len(flavor.ArinaGreeting)+len(arinaOpenings))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDItalicize(t *testing.T) {
|
||||
if got := dndItalicize(""); got != "" {
|
||||
t.Errorf("italicize(empty) = %q, want empty", got)
|
||||
}
|
||||
if got := dndItalicize(" "); got != "" {
|
||||
t.Errorf("italicize(whitespace) = %q, want empty", got)
|
||||
}
|
||||
got := dndItalicize("hello")
|
||||
if got != "\n\n_hello_" {
|
||||
t.Errorf("italicize = %q, want \\n\\n_hello_", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Tabletop conveniences — !roll, !stats, !level. None of these mutate
|
||||
// state; they're pure display/RNG commands.
|
||||
|
||||
// ── !roll <dice> ─────────────────────────────────────────────────────────────
|
||||
|
||||
var diceNotation = regexp.MustCompile(`^(\d*)d(\d+)([+-]\d+)?$`)
|
||||
|
||||
const (
|
||||
dndRollMaxCount = 100
|
||||
dndRollMaxSides = 1000
|
||||
)
|
||||
|
||||
// parseDice parses standard tabletop notation: "2d6+3", "d20", "4d6-1".
|
||||
// Returns (count, sides, modifier, ok).
|
||||
func parseDice(s string) (int, int, int, bool) {
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
m := diceNotation.FindStringSubmatch(s)
|
||||
if m == nil {
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
count := 1
|
||||
if m[1] != "" {
|
||||
n, err := strconv.Atoi(m[1])
|
||||
if err != nil {
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
count = n
|
||||
}
|
||||
sides, err := strconv.Atoi(m[2])
|
||||
if err != nil || sides < 2 {
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
mod := 0
|
||||
if m[3] != "" {
|
||||
n, err := strconv.Atoi(m[3])
|
||||
if err != nil {
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
mod = n
|
||||
}
|
||||
if count < 1 || count > dndRollMaxCount || sides > dndRollMaxSides {
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
return count, sides, mod, true
|
||||
}
|
||||
|
||||
// rollDice returns the individual rolls and the total.
|
||||
func rollDice(count, sides, mod int) ([]int, int) {
|
||||
rolls := make([]int, count)
|
||||
total := mod
|
||||
for i := 0; i < count; i++ {
|
||||
r := 1 + rand.IntN(sides)
|
||||
rolls[i] = r
|
||||
total += r
|
||||
}
|
||||
return rolls, total
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) handleDnDRollCmd(ctx MessageContext, args string) error {
|
||||
args = strings.TrimSpace(args)
|
||||
if args == "" {
|
||||
return p.SendDM(ctx.Sender,
|
||||
"`!roll <dice>` — example: `!roll 2d6+3`, `!roll d20`, `!roll 4d6-1`. Max 100 dice, max 1000 sides.")
|
||||
}
|
||||
count, sides, mod, ok := parseDice(args)
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender,
|
||||
"Couldn't parse dice. Use NdN+M format (e.g. `2d6+3`, `d20`, `4d6-1`).")
|
||||
}
|
||||
rolls, total := rollDice(count, sides, mod)
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("🎲 **%dd%d", count, sides))
|
||||
if mod > 0 {
|
||||
b.WriteString(fmt.Sprintf("+%d", mod))
|
||||
} else if mod < 0 {
|
||||
b.WriteString(fmt.Sprintf("%d", mod))
|
||||
}
|
||||
b.WriteString("**\n")
|
||||
|
||||
if count <= 20 {
|
||||
strs := make([]string, len(rolls))
|
||||
for i, r := range rolls {
|
||||
strs[i] = strconv.Itoa(r)
|
||||
}
|
||||
b.WriteString("Rolls: " + strings.Join(strs, ", "))
|
||||
if mod != 0 {
|
||||
if mod > 0 {
|
||||
b.WriteString(fmt.Sprintf(" (+%d)", mod))
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf(" (%d)", mod))
|
||||
}
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("**Total: %d**", total))
|
||||
|
||||
// Highlight nat-20 / nat-1 on a single d20
|
||||
if count == 1 && sides == 20 {
|
||||
switch rolls[0] {
|
||||
case 20:
|
||||
b.WriteString(" ✨ _critical!_")
|
||||
case 1:
|
||||
b.WriteString(" 💀 _fumble!_")
|
||||
}
|
||||
}
|
||||
|
||||
return p.SendDM(ctx.Sender, b.String())
|
||||
}
|
||||
|
||||
// ── !stats ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDStatsCmd(ctx MessageContext) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character.")
|
||||
}
|
||||
mods := c.Modifiers()
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("**%s %s — Ability Scores**\n", ri.Display, ci.Display))
|
||||
b.WriteString(fmt.Sprintf("STR %2d (%+d) DEX %2d (%+d) CON %2d (%+d)\n",
|
||||
c.STR, mods[0], c.DEX, mods[1], c.CON, mods[2]))
|
||||
b.WriteString(fmt.Sprintf("INT %2d (%+d) WIS %2d (%+d) CHA %2d (%+d)\n",
|
||||
c.INT, mods[3], c.WIS, mods[4], c.CHA, mods[5]))
|
||||
b.WriteString(fmt.Sprintf("\nProficiency: +%d AC: %d", proficiencyBonus(c.Level), c.ArmorClass))
|
||||
return p.SendDM(ctx.Sender, b.String())
|
||||
}
|
||||
|
||||
// ── !level ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDLevelCmd(ctx MessageContext) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character.")
|
||||
}
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("⚔️ Level **%d** %s %s\n", c.Level, ri.Display, ci.Display))
|
||||
if c.Level >= dndMaxLevel {
|
||||
b.WriteString("XP: capped at L20.")
|
||||
} else {
|
||||
next := dndXPToNextLevel(c.Level)
|
||||
pct := int(100.0 * float64(c.XP) / float64(next))
|
||||
b.WriteString(fmt.Sprintf("XP: %d / %d (%d%% to L%d)", c.XP, next, pct, c.Level+1))
|
||||
}
|
||||
return p.SendDM(ctx.Sender, b.String())
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"gogobee/internal/flavor"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// One-shot onboarding DM fired the first time a legacy player encounters
|
||||
// the new D&D layer. Triggered from ensureDnDCharacterForCombat at the
|
||||
// moment of fresh auto-migration; suppressed for genuinely new players
|
||||
// (combat_level <= 1) since the message frames around "previous players".
|
||||
|
||||
// dndLegacyMinLevel — players with combat_level at or above this are
|
||||
// considered "legacy players" who deserve the onboarding spiel. Anyone
|
||||
// at L1 is brand new and gets the standard !setup nudge instead.
|
||||
const dndLegacyMinLevel = 2
|
||||
|
||||
// maybeSendDnDOnboarding sends the welcome DM iff the player has visible
|
||||
// legacy adventure progress AND hasn't been onboarded before. The
|
||||
// OnboardingSent flag survives draft cancellation, !respec, and any other
|
||||
// state mutation — once a player has seen the welcome, they never see it
|
||||
// again. Logs and continues on send failure (DM is best-effort, never blocks combat).
|
||||
func (p *AdventurePlugin) maybeSendDnDOnboarding(userID id.UserID, advChar *AdventureCharacter, dnd *DnDCharacter) {
|
||||
if advChar == nil || advChar.CombatLevel < dndLegacyMinLevel {
|
||||
return
|
||||
}
|
||||
if dnd == nil || dnd.OnboardingSent {
|
||||
return
|
||||
}
|
||||
// Skip entirely if there's no Matrix client — tests construct empty
|
||||
// AdventurePlugin{} and we shouldn't write to the DB on a nil-send.
|
||||
if p == nil || p.Client == nil {
|
||||
return
|
||||
}
|
||||
msg := dndOnboardingText(advChar.CombatLevel, dnd.Level)
|
||||
if err := p.SendDM(userID, msg); err != nil {
|
||||
slog.Error("dnd: onboarding DM failed", "user", userID, "err", err)
|
||||
// Don't mark as sent if delivery failed — they should get a chance
|
||||
// on their next combat. Send failures here are typically transient.
|
||||
return
|
||||
}
|
||||
dnd.OnboardingSent = true
|
||||
if err := SaveDnDCharacter(dnd); err != nil {
|
||||
slog.Error("dnd: persist onboarding flag", "user", userID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func dndOnboardingText(oldLevel, newLevel int) string {
|
||||
prelude := ""
|
||||
if line := flavor.Pick(flavor.ExpeditionStart); line != "" {
|
||||
prelude = "_" + line + "_\n\n"
|
||||
}
|
||||
return prelude + fmt.Sprintf(`Hi there! Welcome to the new Adventure game!
|
||||
|
||||
We shamelessly cribbed.. aimed for feature parity with our competitors.
|
||||
And the result is this..! and adventure game with most of the best Dungeons & Drag-
|
||||
|
||||
"AHEM!" *TwinBee glances at the Pinkerton agent in the corner of the room.
|
||||
|
||||
..d20 System mechanics ready for you to explore!
|
||||
|
||||
As a result of these amazing and entirely necessary changes that weren't done at the whim of a bored engineer.. the level system has changed. But no worries! We spent hours coming up with an algorithm that would ensure each player arrives at a level that is fully representative of their level under the previous system (..by dividing your previous level by five).
|
||||
|
||||
Your previous level **%d** is now Adv 2.0 level **%d**.
|
||||
|
||||
Enjoy!
|
||||
|
||||
Type !setup to get your character situated under this hot new and legally distinct system.`,
|
||||
oldLevel, newLevel)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDnDOnboardingText_ContainsLevelMapping(t *testing.T) {
|
||||
msg := dndOnboardingText(49, 9)
|
||||
if !strings.Contains(msg, "**49**") {
|
||||
t.Error("onboarding text doesn't include old level")
|
||||
}
|
||||
if !strings.Contains(msg, "**9**") {
|
||||
t.Error("onboarding text doesn't include new level")
|
||||
}
|
||||
// Spot-check signature lines from the user's brief.
|
||||
for _, snippet := range []string{
|
||||
"Welcome to the new Adventure game",
|
||||
"Pinkerton agent",
|
||||
"dividing your previous level by five",
|
||||
"!setup",
|
||||
"legally distinct",
|
||||
} {
|
||||
if !strings.Contains(msg, snippet) {
|
||||
t.Errorf("onboarding missing expected snippet: %q", snippet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeSendDnDOnboarding_LegacyThreshold: only fires for combat_level >= 2.
|
||||
// The DM call itself is no-op in tests (Base.Client is nil and SendDM guards),
|
||||
// so we can't assert on send — but we can assert the function doesn't panic
|
||||
// or error for either branch.
|
||||
func TestMaybeSendDnDOnboarding_DoesNotPanic(t *testing.T) {
|
||||
p := &AdventurePlugin{}
|
||||
dnd := &DnDCharacter{Level: 4}
|
||||
|
||||
// Brand-new player (combat_level=1): should be a no-op.
|
||||
p.maybeSendDnDOnboarding("@new:x", &AdventureCharacter{CombatLevel: 1}, dnd)
|
||||
|
||||
// Legacy player (combat_level=20): should attempt to send (no-op'd by nil Client).
|
||||
p.maybeSendDnDOnboarding("@legacy:x", &AdventureCharacter{CombatLevel: 20}, dnd)
|
||||
|
||||
// nil advChar: should be a no-op.
|
||||
p.maybeSendDnDOnboarding("@nil:x", nil, dnd)
|
||||
}
|
||||
|
||||
func TestDnDLegacyMinLevel(t *testing.T) {
|
||||
if dndLegacyMinLevel < 1 {
|
||||
t.Errorf("dndLegacyMinLevel = %d, must be ≥ 1", dndLegacyMinLevel)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package plugin
|
||||
|
||||
// Phase 3 — class passives applied via CombatModifiers.
|
||||
//
|
||||
// Phase 3 keeps abilities passive-only: they auto-trigger via the existing
|
||||
// CombatModifiers machinery rather than being player-activated mid-fight
|
||||
// (the combat engine is one-shot, no turn-based UI). Active/reactive
|
||||
// abilities arrive once we have a model for them — likely tied to !arena
|
||||
// pre-arming or to a turn-based PvP variant.
|
||||
|
||||
// ── Class passive definitions ────────────────────────────────────────────────
|
||||
|
||||
// DnDClassAbility is the lore/UI representation of a class's signature
|
||||
// passive. Used by !abilities and !sheet for display; mechanics live in
|
||||
// applyClassPassives below.
|
||||
type DnDClassAbility struct {
|
||||
Name string
|
||||
Description string
|
||||
}
|
||||
|
||||
var dndClassAbilities = map[DnDClass]DnDClassAbility{
|
||||
ClassFighter: {
|
||||
Name: "Battle Trained",
|
||||
Description: "Years of weapon drill add +5% to all damage you deal.",
|
||||
},
|
||||
ClassRogue: {
|
||||
Name: "Sneak Attack",
|
||||
Description: "Your first strike each combat lands as a critical hit, doubling its damage.",
|
||||
},
|
||||
ClassMage: {
|
||||
Name: "Arcane Focus",
|
||||
Description: "Practiced channeling adds +1 to your attack rolls.",
|
||||
},
|
||||
ClassCleric: {
|
||||
Name: "Divine Favor",
|
||||
Description: "When you fall below half HP, divine intervention restores 5 HP. Once per combat.",
|
||||
},
|
||||
ClassRanger: {
|
||||
Name: "Hunter's Mark",
|
||||
Description: "You read your prey's weak points: +5% damage and +1 to attack rolls.",
|
||||
},
|
||||
}
|
||||
|
||||
// applyRacePassives sets the combat-impacting flags from the player's race.
|
||||
// Races whose passives apply to skill checks or non-combat scenarios
|
||||
// (Tiefling fire resist, Elf sleep immunity, Half-Elf bonus profs, Human
|
||||
// floating +1) are handled in their respective phases and have no combat
|
||||
// hook in Phase 3.
|
||||
func applyRacePassives(stats *CombatStats, mods *CombatModifiers, c *DnDCharacter) {
|
||||
switch c.Race {
|
||||
case RaceHalfling:
|
||||
mods.LuckyReroll = true
|
||||
case RaceOrc:
|
||||
mods.RageReady = true
|
||||
case RaceDwarf:
|
||||
mods.PoisonResist = true
|
||||
}
|
||||
}
|
||||
|
||||
// applyClassPassives mutates a player's CombatModifiers to apply their
|
||||
// class passive. Called after applyDnDPlayerLayer + DerivePlayerStats but
|
||||
// BEFORE consumable application (so consumables can stack on top).
|
||||
//
|
||||
// Some passives ride on existing CombatModifiers fields:
|
||||
// Rogue's Sneak Attack reuses AutoCritFirst (the consumable Crystal Berry
|
||||
// field) — the engine already implements first-hit-auto-crit semantics.
|
||||
// Cleric's Divine Favor reuses HealItem, the under-50%-HP heal trigger.
|
||||
//
|
||||
// This means:
|
||||
// - A Rogue carrying a Crystal Berry doesn't get *two* auto-crits;
|
||||
// AutoCritFirst is already a one-shot bool.
|
||||
// - A Cleric carrying a healing potion stacks: passive 5 + potion 8 = 13.
|
||||
// The passive heal triggers first since both use the same threshold.
|
||||
func applyClassPassives(stats *CombatStats, mods *CombatModifiers, c *DnDCharacter) {
|
||||
switch c.Class {
|
||||
case ClassFighter:
|
||||
mods.DamageBonus += 0.05
|
||||
case ClassRogue:
|
||||
mods.AutoCritFirst = true
|
||||
case ClassMage:
|
||||
stats.AttackBonus++
|
||||
case ClassCleric:
|
||||
// Passive heal at <50% HP. Stacks additively with consumable HealItem.
|
||||
mods.HealItem += 5
|
||||
case ClassRanger:
|
||||
mods.DamageBonus += 0.05
|
||||
stats.AttackBonus++
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// ── Plug 1: HP scaling ──────────────────────────────────────────────────────
|
||||
|
||||
func TestApplyDnDHPScaling_FullHP(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 100}
|
||||
c := &DnDCharacter{HPMax: 50, HPCurrent: 50}
|
||||
applyDnDHPScaling(&stats, c)
|
||||
if stats.MaxHP != 100 {
|
||||
t.Errorf("full HP: MaxHP scaled to %d, want unchanged 100", stats.MaxHP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDHPScaling_HalfHP(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 100}
|
||||
c := &DnDCharacter{HPMax: 50, HPCurrent: 25}
|
||||
applyDnDHPScaling(&stats, c)
|
||||
if stats.MaxHP != 50 {
|
||||
t.Errorf("50%% HP: MaxHP = %d, want 50", stats.MaxHP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDHPScaling_FloorAt25Pct(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 100}
|
||||
c := &DnDCharacter{HPMax: 50, HPCurrent: 0}
|
||||
applyDnDHPScaling(&stats, c)
|
||||
if stats.MaxHP != 25 {
|
||||
t.Errorf("0%% HP: MaxHP = %d, want 25 (floor)", stats.MaxHP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDnDHPScaling_NoOpIfNilOrZero(t *testing.T) {
|
||||
stats := CombatStats{MaxHP: 100}
|
||||
applyDnDHPScaling(&stats, nil)
|
||||
if stats.MaxHP != 100 {
|
||||
t.Errorf("nil char: scaled to %d, want unchanged", stats.MaxHP)
|
||||
}
|
||||
c := &DnDCharacter{HPMax: 0}
|
||||
applyDnDHPScaling(&stats, c)
|
||||
if stats.MaxHP != 100 {
|
||||
t.Errorf("zero HPMax: scaled to %d, want unchanged", stats.MaxHP)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Plug 2: roll summary ────────────────────────────────────────────────────
|
||||
|
||||
func TestDnDRollSummaryLine_Empty(t *testing.T) {
|
||||
r := CombatResult{Events: []CombatEvent{
|
||||
{Actor: "player", Action: "hit", Roll: 0}, // no Roll → not D&D
|
||||
}}
|
||||
if got := dndRollSummaryLine(r); got != "" {
|
||||
t.Errorf("expected empty summary; got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDRollSummaryLine_Basic(t *testing.T) {
|
||||
r := CombatResult{Events: []CombatEvent{
|
||||
{Actor: "player", Action: "hit", Roll: 14, RollAgainst: 12},
|
||||
{Actor: "player", Action: "miss", Roll: 5, RollAgainst: 12},
|
||||
{Actor: "player", Action: "crit", Roll: 20, RollAgainst: 12},
|
||||
{Actor: "player", Action: "miss", Roll: 1, RollAgainst: 12, Desc: "fumble"},
|
||||
{Actor: "enemy", Action: "hit", Roll: 18}, // enemy ignored
|
||||
}}
|
||||
got := dndRollSummaryLine(r)
|
||||
for _, want := range []string{"d20", "2/4 hit", "1 crit", "1 fumble", "nat 20"} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("summary missing %q: %s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDRollSummaryLine_HighestNonNat20(t *testing.T) {
|
||||
r := CombatResult{Events: []CombatEvent{
|
||||
{Actor: "player", Action: "hit", Roll: 17, RollAgainst: 14},
|
||||
{Actor: "player", Action: "miss", Roll: 8, RollAgainst: 14},
|
||||
}}
|
||||
got := dndRollSummaryLine(r)
|
||||
if !strings.Contains(got, "Best: 17") {
|
||||
t.Errorf("expected 'Best: 17' in summary: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Plug 3: !roll dice parser ──────────────────────────────────────────────
|
||||
|
||||
func TestParseDice(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
count, sides, mod int
|
||||
ok bool
|
||||
}{
|
||||
{"d20", 1, 20, 0, true},
|
||||
{"1d20", 1, 20, 0, true},
|
||||
{"2d6+3", 2, 6, 3, true},
|
||||
{"4d6-1", 4, 6, -1, true},
|
||||
{"3D8", 3, 8, 0, true}, // case-insensitive
|
||||
{" 2d6+3 ", 2, 6, 3, true}, // whitespace
|
||||
{"d1", 0, 0, 0, false}, // sides too few
|
||||
{"100d6", 100, 6, 0, true}, // max count
|
||||
{"101d6", 0, 0, 0, false}, // over max
|
||||
{"banana", 0, 0, 0, false},
|
||||
{"d6+", 0, 0, 0, false},
|
||||
{"", 0, 0, 0, false},
|
||||
{"2d6+", 0, 0, 0, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
ct, sd, mod, ok := parseDice(c.in)
|
||||
if ok != c.ok || ct != c.count || sd != c.sides || mod != c.mod {
|
||||
t.Errorf("parseDice(%q) = (%d,%d,%d,%v); want (%d,%d,%d,%v)",
|
||||
c.in, ct, sd, mod, ok, c.count, c.sides, c.mod, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollDice_Bounds(t *testing.T) {
|
||||
// 1000 trials: every roll must be in [1, sides].
|
||||
for i := 0; i < 1000; i++ {
|
||||
rolls, total := rollDice(4, 6, 2)
|
||||
sum := 2
|
||||
for _, r := range rolls {
|
||||
if r < 1 || r > 6 {
|
||||
t.Fatalf("roll out of range: %d", r)
|
||||
}
|
||||
sum += r
|
||||
}
|
||||
if sum != total {
|
||||
t.Fatalf("total mismatch: rolls sum=%d, total=%d", sum, total)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Plug 4: !stats / !level format ─────────────────────────────────────────
|
||||
// (No DB integration here — just smoke-test that the helpers don't panic
|
||||
// against a constructed character. Full DB-integrated tests would be
|
||||
// duplicative with existing prod-DB tests.)
|
||||
@@ -0,0 +1,212 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// TestProdDB_DnDLayer exercises the D&D layer against a copy of the real
|
||||
// prod database. Verifies that:
|
||||
// - Existing AdventureCharacter rows load cleanly
|
||||
// - ensureDnDCharacterForCombat creates a sensible auto-migrated sheet
|
||||
// - The auto-migrated row is well-formed (HP > 0, AC ≥ 10, level ≥ 1)
|
||||
// - !setup overwrite path works on auto-migrated chars
|
||||
// - HP persistence after combat doesn't corrupt the sheet
|
||||
//
|
||||
// Skips silently if the prod DB isn't present.
|
||||
func TestProdDB_DnDLayer(t *testing.T) {
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present at " + src)
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
copyTestFile(t, src, dst)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatalf("Init: %v", err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
|
||||
// 1. Load every adventure character. They must scan without error.
|
||||
chars, err := loadAllAdvCharacters()
|
||||
if err != nil {
|
||||
t.Fatalf("loadAllAdvCharacters: %v", err)
|
||||
}
|
||||
if len(chars) == 0 {
|
||||
t.Fatal("no adventure characters in prod DB")
|
||||
}
|
||||
t.Logf("loaded %d real adventure characters", len(chars))
|
||||
|
||||
// 2. For each, verify they have NO dnd_character row yet, then auto-migrate
|
||||
// and verify the resulting row is sensible.
|
||||
for i := range chars {
|
||||
char := &chars[i]
|
||||
uid := char.UserID
|
||||
|
||||
existing, err := LoadDnDCharacter(uid)
|
||||
if err != nil {
|
||||
t.Errorf("user=%s: LoadDnDCharacter pre-migrate failed: %v", uid, err)
|
||||
continue
|
||||
}
|
||||
if existing != nil {
|
||||
t.Errorf("user=%s: had dnd_character row pre-migrate (should be empty)", uid)
|
||||
continue
|
||||
}
|
||||
|
||||
// Auto-migrate via the production code path.
|
||||
dnd, fresh, err := ensureDnDCharacterForCombat(uid, char)
|
||||
if err != nil {
|
||||
t.Errorf("user=%s: ensureDnDCharacterForCombat failed: %v", uid, err)
|
||||
continue
|
||||
}
|
||||
if dnd == nil {
|
||||
t.Errorf("user=%s: ensureDnDCharacterForCombat returned nil", uid)
|
||||
continue
|
||||
}
|
||||
if !fresh {
|
||||
t.Errorf("user=%s: expected fresh=true on first auto-migrate", uid)
|
||||
}
|
||||
|
||||
// Sanity invariants on the auto-migrated sheet.
|
||||
if dnd.UserID != uid {
|
||||
t.Errorf("user=%s: dnd.UserID=%s mismatch", uid, dnd.UserID)
|
||||
}
|
||||
if !dnd.AutoMigrated {
|
||||
t.Errorf("user=%s: AutoMigrated=false on fresh auto-migration", uid)
|
||||
}
|
||||
if dnd.PendingSetup {
|
||||
t.Errorf("user=%s: PendingSetup=true on fresh auto-migration", uid)
|
||||
}
|
||||
if dnd.Race == "" || dnd.Class == "" {
|
||||
t.Errorf("user=%s: race/class empty: race=%q class=%q", uid, dnd.Race, dnd.Class)
|
||||
}
|
||||
if dnd.Level < 1 {
|
||||
t.Errorf("user=%s: level %d < 1", uid, dnd.Level)
|
||||
}
|
||||
// Migrated level = combat_level/5 clamped to [1, 20].
|
||||
expectLevel := dndLevelFromCombatLevel(char.CombatLevel)
|
||||
if dnd.Level != expectLevel {
|
||||
t.Errorf("user=%s: dnd.Level=%d, want %d (from combat_level=%d)",
|
||||
uid, dnd.Level, expectLevel, char.CombatLevel)
|
||||
}
|
||||
if dnd.HPMax < 1 || dnd.HPCurrent != dnd.HPMax {
|
||||
t.Errorf("user=%s: HP invariant: max=%d cur=%d", uid, dnd.HPMax, dnd.HPCurrent)
|
||||
}
|
||||
if dnd.ArmorClass < 10 {
|
||||
t.Errorf("user=%s: AC %d < 10 floor", uid, dnd.ArmorClass)
|
||||
}
|
||||
// Stat scores after racial mods should still be in legal range (1..20).
|
||||
for j, score := range []int{dnd.STR, dnd.DEX, dnd.CON, dnd.INT, dnd.WIS, dnd.CHA} {
|
||||
if score < 1 || score > 20 {
|
||||
t.Errorf("user=%s: stat[%d]=%d out of range", uid, j, score)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("auto-migrated user=%s → L%d %s %s HP=%d AC=%d STR/DEX/CON/INT/WIS/CHA=%d/%d/%d/%d/%d/%d",
|
||||
uid, dnd.Level, dnd.Race, dnd.Class, dnd.HPMax, dnd.ArmorClass,
|
||||
dnd.STR, dnd.DEX, dnd.CON, dnd.INT, dnd.WIS, dnd.CHA)
|
||||
}
|
||||
|
||||
// 3. Re-load each auto-migrated char — round-trip integrity.
|
||||
for i := range chars {
|
||||
uid := chars[i].UserID
|
||||
dnd, err := LoadDnDCharacter(uid)
|
||||
if err != nil {
|
||||
t.Errorf("user=%s: re-load failed: %v", uid, err)
|
||||
continue
|
||||
}
|
||||
if dnd == nil {
|
||||
t.Errorf("user=%s: re-load returned nil (auto-migrate didn't persist)", uid)
|
||||
continue
|
||||
}
|
||||
if !dnd.AutoMigrated || dnd.PendingSetup {
|
||||
t.Errorf("user=%s: post-reload flags wrong: auto=%v pending=%v",
|
||||
uid, dnd.AutoMigrated, dnd.PendingSetup)
|
||||
}
|
||||
}
|
||||
|
||||
// 4. ensureDnDCharacterForCombat is idempotent — second call returns the
|
||||
// same row, doesn't create a duplicate.
|
||||
uid := chars[0].UserID
|
||||
first, _ := LoadDnDCharacter(uid)
|
||||
second, freshAgain, err := ensureDnDCharacterForCombat(uid, &chars[0])
|
||||
if err != nil {
|
||||
t.Errorf("idempotent ensure failed: %v", err)
|
||||
}
|
||||
if freshAgain {
|
||||
t.Error("second ensure call returned fresh=true; should be false (already migrated)")
|
||||
}
|
||||
if first != nil && second != nil {
|
||||
if first.Race != second.Race || first.Class != second.Class {
|
||||
t.Errorf("ensure returned different sheet on second call: %v vs %v",
|
||||
first, second)
|
||||
}
|
||||
}
|
||||
|
||||
// 5. HP persistence smoke test — simulate a combat that left the player
|
||||
// at 50% HP. Verify dnd_character.hp_current shifts proportionally.
|
||||
persistDnDHPAfterCombat(uid, 100, 50)
|
||||
after, err := LoadDnDCharacter(uid)
|
||||
if err != nil || after == nil {
|
||||
t.Fatalf("post-persist load: %v", err)
|
||||
}
|
||||
want := after.HPMax / 2
|
||||
if after.HPCurrent < want-1 || after.HPCurrent > want+1 {
|
||||
t.Errorf("hp_current=%d after 50%% loss; want ~%d (hp_max=%d)",
|
||||
after.HPCurrent, want, after.HPMax)
|
||||
}
|
||||
t.Logf("HP persistence verified: %d/%d after 50%% combat damage", after.HPCurrent, after.HPMax)
|
||||
|
||||
// 6. !setup overwrite path: an auto-migrated char should be wipeable via
|
||||
// loadOrInitDraft → DELETE → fresh draft.
|
||||
draft, err := loadOrInitDraft(uid)
|
||||
if err != nil {
|
||||
t.Fatalf("loadOrInitDraft on auto-migrated: %v", err)
|
||||
}
|
||||
if !draft.PendingSetup {
|
||||
t.Error("draft should have PendingSetup=true")
|
||||
}
|
||||
// The auto-migrated row should now be deleted.
|
||||
cleared, _ := LoadDnDCharacter(uid)
|
||||
if cleared != nil {
|
||||
t.Errorf("auto-migrated row not cleared by loadOrInitDraft: %+v", cleared)
|
||||
}
|
||||
|
||||
// 7. Adventure characters list should still be loadable without
|
||||
// interference from D&D-layer joins.
|
||||
chars2, err := loadAllAdvCharacters()
|
||||
if err != nil {
|
||||
t.Fatalf("post-test reload failed: %v", err)
|
||||
}
|
||||
if len(chars2) != len(chars) {
|
||||
t.Errorf("char count drift: pre=%d post=%d", len(chars), len(chars2))
|
||||
}
|
||||
}
|
||||
|
||||
func copyTestFile(t *testing.T, src, dst string) {
|
||||
t.Helper()
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer out.Close()
|
||||
if _, err := io.Copy(out, in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// silence unused warning if id pkg drifts
|
||||
var _ = id.UserID("")
|
||||
@@ -0,0 +1,173 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Phase 6 — !rest short / !rest long.
|
||||
//
|
||||
// Short rest: 1h cooldown, no daily-action cost. Recovers 1d6+CON HP at L1-4
|
||||
// and 2*(1d6+CON) at L5+ (matching v1.0 §10.1's "x2 at level 5+" line).
|
||||
//
|
||||
// Long rest: 24h cooldown. Requires housing (HouseTier > 0) OR pays the
|
||||
// Thom Krooke inn (200 euros). Full HP recovery; resources reset (none yet
|
||||
// in Phase 6, but the wiring is in place for Phase 7+).
|
||||
//
|
||||
// These commands operate on the D&D layer only. The legacy `!adventure` menu
|
||||
// "rest" choice is unchanged — it remains the daily-action narrative day-skip.
|
||||
|
||||
const (
|
||||
dndShortRestCooldown = 1 * time.Hour
|
||||
dndLongRestCooldown = 24 * time.Hour
|
||||
dndInnCost = 200
|
||||
)
|
||||
|
||||
func (p *AdventurePlugin) handleDnDRestCmd(ctx MessageContext, args string) error {
|
||||
args = strings.TrimSpace(strings.ToLower(args))
|
||||
switch args {
|
||||
case "short":
|
||||
return p.handleDnDShortRest(ctx)
|
||||
case "long":
|
||||
return p.handleDnDLongRest(ctx)
|
||||
case "":
|
||||
return p.SendDM(ctx.Sender, dndRestHelpText())
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "Unknown rest type. Use `!rest short` or `!rest long`.")
|
||||
}
|
||||
|
||||
func dndRestHelpText() string {
|
||||
return "🛌 **Adv 2.0 Rest**\n\n" +
|
||||
"`!rest short` — 1h cooldown. Recovers 1d6 + CON HP. No action cost.\n" +
|
||||
"`!rest long` — 24h cooldown. Full HP recovery. Requires housing or pays the inn (€200)."
|
||||
}
|
||||
|
||||
// ── Short rest ───────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDShortRest(ctx MessageContext) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character.")
|
||||
}
|
||||
|
||||
if c.LastShortRestAt != nil {
|
||||
elapsed := time.Since(*c.LastShortRestAt)
|
||||
if elapsed < dndShortRestCooldown {
|
||||
remaining := dndShortRestCooldown - elapsed
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"Short rest on cooldown — %s remaining.", formatRespecDuration(remaining)))
|
||||
}
|
||||
}
|
||||
|
||||
if c.HPCurrent >= c.HPMax {
|
||||
return p.SendDM(ctx.Sender, "You're already at full HP. Save the rest for when you need it.")
|
||||
}
|
||||
|
||||
conMod := abilityModifier(c.CON)
|
||||
healDie := 1 + rand.IntN(6) // 1d6
|
||||
heal := healDie + conMod
|
||||
if heal < 1 {
|
||||
heal = 1
|
||||
}
|
||||
if c.Level >= 5 {
|
||||
heal *= 2 // v1.0 §10.1: "x2 at levels 5+"
|
||||
}
|
||||
|
||||
before := c.HPCurrent
|
||||
c.HPCurrent += heal
|
||||
if c.HPCurrent > c.HPMax {
|
||||
c.HPCurrent = c.HPMax
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
c.LastShortRestAt = &now
|
||||
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't save rest state: "+err.Error())
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"🛌 **Short rest.** You recover **%d HP** (%d→%d / %d).\n_Next short rest available in 1 hour._",
|
||||
c.HPCurrent-before, before, c.HPCurrent, c.HPMax)
|
||||
if line := dndRestShortFlavorLine(); line != "" {
|
||||
msg += "\n\n_" + line + "_"
|
||||
}
|
||||
return p.SendDM(ctx.Sender, msg)
|
||||
}
|
||||
|
||||
// ── Long rest ────────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDLongRest(ctx MessageContext) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
advChar, err := loadAdvCharacter(ctx.Sender)
|
||||
if err != nil || advChar == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character.")
|
||||
}
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your Adv 2.0 sheet.")
|
||||
}
|
||||
|
||||
if c.LastLongRestAt != nil {
|
||||
elapsed := time.Since(*c.LastLongRestAt)
|
||||
if elapsed < dndLongRestCooldown {
|
||||
remaining := dndLongRestCooldown - elapsed
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"Long rest on cooldown — %s remaining.", formatRespecDuration(remaining)))
|
||||
}
|
||||
}
|
||||
|
||||
// Eligibility: housing OR pay inn fee.
|
||||
hasHousing := advChar.HouseTier > 0
|
||||
innPaid := false
|
||||
if !hasHousing {
|
||||
if p.euro == nil || !p.euro.Debit(ctx.Sender, float64(dndInnCost), "dnd_inn_long_rest") {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"You need housing or €%d for the inn at Thom Krooke's. Run `!thom` to see housing options.",
|
||||
dndInnCost))
|
||||
}
|
||||
innPaid = true
|
||||
}
|
||||
|
||||
c.HPCurrent = c.HPMax
|
||||
c.TempHP = 0
|
||||
now := time.Now().UTC()
|
||||
c.LastLongRestAt = &now
|
||||
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't save rest state: "+err.Error())
|
||||
}
|
||||
_ = refreshAllResources(ctx.Sender)
|
||||
// Phase 9: spell slots refresh on long rest.
|
||||
_ = refreshSpellSlots(ctx.Sender)
|
||||
// Phase 9: Cleric prep flags reset (SP4) — until SP4 ships, default
|
||||
// Cleric grants are already prepared=1 so this is a no-op for them.
|
||||
// Voluntary concentration ends at long rest (mage_armor's 8h is exactly
|
||||
// the rest interval; resetting here keeps state clean).
|
||||
c.ConcentrationSpell = ""
|
||||
c.ConcentrationExpiresAt = nil
|
||||
c.PendingCast = ""
|
||||
_ = SaveDnDCharacter(c)
|
||||
|
||||
loc := "your home"
|
||||
if innPaid {
|
||||
loc = fmt.Sprintf("the inn (€%d spent)", dndInnCost)
|
||||
}
|
||||
msg := fmt.Sprintf(
|
||||
"🌙 **Long rest** at %s. Full HP recovered (%d/%d).\n_Next long rest available in 24 hours._",
|
||||
loc, c.HPCurrent, c.HPMax)
|
||||
// HomeLongRest pool when at home; generic RestLong otherwise.
|
||||
if line := dndRestLongFlavorLine(hasHousing); line != "" {
|
||||
msg += "\n\n_" + line + "_"
|
||||
}
|
||||
return p.SendDM(ctx.Sender, msg)
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func setupRestTestDB(t *testing.T) {
|
||||
t.Helper()
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
}
|
||||
|
||||
func makeRestTestChar(t *testing.T, uid id.UserID, level int) *DnDCharacter {
|
||||
t.Helper()
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: level,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
}
|
||||
conMod := abilityModifier(c.CON)
|
||||
c.HPMax = computeMaxHP(c.Class, conMod, level)
|
||||
c.HPCurrent = 1 // wounded
|
||||
c.ArmorClass = computeAC(c.Class, abilityModifier(c.DEX))
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Also need an adventure_characters row so loadAdvCharacter doesn't fail.
|
||||
if err := createAdvCharacter(uid, "rest_test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func TestShortRest_HealsWithinExpectedRange(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@short_rest:example")
|
||||
c := makeRestTestChar(t, uid, 3) // L3 → 1d6+CON, no x2
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDShortRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := LoadDnDCharacter(uid)
|
||||
if err != nil || got == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conMod := abilityModifier(c.CON) // +2
|
||||
// Heal range L1-4: 1d6 + 2 = 3..8
|
||||
healed := got.HPCurrent - 1
|
||||
if healed < 1+conMod || healed > 6+conMod {
|
||||
t.Errorf("healed %d HP, want %d..%d (1d6+%d)", healed, 1+conMod, 6+conMod, conMod)
|
||||
}
|
||||
if got.LastShortRestAt == nil {
|
||||
t.Error("LastShortRestAt not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShortRest_DoublesAtL5(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@short_rest_l5:example")
|
||||
c := makeRestTestChar(t, uid, 5) // L5 → 2*(1d6+CON)
|
||||
conMod := abilityModifier(c.CON)
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDShortRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
healed := got.HPCurrent - 1
|
||||
// Range: 2*(1+2)..2*(6+2) = 6..16
|
||||
low, high := 2*(1+conMod), 2*(6+conMod)
|
||||
if healed < low || healed > high {
|
||||
t.Errorf("L5 healed %d HP, want %d..%d", healed, low, high)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShortRest_CooldownEnforced(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@short_cd:example")
|
||||
makeRestTestChar(t, uid, 3)
|
||||
p := &AdventurePlugin{}
|
||||
|
||||
// First rest succeeds
|
||||
if err := p.handleDnDShortRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got1, _ := LoadDnDCharacter(uid)
|
||||
hpAfterFirst := got1.HPCurrent
|
||||
|
||||
// Second immediate rest should NOT heal further (cooldown blocks).
|
||||
if err := p.handleDnDShortRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got2, _ := LoadDnDCharacter(uid)
|
||||
if got2.HPCurrent != hpAfterFirst {
|
||||
t.Errorf("cooldown not enforced: HP changed from %d → %d on second rest",
|
||||
hpAfterFirst, got2.HPCurrent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShortRest_AlreadyFullHP(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@short_full:example")
|
||||
c := makeRestTestChar(t, uid, 3)
|
||||
c.HPCurrent = c.HPMax
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDShortRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.LastShortRestAt != nil {
|
||||
t.Error("rest at full HP shouldn't consume cooldown")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongRest_RequiresHousingOrInn(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@long_no_house:example")
|
||||
makeRestTestChar(t, uid, 3)
|
||||
// AdventureCharacter has HouseTier=0; player has no euros either by default.
|
||||
|
||||
p := &AdventurePlugin{euro: nil} // no euro plugin → can't pay inn
|
||||
if err := p.handleDnDLongRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.HPCurrent == got.HPMax {
|
||||
t.Error("long rest succeeded without housing or inn payment")
|
||||
}
|
||||
if got.LastLongRestAt != nil {
|
||||
t.Error("LastLongRestAt set despite failed rest")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongRest_WithHousing(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@long_house:example")
|
||||
makeRestTestChar(t, uid, 3)
|
||||
// Upgrade to housing.
|
||||
advChar, _ := loadAdvCharacter(uid)
|
||||
advChar.HouseTier = 2
|
||||
if err := saveAdvCharacter(advChar); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDLongRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.HPCurrent != got.HPMax {
|
||||
t.Errorf("long rest with housing didn't fully heal: %d/%d", got.HPCurrent, got.HPMax)
|
||||
}
|
||||
if got.LastLongRestAt == nil {
|
||||
t.Error("LastLongRestAt not set after successful long rest")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongRest_CooldownEnforced(t *testing.T) {
|
||||
setupRestTestDB(t)
|
||||
uid := id.UserID("@long_cd:example")
|
||||
c := makeRestTestChar(t, uid, 3)
|
||||
advChar, _ := loadAdvCharacter(uid)
|
||||
advChar.HouseTier = 1
|
||||
saveAdvCharacter(advChar)
|
||||
|
||||
now := time.Now().UTC().Add(-1 * time.Hour) // recent rest
|
||||
c.LastLongRestAt = &now
|
||||
c.HPCurrent = 1
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if err := p.handleDnDLongRest(MessageContext{Sender: uid}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.HPCurrent != 1 {
|
||||
t.Errorf("long rest cooldown not enforced; HP went from 1 → %d", got.HPCurrent)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// ── Race passives ────────────────────────────────────────────────────────────
|
||||
|
||||
func TestApplyRacePassives(t *testing.T) {
|
||||
cases := []struct {
|
||||
race DnDRace
|
||||
wantLucky, wantRage, wantPoisonOK bool
|
||||
}{
|
||||
{RaceHalfling, true, false, false},
|
||||
{RaceOrc, false, true, false},
|
||||
{RaceDwarf, false, false, true},
|
||||
{RaceHuman, false, false, false},
|
||||
{RaceElf, false, false, false},
|
||||
{RaceTiefling, false, false, false},
|
||||
{RaceHalfElf, false, false, false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
mods := CombatModifiers{}
|
||||
stats := CombatStats{}
|
||||
applyRacePassives(&stats, &mods, &DnDCharacter{Race: tc.race})
|
||||
if mods.LuckyReroll != tc.wantLucky {
|
||||
t.Errorf("%s LuckyReroll = %v, want %v", tc.race, mods.LuckyReroll, tc.wantLucky)
|
||||
}
|
||||
if mods.RageReady != tc.wantRage {
|
||||
t.Errorf("%s RageReady = %v, want %v", tc.race, mods.RageReady, tc.wantRage)
|
||||
}
|
||||
if mods.PoisonResist != tc.wantPoisonOK {
|
||||
t.Errorf("%s PoisonResist = %v, want %v", tc.race, mods.PoisonResist, tc.wantPoisonOK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestHalflingLuckyEmitsReroll: a Halfling fighter rolling many d20s should
|
||||
// emit at least one lucky_reroll event over a long fight, and never more than
|
||||
// one (single-use per combat).
|
||||
func TestHalflingLuckyEmitsReroll(t *testing.T) {
|
||||
player := Combatant{
|
||||
IsPlayer: true,
|
||||
Stats: CombatStats{MaxHP: 100000, Attack: 5, Defense: 0, Speed: 50, AC: 10, AttackBonus: 5},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0, LuckyReroll: true},
|
||||
}
|
||||
enemy := Combatant{
|
||||
Stats: CombatStats{MaxHP: 100000, Attack: 1, Defense: 0, Speed: 50, AC: 13, AttackBonus: 0},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
phases := []CombatPhase{{Name: "Long", Rounds: 200, AttackWeight: 1.0, DefenseWeight: 1.0, SpeedWeight: 1.0}}
|
||||
|
||||
saw := 0
|
||||
for trial := 0; trial < 5; trial++ {
|
||||
result := SimulateCombat(player, enemy, phases)
|
||||
rerolls := 0
|
||||
for _, ev := range result.Events {
|
||||
if ev.Action == "lucky_reroll" {
|
||||
rerolls++
|
||||
}
|
||||
}
|
||||
if rerolls > 1 {
|
||||
t.Errorf("trial %d: %d lucky_reroll events in one fight (should be ≤1)", trial, rerolls)
|
||||
}
|
||||
if rerolls == 1 {
|
||||
saw++
|
||||
}
|
||||
}
|
||||
if saw == 0 {
|
||||
t.Error("never observed a Halfling Lucky reroll over 5 long fights — extremely unlikely (~5%^5)")
|
||||
}
|
||||
}
|
||||
|
||||
// TestOrcRageFiresOnLowHP: an Orc whose HP gets driven below 50% should emit
|
||||
// a "rage" event and have higher damage on the following attack.
|
||||
func TestOrcRageFiresOnLowHP(t *testing.T) {
|
||||
// Player starts with 50 max HP, low attack. Enemy is a tank that hits
|
||||
// back hard so the player crosses the 50% threshold.
|
||||
player := Combatant{
|
||||
IsPlayer: true,
|
||||
Stats: CombatStats{MaxHP: 50, Attack: 10, Defense: 5, Speed: 5, AC: 10, AttackBonus: 5},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0, RageReady: true},
|
||||
}
|
||||
enemy := Combatant{
|
||||
Stats: CombatStats{MaxHP: 100000, Attack: 30, Defense: 5, Speed: 5, AC: 10, AttackBonus: 8},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
}
|
||||
phases := []CombatPhase{{Name: "Brawl", Rounds: 40, AttackWeight: 1.0, DefenseWeight: 1.0, SpeedWeight: 1.0}}
|
||||
|
||||
rageFiredEver := false
|
||||
for trial := 0; trial < 5; trial++ {
|
||||
result := SimulateCombat(player, enemy, phases)
|
||||
rageCount := 0
|
||||
for _, ev := range result.Events {
|
||||
if ev.Action == "rage" {
|
||||
rageCount++
|
||||
}
|
||||
}
|
||||
if rageCount > 1 {
|
||||
t.Errorf("trial %d: %d rage events (should be ≤1)", trial, rageCount)
|
||||
}
|
||||
if rageCount == 1 {
|
||||
rageFiredEver = true
|
||||
}
|
||||
}
|
||||
if !rageFiredEver {
|
||||
t.Error("Orc Rage never fired over 5 brutal fights — should always trigger when player crosses 50%")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDwarfPoisonResistance: poison_tick damage applied to a Dwarf should be
|
||||
// roughly half of the unprotected baseline. We measure by summing the actual
|
||||
// poison_tick events rather than HP delta, since the engine's exhaustion
|
||||
// tiebreaker can zero HP independently of poison damage.
|
||||
func TestDwarfPoisonResistance(t *testing.T) {
|
||||
enemy := Combatant{
|
||||
Stats: CombatStats{MaxHP: 1000, Attack: 5, Defense: 0, Speed: 5, AC: 10, AttackBonus: 0},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0},
|
||||
Ability: &MonsterAbility{Name: "Spit", Phase: "any", ProcChance: 1.0, Effect: "poison"},
|
||||
}
|
||||
phases := []CombatPhase{{Name: "Tick", Rounds: 5, AttackWeight: 0.1, DefenseWeight: 1.0, SpeedWeight: 0.1}}
|
||||
|
||||
makePlayer := func(resist bool) Combatant {
|
||||
return Combatant{
|
||||
IsPlayer: true,
|
||||
Stats: CombatStats{MaxHP: 200, Attack: 1, Defense: 100, Speed: 100, AC: 99, AttackBonus: 0},
|
||||
Mods: CombatModifiers{DamageReduct: 1.0, PoisonResist: resist},
|
||||
}
|
||||
}
|
||||
sumPoison := func(r CombatResult) int {
|
||||
s := 0
|
||||
for _, ev := range r.Events {
|
||||
if ev.Action == "poison_tick" {
|
||||
s += ev.Damage
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
totalUnprot, totalProt := 0, 0
|
||||
const trials = 300
|
||||
for i := 0; i < trials; i++ {
|
||||
totalUnprot += sumPoison(SimulateCombat(makePlayer(false), enemy, phases))
|
||||
totalProt += sumPoison(SimulateCombat(makePlayer(true), enemy, phases))
|
||||
}
|
||||
if totalUnprot == 0 {
|
||||
t.Fatal("no unprotected poison damage observed; test setup broken")
|
||||
}
|
||||
avgU := float64(totalUnprot) / float64(trials)
|
||||
avgP := float64(totalProt) / float64(trials)
|
||||
ratio := avgP / avgU
|
||||
if ratio < 0.35 || ratio > 0.65 {
|
||||
t.Errorf("dwarf poison ratio = %.3f (avg unprot=%.1f, prot=%.1f); want ~0.5",
|
||||
ratio, avgU, avgP)
|
||||
}
|
||||
}
|
||||
|
||||
// ── combat_level freeze ──────────────────────────────────────────────────────
|
||||
|
||||
func TestCheckAdvLevelUp_FrozenForDnDChars(t *testing.T) {
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
|
||||
uid := id.UserID("@freeze_test:example")
|
||||
|
||||
// Case 1: no dnd_character → combat XP advances combat_level normally.
|
||||
char := &AdventureCharacter{
|
||||
UserID: uid,
|
||||
DisplayName: "freeze_test",
|
||||
CombatLevel: 5,
|
||||
CombatXP: 1000, // far over the threshold for L6
|
||||
}
|
||||
leveled, newLvl := checkAdvLevelUp(char, "combat")
|
||||
if !leveled || newLvl <= 5 {
|
||||
t.Errorf("non-DnD player: leveled=%v newLvl=%d, want leveled=true, newLvl>5", leveled, newLvl)
|
||||
}
|
||||
|
||||
// Case 2: confirmed dnd_character → frozen.
|
||||
dnd := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 1,
|
||||
STR: 15, DEX: 14, CON: 13, INT: 12, WIS: 10, CHA: 8,
|
||||
HPMax: 12, HPCurrent: 12, ArmorClass: 16,
|
||||
PendingSetup: false, AutoMigrated: false,
|
||||
}
|
||||
if err := SaveDnDCharacter(dnd); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
char2 := &AdventureCharacter{
|
||||
UserID: uid,
|
||||
DisplayName: "freeze_test",
|
||||
CombatLevel: 5,
|
||||
CombatXP: 1000,
|
||||
}
|
||||
leveled, newLvl = checkAdvLevelUp(char2, "combat")
|
||||
if leveled || newLvl != 5 {
|
||||
t.Errorf("DnD player: leveled=%v newLvl=%d, want leveled=false, newLvl=5", leveled, newLvl)
|
||||
}
|
||||
|
||||
// Case 3: skill levels still advance for the same player.
|
||||
char2.MiningSkill = 5
|
||||
char2.MiningXP = 1000
|
||||
leveled, newLvl = checkAdvLevelUp(char2, "mining")
|
||||
if !leveled || newLvl <= 5 {
|
||||
t.Errorf("DnD player mining: leveled=%v newLvl=%d, want leveled=true", leveled, newLvl)
|
||||
}
|
||||
}
|
||||
|
||||
// ── !respec cooldown logic ──────────────────────────────────────────────────
|
||||
|
||||
func TestRespecCooldownFormat(t *testing.T) {
|
||||
cases := []struct {
|
||||
d time.Duration
|
||||
want string
|
||||
}{
|
||||
{7 * 24 * time.Hour, "7d"},
|
||||
{6*24*time.Hour + 5*time.Hour, "6d 5h"},
|
||||
{3 * time.Hour, "3h"},
|
||||
{45 * time.Minute, "45m"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := formatRespecDuration(c.d)
|
||||
if got != c.want {
|
||||
t.Errorf("formatRespecDuration(%v) = %q, want %q", c.d, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// !setup flow. Player runs subcommands; draft persists in dnd_character with
|
||||
// pending_setup=1 until !setup confirm finalizes.
|
||||
//
|
||||
// !setup — show current draft + next step
|
||||
// !setup race <name> — pick race
|
||||
// !setup class <name> — pick class
|
||||
// !setup stats <s> <d> <c> <i> <w> <h> — assign standard array
|
||||
// !setup confirm — finalize, compute HP/AC, clear pending_setup
|
||||
// !setup cancel — wipe the draft
|
||||
|
||||
// ── Archetype → Race/Class inference ─────────────────────────────────────────
|
||||
|
||||
type dndSuggestion struct {
|
||||
Race DnDRace
|
||||
Class DnDClass
|
||||
Why string // archetype name that drove the suggestion
|
||||
}
|
||||
|
||||
// inferDnDFromArchetypes returns a (race, class) suggestion based on the
|
||||
// player's highest-signal archetype, or the Human Fighter fallback if no
|
||||
// archetype gives a clear signal.
|
||||
//
|
||||
// Map keyed to the *real* archetype names in archetype.go (v1.1 §3.2).
|
||||
func inferDnDFromArchetypes(userID id.UserID) dndSuggestion {
|
||||
results := GetUserArchetypes(string(userID))
|
||||
|
||||
// archetype name → (class, race). First match wins; results are already
|
||||
// sorted by signal_score desc.
|
||||
mapping := map[string]struct {
|
||||
Class DnDClass
|
||||
Race DnDRace
|
||||
}{
|
||||
"Arena Champion": {ClassFighter, RaceOrc},
|
||||
"Dungeon Crawler": {ClassFighter, RaceHuman},
|
||||
"The Adventurer": {ClassRanger, RaceHuman},
|
||||
"The Angler": {ClassRanger, RaceElf},
|
||||
"The Forager": {ClassRanger, RaceHalfling},
|
||||
"The Miner": {ClassFighter, RaceDwarf},
|
||||
"The Merchant": {ClassRogue, RaceHalfling},
|
||||
"Whale": {ClassRogue, RaceHuman},
|
||||
"Degenerate": {ClassRogue, RaceTiefling},
|
||||
"Novelist": {ClassMage, RaceElf},
|
||||
"Philosopher": {ClassMage, RaceTiefling},
|
||||
"Wordsmith": {ClassMage, RaceElf},
|
||||
"Linkmaster": {ClassMage, RaceHuman},
|
||||
"Inquisitor": {ClassMage, RaceTiefling},
|
||||
"Cheerleader": {ClassCleric, RaceHalfElf},
|
||||
"Hype Machine": {ClassCleric, RaceHalfElf},
|
||||
"Patron": {ClassCleric, RaceDwarf},
|
||||
"Reactor": {ClassCleric, RaceHalfling},
|
||||
"Gearhead": {ClassFighter, RaceDwarf},
|
||||
"Shark": {ClassRogue, RaceHalfElf},
|
||||
"Trivia Nerd": {ClassMage, RaceHalfElf},
|
||||
}
|
||||
|
||||
for _, r := range results {
|
||||
if m, ok := mapping[r.Name]; ok {
|
||||
return dndSuggestion{Race: m.Race, Class: m.Class, Why: r.Name}
|
||||
}
|
||||
}
|
||||
return dndSuggestion{Race: RaceHuman, Class: ClassFighter, Why: "default"}
|
||||
}
|
||||
|
||||
// ── Command handler ──────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDSetupCmd(ctx MessageContext, args string) error {
|
||||
// Audit fix A: serialize per-user state mutations. Reuses the existing
|
||||
// adventure lock so !setup also serializes against !arena, !adventure
|
||||
// dungeon, etc. — all of which can write to dnd_character via auto-migration.
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
args = strings.TrimSpace(args)
|
||||
lower := strings.ToLower(args)
|
||||
|
||||
// Bare !setup → show status / instructions.
|
||||
if args == "" {
|
||||
return p.dndSetupStatus(ctx)
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(lower, "race "):
|
||||
return p.dndSetupRace(ctx, strings.TrimSpace(args[5:]))
|
||||
case strings.HasPrefix(lower, "class "):
|
||||
return p.dndSetupClass(ctx, strings.TrimSpace(args[6:]))
|
||||
case strings.HasPrefix(lower, "stats "):
|
||||
return p.dndSetupStats(ctx, strings.TrimSpace(args[6:]))
|
||||
case lower == "confirm":
|
||||
return p.dndSetupConfirm(ctx)
|
||||
case lower == "cancel":
|
||||
return p.dndSetupCancel(ctx)
|
||||
}
|
||||
return p.SendDM(ctx.Sender,"Unknown !setup subcommand. Try !setup with no args for instructions.")
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) dndSetupStatus(ctx MessageContext) error {
|
||||
c, err := LoadDnDCharacter(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't load your Adv 2.0 draft: "+err.Error())
|
||||
}
|
||||
|
||||
// No row yet → fresh setup. Show suggestion + race menu.
|
||||
if c == nil {
|
||||
// Legacy-player welcome: if they're meeting D&D for the first time
|
||||
// via `!setup` (rather than via combat auto-migration), they still
|
||||
// deserve the onboarding DM. We persist a stub draft row so the
|
||||
// OnboardingSent flag carries forward — neither this nor any later
|
||||
// auto-migration will re-send the welcome.
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
if advChar != nil && advChar.CombatLevel >= dndLegacyMinLevel {
|
||||
now := time.Now().UTC()
|
||||
// Seed the stub's Level with the computed mapping so the welcome DM
|
||||
// reports the right number ("your level X is now Adv 2.0 level Y").
|
||||
// On !setup confirm the level is recomputed from the same formula,
|
||||
// so the value here matches what the player will actually end up with.
|
||||
stub := &DnDCharacter{
|
||||
UserID: ctx.Sender,
|
||||
Level: dndLevelFromCombatLevel(advChar.CombatLevel),
|
||||
ArmorClass: 10,
|
||||
PendingSetup: true,
|
||||
OnboardingSent: false, // maybeSendDnDOnboarding will flip this on success
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
if err := SaveDnDCharacter(stub); err != nil {
|
||||
slog.Error("dnd: setup stub save failed", "user", ctx.Sender, "err", err)
|
||||
} else {
|
||||
p.maybeSendDnDOnboarding(ctx.Sender, advChar, stub)
|
||||
}
|
||||
}
|
||||
|
||||
sug := inferDnDFromArchetypes(ctx.Sender)
|
||||
var b strings.Builder
|
||||
b.WriteString("⚔️ **Adv 2.0 Setup** — let's build your character.\n\n")
|
||||
b.WriteString(fmt.Sprintf("Based on your play style we'd suggest a **%s %s** "+
|
||||
"_(driven by your %s archetype)_.\n\n",
|
||||
titleRace(sug.Race), titleClass(sug.Class), sug.Why))
|
||||
b.WriteString("**Step 1 — Race.** Pick one of:\n")
|
||||
b.WriteString(renderRaceMenu())
|
||||
b.WriteString("\nReply: `!setup race <name>` (e.g. `!setup race elf`)\n")
|
||||
return p.SendDM(ctx.Sender,b.String())
|
||||
}
|
||||
|
||||
// Confirmed already → reroute to !sheet, unless this is an auto-migrated
|
||||
// character, in which case we let the player rebuild freely.
|
||||
if !c.PendingSetup {
|
||||
if c.AutoMigrated {
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("⚔️ **Adv 2.0 Setup**\n\nWe auto-built you a **%s %s** based on your play style when you first fought, "+
|
||||
"so you'd never miss a battle. You can rebuild freely — no cooldown.\n\n", ri.Display, ci.Display))
|
||||
b.WriteString("**Step 1 — Race.** Pick one of:\n")
|
||||
b.WriteString(renderRaceMenu())
|
||||
b.WriteString("\nReply: `!setup race <name>` (or `!sheet` to keep what you have).\n")
|
||||
return p.SendDM(ctx.Sender, b.String())
|
||||
}
|
||||
return p.SendDM(ctx.Sender, "You've already set up your character. Use `!sheet` to view it, or `!respec` to start over (cooldown applies).")
|
||||
}
|
||||
|
||||
// Draft in progress — show what's set and what's next.
|
||||
var b strings.Builder
|
||||
b.WriteString("⚔️ **Adv 2.0 Setup** — draft in progress.\n\n")
|
||||
if c.Race == "" {
|
||||
b.WriteString("**Next: Step 1 — Race.**\n")
|
||||
b.WriteString(renderRaceMenu())
|
||||
b.WriteString("\nReply: `!setup race <name>`\n")
|
||||
return p.SendDM(ctx.Sender,b.String())
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("Race: **%s** ✓\n", titleRace(c.Race)))
|
||||
if c.Class == "" {
|
||||
b.WriteString("\n**Next: Step 2 — Class.**\n")
|
||||
b.WriteString(renderClassMenu())
|
||||
b.WriteString("\nReply: `!setup class <name>`\n")
|
||||
return p.SendDM(ctx.Sender,b.String())
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("Class: **%s** ✓\n", titleClass(c.Class)))
|
||||
if !statsAssigned(c) {
|
||||
b.WriteString("\n**Next: Step 3 — Ability Scores.**\n")
|
||||
b.WriteString("Assign these six values — **15 14 13 12 10 8** — to STR, DEX, CON, INT, WIS, CHA. Each value used exactly once.\n\n")
|
||||
b.WriteString("Reply: `!setup stats 15 14 13 12 10 8` (rearrange to taste).\n")
|
||||
return p.SendDM(ctx.Sender,b.String())
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("Stats (pre-racial): STR %d DEX %d CON %d INT %d WIS %d CHA %d ✓\n",
|
||||
c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA))
|
||||
b.WriteString("\n**Step 4 — Confirm.** Reply `!setup confirm` to finalize, or `!setup cancel` to scrap and start over.\n")
|
||||
b.WriteString(renderConfirmPreview(c))
|
||||
return p.SendDM(ctx.Sender,b.String())
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) dndSetupRace(ctx MessageContext, raceArg string) error {
|
||||
r, ok := parseRace(raceArg)
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender,"Unknown race. Options: human, elf, dwarf, halfling, orc, tiefling, half-elf")
|
||||
}
|
||||
c, err := loadOrInitDraft(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't open your draft: "+err.Error())
|
||||
}
|
||||
c.Race = r
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't save: "+err.Error())
|
||||
}
|
||||
ri, _ := raceInfo(r)
|
||||
return p.SendDM(ctx.Sender,fmt.Sprintf("Race set: **%s**. _%s_\n\nNext: `!setup class <name>` — see options with `!setup`.",
|
||||
ri.Display, ri.Passive))
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) dndSetupClass(ctx MessageContext, classArg string) error {
|
||||
cl, ok := parseClass(classArg)
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender,"Unknown class. Options: fighter, rogue, mage, cleric, ranger")
|
||||
}
|
||||
c, err := loadOrInitDraft(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't open your draft: "+err.Error())
|
||||
}
|
||||
c.Class = cl
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't save: "+err.Error())
|
||||
}
|
||||
ci, _ := classInfo(cl)
|
||||
return p.SendDM(ctx.Sender,fmt.Sprintf("Class set: **%s** (HP die d%d, primary %s/%s).\n\n"+
|
||||
"Next: assign your stats. The standard array is **15 14 13 12 10 8** — six numbers, each used once.\n"+
|
||||
"Order: STR DEX CON INT WIS CHA.\n\n"+
|
||||
"Example: `!setup stats 15 14 13 12 10 8` (all rolled into STR-first; rearrange to taste).",
|
||||
ci.Display, ci.HPDie, ci.PrimaryA, ci.PrimaryB))
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) dndSetupStats(ctx MessageContext, statsArg string) error {
|
||||
scores, err := parseStatsArg(statsArg)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, err.Error()+
|
||||
"\n\nFormat: `!setup stats 15 14 13 12 10 8` (in STR DEX CON INT WIS CHA order)."+
|
||||
"\nCommas and parentheses are fine too — `!setup stats 15, 14, 13, 12, 10, 8` works.")
|
||||
}
|
||||
if !isStandardArray(scores) {
|
||||
return p.SendDM(ctx.Sender, "Stats must be a permutation of the standard array {15, 14, 13, 12, 10, 8} — each value used exactly once.\n\n"+
|
||||
"Try: `!setup stats 15 14 13 12 10 8` and rearrange to taste.")
|
||||
}
|
||||
c, err := loadOrInitDraft(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't open your draft: "+err.Error())
|
||||
}
|
||||
c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA = scores[0], scores[1], scores[2], scores[3], scores[4], scores[5]
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't save: "+err.Error())
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("Stats saved (pre-racial bonuses).\n")
|
||||
b.WriteString(renderConfirmPreview(c))
|
||||
b.WriteString("\nReply `!setup confirm` to finalize.")
|
||||
return p.SendDM(ctx.Sender,b.String())
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) dndSetupConfirm(ctx MessageContext) error {
|
||||
c, err := LoadDnDCharacter(ctx.Sender)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender,"No setup draft found. Run `!setup` to start.")
|
||||
}
|
||||
if !c.PendingSetup {
|
||||
return p.SendDM(ctx.Sender,"Already confirmed. Use `!sheet` to view your character.")
|
||||
}
|
||||
if c.Race == "" || c.Class == "" || !statsAssigned(c) {
|
||||
return p.SendDM(ctx.Sender,"Draft incomplete. Run `!setup` to see what's missing.")
|
||||
}
|
||||
|
||||
// Apply racial modifiers to the assigned scores.
|
||||
final := applyRaceMods(c.Race, [6]int{c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA})
|
||||
c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA = final[0], final[1], final[2], final[3], final[4], final[5]
|
||||
|
||||
// Initial D&D level seeded from existing combat_level (v1.1 §4.1).
|
||||
// combat_level "freezes" thereafter — dnd_level is canonical.
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
startLevel := 1
|
||||
if advChar != nil {
|
||||
startLevel = dndLevelFromCombatLevel(advChar.CombatLevel)
|
||||
}
|
||||
c.Level = startLevel
|
||||
|
||||
conMod := abilityModifier(c.CON)
|
||||
dexMod := abilityModifier(c.DEX)
|
||||
c.HPMax = computeMaxHP(c.Class, conMod, c.Level)
|
||||
c.HPCurrent = c.HPMax
|
||||
c.TempHP = 0
|
||||
c.ArmorClass = computeAC(c.Class, dexMod)
|
||||
c.PendingSetup = false
|
||||
c.AutoMigrated = false // manually confirmed — no longer an auto-migration
|
||||
c.UpdatedAt = time.Now().UTC()
|
||||
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't save: "+err.Error())
|
||||
}
|
||||
_ = initResources(ctx.Sender, c.Class)
|
||||
// Phase 9: caster classes get a default known-spell list and slot pool.
|
||||
// Idempotent — !setup confirm after a respec wipe will repopulate.
|
||||
_ = ensureSpellsForCharacter(c)
|
||||
|
||||
return p.SendDM(ctx.Sender,renderSetupComplete(c))
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) dndSetupCancel(ctx MessageContext) error {
|
||||
c, err := LoadDnDCharacter(ctx.Sender)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender,"No draft to cancel.")
|
||||
}
|
||||
if !c.PendingSetup {
|
||||
return p.SendDM(ctx.Sender,"Your character is already finalized — use `!respec` instead.")
|
||||
}
|
||||
if _, err := dbExecCancel(ctx.Sender); err != nil {
|
||||
return p.SendDM(ctx.Sender,"Couldn't cancel: "+err.Error())
|
||||
}
|
||||
return p.SendDM(ctx.Sender,"Draft scrapped. Run `!setup` to start over.")
|
||||
}
|
||||
|
||||
// ── !respec ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const (
|
||||
dndRespecCost = 5000
|
||||
dndRespecCooldown = 7 * 24 * time.Hour
|
||||
)
|
||||
|
||||
func (p *AdventurePlugin) handleDnDRespecCmd(ctx MessageContext) error {
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
c, err := LoadDnDCharacter(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character: "+err.Error())
|
||||
}
|
||||
if c == nil {
|
||||
return p.SendDM(ctx.Sender, "You don't have a character yet — run `!setup` instead.")
|
||||
}
|
||||
if c.PendingSetup {
|
||||
return p.SendDM(ctx.Sender, "You already have a setup draft in progress. Run `!setup` to continue or `!setup cancel` to scrap it.")
|
||||
}
|
||||
if c.AutoMigrated {
|
||||
return p.SendDM(ctx.Sender, "Your character was auto-built — `!setup` lets you rebuild for free, no respec needed.")
|
||||
}
|
||||
|
||||
if c.LastRespecAt != nil {
|
||||
elapsed := time.Since(*c.LastRespecAt)
|
||||
if elapsed < dndRespecCooldown {
|
||||
remaining := dndRespecCooldown - elapsed
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"`!respec` is on cooldown — %s remaining.", formatRespecDuration(remaining)))
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-check balance so insufficient-funds players get the right error
|
||||
// without any state mutation.
|
||||
if p.euro == nil || p.euro.GetBalance(ctx.Sender) < float64(dndRespecCost) {
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf("`!respec` costs %d euros — you don't have enough.", dndRespecCost))
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
c.Race = ""
|
||||
c.Class = ""
|
||||
c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA = 8, 8, 8, 8, 8, 8
|
||||
c.HPMax = 0
|
||||
c.HPCurrent = 0
|
||||
c.TempHP = 0
|
||||
c.ArmorClass = 10
|
||||
c.Level = 1
|
||||
c.XP = 0
|
||||
c.ArmedAbility = ""
|
||||
c.PendingSetup = true
|
||||
c.AutoMigrated = false
|
||||
c.LastRespecAt = &now
|
||||
// Save the wipe BEFORE debiting euros (audit fix B). If save fails, the
|
||||
// player's old state survives and they keep their euros — better than
|
||||
// a destructive debit-without-wipe.
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't save respec state: "+err.Error())
|
||||
}
|
||||
// Wipe old class's resource pool so respec'd Mages don't carry Fighter
|
||||
// stamina rows etc. (audit fix E).
|
||||
if _, err := db.Get().Exec(
|
||||
`DELETE FROM dnd_resources WHERE user_id = ?`, string(ctx.Sender),
|
||||
); err != nil {
|
||||
slog.Error("dnd: respec resource wipe", "user", ctx.Sender, "err", err)
|
||||
}
|
||||
// Phase 9: also wipe known spells + slot pool so respec from caster →
|
||||
// non-caster (or caster → caster of another class) starts clean.
|
||||
if err := wipeSpellsForUser(ctx.Sender); err != nil {
|
||||
slog.Error("dnd: respec spell wipe", "user", ctx.Sender, "err", err)
|
||||
}
|
||||
// Debit last. If this fails (rare race — euros spent elsewhere between
|
||||
// the pre-check and now), the player got a free respec. Strictly better
|
||||
// than the alternative of euros-lost-with-wipe-not-applied.
|
||||
if !p.euro.Debit(ctx.Sender, float64(dndRespecCost), "dnd respec") {
|
||||
slog.Warn("dnd: respec wipe completed but debit failed (race vs. balance change)",
|
||||
"user", ctx.Sender)
|
||||
}
|
||||
|
||||
return p.SendDM(ctx.Sender, fmt.Sprintf(
|
||||
"💸 %d euros spent. Your character is wiped. Run `!setup` to build a new one.\n\n"+
|
||||
"Cooldown: %s before next respec.",
|
||||
dndRespecCost, formatRespecDuration(dndRespecCooldown)))
|
||||
}
|
||||
|
||||
func formatRespecDuration(d time.Duration) string {
|
||||
hours := int(d.Hours())
|
||||
if hours >= 24 {
|
||||
days := hours / 24
|
||||
hours = hours % 24
|
||||
if hours == 0 {
|
||||
return fmt.Sprintf("%dd", days)
|
||||
}
|
||||
return fmt.Sprintf("%dd %dh", days, hours)
|
||||
}
|
||||
if hours > 0 {
|
||||
return fmt.Sprintf("%dh", hours)
|
||||
}
|
||||
mins := int(d.Minutes())
|
||||
return fmt.Sprintf("%dm", mins)
|
||||
}
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func loadOrInitDraft(userID id.UserID) (*DnDCharacter, error) {
|
||||
c, err := LoadDnDCharacter(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c != nil {
|
||||
// Auto-migrated chars can be freely rebuilt — wipe and start fresh.
|
||||
// If the player cancels, their next combat will auto-migrate again.
|
||||
if c.AutoMigrated && !c.PendingSetup {
|
||||
if _, err := db.Get().Exec(
|
||||
`DELETE FROM dnd_character WHERE user_id = ?`, string(userID),
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("clear auto-migrated row: %w", err)
|
||||
}
|
||||
// fall through to fresh draft
|
||||
} else if !c.PendingSetup {
|
||||
return nil, fmt.Errorf("character already finalized — use !respec")
|
||||
} else {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
// Fresh draft.
|
||||
now := time.Now().UTC()
|
||||
return &DnDCharacter{
|
||||
UserID: userID,
|
||||
Level: 1,
|
||||
PendingSetup: true,
|
||||
ArmorClass: 10,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func dbExecCancel(userID id.UserID) (int64, error) {
|
||||
res, err := db.Get().Exec(`DELETE FROM dnd_character WHERE user_id = ? AND pending_setup = 1`, string(userID))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// parseStatsArg accepts the six standard-array values in any of several
|
||||
// natural forms. All of these work:
|
||||
//
|
||||
// 15 14 13 12 10 8
|
||||
// 15, 14, 13, 12, 10, 8
|
||||
// (15, 14, 13, 12, 10, 8)
|
||||
// {15 14 13 12 10 8}
|
||||
// [15,14,13,12,10,8]
|
||||
//
|
||||
// Returns the scores in input order. Validation that they're a permutation
|
||||
// of the standard array happens in the caller via isStandardArray.
|
||||
func parseStatsArg(s string) ([6]int, error) {
|
||||
var out [6]int
|
||||
// Normalize separators: turn commas and bracket-pair characters into
|
||||
// spaces, then split on whitespace.
|
||||
cleaned := s
|
||||
for _, ch := range []string{",", "(", ")", "[", "]", "{", "}"} {
|
||||
cleaned = strings.ReplaceAll(cleaned, ch, " ")
|
||||
}
|
||||
parts := strings.Fields(cleaned)
|
||||
if len(parts) != 6 {
|
||||
return out, fmt.Errorf("Need exactly 6 numbers, got %d.", len(parts))
|
||||
}
|
||||
for i, tok := range parts {
|
||||
n, err := strconv.Atoi(tok)
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("Stat %d isn't a number: %q.", i+1, tok)
|
||||
}
|
||||
out[i] = n
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func parseRace(s string) (DnDRace, bool) {
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
s = strings.ReplaceAll(s, "-", "_")
|
||||
for _, ri := range dndRaces {
|
||||
if string(ri.Key) == s || strings.EqualFold(ri.Display, s) {
|
||||
return ri.Key, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func parseClass(s string) (DnDClass, bool) {
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
for _, ci := range dndClasses {
|
||||
if string(ci.Key) == s || strings.EqualFold(ci.Display, s) {
|
||||
return ci.Key, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func isStandardArray(scores [6]int) bool {
|
||||
a := scores
|
||||
sort.Sort(sort.Reverse(sort.IntSlice(a[:])))
|
||||
want := standardArray
|
||||
return a == want
|
||||
}
|
||||
|
||||
func statsAssigned(c *DnDCharacter) bool {
|
||||
// All-8 means default-init; treat as not yet assigned.
|
||||
if c.STR == 8 && c.DEX == 8 && c.CON == 8 && c.INT == 8 && c.WIS == 8 && c.CHA == 8 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func titleRace(r DnDRace) string {
|
||||
if ri, ok := raceInfo(r); ok {
|
||||
return ri.Display
|
||||
}
|
||||
return string(r)
|
||||
}
|
||||
|
||||
func titleClass(c DnDClass) string {
|
||||
if ci, ok := classInfo(c); ok {
|
||||
return ci.Display
|
||||
}
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func renderRaceMenu() string {
|
||||
var b strings.Builder
|
||||
for _, ri := range dndRaces {
|
||||
b.WriteString(fmt.Sprintf(" • **%s** — %s\n", ri.Display, ri.Passive))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func renderClassMenu() string {
|
||||
var b strings.Builder
|
||||
for _, ci := range dndClasses {
|
||||
b.WriteString(fmt.Sprintf(" • **%s** (d%d, %s/%s)\n", ci.Display, ci.HPDie, ci.PrimaryA, ci.PrimaryB))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func renderConfirmPreview(c *DnDCharacter) string {
|
||||
final := applyRaceMods(c.Race, [6]int{c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA})
|
||||
mods := [6]int{
|
||||
abilityModifier(final[0]), abilityModifier(final[1]), abilityModifier(final[2]),
|
||||
abilityModifier(final[3]), abilityModifier(final[4]), abilityModifier(final[5]),
|
||||
}
|
||||
conMod := mods[2]
|
||||
dexMod := mods[1]
|
||||
advChar, _ := loadAdvCharacter(c.UserID)
|
||||
lvl := 1
|
||||
if advChar != nil {
|
||||
lvl = dndLevelFromCombatLevel(advChar.CombatLevel)
|
||||
}
|
||||
hp := computeMaxHP(c.Class, conMod, lvl)
|
||||
ac := computeAC(c.Class, dexMod)
|
||||
return fmt.Sprintf(
|
||||
"\n**Preview** (post-racial):\n"+
|
||||
" STR %d (%+d) DEX %d (%+d) CON %d (%+d)\n"+
|
||||
" INT %d (%+d) WIS %d (%+d) CHA %d (%+d)\n"+
|
||||
" HP %d AC %d Level %d\n",
|
||||
final[0], mods[0], final[1], mods[1], final[2], mods[2],
|
||||
final[3], mods[3], final[4], mods[4], final[5], mods[5],
|
||||
hp, ac, lvl,
|
||||
)
|
||||
}
|
||||
|
||||
func renderSetupComplete(c *DnDCharacter) string {
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
return fmt.Sprintf(
|
||||
"⚔️ **Character Sheet Forged**\n\n"+
|
||||
"You are a **Level %d %s %s**.\n"+
|
||||
" HP %d/%d AC %d\n"+
|
||||
" STR %d DEX %d CON %d INT %d WIS %d CHA %d\n\n"+
|
||||
"_%s_\n\n"+
|
||||
"Use `!sheet` anytime to review. Combat, abilities, and rest mechanics arrive in the next phases.",
|
||||
c.Level, ri.Display, ci.Display,
|
||||
c.HPCurrent, c.HPMax, c.ArmorClass,
|
||||
c.STR, c.DEX, c.CON, c.INT, c.WIS, c.CHA,
|
||||
ri.Passive,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (p *AdventurePlugin) handleDnDAbilitiesCmd(ctx MessageContext) error {
|
||||
c, err := LoadDnDCharacter(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character: "+err.Error())
|
||||
}
|
||||
if c == nil || c.PendingSetup {
|
||||
return p.SendDM(ctx.Sender, "No Adv 2.0 character yet — run `!setup` (or just enter combat and we'll auto-build one).")
|
||||
}
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
ab := dndClassAbilities[c.Class]
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("**%s %s — Abilities**\n\n", ri.Display, ci.Display))
|
||||
b.WriteString(fmt.Sprintf("**Class passive — %s**\n %s\n\n", ab.Name, ab.Description))
|
||||
b.WriteString(fmt.Sprintf("**Race trait**\n %s\n", ri.Passive))
|
||||
|
||||
// Active abilities (Phase 6)
|
||||
actives := classActiveAbilities(c.Class)
|
||||
if len(actives) > 0 {
|
||||
resType, _ := classResourceMax(c.Class)
|
||||
cur, max, _ := getResource(c.UserID, resType)
|
||||
b.WriteString(fmt.Sprintf("\n**Active abilities** (%s %d/%d)\n", resType, cur, max))
|
||||
for _, a := range actives {
|
||||
b.WriteString(fmt.Sprintf(" • **%s** (1 %s) — %s\n", a.Name, a.Resource, a.Description))
|
||||
}
|
||||
b.WriteString("\nUse `!arm <ability>` to ready one for your next combat. Refreshes on long rest.\n")
|
||||
if c.ArmedAbility != "" {
|
||||
b.WriteString(fmt.Sprintf("\n_Currently armed: **%s**_\n", displayAbility(c.ArmedAbility)))
|
||||
}
|
||||
}
|
||||
return p.SendDM(ctx.Sender, b.String())
|
||||
}
|
||||
|
||||
// !sheet — read-only D&D character sheet renderer.
|
||||
//
|
||||
// Joins:
|
||||
// dnd_character (D&D layer)
|
||||
// adventure_characters (legacy skills, pet, housing — for at-a-glance context)
|
||||
// adventure_equipment (current gear; renders with legacy fields until Phase 4)
|
||||
// adventure_treasures (= attunement substrate per v1.1 §7.4)
|
||||
|
||||
func (p *AdventurePlugin) handleDnDSheetCmd(ctx MessageContext) error {
|
||||
c, err := LoadDnDCharacter(ctx.Sender)
|
||||
if err != nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your sheet: "+err.Error())
|
||||
}
|
||||
if c == nil || c.PendingSetup {
|
||||
return p.SendDM(ctx.Sender,
|
||||
"You don't have an Adv 2.0 character yet.\n\nRun `!setup` to begin character creation. "+
|
||||
"Your existing adventure progress (skills, pets, coins, arena streak) will be preserved.")
|
||||
}
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
equip, _ := loadAdvEquipment(ctx.Sender)
|
||||
treasures, _ := loadAdvTreasureBonuses(ctx.Sender)
|
||||
|
||||
return p.SendDM(ctx.Sender, renderDnDSheet(c, advChar, equip, treasures))
|
||||
}
|
||||
|
||||
func renderDnDSheet(c *DnDCharacter, adv *AdventureCharacter, equip map[EquipmentSlot]*AdvEquipment, treasures []AdvTreasureBonus) string {
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
mods := c.Modifiers()
|
||||
|
||||
var b strings.Builder
|
||||
name := string(c.UserID)
|
||||
if adv != nil && adv.DisplayName != "" {
|
||||
name = adv.DisplayName
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("⚔️ **%s** — Level %d %s %s\n", name, c.Level, ri.Display, ci.Display))
|
||||
b.WriteString(strings.Repeat("─", 36) + "\n")
|
||||
|
||||
// Vitals
|
||||
b.WriteString(fmt.Sprintf("**HP** %d/%d", c.HPCurrent, c.HPMax))
|
||||
if c.TempHP > 0 {
|
||||
b.WriteString(fmt.Sprintf(" (+%d temp)", c.TempHP))
|
||||
}
|
||||
b.WriteString(fmt.Sprintf(" **AC** %d", c.ArmorClass))
|
||||
if c.Level >= dndMaxLevel {
|
||||
b.WriteString(" **XP** capped (L20)\n")
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf(" **XP** %d / %d (next L%d)\n",
|
||||
c.XP, dndXPToNextLevel(c.Level), c.Level+1))
|
||||
}
|
||||
|
||||
// Ability scores with modifiers
|
||||
b.WriteString(fmt.Sprintf("STR %2d (%+d) DEX %2d (%+d) CON %2d (%+d)\n",
|
||||
c.STR, mods[0], c.DEX, mods[1], c.CON, mods[2]))
|
||||
b.WriteString(fmt.Sprintf("INT %2d (%+d) WIS %2d (%+d) CHA %2d (%+d)\n",
|
||||
c.INT, mods[3], c.WIS, mods[4], c.CHA, mods[5]))
|
||||
b.WriteString(fmt.Sprintf("\n_%s_\n", ri.Passive))
|
||||
|
||||
// Equipment — D&D 10-slot view, with rarity inferred from legacy fields.
|
||||
b.WriteString("\n**Equipment**\n")
|
||||
dndEquip := map[DnDSlot]*AdvEquipment{}
|
||||
for _, slot := range allSlots {
|
||||
eq, ok := equip[slot]
|
||||
if !ok || eq == nil {
|
||||
continue
|
||||
}
|
||||
dndEquip[mapLegacySlot(slot)] = eq
|
||||
}
|
||||
anyEquipped := false
|
||||
for _, ds := range dndSlotOrder {
|
||||
eq := dndEquip[ds]
|
||||
if eq == nil {
|
||||
continue
|
||||
}
|
||||
anyEquipped = true
|
||||
rarity := equipmentRarity(eq)
|
||||
tag := ""
|
||||
if eq.Masterwork {
|
||||
tag = " ★"
|
||||
}
|
||||
b.WriteString(fmt.Sprintf(" %s %-9s T%d %d%%%s %s _(%s)_\n",
|
||||
rarityIcon(rarity), string(ds), eq.Tier, eq.Condition, tag, eq.Name, rarity))
|
||||
}
|
||||
if !anyEquipped {
|
||||
b.WriteString(" _(none equipped)_\n")
|
||||
}
|
||||
|
||||
// Attunements (re-using adventure_treasures per v1.1 §7.4)
|
||||
if len(treasures) > 0 {
|
||||
b.WriteString("\n**Attunements** (treasures)\n")
|
||||
// Group by treasure_key — one treasure can have multiple bonuses.
|
||||
byKey := map[string][]AdvTreasureBonus{}
|
||||
var keys []string
|
||||
for _, t := range treasures {
|
||||
if _, seen := byKey[t.TreasureKey]; !seen {
|
||||
keys = append(keys, t.TreasureKey)
|
||||
}
|
||||
byKey[t.TreasureKey] = append(byKey[t.TreasureKey], t)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
bonuses := byKey[k]
|
||||
name := bonuses[0].Name
|
||||
parts := make([]string, 0, len(bonuses))
|
||||
for _, bn := range bonuses {
|
||||
parts = append(parts, fmt.Sprintf("%s %+.1f", bn.BonusType, bn.BonusValue))
|
||||
}
|
||||
b.WriteString(fmt.Sprintf(" • %s — %s\n", name, strings.Join(parts, ", ")))
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy adventure context — preserved progress at a glance
|
||||
if adv != nil {
|
||||
b.WriteString("\n**Adventure progress** _(preserved)_\n")
|
||||
b.WriteString(fmt.Sprintf(" Mining %d Foraging %d Fishing %d Combat (legacy) %d\n",
|
||||
adv.MiningSkill, adv.ForagingSkill, adv.FishingSkill, adv.CombatLevel))
|
||||
b.WriteString(fmt.Sprintf(" Arena %dW/%dL Streak %d (best %d)\n",
|
||||
adv.ArenaWins, adv.ArenaLosses, adv.CurrentStreak, adv.BestStreak))
|
||||
if adv.PetName != "" {
|
||||
b.WriteString(fmt.Sprintf(" Pet: %s the %s (lv %d)\n", adv.PetName, adv.PetType, adv.PetLevel))
|
||||
}
|
||||
if adv.HouseTier > 0 {
|
||||
b.WriteString(fmt.Sprintf(" Housing: tier %d\n", adv.HouseTier))
|
||||
}
|
||||
}
|
||||
|
||||
b.WriteString("\n_Combat, abilities, and rest mechanics arrive in upcoming phases._")
|
||||
return b.String()
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 5 — D&D skill check resolver and !check command.
|
||||
//
|
||||
// Skill checks are d20 + ability modifier + race bonus vs. a target DC.
|
||||
// Nat 20 auto-succeeds, nat 1 auto-fails (matches D&D 5e). Used by !check
|
||||
// for ad-hoc rolls and by NPC handlers (Thom Krooke / Misty / Arina) for
|
||||
// gated bonuses.
|
||||
|
||||
// ── Skill table ──────────────────────────────────────────────────────────────
|
||||
|
||||
type DnDSkill string
|
||||
|
||||
const (
|
||||
SkillAthletics DnDSkill = "athletics"
|
||||
SkillAcrobatics DnDSkill = "acrobatics"
|
||||
SkillStealth DnDSkill = "stealth"
|
||||
SkillArcana DnDSkill = "arcana"
|
||||
SkillInvestigation DnDSkill = "investigation"
|
||||
SkillPerception DnDSkill = "perception"
|
||||
SkillInsight DnDSkill = "insight"
|
||||
SkillPersuasion DnDSkill = "persuasion"
|
||||
SkillIntimidation DnDSkill = "intimidation"
|
||||
SkillDeception DnDSkill = "deception"
|
||||
)
|
||||
|
||||
type dndSkillInfo struct {
|
||||
Key DnDSkill
|
||||
Display string
|
||||
Stat string // "str", "dex", "con", "int", "wis", "cha"
|
||||
}
|
||||
|
||||
var dndSkillTable = []dndSkillInfo{
|
||||
{SkillAthletics, "Athletics", "str"},
|
||||
{SkillAcrobatics, "Acrobatics", "dex"},
|
||||
{SkillStealth, "Stealth", "dex"},
|
||||
{SkillArcana, "Arcana", "int"},
|
||||
{SkillInvestigation, "Investigation", "int"},
|
||||
{SkillPerception, "Perception", "wis"},
|
||||
{SkillInsight, "Insight", "wis"},
|
||||
{SkillPersuasion, "Persuasion", "cha"},
|
||||
{SkillIntimidation, "Intimidation", "cha"},
|
||||
{SkillDeception, "Deception", "cha"},
|
||||
}
|
||||
|
||||
func skillInfo(s DnDSkill) (dndSkillInfo, bool) {
|
||||
for _, si := range dndSkillTable {
|
||||
if si.Key == s {
|
||||
return si, true
|
||||
}
|
||||
}
|
||||
return dndSkillInfo{}, false
|
||||
}
|
||||
|
||||
func parseSkill(s string) (DnDSkill, bool) {
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
for _, si := range dndSkillTable {
|
||||
if string(si.Key) == s || strings.EqualFold(si.Display, s) {
|
||||
return si.Key, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// ── DC table ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const (
|
||||
DCTrivial = 5
|
||||
DCEasy = 10
|
||||
DCMedium = 15
|
||||
DCHard = 20
|
||||
DCVeryHard = 25
|
||||
DCImpossible = 30
|
||||
)
|
||||
|
||||
func parseDC(s string) (int, bool) {
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
switch s {
|
||||
case "trivial":
|
||||
return DCTrivial, true
|
||||
case "easy":
|
||||
return DCEasy, true
|
||||
case "medium", "med":
|
||||
return DCMedium, true
|
||||
case "hard":
|
||||
return DCHard, true
|
||||
case "veryhard", "very_hard", "very-hard":
|
||||
return DCVeryHard, true
|
||||
case "impossible":
|
||||
return DCImpossible, true
|
||||
}
|
||||
if n, err := strconv.Atoi(s); err == nil && n > 0 {
|
||||
return n, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// ── Resolver ─────────────────────────────────────────────────────────────────
|
||||
|
||||
// SkillCheckResult is the outcome of a single d20 check.
|
||||
type SkillCheckResult struct {
|
||||
Skill DnDSkill
|
||||
DC int
|
||||
Roll int // raw d20 [1, 20]
|
||||
Mod int // stat mod + race bonus
|
||||
Total int // roll + mod (or auto-{success,fail} flag)
|
||||
Success bool
|
||||
Auto bool // true if nat 20 / nat 1 short-circuited
|
||||
}
|
||||
|
||||
// statValue extracts the named ability score from a DnDCharacter.
|
||||
func statValue(c *DnDCharacter, stat string) int {
|
||||
switch stat {
|
||||
case "str":
|
||||
return c.STR
|
||||
case "dex":
|
||||
return c.DEX
|
||||
case "con":
|
||||
return c.CON
|
||||
case "int":
|
||||
return c.INT
|
||||
case "wis":
|
||||
return c.WIS
|
||||
case "cha":
|
||||
return c.CHA
|
||||
}
|
||||
return 10
|
||||
}
|
||||
|
||||
// raceSkillBonus returns the per-skill bonus from a player's race.
|
||||
// Half-Elf gets +1 to every skill (rough mapping of "two bonus skill profs").
|
||||
// Tiefling gets +2 to CHA-based skills (matches the doc's "+bonus on CHA checks").
|
||||
func raceSkillBonus(c *DnDCharacter, info dndSkillInfo) int {
|
||||
switch c.Race {
|
||||
case RaceHalfElf:
|
||||
return 1
|
||||
case RaceTiefling:
|
||||
if info.Stat == "cha" {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// performSkillCheck rolls the d20 and computes the result.
|
||||
func performSkillCheck(c *DnDCharacter, skill DnDSkill, dc int) SkillCheckResult {
|
||||
info, _ := skillInfo(skill)
|
||||
mod := abilityModifier(statValue(c, info.Stat)) + raceSkillBonus(c, info)
|
||||
roll := 1 + rand.IntN(20)
|
||||
res := SkillCheckResult{Skill: skill, DC: dc, Roll: roll, Mod: mod}
|
||||
|
||||
switch roll {
|
||||
case 20:
|
||||
res.Success = true
|
||||
res.Auto = true
|
||||
res.Total = roll + mod
|
||||
case 1:
|
||||
res.Success = false
|
||||
res.Auto = true
|
||||
res.Total = roll + mod
|
||||
default:
|
||||
res.Total = roll + mod
|
||||
res.Success = res.Total >= dc
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ── !check command ──────────────────────────────────────────────────────────
|
||||
|
||||
func (p *AdventurePlugin) handleDnDCheckCmd(ctx MessageContext, args string) error {
|
||||
// !check can trigger auto-migration which writes to dnd_character.
|
||||
userMu := p.advUserLock(ctx.Sender)
|
||||
userMu.Lock()
|
||||
defer userMu.Unlock()
|
||||
|
||||
args = strings.TrimSpace(args)
|
||||
if args == "" {
|
||||
return p.SendDM(ctx.Sender, dndCheckHelpText())
|
||||
}
|
||||
|
||||
fields := strings.Fields(args)
|
||||
skill, ok := parseSkill(fields[0])
|
||||
if !ok {
|
||||
return p.SendDM(ctx.Sender,
|
||||
"Unknown skill. Try: "+strings.Join(dndSkillNames(), ", "))
|
||||
}
|
||||
|
||||
dc := DCMedium
|
||||
if len(fields) >= 2 {
|
||||
if parsed, ok := parseDC(fields[1]); ok {
|
||||
dc = parsed
|
||||
} else {
|
||||
return p.SendDM(ctx.Sender,
|
||||
"DC must be a number or one of: trivial, easy, medium, hard, veryhard, impossible")
|
||||
}
|
||||
}
|
||||
|
||||
advChar, _ := loadAdvCharacter(ctx.Sender)
|
||||
c, err := p.ensureCharForDnDCmd(ctx.Sender, advChar)
|
||||
if err != nil || c == nil {
|
||||
return p.SendDM(ctx.Sender, "Couldn't load your character.")
|
||||
}
|
||||
|
||||
res := performSkillCheck(c, skill, dc)
|
||||
return p.SendDM(ctx.Sender, renderSkillCheck(res))
|
||||
}
|
||||
|
||||
func renderSkillCheck(res SkillCheckResult) string {
|
||||
info, _ := skillInfo(res.Skill)
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("🎲 **%s** check (DC %d)\n", info.Display, res.DC))
|
||||
b.WriteString(fmt.Sprintf(" d20 = %d + %s mod %+d = **%d**\n",
|
||||
res.Roll, strings.ToUpper(info.Stat), res.Mod, res.Total))
|
||||
if res.Auto && res.Roll == 20 {
|
||||
b.WriteString(" ✅ **Critical success** (nat 20)\n")
|
||||
} else if res.Auto && res.Roll == 1 {
|
||||
b.WriteString(" ❌ **Critical failure** (nat 1)\n")
|
||||
} else if res.Success {
|
||||
b.WriteString(" ✅ Success\n")
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf(" ❌ Failed (needed %d)\n", res.DC))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func dndCheckHelpText() string {
|
||||
var b strings.Builder
|
||||
b.WriteString("**Skill Check** — `!check <skill> [dc]`\n\n")
|
||||
b.WriteString("Skills: " + strings.Join(dndSkillNames(), ", ") + "\n\n")
|
||||
b.WriteString("DC: a number, or `trivial` (5), `easy` (10), `medium` (15, default), ")
|
||||
b.WriteString("`hard` (20), `veryhard` (25), `impossible` (30)\n\n")
|
||||
b.WriteString("Example: `!check athletics hard`")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// ── NPC skill-check hooks ────────────────────────────────────────────────────
|
||||
//
|
||||
// These are silent upside helpers: if the player has a confirmed D&D
|
||||
// character and rolls well on the relevant skill, the NPC interaction's
|
||||
// cost is refunded. Legacy (no D&D character) players see no change.
|
||||
//
|
||||
// The result type distinguishes "no check attempted" (no D&D char) from
|
||||
// "checked, failed" — so callers can surface different flavor for each.
|
||||
|
||||
// NPCSkillCheckResult tells the caller whether a D&D skill check was
|
||||
// even applicable (Attempted=false → no D&D char) and, if so, whether it
|
||||
// succeeded.
|
||||
type NPCSkillCheckResult struct {
|
||||
Attempted bool
|
||||
Succeeded bool
|
||||
}
|
||||
|
||||
func dndNPCInsightRefund(userID id.UserID, euro *EuroPlugin, cost int) NPCSkillCheckResult {
|
||||
return dndNPCRefundCheck(userID, euro, SkillInsight, 12, cost, "misty_insight_refund")
|
||||
}
|
||||
|
||||
func dndNPCArcanaRefund(userID id.UserID, euro *EuroPlugin, cost int) NPCSkillCheckResult {
|
||||
return dndNPCRefundCheck(userID, euro, SkillArcana, 14, cost, "arina_arcana_refund")
|
||||
}
|
||||
|
||||
// dndNPCPersuasionDiscount: returns true if the player passed a Persuasion
|
||||
// check (DC 15). Caller applies the 10% discount. No euro side effect here.
|
||||
func dndNPCPersuasionDiscount(userID id.UserID) bool {
|
||||
c, err := LoadDnDCharacter(userID)
|
||||
if err != nil || c == nil || c.PendingSetup {
|
||||
return false
|
||||
}
|
||||
return performSkillCheck(c, SkillPersuasion, 15).Success
|
||||
}
|
||||
|
||||
func dndNPCRefundCheck(userID id.UserID, euro *EuroPlugin, skill DnDSkill, dc int, cost int, reason string) NPCSkillCheckResult {
|
||||
c, err := LoadDnDCharacter(userID)
|
||||
if err != nil || c == nil || c.PendingSetup {
|
||||
return NPCSkillCheckResult{}
|
||||
}
|
||||
res := performSkillCheck(c, skill, dc)
|
||||
if !res.Success {
|
||||
return NPCSkillCheckResult{Attempted: true, Succeeded: false}
|
||||
}
|
||||
if euro != nil {
|
||||
euro.Credit(userID, float64(cost), reason)
|
||||
}
|
||||
return NPCSkillCheckResult{Attempted: true, Succeeded: true}
|
||||
}
|
||||
|
||||
func dndSkillNames() []string {
|
||||
out := make([]string, 0, len(dndSkillTable))
|
||||
for _, si := range dndSkillTable {
|
||||
out = append(out, string(si.Key))
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSkillTableComplete(t *testing.T) {
|
||||
expectedStats := map[DnDSkill]string{
|
||||
SkillAthletics: "str", SkillAcrobatics: "dex", SkillStealth: "dex",
|
||||
SkillArcana: "int", SkillInvestigation: "int",
|
||||
SkillPerception: "wis", SkillInsight: "wis",
|
||||
SkillPersuasion: "cha", SkillIntimidation: "cha", SkillDeception: "cha",
|
||||
}
|
||||
if len(dndSkillTable) != len(expectedStats) {
|
||||
t.Errorf("dndSkillTable size = %d, want %d", len(dndSkillTable), len(expectedStats))
|
||||
}
|
||||
for _, si := range dndSkillTable {
|
||||
want, ok := expectedStats[si.Key]
|
||||
if !ok {
|
||||
t.Errorf("unexpected skill %s", si.Key)
|
||||
continue
|
||||
}
|
||||
if si.Stat != want {
|
||||
t.Errorf("%s stat = %s, want %s", si.Key, si.Stat, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSkill(t *testing.T) {
|
||||
for _, s := range dndSkillTable {
|
||||
got, ok := parseSkill(s.Display)
|
||||
if !ok || got != s.Key {
|
||||
t.Errorf("parseSkill(%q) = %v, %v; want %v, true", s.Display, got, ok, s.Key)
|
||||
}
|
||||
}
|
||||
if _, ok := parseSkill("acrobatics"); !ok {
|
||||
t.Errorf("parseSkill lowercase failed")
|
||||
}
|
||||
if _, ok := parseSkill("flying"); ok {
|
||||
t.Errorf("parseSkill bogus skill returned ok")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDC(t *testing.T) {
|
||||
cases := []struct {
|
||||
s string
|
||||
want int
|
||||
ok bool
|
||||
}{
|
||||
{"trivial", 5, true},
|
||||
{"easy", 10, true},
|
||||
{"medium", 15, true},
|
||||
{"med", 15, true},
|
||||
{"hard", 20, true},
|
||||
{"veryhard", 25, true},
|
||||
{"very_hard", 25, true},
|
||||
{"impossible", 30, true},
|
||||
{"17", 17, true},
|
||||
{"99", 99, true},
|
||||
{"-5", 0, false},
|
||||
{"banana", 0, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, ok := parseDC(c.s)
|
||||
if got != c.want || ok != c.ok {
|
||||
t.Errorf("parseDC(%q) = (%d, %v), want (%d, %v)", c.s, got, ok, c.want, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatValue(t *testing.T) {
|
||||
c := &DnDCharacter{STR: 14, DEX: 16, CON: 12, INT: 10, WIS: 8, CHA: 18}
|
||||
cases := []struct {
|
||||
stat string
|
||||
want int
|
||||
}{
|
||||
{"str", 14}, {"dex", 16}, {"con", 12},
|
||||
{"int", 10}, {"wis", 8}, {"cha", 18},
|
||||
{"unknown", 10}, // default
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := statValue(c, tc.stat); got != tc.want {
|
||||
t.Errorf("statValue(%s) = %d, want %d", tc.stat, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRaceSkillBonus(t *testing.T) {
|
||||
athletics, _ := skillInfo(SkillAthletics)
|
||||
persuasion, _ := skillInfo(SkillPersuasion)
|
||||
|
||||
// Half-Elf: +1 to all skills
|
||||
he := &DnDCharacter{Race: RaceHalfElf}
|
||||
if got := raceSkillBonus(he, athletics); got != 1 {
|
||||
t.Errorf("HalfElf athletics = %d, want 1", got)
|
||||
}
|
||||
if got := raceSkillBonus(he, persuasion); got != 1 {
|
||||
t.Errorf("HalfElf persuasion = %d, want 1", got)
|
||||
}
|
||||
|
||||
// Tiefling: +2 only on CHA
|
||||
tf := &DnDCharacter{Race: RaceTiefling}
|
||||
if got := raceSkillBonus(tf, athletics); got != 0 {
|
||||
t.Errorf("Tiefling athletics = %d, want 0", got)
|
||||
}
|
||||
if got := raceSkillBonus(tf, persuasion); got != 2 {
|
||||
t.Errorf("Tiefling persuasion = %d, want 2", got)
|
||||
}
|
||||
|
||||
// Other races: 0
|
||||
hu := &DnDCharacter{Race: RaceHuman}
|
||||
if got := raceSkillBonus(hu, persuasion); got != 0 {
|
||||
t.Errorf("Human persuasion = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPerformSkillCheck_HitRate: a +5 mod vs DC 15 should pass on roll 10+.
|
||||
// That's 11/20 outcomes (10..20) plus auto-success on nat 20 = 11/20 = 55%.
|
||||
// Run many trials and check the rate is in band.
|
||||
func TestPerformSkillCheck_HitRate(t *testing.T) {
|
||||
// Fighter STR 16 (+3 mod) → vs DC 15, hits on roll 12+ = 9/20 = 45%.
|
||||
c := &DnDCharacter{Class: ClassFighter, Race: RaceHuman, STR: 16}
|
||||
hits, trials := 0, 5000
|
||||
for i := 0; i < trials; i++ {
|
||||
if performSkillCheck(c, SkillAthletics, 15).Success {
|
||||
hits++
|
||||
}
|
||||
}
|
||||
rate := float64(hits) / float64(trials)
|
||||
// 45% expected, allow 41-49%.
|
||||
if rate < 0.41 || rate > 0.49 {
|
||||
t.Errorf("hit rate = %.3f, want ~0.45", rate)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPerformSkillCheck_AutoSuccess: nat 20 auto-succeeds even when total < DC.
|
||||
// nat 1 auto-fails even when total >= DC.
|
||||
func TestPerformSkillCheck_NatExtremes(t *testing.T) {
|
||||
c := &DnDCharacter{Class: ClassMage, Race: RaceHuman, INT: 1}
|
||||
// INT 1 → mod -5. Vs DC 30 (impossible), only nat 20 wins.
|
||||
saw20, sawNon20 := 0, 0
|
||||
for i := 0; i < 500; i++ {
|
||||
r := performSkillCheck(c, SkillArcana, 30)
|
||||
if r.Success {
|
||||
if r.Roll == 20 {
|
||||
saw20++
|
||||
} else {
|
||||
sawNon20++
|
||||
}
|
||||
}
|
||||
}
|
||||
if saw20 == 0 {
|
||||
t.Error("never saw a nat-20 success at impossible DC over 500 rolls")
|
||||
}
|
||||
if sawNon20 > 0 {
|
||||
t.Errorf("got %d non-nat-20 successes at DC 30 with -5 mod (impossible)", sawNon20)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkillCheckResult_Auto(t *testing.T) {
|
||||
c := &DnDCharacter{Class: ClassFighter, STR: 18}
|
||||
// Force run until we see at least one auto-result and verify shape.
|
||||
for i := 0; i < 200; i++ {
|
||||
r := performSkillCheck(c, SkillAthletics, 15)
|
||||
if r.Roll == 20 {
|
||||
if !r.Auto || !r.Success {
|
||||
t.Errorf("nat 20 should be auto-success: %+v", r)
|
||||
}
|
||||
}
|
||||
if r.Roll == 1 {
|
||||
if !r.Auto || r.Success {
|
||||
t.Errorf("nat 1 should be auto-fail: %+v", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,609 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 9 — spell system.
|
||||
//
|
||||
// Implements the registry side of gogobee_spell_system.md: 76 in-scope spells
|
||||
// (3 reaction spells deferred to Phase 11), three casters (Mage/Cleric/Ranger),
|
||||
// spell slots, spell save DC, spell attack bonus, and the migration helper
|
||||
// that auto-grants a sensible known list to existing players.
|
||||
//
|
||||
// SP2/SP3 (in dnd_spells_cast.go and dnd_combat.go) handle !cast and the
|
||||
// pending-cast resolution at combat time.
|
||||
|
||||
// ── Effect categories ────────────────────────────────────────────────────────
|
||||
|
||||
type SpellEffectKind string
|
||||
|
||||
const (
|
||||
// In-combat / pre-combat (queued via pending_cast)
|
||||
EffectDamageAttack SpellEffectKind = "damage_attack" // spell attack roll vs AC
|
||||
EffectDamageSave SpellEffectKind = "damage_save" // target saves; half on success
|
||||
EffectDamageAuto SpellEffectKind = "damage_auto" // no save, no attack (Magic Missile)
|
||||
EffectControl SpellEffectKind = "control" // save vs DC; failure → condition
|
||||
EffectBuffSelf SpellEffectKind = "buff_self" // AC/attack/HP self-buff for next fight
|
||||
EffectBuffAlly SpellEffectKind = "buff_ally" // same, on a target player
|
||||
// Out-of-combat / immediate-resolution
|
||||
EffectSpellHeal SpellEffectKind = "spell_heal"
|
||||
EffectUtility SpellEffectKind = "utility"
|
||||
// Deferred to Phase 11 (turn-based bosses)
|
||||
EffectReaction SpellEffectKind = "reaction"
|
||||
)
|
||||
|
||||
// ── Spell timing & damage type ───────────────────────────────────────────────
|
||||
|
||||
type SpellCastTime string
|
||||
|
||||
const (
|
||||
CastAction SpellCastTime = "action"
|
||||
CastBonusAction SpellCastTime = "bonus_action"
|
||||
CastReaction SpellCastTime = "reaction"
|
||||
CastRitual SpellCastTime = "ritual" // 10 min, no slot
|
||||
)
|
||||
|
||||
// SpellDefinition is the static description of a spell. Not stored per-player;
|
||||
// known spells are tracked in dnd_known_spells, slot pool in dnd_spell_slots,
|
||||
// and the queued cast lives in dnd_character.pending_cast as a JSON blob.
|
||||
type SpellDefinition struct {
|
||||
ID string
|
||||
Name string
|
||||
Level int // 0 = cantrip
|
||||
School string
|
||||
Classes []DnDClass
|
||||
Effect SpellEffectKind
|
||||
CastTime SpellCastTime
|
||||
Concentration bool
|
||||
// SaveStat — empty for attack-roll or auto-effect spells.
|
||||
SaveStat string // "STR" | "DEX" | "CON" | "INT" | "WIS" | "CHA"
|
||||
// AttackRoll — true for spell attack rolls (Fire Bolt, Inflict Wounds).
|
||||
AttackRoll bool
|
||||
// DamageDice — descriptive only ("3d6", "1d10"). Roll bounds tested in
|
||||
// dnd_spells_test.go via simple regex on this field.
|
||||
DamageDice string
|
||||
DamageType string
|
||||
Description string
|
||||
// Upcast describes scaling at higher slots ("+1d6 per slot above 3rd").
|
||||
Upcast string
|
||||
// MaterialCost is in coins; non-zero spells (Revivify, Raise Dead) debit
|
||||
// at cast time and refuse if balance is short.
|
||||
MaterialCost int
|
||||
// AOE — true when the spell hits all enemies in the encounter.
|
||||
AOE bool
|
||||
}
|
||||
|
||||
// ── Registry ─────────────────────────────────────────────────────────────────
|
||||
|
||||
var dndSpellRegistry = func() map[string]SpellDefinition {
|
||||
out := make(map[string]SpellDefinition, 80)
|
||||
for _, s := range buildSpellList() {
|
||||
out[s.ID] = s
|
||||
}
|
||||
return out
|
||||
}()
|
||||
|
||||
func lookupSpell(id string) (SpellDefinition, bool) {
|
||||
s, ok := dndSpellRegistry[strings.ToLower(strings.TrimSpace(id))]
|
||||
return s, ok
|
||||
}
|
||||
|
||||
// parseSpell accepts loose user input ("Fire Bolt", "fire-bolt", "fire_bolt").
|
||||
func parseSpell(s string) (SpellDefinition, bool) {
|
||||
key := strings.ToLower(strings.TrimSpace(s))
|
||||
key = strings.ReplaceAll(key, " ", "_")
|
||||
key = strings.ReplaceAll(key, "-", "_")
|
||||
if def, ok := dndSpellRegistry[key]; ok {
|
||||
return def, true
|
||||
}
|
||||
for _, def := range dndSpellRegistry {
|
||||
if strings.EqualFold(def.Name, s) {
|
||||
return def, true
|
||||
}
|
||||
}
|
||||
return SpellDefinition{}, false
|
||||
}
|
||||
|
||||
func spellsForClass(class DnDClass, levelMax int) []SpellDefinition {
|
||||
var out []SpellDefinition
|
||||
for _, s := range dndSpellRegistry {
|
||||
if s.Level > levelMax {
|
||||
continue
|
||||
}
|
||||
for _, c := range s.Classes {
|
||||
if c == class {
|
||||
out = append(out, s)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ── Slot tables ──────────────────────────────────────────────────────────────
|
||||
|
||||
// slotsForClassLevel returns the spell slot pool a caster of this class+level
|
||||
// should have at full rest. Returned map is slot_level → total. Non-casters
|
||||
// return an empty map.
|
||||
func slotsForClassLevel(class DnDClass, level int) map[int]int {
|
||||
if level < 1 {
|
||||
return nil
|
||||
}
|
||||
switch class {
|
||||
case ClassMage:
|
||||
return mageSlots(level)
|
||||
case ClassCleric:
|
||||
return clericSlots(level)
|
||||
case ClassRanger:
|
||||
return rangerSlots(level)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Tables transcribed from gogobee_spell_system.md §1. We interpolate
|
||||
// between the doc's milestone rows so every level 1..20 has a defined pool.
|
||||
func mageSlots(level int) map[int]int {
|
||||
// Standard 5e full caster table (mage = wizard).
|
||||
rows := [][6]int{
|
||||
// L1, L2, L3, L4, L5
|
||||
{2, 0, 0, 0, 0}, // 1
|
||||
{3, 0, 0, 0, 0}, // 2
|
||||
{4, 2, 0, 0, 0}, // 3
|
||||
{4, 3, 0, 0, 0}, // 4
|
||||
{4, 3, 2, 0, 0}, // 5
|
||||
{4, 3, 3, 0, 0}, // 6
|
||||
{4, 3, 3, 1, 0}, // 7
|
||||
{4, 3, 3, 2, 0}, // 8
|
||||
{4, 3, 3, 3, 1}, // 9
|
||||
{4, 3, 3, 3, 2}, // 10
|
||||
{4, 3, 3, 3, 2}, // 11
|
||||
{4, 3, 3, 3, 2}, // 12
|
||||
{4, 3, 3, 3, 2}, // 13
|
||||
{4, 3, 3, 3, 2}, // 14
|
||||
{4, 3, 3, 3, 2}, // 15
|
||||
{4, 3, 3, 3, 2}, // 16
|
||||
{4, 3, 3, 3, 2}, // 17
|
||||
{4, 3, 3, 3, 3}, // 18
|
||||
{4, 3, 3, 3, 3}, // 19
|
||||
{4, 3, 3, 3, 3}, // 20
|
||||
}
|
||||
if level > len(rows) {
|
||||
level = len(rows)
|
||||
}
|
||||
r := rows[level-1]
|
||||
return packSlots(r[0], r[1], r[2], r[3], r[4])
|
||||
}
|
||||
|
||||
func clericSlots(level int) map[int]int {
|
||||
rows := [][6]int{
|
||||
{2, 0, 0, 0, 0}, // 1
|
||||
{3, 0, 0, 0, 0}, // 2
|
||||
{4, 2, 0, 0, 0}, // 3
|
||||
{4, 3, 0, 0, 0}, // 4
|
||||
{4, 3, 2, 0, 0}, // 5
|
||||
{4, 3, 3, 0, 0}, // 6
|
||||
{4, 3, 3, 1, 0}, // 7
|
||||
{4, 3, 3, 2, 0}, // 8
|
||||
{4, 3, 3, 3, 1}, // 9
|
||||
{4, 3, 3, 3, 2}, // 10
|
||||
{4, 3, 3, 3, 2}, // 11
|
||||
{4, 3, 3, 3, 2}, // 12
|
||||
{4, 3, 3, 3, 2}, // 13
|
||||
{4, 3, 3, 3, 2}, // 14
|
||||
{4, 3, 3, 3, 2}, // 15
|
||||
{4, 3, 3, 3, 2}, // 16
|
||||
{4, 3, 3, 3, 3}, // 17
|
||||
{4, 3, 3, 3, 3}, // 18
|
||||
{4, 3, 3, 3, 3}, // 19
|
||||
{4, 3, 3, 3, 3}, // 20
|
||||
}
|
||||
if level > len(rows) {
|
||||
level = len(rows)
|
||||
}
|
||||
r := rows[level-1]
|
||||
return packSlots(r[0], r[1], r[2], r[3], r[4])
|
||||
}
|
||||
|
||||
func rangerSlots(level int) map[int]int {
|
||||
// Half-caster — no slots until L2, max 3rd-level.
|
||||
rows := [][6]int{
|
||||
{0, 0, 0, 0, 0}, // 1
|
||||
{2, 0, 0, 0, 0}, // 2
|
||||
{3, 0, 0, 0, 0}, // 3
|
||||
{3, 0, 0, 0, 0}, // 4
|
||||
{3, 0, 0, 0, 0}, // 5
|
||||
{3, 0, 0, 0, 0}, // 6
|
||||
{3, 1, 0, 0, 0}, // 7 (doc table)
|
||||
{3, 2, 0, 0, 0}, // 8
|
||||
{3, 2, 0, 0, 0}, // 9 (doc has 3/2 known; slots step at 9 too)
|
||||
{3, 2, 0, 0, 0}, // 10
|
||||
{3, 2, 0, 0, 0}, // 11
|
||||
{3, 2, 0, 0, 0}, // 12
|
||||
{3, 2, 1, 0, 0}, // 13
|
||||
{3, 2, 1, 0, 0}, // 14
|
||||
{3, 2, 1, 0, 0}, // 15
|
||||
{3, 2, 1, 0, 0}, // 16
|
||||
{3, 2, 2, 0, 0}, // 17
|
||||
{3, 2, 2, 0, 0}, // 18
|
||||
{3, 3, 2, 0, 0}, // 19
|
||||
{3, 3, 2, 0, 0}, // 20
|
||||
}
|
||||
if level > len(rows) {
|
||||
level = len(rows)
|
||||
}
|
||||
r := rows[level-1]
|
||||
return packSlots(r[0], r[1], r[2], r[3], r[4])
|
||||
}
|
||||
|
||||
func packSlots(l1, l2, l3, l4, l5 int) map[int]int {
|
||||
out := map[int]int{}
|
||||
for i, n := range []int{l1, l2, l3, l4, l5} {
|
||||
if n > 0 {
|
||||
out[i+1] = n
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ── DC math ──────────────────────────────────────────────────────────────────
|
||||
|
||||
// spellcastingMod returns the ability modifier used for spell DCs and attacks.
|
||||
func spellcastingMod(c *DnDCharacter) int {
|
||||
if c == nil {
|
||||
return 0
|
||||
}
|
||||
switch c.Class {
|
||||
case ClassMage:
|
||||
return abilityModifier(c.INT)
|
||||
case ClassCleric, ClassRanger:
|
||||
return abilityModifier(c.WIS)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// spellSaveDC = 8 + proficiency bonus + spellcasting modifier.
|
||||
func spellSaveDC(c *DnDCharacter) int {
|
||||
return 8 + proficiencyBonus(c.Level) + spellcastingMod(c)
|
||||
}
|
||||
|
||||
// spellAttackBonus = proficiency bonus + spellcasting modifier.
|
||||
func spellAttackBonus(c *DnDCharacter) int {
|
||||
return proficiencyBonus(c.Level) + spellcastingMod(c)
|
||||
}
|
||||
|
||||
// classIsCaster returns true for the three caster classes Phase 9 covers.
|
||||
func classIsCaster(class DnDClass) bool {
|
||||
switch class {
|
||||
case ClassMage, ClassCleric, ClassRanger:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ── Slot persistence ─────────────────────────────────────────────────────────
|
||||
|
||||
// setSpellSlotsForLevel writes the slot pool for a class+level, fully
|
||||
// resetting any prior pool. Used by setup/migration/respec.
|
||||
func setSpellSlotsForLevel(userID id.UserID, class DnDClass, level int) error {
|
||||
pool := slotsForClassLevel(class, level)
|
||||
tx, err := db.Get().Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, err := tx.Exec(`DELETE FROM dnd_spell_slots WHERE user_id = ?`, string(userID)); err != nil {
|
||||
return err
|
||||
}
|
||||
for lvl, total := range pool {
|
||||
if _, err := tx.Exec(`
|
||||
INSERT INTO dnd_spell_slots (user_id, slot_level, total, used)
|
||||
VALUES (?, ?, ?, 0)`,
|
||||
string(userID), lvl, total); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// getSpellSlots returns slot_level → (total, used) for a player.
|
||||
func getSpellSlots(userID id.UserID) (map[int][2]int, error) {
|
||||
rows, err := db.Get().Query(
|
||||
`SELECT slot_level, total, used FROM dnd_spell_slots WHERE user_id = ? ORDER BY slot_level`,
|
||||
string(userID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
out := map[int][2]int{}
|
||||
for rows.Next() {
|
||||
var lvl, total, used int
|
||||
if err := rows.Scan(&lvl, &total, &used); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out[lvl] = [2]int{total, used}
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// consumeSpellSlot decrements used+1 if a slot is available at slotLevel.
|
||||
// Returns true on success.
|
||||
func consumeSpellSlot(userID id.UserID, slotLevel int) (bool, error) {
|
||||
res, err := db.Get().Exec(`
|
||||
UPDATE dnd_spell_slots
|
||||
SET used = used + 1
|
||||
WHERE user_id = ? AND slot_level = ? AND used < total`,
|
||||
string(userID), slotLevel)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
// refundSpellSlot re-credits one slot at slotLevel (used in audit-style
|
||||
// rollback paths and voluntary `!cast --drop`).
|
||||
func refundSpellSlot(userID id.UserID, slotLevel int) error {
|
||||
_, err := db.Get().Exec(`
|
||||
UPDATE dnd_spell_slots
|
||||
SET used = MAX(0, used - 1)
|
||||
WHERE user_id = ? AND slot_level = ?`,
|
||||
string(userID), slotLevel)
|
||||
return err
|
||||
}
|
||||
|
||||
// refreshSpellSlots resets used=0 across all of a player's slots. Called
|
||||
// on long rest.
|
||||
func refreshSpellSlots(userID id.UserID) error {
|
||||
_, err := db.Get().Exec(
|
||||
`UPDATE dnd_spell_slots SET used = 0 WHERE user_id = ?`,
|
||||
string(userID))
|
||||
return err
|
||||
}
|
||||
|
||||
// ── Known spells ─────────────────────────────────────────────────────────────
|
||||
|
||||
func addKnownSpell(userID id.UserID, spellID string, source string, prepared bool) error {
|
||||
prep := 1
|
||||
if !prepared {
|
||||
prep = 0
|
||||
}
|
||||
_, err := db.Get().Exec(`
|
||||
INSERT INTO dnd_known_spells (user_id, spell_id, source, prepared)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(user_id, spell_id) DO UPDATE SET source=excluded.source`,
|
||||
string(userID), spellID, source, prep)
|
||||
return err
|
||||
}
|
||||
|
||||
func setSpellPrepared(userID id.UserID, spellID string, prepared bool) error {
|
||||
prep := 0
|
||||
if prepared {
|
||||
prep = 1
|
||||
}
|
||||
_, err := db.Get().Exec(`
|
||||
UPDATE dnd_known_spells SET prepared = ?
|
||||
WHERE user_id = ? AND spell_id = ?`,
|
||||
prep, string(userID), spellID)
|
||||
return err
|
||||
}
|
||||
|
||||
type knownSpellRow struct {
|
||||
SpellID string
|
||||
Source string
|
||||
Prepared bool
|
||||
}
|
||||
|
||||
func listKnownSpells(userID id.UserID) ([]knownSpellRow, error) {
|
||||
rows, err := db.Get().Query(
|
||||
`SELECT spell_id, source, prepared FROM dnd_known_spells
|
||||
WHERE user_id = ? ORDER BY spell_id`,
|
||||
string(userID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []knownSpellRow
|
||||
for rows.Next() {
|
||||
var r knownSpellRow
|
||||
var prep int
|
||||
if err := rows.Scan(&r.SpellID, &r.Source, &prep); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Prepared = prep == 1
|
||||
out = append(out, r)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func playerKnowsSpell(userID id.UserID, spellID string) (bool, bool, error) {
|
||||
var prep int
|
||||
err := db.Get().QueryRow(
|
||||
`SELECT prepared FROM dnd_known_spells WHERE user_id = ? AND spell_id = ?`,
|
||||
string(userID), spellID).Scan(&prep)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return false, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
return true, prep == 1, nil
|
||||
}
|
||||
|
||||
// wipeSpellsForUser clears known + slot rows. Used by !respec.
|
||||
func wipeSpellsForUser(userID id.UserID) error {
|
||||
if _, err := db.Get().Exec(`DELETE FROM dnd_known_spells WHERE user_id = ?`, string(userID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := db.Get().Exec(`DELETE FROM dnd_spell_slots WHERE user_id = ?`, string(userID)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ── Concentration ────────────────────────────────────────────────────────────
|
||||
|
||||
// setConcentration stamps a new concentration spell on the character. Returns
|
||||
// the previous spell id (empty if none) so the caller can narrate the
|
||||
// supersession. Caller is responsible for SaveDnDCharacter.
|
||||
func setConcentration(c *DnDCharacter, spellID string, duration time.Duration) string {
|
||||
prev := c.ConcentrationSpell
|
||||
c.ConcentrationSpell = spellID
|
||||
if duration > 0 {
|
||||
exp := time.Now().Add(duration)
|
||||
c.ConcentrationExpiresAt = &exp
|
||||
} else {
|
||||
c.ConcentrationExpiresAt = nil
|
||||
}
|
||||
return prev
|
||||
}
|
||||
|
||||
// concentrationActive returns the active concentration spell id, or "" if
|
||||
// none / expired. Mutates the caller's DnDCharacter copy when expiry is hit
|
||||
// (caller should Save afterwards if it cares).
|
||||
func concentrationActive(c *DnDCharacter) string {
|
||||
if c == nil || c.ConcentrationSpell == "" {
|
||||
return ""
|
||||
}
|
||||
if c.ConcentrationExpiresAt != nil && time.Now().After(*c.ConcentrationExpiresAt) {
|
||||
c.ConcentrationSpell = ""
|
||||
c.ConcentrationExpiresAt = nil
|
||||
return ""
|
||||
}
|
||||
return c.ConcentrationSpell
|
||||
}
|
||||
|
||||
// ── Migration / auto-grant ───────────────────────────────────────────────────
|
||||
|
||||
// ensureSpellsForCharacter populates a sensible known-spell list and slot
|
||||
// pool for a caster who has none. Idempotent: skips if any spells are
|
||||
// already known for the user. Called from !setup confirm and from
|
||||
// ensureDnDCharacterForCombat (auto-migration path).
|
||||
//
|
||||
// Defaults are conservative — a caster always has at least cantrips and
|
||||
// enough leveled options to be functional. Players can swap via
|
||||
// !spells learn (Mage) or !prepare (Cleric) once SP4 lands.
|
||||
func ensureSpellsForCharacter(c *DnDCharacter) error {
|
||||
if c == nil || !classIsCaster(c.Class) {
|
||||
return nil
|
||||
}
|
||||
existing, err := listKnownSpells(c.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(existing) > 0 {
|
||||
// Refresh the slot pool in case level has changed since the prior
|
||||
// grant (covers level-up between sessions).
|
||||
return setSpellSlotsForLevel(c.UserID, c.Class, c.Level)
|
||||
}
|
||||
defaults := defaultKnownSpells(c.Class, c.Level)
|
||||
for _, sid := range defaults {
|
||||
// Cleric "prepares" daily — but prep system is SP4. Until then,
|
||||
// every default cleric spell is auto-prepared so !cast works.
|
||||
if err := addKnownSpell(c.UserID, sid, "class", true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return setSpellSlotsForLevel(c.UserID, c.Class, c.Level)
|
||||
}
|
||||
|
||||
// defaultKnownSpells returns a sensible starter list for class+level. Tuned
|
||||
// to give each caster at least a damage option, a buff/utility, and a heal
|
||||
// where applicable. Cantrips first, then leveled spells up to the player's
|
||||
// max slot level. Picks are deterministic so tests can lock them down.
|
||||
func defaultKnownSpells(class DnDClass, level int) []string {
|
||||
maxSlot := highestAvailableSlot(class, level)
|
||||
switch class {
|
||||
case ClassMage:
|
||||
out := []string{"fire_bolt", "minor_illusion", "mending"}
|
||||
if level >= 1 {
|
||||
out = append(out, "magic_missile", "mage_armor", "shield", "burning_hands", "detect_magic")
|
||||
}
|
||||
if maxSlot >= 2 {
|
||||
out = append(out, "scorching_ray", "misty_step", "mirror_image")
|
||||
}
|
||||
if maxSlot >= 3 {
|
||||
out = append(out, "fireball", "counterspell")
|
||||
}
|
||||
if maxSlot >= 4 {
|
||||
out = append(out, "ice_storm", "greater_invisibility")
|
||||
}
|
||||
if maxSlot >= 5 {
|
||||
out = append(out, "cone_of_cold", "wall_of_force")
|
||||
}
|
||||
return out
|
||||
case ClassCleric:
|
||||
out := []string{"sacred_flame", "guidance", "mending"}
|
||||
if level >= 1 {
|
||||
out = append(out, "cure_wounds", "healing_word_spell", "bless", "guiding_bolt", "shield_of_faith")
|
||||
}
|
||||
if maxSlot >= 2 {
|
||||
out = append(out, "spiritual_weapon", "lesser_restoration", "aid")
|
||||
}
|
||||
if maxSlot >= 3 {
|
||||
out = append(out, "spirit_guardians", "revivify", "mass_healing_word")
|
||||
}
|
||||
if maxSlot >= 4 {
|
||||
out = append(out, "guardian_of_faith", "death_ward")
|
||||
}
|
||||
if maxSlot >= 5 {
|
||||
out = append(out, "mass_cure_wounds", "flame_strike")
|
||||
}
|
||||
return out
|
||||
case ClassRanger:
|
||||
// Rangers have no spells until level 2.
|
||||
if level < 2 {
|
||||
return []string{"guidance", "thorn_whip"}
|
||||
}
|
||||
out := []string{"guidance", "thorn_whip"}
|
||||
out = append(out, "hunters_mark", "cure_wounds")
|
||||
if maxSlot >= 2 {
|
||||
out = append(out, "pass_without_trace", "spike_growth")
|
||||
}
|
||||
if maxSlot >= 3 {
|
||||
out = append(out, "lightning_arrow", "conjure_barrage")
|
||||
}
|
||||
return out
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func highestAvailableSlot(class DnDClass, level int) int {
|
||||
pool := slotsForClassLevel(class, level)
|
||||
high := 0
|
||||
for lvl := range pool {
|
||||
if lvl > high {
|
||||
high = lvl
|
||||
}
|
||||
}
|
||||
return high
|
||||
}
|
||||
|
||||
// ── Display helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
func displaySpellName(spellID string) string {
|
||||
if s, ok := lookupSpell(spellID); ok {
|
||||
return s.Name
|
||||
}
|
||||
return spellID
|
||||
}
|
||||
|
||||
func renderSlotLine(slots map[int][2]int) string {
|
||||
if len(slots) == 0 {
|
||||
return "_(no spell slots)_"
|
||||
}
|
||||
var parts []string
|
||||
for lvl := 1; lvl <= 5; lvl++ {
|
||||
if pair, ok := slots[lvl]; ok {
|
||||
parts = append(parts, fmt.Sprintf("L%d %d/%d", lvl, pair[0]-pair[1], pair[0]))
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, " · ")
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
package plugin
|
||||
|
||||
// Phase 9 spell registry data. All 76 in-scope spells from
|
||||
// gogobee_spell_system.md. Reaction spells (Shield, Counterspell,
|
||||
// Absorb Elements) are included with EffectReaction so the registry is
|
||||
// complete; SP2's !cast refuses them with a "Phase 11" note.
|
||||
|
||||
func buildSpellList() []SpellDefinition {
|
||||
mage := []DnDClass{ClassMage}
|
||||
cleric := []DnDClass{ClassCleric}
|
||||
ranger := []DnDClass{ClassRanger}
|
||||
mageCleric := []DnDClass{ClassMage, ClassCleric}
|
||||
clericRanger := []DnDClass{ClassCleric, ClassRanger}
|
||||
rangerCleric := []DnDClass{ClassRanger, ClassCleric}
|
||||
allCasters := []DnDClass{ClassMage, ClassCleric, ClassRanger}
|
||||
|
||||
return []SpellDefinition{
|
||||
// ── Cantrips (level 0) ────────────────────────────────────────────────
|
||||
{ID: "fire_bolt", Name: "Fire Bolt", Level: 0, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "1d10", DamageType: "fire",
|
||||
Description: "Hurl a mote of fire at a target.",
|
||||
Upcast: "2d10 at L5, 3d10 at L11"},
|
||||
{ID: "toll_the_dead", Name: "Toll the Dead", Level: 0, School: "necromancy",
|
||||
Classes: mageCleric, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "WIS", DamageDice: "1d8", DamageType: "necrotic",
|
||||
Description: "1d8 necrotic; 1d12 if target is missing HP."},
|
||||
{ID: "chill_touch", Name: "Chill Touch", Level: 0, School: "necromancy",
|
||||
Classes: mageCleric, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "1d8", DamageType: "necrotic",
|
||||
Description: "Spectral hand — target can't heal until next turn."},
|
||||
{ID: "poison_spray", Name: "Poison Spray", Level: 0, School: "conjuration",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "CON", DamageDice: "1d12", DamageType: "poison",
|
||||
Description: "Puff of noxious gas; CON save or full damage."},
|
||||
{ID: "shocking_grasp", Name: "Shocking Grasp", Level: 0, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "1d8", DamageType: "lightning",
|
||||
Description: "Lightning leaps from your touch; target loses Reaction."},
|
||||
{ID: "sacred_flame", Name: "Sacred Flame", Level: 0, School: "evocation",
|
||||
Classes: cleric, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "1d8", DamageType: "radiant",
|
||||
Description: "Flame-like radiance descends; ignores cover."},
|
||||
{ID: "guidance", Name: "Guidance", Level: 0, School: "divination",
|
||||
Classes: clericRanger, Effect: EffectUtility, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "+1d4 to one ability check (self or ally)."},
|
||||
{ID: "shillelagh", Name: "Shillelagh", Level: 0, School: "transmutation",
|
||||
Classes: rangerCleric, Effect: EffectBuffSelf, CastTime: CastBonusAction,
|
||||
Concentration: true,
|
||||
Description: "Club/staff uses WIS for attack+damage; 1d8."},
|
||||
{ID: "thorn_whip", Name: "Thorn Whip", Level: 0, School: "transmutation",
|
||||
Classes: ranger, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "1d6", DamageType: "piercing",
|
||||
Description: "Vine of thorns; pull target 10 ft."},
|
||||
{ID: "mending", Name: "Mending", Level: 0, School: "transmutation",
|
||||
Classes: allCasters, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Repair one non-magical item. Out of combat only."},
|
||||
{ID: "message", Name: "Message", Level: 0, School: "transmutation",
|
||||
Classes: mage, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Whisper to target up to 120 ft."},
|
||||
{ID: "minor_illusion", Name: "Minor Illusion", Level: 0, School: "illusion",
|
||||
Classes: mage, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Create a sound or image."},
|
||||
|
||||
// ── 1st level — Mage ──────────────────────────────────────────────────
|
||||
{ID: "magic_missile", Name: "Magic Missile", Level: 1, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageAuto, CastTime: CastAction,
|
||||
DamageDice: "3d4+3", DamageType: "force",
|
||||
Description: "Three darts × 1d4+1 force; auto-hit.",
|
||||
Upcast: "+1 dart per slot above 1st"},
|
||||
{ID: "thunderwave", Name: "Thunderwave", Level: 1, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "CON", DamageDice: "2d8", DamageType: "thunder", AOE: true,
|
||||
Description: "Wave of force in 15 ft cube; push 10 ft.",
|
||||
Upcast: "+1d8 per slot above 1st"},
|
||||
{ID: "mage_armor", Name: "Mage Armor", Level: 1, School: "abjuration",
|
||||
Classes: mage, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Description: "AC = 13 + DEX mod (no armor required) for 8 hours."},
|
||||
{ID: "burning_hands", Name: "Burning Hands", Level: 1, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "3d6", DamageType: "fire", AOE: true,
|
||||
Description: "Cone of fire; DEX save half.",
|
||||
Upcast: "+1d6 per slot above 1st"},
|
||||
{ID: "detect_magic", Name: "Detect Magic", Level: 1, School: "divination",
|
||||
Classes: mage, Effect: EffectUtility, CastTime: CastRitual,
|
||||
Concentration: true,
|
||||
Description: "Sense magic within 30 ft. Ritual castable (no slot)."},
|
||||
{ID: "fog_cloud", Name: "Fog Cloud", Level: 1, School: "conjuration",
|
||||
Classes: []DnDClass{ClassMage, ClassRanger}, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "20 ft heavily obscured radius. Attacks inside have disadvantage."},
|
||||
{ID: "grease", Name: "Grease", Level: 1, School: "conjuration",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
SaveStat: "DEX", AOE: true,
|
||||
Description: "10 ft square; DEX save or Prone. Difficult terrain."},
|
||||
{ID: "shield", Name: "Shield", Level: 1, School: "abjuration",
|
||||
Classes: mage, Effect: EffectReaction, CastTime: CastReaction,
|
||||
Description: "+5 AC as Reaction until next turn. (Phase 11)"},
|
||||
{ID: "sleep", Name: "Sleep", Level: 1, School: "enchantment",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
AOE: true,
|
||||
Description: "Incapacitate creatures totaling 5d8 HP (weakest first).",
|
||||
Upcast: "+2d8 per slot above 1st"},
|
||||
{ID: "chromatic_orb", Name: "Chromatic Orb", Level: 1, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "3d8", DamageType: "varies",
|
||||
Description: "3d8 of chosen damage type.",
|
||||
Upcast: "+1d8 per slot above 1st"},
|
||||
|
||||
// ── 1st level — Cleric ────────────────────────────────────────────────
|
||||
{ID: "cure_wounds", Name: "Cure Wounds", Level: 1, School: "evocation",
|
||||
Classes: clericRanger, Effect: EffectSpellHeal, CastTime: CastAction,
|
||||
DamageDice: "1d8",
|
||||
Description: "Heal 1d8 + WIS mod HP. Touch.",
|
||||
Upcast: "+1d8 per slot above 1st"},
|
||||
{ID: "bless", Name: "Bless", Level: 1, School: "enchantment",
|
||||
Classes: cleric, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "Up to 3 targets: +1d4 to attack rolls and saves. 1 min."},
|
||||
{ID: "inflict_wounds", Name: "Inflict Wounds", Level: 1, School: "necromancy",
|
||||
Classes: cleric, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "3d10", DamageType: "necrotic",
|
||||
Description: "3d10 necrotic. Melee spell attack.",
|
||||
Upcast: "+1d10 per slot above 1st"},
|
||||
{ID: "guiding_bolt", Name: "Guiding Bolt", Level: 1, School: "evocation",
|
||||
Classes: cleric, Effect: EffectDamageAttack, CastTime: CastAction,
|
||||
AttackRoll: true, DamageDice: "4d6", DamageType: "radiant",
|
||||
Description: "Next attack on target has advantage.",
|
||||
Upcast: "+1d6 per slot above 1st"},
|
||||
{ID: "shield_of_faith", Name: "Shield of Faith", Level: 1, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectBuffAlly, CastTime: CastBonusAction,
|
||||
Concentration: true,
|
||||
Description: "+2 AC to one target. 10 min."},
|
||||
{ID: "healing_word_spell", Name: "Healing Word", Level: 1, School: "evocation",
|
||||
Classes: cleric, Effect: EffectSpellHeal, CastTime: CastBonusAction,
|
||||
DamageDice: "1d4",
|
||||
Description: "1d4 + WIS mod HP. Range 60 ft.",
|
||||
Upcast: "+1d4 per slot above 1st"},
|
||||
{ID: "command", Name: "Command", Level: 1, School: "enchantment",
|
||||
Classes: cleric, Effect: EffectControl, CastTime: CastAction,
|
||||
SaveStat: "WIS",
|
||||
Description: "One-word command (Flee/Grovel/Halt). 1 turn.",
|
||||
Upcast: "+1 target per slot above 1st"},
|
||||
{ID: "protection_from_evil", Name: "Protection from Evil and Good", Level: 1, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "Aberrations/fiends/undead have disadvantage vs. target."},
|
||||
|
||||
// ── 1st level — Ranger ────────────────────────────────────────────────
|
||||
{ID: "hunters_mark", Name: "Hunter's Mark", Level: 1, School: "divination",
|
||||
Classes: ranger, Effect: EffectBuffSelf, CastTime: CastBonusAction,
|
||||
Concentration: true,
|
||||
Description: "+1d6 damage to marked target; track as bonus action. 1 hr."},
|
||||
{ID: "ensnaring_strike", Name: "Ensnaring Strike", Level: 1, School: "conjuration",
|
||||
Classes: ranger, Effect: EffectControl, CastTime: CastBonusAction,
|
||||
Concentration: true, SaveStat: "STR",
|
||||
Description: "On hit: STR save or Restrained; 1d6/turn."},
|
||||
{ID: "speak_with_animals", Name: "Speak with Animals", Level: 1, School: "divination",
|
||||
Classes: ranger, Effect: EffectUtility, CastTime: CastRitual,
|
||||
Description: "Communicate with beasts. 10 min."},
|
||||
{ID: "absorb_elements", Name: "Absorb Elements", Level: 1, School: "abjuration",
|
||||
Classes: ranger, Effect: EffectReaction, CastTime: CastReaction,
|
||||
Description: "Reaction: resistance to incoming elemental damage. (Phase 11)"},
|
||||
|
||||
// ── 2nd level — Mage ──────────────────────────────────────────────────
|
||||
{ID: "scorching_ray", Name: "Scorching Ray", Level: 2, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageAuto, CastTime: CastAction,
|
||||
DamageDice: "6d6", DamageType: "fire",
|
||||
Description: "3 rays × 2d6 fire; each is a separate auto-hit.",
|
||||
Upcast: "+1 ray per slot above 2nd"},
|
||||
{ID: "mirror_image", Name: "Mirror Image", Level: 2, School: "illusion",
|
||||
Classes: mage, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Description: "3 duplicates absorb hits."},
|
||||
{ID: "misty_step", Name: "Misty Step", Level: 2, School: "conjuration",
|
||||
Classes: mage, Effect: EffectBuffSelf, CastTime: CastBonusAction,
|
||||
Description: "Bonus-action teleport up to 30 ft."},
|
||||
{ID: "hold_person", Name: "Hold Person", Level: 2, School: "enchantment",
|
||||
Classes: mageCleric, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS",
|
||||
Description: "Paralyzed; auto-crit melee while held.",
|
||||
Upcast: "+1 target per slot above 2nd"},
|
||||
{ID: "shatter", Name: "Shatter", Level: 2, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "CON", DamageDice: "3d8", DamageType: "thunder", AOE: true,
|
||||
Description: "3d8 thunder in 10 ft sphere.",
|
||||
Upcast: "+1d8 per slot above 2nd"},
|
||||
{ID: "blur", Name: "Blur", Level: 2, School: "illusion",
|
||||
Classes: mage, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "All attacks vs. you have disadvantage."},
|
||||
{ID: "web", Name: "Web", Level: 2, School: "conjuration",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "STR", AOE: true,
|
||||
Description: "20 ft cube; Restrained (STR DC to escape)."},
|
||||
{ID: "levitate", Name: "Levitate", Level: 2, School: "transmutation",
|
||||
Classes: mage, Effect: EffectUtility, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "CON",
|
||||
Description: "Float up to 20 ft; immune to ground-based effects."},
|
||||
{ID: "knock", Name: "Knock", Level: 2, School: "transmutation",
|
||||
Classes: mage, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Open any mundane lock or magically sealed door."},
|
||||
|
||||
// ── 2nd level — Cleric ────────────────────────────────────────────────
|
||||
{ID: "spiritual_weapon", Name: "Spiritual Weapon", Level: 2, School: "evocation",
|
||||
Classes: cleric, Effect: EffectBuffSelf, CastTime: CastBonusAction,
|
||||
DamageDice: "1d8",
|
||||
Description: "Bonus-action spectral weapon attacks 1d8+WIS each turn. 1 min.",
|
||||
Upcast: "+1d8 per 2 slots above 2nd"},
|
||||
{ID: "lesser_restoration", Name: "Lesser Restoration", Level: 2, School: "abjuration",
|
||||
Classes: clericRanger, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Remove one condition (Blinded/Deafened/Paralyzed/Poisoned)."},
|
||||
{ID: "prayer_of_healing", Name: "Prayer of Healing", Level: 2, School: "evocation",
|
||||
Classes: cleric, Effect: EffectSpellHeal, CastTime: CastAction,
|
||||
DamageDice: "2d8",
|
||||
Description: "Up to 6 targets: 2d8 + WIS mod HP. Out of combat only."},
|
||||
{ID: "silence", Name: "Silence", Level: 2, School: "illusion",
|
||||
Classes: clericRanger, Effect: EffectUtility, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "No sound in 20 ft sphere; no verbal spells."},
|
||||
{ID: "aid", Name: "Aid", Level: 2, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Description: "3 targets: +5 max HP and current HP. 8 hr.",
|
||||
Upcast: "+5 HP per slot above 2nd"},
|
||||
{ID: "augury", Name: "Augury", Level: 2, School: "divination",
|
||||
Classes: cleric, Effect: EffectUtility, CastTime: CastRitual,
|
||||
Description: "Omen about action in next 30 min. TwinBee delivers."},
|
||||
|
||||
// ── 2nd level — Ranger ────────────────────────────────────────────────
|
||||
{ID: "pass_without_trace", Name: "Pass Without Trace", Level: 2, School: "abjuration",
|
||||
Classes: ranger, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "+10 to Stealth; can't be tracked magically."},
|
||||
{ID: "spike_growth", Name: "Spike Growth", Level: 2, School: "transmutation",
|
||||
Classes: ranger, Effect: EffectDamageAuto, CastTime: CastAction,
|
||||
Concentration: true, DamageDice: "2d4", DamageType: "piercing", AOE: true,
|
||||
Description: "20 ft radius; 2d4 per 5 ft moved through. Difficult terrain."},
|
||||
{ID: "beast_sense", Name: "Beast Sense", Level: 2, School: "divination",
|
||||
Classes: ranger, Effect: EffectUtility, CastTime: CastRitual,
|
||||
Concentration: true,
|
||||
Description: "See/hear through a beast's senses."},
|
||||
{ID: "cordon_of_arrows", Name: "Cordon of Arrows", Level: 2, School: "transmutation",
|
||||
Classes: ranger, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Description: "4 arrows guard area; fire on intruders (1d6+DEX). 8 hr."},
|
||||
{ID: "find_traps", Name: "Find Traps", Level: 2, School: "divination",
|
||||
Classes: ranger, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Detect presence of traps within 120 ft."},
|
||||
|
||||
// ── 3rd level — Mage ──────────────────────────────────────────────────
|
||||
{ID: "fireball", Name: "Fireball", Level: 3, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "8d6", DamageType: "fire", AOE: true,
|
||||
Description: "8d6 fire in 20 ft radius. DEX save half.",
|
||||
Upcast: "+1d6 per slot above 3rd"},
|
||||
{ID: "lightning_bolt", Name: "Lightning Bolt", Level: 3, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "8d6", DamageType: "lightning", AOE: true,
|
||||
Description: "8d6 lightning in 100 ft line. DEX save half.",
|
||||
Upcast: "+1d6 per slot above 3rd"},
|
||||
{ID: "counterspell", Name: "Counterspell", Level: 3, School: "abjuration",
|
||||
Classes: mage, Effect: EffectReaction, CastTime: CastReaction,
|
||||
Description: "Reaction: cancel a spell of 3rd level or lower. (Phase 11)"},
|
||||
{ID: "fly", Name: "Fly", Level: 3, School: "transmutation",
|
||||
Classes: mage, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "Target gains 60 ft fly speed. 10 min."},
|
||||
{ID: "hypnotic_pattern", Name: "Hypnotic Pattern", Level: 3, School: "illusion",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS", AOE: true,
|
||||
Description: "Creatures in 30 ft cube: Incapacitated, speed 0."},
|
||||
{ID: "dispel_magic", Name: "Dispel Magic", Level: 3, School: "abjuration",
|
||||
Classes: mageCleric, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "End one magical effect on target."},
|
||||
{ID: "slow", Name: "Slow", Level: 3, School: "transmutation",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS", AOE: true,
|
||||
Description: "Up to 6 targets: halve speed, -2 AC, no reactions."},
|
||||
{ID: "animate_dead", Name: "Animate Dead", Level: 3, School: "necromancy",
|
||||
Classes: mageCleric, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Animate up to 3 corpses as skeletons/zombies. 24 hr."},
|
||||
|
||||
// ── 3rd level — Cleric ────────────────────────────────────────────────
|
||||
{ID: "spirit_guardians", Name: "Spirit Guardians", Level: 3, School: "conjuration",
|
||||
Classes: cleric, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS", DamageDice: "3d8",
|
||||
DamageType: "radiant", AOE: true,
|
||||
Description: "15 ft aura: 3d8/turn to enemies. WIS save half.",
|
||||
Upcast: "+1d8 per slot above 3rd"},
|
||||
{ID: "revivify", Name: "Revivify", Level: 3, School: "necromancy",
|
||||
Classes: cleric, Effect: EffectUtility, CastTime: CastAction,
|
||||
MaterialCost: 300,
|
||||
Description: "Restore a creature dead <1 min to 1 HP. 300-coin diamond."},
|
||||
{ID: "mass_healing_word", Name: "Mass Healing Word", Level: 3, School: "evocation",
|
||||
Classes: cleric, Effect: EffectSpellHeal, CastTime: CastBonusAction,
|
||||
DamageDice: "1d4",
|
||||
Description: "Up to 6 targets: 1d4 + WIS mod HP."},
|
||||
{ID: "beacon_of_hope", Name: "Beacon of Hope", Level: 3, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "Targets have advantage on WIS saves and death saves; max healing."},
|
||||
{ID: "remove_curse", Name: "Remove Curse", Level: 3, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "End one curse on target or object."},
|
||||
|
||||
// ── 3rd level — Ranger ────────────────────────────────────────────────
|
||||
{ID: "lightning_arrow", Name: "Lightning Arrow", Level: 3, School: "transmutation",
|
||||
Classes: ranger, Effect: EffectDamageSave, CastTime: CastBonusAction,
|
||||
SaveStat: "DEX", DamageDice: "4d8", DamageType: "lightning", AOE: true,
|
||||
Description: "Ranged: 4d8 lightning on hit; 2d8 to creatures within 10 ft."},
|
||||
{ID: "conjure_barrage", Name: "Conjure Barrage", Level: 3, School: "conjuration",
|
||||
Classes: ranger, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "3d8", DamageType: "varies", AOE: true,
|
||||
Description: "3d8 of weapon type in 60 ft cone. DEX save half."},
|
||||
{ID: "water_walk", Name: "Water Walk", Level: 3, School: "transmutation",
|
||||
Classes: ranger, Effect: EffectUtility, CastTime: CastRitual,
|
||||
Description: "Up to 10 targets walk on liquid surfaces. 1 hr."},
|
||||
{ID: "plant_growth", Name: "Plant Growth", Level: 3, School: "transmutation",
|
||||
Classes: ranger, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "100 ft difficult terrain; or enhance crops."},
|
||||
{ID: "nondetection", Name: "Nondetection", Level: 3, School: "abjuration",
|
||||
Classes: ranger, Effect: EffectUtility, CastTime: CastAction,
|
||||
Description: "Target undetectable by divination magic. 8 hr."},
|
||||
|
||||
// ── 4th level (Mage / Cleric) ─────────────────────────────────────────
|
||||
{ID: "banishment", Name: "Banishment", Level: 4, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "CHA",
|
||||
Description: "Send extraplanar creature to home plane temporarily."},
|
||||
{ID: "polymorph", Name: "Polymorph", Level: 4, School: "transmutation",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS",
|
||||
Description: "Transform target into beast. Max CR = target's level."},
|
||||
{ID: "ice_storm", Name: "Ice Storm", Level: 4, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "6d6", DamageType: "cold", AOE: true,
|
||||
Description: "2d8 bludgeoning + 4d6 cold in 20 ft cylinder."},
|
||||
{ID: "wall_of_fire", Name: "Wall of Fire", Level: 4, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "DEX", DamageDice: "5d8",
|
||||
DamageType: "fire", AOE: true,
|
||||
Description: "60 ft wall; 5d8 fire to those passing through."},
|
||||
{ID: "greater_invisibility", Name: "Greater Invisibility", Level: 4, School: "illusion",
|
||||
Classes: mage, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "Target invisible; attacks have advantage; can't be targeted. 1 min."},
|
||||
{ID: "guardian_of_faith", Name: "Guardian of Faith", Level: 4, School: "conjuration",
|
||||
Classes: cleric, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Description: "Spectral guardian deals 20 radiant to approaching enemies."},
|
||||
{ID: "death_ward", Name: "Death Ward", Level: 4, School: "abjuration",
|
||||
Classes: cleric, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Description: "Next time target would drop to 0 HP: drops to 1 instead. 8 hr."},
|
||||
{ID: "freedom_of_movement", Name: "Freedom of Movement", Level: 4, School: "abjuration",
|
||||
Classes: clericRanger, Effect: EffectBuffAlly, CastTime: CastAction,
|
||||
Description: "Target ignores Difficult terrain, paralysis, restraint. 1 hr."},
|
||||
|
||||
// ── 5th level (Mage / Cleric) ─────────────────────────────────────────
|
||||
{ID: "cone_of_cold", Name: "Cone of Cold", Level: 5, School: "evocation",
|
||||
Classes: mage, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "CON", DamageDice: "8d8", DamageType: "cold", AOE: true,
|
||||
Description: "8d8 cold in 60 ft cone. CON save half.",
|
||||
Upcast: "+1d8 per slot above 5th"},
|
||||
{ID: "hold_monster", Name: "Hold Monster", Level: 5, School: "enchantment",
|
||||
Classes: mage, Effect: EffectControl, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS",
|
||||
Description: "Paralyze any creature type."},
|
||||
{ID: "wall_of_force", Name: "Wall of Force", Level: 5, School: "evocation",
|
||||
Classes: mage, Effect: EffectBuffSelf, CastTime: CastAction,
|
||||
Concentration: true,
|
||||
Description: "Invisible impenetrable wall."},
|
||||
{ID: "scrying", Name: "Scrying", Level: 5, School: "divination",
|
||||
Classes: mageCleric, Effect: EffectUtility, CastTime: CastAction,
|
||||
Concentration: true, SaveStat: "WIS",
|
||||
Description: "Observe target at any distance."},
|
||||
{ID: "mass_cure_wounds", Name: "Mass Cure Wounds", Level: 5, School: "evocation",
|
||||
Classes: cleric, Effect: EffectSpellHeal, CastTime: CastAction,
|
||||
DamageDice: "3d8",
|
||||
Description: "Up to 6 targets: 3d8 + WIS mod HP."},
|
||||
{ID: "flame_strike", Name: "Flame Strike", Level: 5, School: "evocation",
|
||||
Classes: cleric, Effect: EffectDamageSave, CastTime: CastAction,
|
||||
SaveStat: "DEX", DamageDice: "8d6", DamageType: "fire", AOE: true,
|
||||
Description: "4d6 fire + 4d6 radiant in 10 ft cylinder."},
|
||||
{ID: "divine_word", Name: "Divine Word", Level: 5, School: "evocation",
|
||||
Classes: cleric, Effect: EffectControl, CastTime: CastBonusAction,
|
||||
SaveStat: "WIS",
|
||||
Description: "Targets suffer effects based on HP. Kills below 20 HP."},
|
||||
{ID: "raise_dead", Name: "Raise Dead", Level: 5, School: "necromancy",
|
||||
Classes: cleric, Effect: EffectUtility, CastTime: CastAction,
|
||||
MaterialCost: 500,
|
||||
Description: "Restore a creature dead up to 10 days. 500-coin diamond."},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// ── Registry coverage ────────────────────────────────────────────────────────
|
||||
|
||||
func TestSpellRegistryCoverage(t *testing.T) {
|
||||
// Phase 9 ships 76 in-scope spells + 3 reaction spells in the registry.
|
||||
// 79 total. Hard-bound so accidental drops surface in CI.
|
||||
if got := len(dndSpellRegistry); got < 76 {
|
||||
t.Errorf("spell registry has %d entries, want ≥76", got)
|
||||
}
|
||||
|
||||
// Every spell must declare at least one class, a name, and a level 0..5.
|
||||
for id, s := range dndSpellRegistry {
|
||||
if s.Name == "" {
|
||||
t.Errorf("spell %q has empty Name", id)
|
||||
}
|
||||
if len(s.Classes) == 0 {
|
||||
t.Errorf("spell %q has no classes", id)
|
||||
}
|
||||
if s.Level < 0 || s.Level > 5 {
|
||||
t.Errorf("spell %q level %d out of [0,5]", id, s.Level)
|
||||
}
|
||||
if s.Effect == "" {
|
||||
t.Errorf("spell %q has empty Effect", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEachClassHasSpellsAtEachAvailableLevel(t *testing.T) {
|
||||
// Mage at L9: should have at least one spell at every level 0..5.
|
||||
for _, lvl := range []int{0, 1, 2, 3, 4, 5} {
|
||||
if !classHasSpellAtLevel(ClassMage, lvl) {
|
||||
t.Errorf("Mage missing any L%d spell", lvl)
|
||||
}
|
||||
}
|
||||
// Cleric at L9: 0..5.
|
||||
for _, lvl := range []int{0, 1, 2, 3, 4, 5} {
|
||||
if !classHasSpellAtLevel(ClassCleric, lvl) {
|
||||
t.Errorf("Cleric missing any L%d spell", lvl)
|
||||
}
|
||||
}
|
||||
// Ranger at L13: 0..3.
|
||||
for _, lvl := range []int{0, 1, 2, 3} {
|
||||
if !classHasSpellAtLevel(ClassRanger, lvl) {
|
||||
t.Errorf("Ranger missing any L%d spell", lvl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func classHasSpellAtLevel(class DnDClass, level int) bool {
|
||||
for _, s := range dndSpellRegistry {
|
||||
if s.Level != level {
|
||||
continue
|
||||
}
|
||||
for _, c := range s.Classes {
|
||||
if c == class {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestParseSpellLooseInput(t *testing.T) {
|
||||
cases := []struct{ input, wantID string }{
|
||||
{"fire_bolt", "fire_bolt"},
|
||||
{"Fire Bolt", "fire_bolt"},
|
||||
{"fire-bolt", "fire_bolt"},
|
||||
{" Magic Missile ", "magic_missile"},
|
||||
{"hunters_mark", "hunters_mark"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got, ok := parseSpell(tc.input)
|
||||
if !ok {
|
||||
t.Errorf("parseSpell(%q): not found", tc.input)
|
||||
continue
|
||||
}
|
||||
if got.ID != tc.wantID {
|
||||
t.Errorf("parseSpell(%q): id=%q, want %q", tc.input, got.ID, tc.wantID)
|
||||
}
|
||||
}
|
||||
if _, ok := parseSpell("totally not a spell"); ok {
|
||||
t.Errorf("parseSpell on garbage should miss")
|
||||
}
|
||||
}
|
||||
|
||||
// ── Slot tables ──────────────────────────────────────────────────────────────
|
||||
|
||||
func TestSlotsForClassLevel(t *testing.T) {
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
level int
|
||||
want map[int]int
|
||||
}{
|
||||
// Mage spec rows (gogobee_spell_system.md §1)
|
||||
{ClassMage, 1, map[int]int{1: 2}},
|
||||
{ClassMage, 5, map[int]int{1: 4, 2: 3, 3: 2}},
|
||||
{ClassMage, 9, map[int]int{1: 4, 2: 3, 3: 3, 4: 3, 5: 1}},
|
||||
// Cleric rows
|
||||
{ClassCleric, 1, map[int]int{1: 2}},
|
||||
{ClassCleric, 5, map[int]int{1: 4, 2: 3, 3: 2}},
|
||||
// Ranger half-caster
|
||||
{ClassRanger, 1, map[int]int{}},
|
||||
{ClassRanger, 5, map[int]int{1: 3}},
|
||||
{ClassRanger, 13, map[int]int{1: 3, 2: 2, 3: 1}},
|
||||
// Non-caster
|
||||
{ClassFighter, 5, nil},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := slotsForClassLevel(tc.class, tc.level)
|
||||
if !mapEq(got, tc.want) {
|
||||
t.Errorf("slotsForClassLevel(%s, %d) = %v, want %v",
|
||||
tc.class, tc.level, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mapEq(a, b map[int]int) bool {
|
||||
if (a == nil) != (b == nil) && (len(a)+len(b)) != 0 {
|
||||
return false
|
||||
}
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for k, v := range a {
|
||||
if b[k] != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ── DC math ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func TestSpellSaveDC(t *testing.T) {
|
||||
// Mage L5, INT 18 (mod +4). Prof L5 = +3. DC = 8 + 3 + 4 = 15.
|
||||
c := &DnDCharacter{Class: ClassMage, Level: 5, INT: 18}
|
||||
if got := spellSaveDC(c); got != 15 {
|
||||
t.Errorf("Mage L5 INT18 DC = %d, want 15", got)
|
||||
}
|
||||
// Cleric L9, WIS 16 (mod +3). Prof L9 = +4. DC = 8 + 4 + 3 = 15.
|
||||
c = &DnDCharacter{Class: ClassCleric, Level: 9, WIS: 16}
|
||||
if got := spellSaveDC(c); got != 15 {
|
||||
t.Errorf("Cleric L9 WIS16 DC = %d, want 15", got)
|
||||
}
|
||||
// Ranger L4, WIS 14 (mod +2). Prof L4 = +2. DC = 8 + 2 + 2 = 12.
|
||||
c = &DnDCharacter{Class: ClassRanger, Level: 4, WIS: 14}
|
||||
if got := spellSaveDC(c); got != 12 {
|
||||
t.Errorf("Ranger L4 WIS14 DC = %d, want 12", got)
|
||||
}
|
||||
// Non-caster falls back to 8 + prof + 0.
|
||||
c = &DnDCharacter{Class: ClassFighter, Level: 5, INT: 18}
|
||||
if got := spellSaveDC(c); got != 11 {
|
||||
t.Errorf("Fighter L5 fallback DC = %d, want 11", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpellAttackBonus(t *testing.T) {
|
||||
c := &DnDCharacter{Class: ClassMage, Level: 5, INT: 18}
|
||||
if got := spellAttackBonus(c); got != 7 {
|
||||
t.Errorf("Mage L5 INT18 atk = %d, want 7", got)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Default known list ──────────────────────────────────────────────────────
|
||||
|
||||
func TestDefaultKnownSpellsExistInRegistry(t *testing.T) {
|
||||
for _, class := range []DnDClass{ClassMage, ClassCleric, ClassRanger} {
|
||||
for _, lvl := range []int{1, 3, 5, 9, 13, 20} {
|
||||
for _, sid := range defaultKnownSpells(class, lvl) {
|
||||
if _, ok := lookupSpell(sid); !ok {
|
||||
t.Errorf("default for %s L%d references unknown spell %q",
|
||||
class, lvl, sid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultKnownSpellsScaleWithLevel(t *testing.T) {
|
||||
// Higher-level Mage knows strictly more spells than L1.
|
||||
low := len(defaultKnownSpells(ClassMage, 1))
|
||||
hi := len(defaultKnownSpells(ClassMage, 9))
|
||||
if hi <= low {
|
||||
t.Errorf("Mage L9 known (%d) should exceed L1 (%d)", hi, low)
|
||||
}
|
||||
// Ranger L1 knows almost nothing (no spells until L2).
|
||||
if got := len(defaultKnownSpells(ClassRanger, 1)); got > 2 {
|
||||
t.Errorf("Ranger L1 default %d spells, want ≤2 cantrips", got)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Concentration helper ────────────────────────────────────────────────────
|
||||
|
||||
func TestSetConcentrationSupersedes(t *testing.T) {
|
||||
c := &DnDCharacter{}
|
||||
prev := setConcentration(c, "bless", 0)
|
||||
if prev != "" {
|
||||
t.Errorf("first concentration: prev=%q, want empty", prev)
|
||||
}
|
||||
prev = setConcentration(c, "hunters_mark", 0)
|
||||
if prev != "bless" {
|
||||
t.Errorf("second concentration: prev=%q, want bless", prev)
|
||||
}
|
||||
if c.ConcentrationSpell != "hunters_mark" {
|
||||
t.Errorf("after super: active=%q, want hunters_mark", c.ConcentrationSpell)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Migration safety ────────────────────────────────────────────────────────
|
||||
|
||||
func TestEnsureSpellsForCharacterNonCasterIsNoOp(t *testing.T) {
|
||||
c := &DnDCharacter{UserID: id.UserID("@test:fighter"), Class: ClassFighter, Level: 5}
|
||||
if err := ensureSpellsForCharacter(c); err != nil {
|
||||
// Note: this hits the DB; in env without DB, function should still
|
||||
// return nil for non-caster before any DB call. Verify that early exit.
|
||||
t.Errorf("ensureSpellsForCharacter on Fighter: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRangerNoSpellsBeforeLevel2(t *testing.T) {
|
||||
if got := len(slotsForClassLevel(ClassRanger, 1)); got != 0 {
|
||||
t.Errorf("Ranger L1 slot count = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAbilityModifier(t *testing.T) {
|
||||
cases := []struct {
|
||||
score, want int
|
||||
}{
|
||||
{1, -5},
|
||||
{8, -1},
|
||||
{9, -1},
|
||||
{10, 0},
|
||||
{11, 0},
|
||||
{12, 1},
|
||||
{13, 1},
|
||||
{14, 2},
|
||||
{15, 2},
|
||||
{16, 3},
|
||||
{18, 4},
|
||||
{20, 5},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := abilityModifier(c.score)
|
||||
if got != c.want {
|
||||
t.Errorf("abilityModifier(%d) = %d, want %d", c.score, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStandardArray(t *testing.T) {
|
||||
good := [][]int{
|
||||
{15, 14, 13, 12, 10, 8},
|
||||
{8, 10, 12, 13, 14, 15},
|
||||
{14, 8, 15, 10, 13, 12},
|
||||
}
|
||||
for _, g := range good {
|
||||
var arr [6]int
|
||||
copy(arr[:], g)
|
||||
if !isStandardArray(arr) {
|
||||
t.Errorf("isStandardArray(%v) = false, want true", g)
|
||||
}
|
||||
}
|
||||
bad := [][]int{
|
||||
{15, 15, 13, 12, 10, 8}, // duplicate 15
|
||||
{16, 14, 13, 12, 10, 8}, // out-of-range
|
||||
{15, 14, 13, 12, 10, 9}, // 9 instead of 8
|
||||
{15, 14, 13, 12, 11, 8}, // 11 instead of 10
|
||||
}
|
||||
for _, ba := range bad {
|
||||
var arr [6]int
|
||||
copy(arr[:], ba)
|
||||
if isStandardArray(arr) {
|
||||
t.Errorf("isStandardArray(%v) = true, want false", ba)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeMaxHP_FighterLevel1(t *testing.T) {
|
||||
// Fighter d10, CON +2 → L1 HP = 10 + 2 = 12
|
||||
got := computeMaxHP(ClassFighter, 2, 1)
|
||||
if got != 12 {
|
||||
t.Errorf("Fighter L1 (CON+2) = %d, want 12", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeMaxHP_MageLevel5(t *testing.T) {
|
||||
// Mage d6, CON +1
|
||||
// L1: 6 + 1 = 7
|
||||
// L2-5: 4 levels × (avg 4 + 1) = 4 × 5 = 20
|
||||
// Total: 27
|
||||
got := computeMaxHP(ClassMage, 1, 5)
|
||||
if got != 27 {
|
||||
t.Errorf("Mage L5 (CON+1) = %d, want 27", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeMaxHP_FloorAt1(t *testing.T) {
|
||||
// Pathological: very negative CON, low level → still ≥1 per level
|
||||
got := computeMaxHP(ClassMage, -5, 1)
|
||||
if got < 1 {
|
||||
t.Errorf("HP floor violated: got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeAC(t *testing.T) {
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
dexMod int
|
||||
want int
|
||||
}{
|
||||
{ClassFighter, 0, 16}, // 10 + 0 + 6
|
||||
{ClassFighter, 2, 18}, // 10 + 2 + 6
|
||||
{ClassRogue, 3, 14}, // 10 + 3 + 1
|
||||
{ClassMage, 0, 10}, // 10 + 0 + 0
|
||||
{ClassCleric, 1, 14}, // 10 + 1 + 3
|
||||
{ClassRanger, 2, 15}, // 10 + 2 + 3
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := computeAC(c.class, c.dexMod)
|
||||
if got != c.want {
|
||||
t.Errorf("computeAC(%s, dex%+d) = %d, want %d", c.class, c.dexMod, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyRaceMods(t *testing.T) {
|
||||
// Elf: STR +0, DEX +2, CON -1, INT +1, WIS +1, CHA +0
|
||||
base := [6]int{10, 10, 10, 10, 10, 10}
|
||||
got := applyRaceMods(RaceElf, base)
|
||||
want := [6]int{10, 12, 9, 11, 11, 10}
|
||||
if got != want {
|
||||
t.Errorf("applyRaceMods(Elf) = %v, want %v", got, want)
|
||||
}
|
||||
// Orc: STR +3, DEX -1, CON +2, INT -1, WIS -1, CHA -1
|
||||
got = applyRaceMods(RaceOrc, base)
|
||||
want = [6]int{13, 9, 12, 9, 9, 9}
|
||||
if got != want {
|
||||
t.Errorf("applyRaceMods(Orc) = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRaceClass(t *testing.T) {
|
||||
if r, ok := parseRace("Elf"); !ok || r != RaceElf {
|
||||
t.Errorf("parseRace(Elf) = %v, %v", r, ok)
|
||||
}
|
||||
if r, ok := parseRace("half-elf"); !ok || r != RaceHalfElf {
|
||||
t.Errorf("parseRace(half-elf) = %v, %v", r, ok)
|
||||
}
|
||||
if _, ok := parseRace("dragonborn"); ok {
|
||||
t.Errorf("parseRace(dragonborn) = ok, want false")
|
||||
}
|
||||
if c, ok := parseClass("Fighter"); !ok || c != ClassFighter {
|
||||
t.Errorf("parseClass(Fighter) = %v, %v", c, ok)
|
||||
}
|
||||
if _, ok := parseClass("monk"); ok {
|
||||
t.Errorf("parseClass(monk) = ok, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatsAssigned(t *testing.T) {
|
||||
defaultC := &DnDCharacter{STR: 8, DEX: 8, CON: 8, INT: 8, WIS: 8, CHA: 8}
|
||||
if statsAssigned(defaultC) {
|
||||
t.Error("statsAssigned(all-8s) = true, want false")
|
||||
}
|
||||
withStats := &DnDCharacter{STR: 15, DEX: 14, CON: 13, INT: 12, WIS: 10, CHA: 8}
|
||||
if !statsAssigned(withStats) {
|
||||
t.Error("statsAssigned(real stats) = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStatsArg(t *testing.T) {
|
||||
want := [6]int{15, 14, 13, 12, 10, 8}
|
||||
cases := []string{
|
||||
"15 14 13 12 10 8",
|
||||
"15, 14, 13, 12, 10, 8",
|
||||
"(15, 14, 13, 12, 10, 8)",
|
||||
"[15,14,13,12,10,8]",
|
||||
"{15 14 13 12 10 8}",
|
||||
" 15,14 ,13, 12 ,10, 8 ",
|
||||
}
|
||||
for _, in := range cases {
|
||||
got, err := parseStatsArg(in)
|
||||
if err != nil {
|
||||
t.Errorf("parseStatsArg(%q) returned error: %v", in, err)
|
||||
continue
|
||||
}
|
||||
if got != want {
|
||||
t.Errorf("parseStatsArg(%q) = %v, want %v", in, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
bad := []string{
|
||||
"", // empty
|
||||
"15 14 13 12 10", // 5 numbers
|
||||
"15 14 13 12 10 8 7", // 7 numbers
|
||||
"15 14 13 12 10 abc", // non-number
|
||||
"banana", // garbage
|
||||
}
|
||||
for _, in := range bad {
|
||||
if _, err := parseStatsArg(in); err == nil {
|
||||
t.Errorf("parseStatsArg(%q) should have errored", in)
|
||||
}
|
||||
}
|
||||
|
||||
// A different permutation should still parse and just return the
|
||||
// numbers in order — validation against the standard array is
|
||||
// a separate concern (isStandardArray).
|
||||
got, err := parseStatsArg("8, 10, 12, 13, 14, 15")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != [6]int{8, 10, 12, 13, 14, 15} {
|
||||
t.Errorf("permutation order not preserved: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDLevelFromCombatLevel(t *testing.T) {
|
||||
cases := []struct{ combat, want int }{
|
||||
{0, 1}, // floor
|
||||
{1, 1},
|
||||
{4, 1},
|
||||
{5, 1},
|
||||
{9, 1},
|
||||
{10, 2},
|
||||
{15, 3},
|
||||
{20, 4}, // nonk
|
||||
{24, 4}, // quack
|
||||
{25, 5},
|
||||
{28, 5}, // prosolis
|
||||
{30, 6},
|
||||
{45, 9},
|
||||
{49, 9}, // holymachina
|
||||
{50, 10},
|
||||
{99, 19},
|
||||
{100, 20}, // clamp
|
||||
{500, 20}, // clamp
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := dndLevelFromCombatLevel(c.combat)
|
||||
if got != c.want {
|
||||
t.Errorf("dndLevelFromCombatLevel(%d) = %d, want %d", c.combat, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifiersOnCharacter(t *testing.T) {
|
||||
c := &DnDCharacter{STR: 16, DEX: 12, CON: 14, INT: 10, WIS: 8, CHA: 18}
|
||||
mods := c.Modifiers()
|
||||
want := [6]int{3, 1, 2, 0, -1, 4}
|
||||
if mods != want {
|
||||
t.Errorf("Modifiers() = %v, want %v", mods, want)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Phase 3 — XP, level-up, and progression.
|
||||
//
|
||||
// XP curve anchors come from the design doc (v1.0 §4.1). Intermediate levels
|
||||
// are interpolated to give a smooth ramp. Cumulative XP — the value stored
|
||||
// in dnd_character.dnd_xp resets to 0 on level-up (carrying over surplus).
|
||||
//
|
||||
// Two design choices worth flagging:
|
||||
// 1. XP is *segment-based*. dnd_xp tracks XP toward the next level, not
|
||||
// total XP earned across all levels. This keeps the math simple and
|
||||
// means a player who migrated in at L8 starts with 0/[L9-cost], no
|
||||
// adjustment needed for the levels they "didn't earn."
|
||||
// 2. Combat XP only — no XP from gathering activities. Mining/foraging/
|
||||
// fishing keep their own legacy skill XP tracks.
|
||||
|
||||
// dndXPTable[L] = cumulative XP needed to reach level L from level 1.
|
||||
// L=0 is unused (D&D characters start at L1).
|
||||
var dndXPTable = [...]int{
|
||||
0, // L1 (start)
|
||||
300, // L2
|
||||
900, // L3
|
||||
1700, // L4
|
||||
2700, // L5 (anchor: doc)
|
||||
4300, // L6
|
||||
6500, // L7 (anchor: doc)
|
||||
9000, // L8
|
||||
11500, // L9
|
||||
14000, // L10 (anchor: doc)
|
||||
18000, // L11
|
||||
22000, // L12
|
||||
26000, // L13
|
||||
30000, // L14
|
||||
34000, // L15 (anchor: doc)
|
||||
44000, // L16
|
||||
54000, // L17
|
||||
64000, // L18
|
||||
74000, // L19
|
||||
85000, // L20 (anchor: doc)
|
||||
}
|
||||
|
||||
const dndMaxLevel = 20
|
||||
|
||||
// dndXPToNextLevel returns the segment cost to advance from currentLevel to
|
||||
// currentLevel+1. Returns 0 at L20 (already capped).
|
||||
func dndXPToNextLevel(currentLevel int) int {
|
||||
if currentLevel < 1 {
|
||||
currentLevel = 1
|
||||
}
|
||||
if currentLevel >= dndMaxLevel {
|
||||
return 0
|
||||
}
|
||||
return dndXPTable[currentLevel] - dndXPTable[currentLevel-1]
|
||||
}
|
||||
|
||||
// LevelUpEvent describes one level threshold crossed. A single grantDnDXP
|
||||
// call can produce multiple events (cascading level-ups).
|
||||
type LevelUpEvent struct {
|
||||
NewLevel int
|
||||
HPGain int // hp_max delta
|
||||
}
|
||||
|
||||
// grantDnDXP adds XP to the player's D&D character and processes any
|
||||
// level-ups that result. Returns the level-up events (empty if none).
|
||||
//
|
||||
// Side effects:
|
||||
// - dnd_xp incremented (with carry-over on level-up)
|
||||
// - dnd_level incremented for each level threshold crossed
|
||||
// - hp_max recomputed and hp_current bumped by the gain
|
||||
// - DM sent for each level-up
|
||||
// - dnd_character row persisted
|
||||
//
|
||||
// No-op if the player has no D&D character (auto-migration normally
|
||||
// guarantees one before any combat, so this is paranoia).
|
||||
func (p *AdventurePlugin) grantDnDXP(userID id.UserID, amount int) ([]LevelUpEvent, error) {
|
||||
if amount <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
c, err := LoadDnDCharacter(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c == nil || c.PendingSetup {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
c.XP += amount
|
||||
|
||||
var events []LevelUpEvent
|
||||
for c.Level < dndMaxLevel {
|
||||
cost := dndXPToNextLevel(c.Level)
|
||||
if c.XP < cost {
|
||||
break
|
||||
}
|
||||
c.XP -= cost
|
||||
|
||||
// Recompute HP max for the new level. HPCurrent gains the same delta.
|
||||
conMod := abilityModifier(c.CON)
|
||||
oldMax := c.HPMax
|
||||
c.Level++
|
||||
c.HPMax = computeMaxHP(c.Class, conMod, c.Level)
|
||||
gain := c.HPMax - oldMax
|
||||
if gain < 1 {
|
||||
gain = 1 // floor — even with very negative CON, give at least 1
|
||||
c.HPMax = oldMax + 1
|
||||
}
|
||||
c.HPCurrent += gain
|
||||
if c.HPCurrent > c.HPMax {
|
||||
c.HPCurrent = c.HPMax
|
||||
}
|
||||
// AC may change too if DEX-derived (unlikely without item changes).
|
||||
c.ArmorClass = computeAC(c.Class, abilityModifier(c.DEX))
|
||||
|
||||
events = append(events, LevelUpEvent{NewLevel: c.Level, HPGain: gain})
|
||||
}
|
||||
|
||||
// Cap at L20 — overflow XP is silently dropped.
|
||||
if c.Level >= dndMaxLevel {
|
||||
c.XP = 0
|
||||
}
|
||||
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
return events, err
|
||||
}
|
||||
|
||||
if len(events) > 0 {
|
||||
p.sendLevelUpDM(userID, c, events, amount)
|
||||
}
|
||||
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (p *AdventurePlugin) sendLevelUpDM(userID id.UserID, c *DnDCharacter, events []LevelUpEvent, xpThisGrant int) {
|
||||
if p == nil || p.Client == nil {
|
||||
return // tests construct AdventurePlugin{} without a Matrix client
|
||||
}
|
||||
ri, _ := raceInfo(c.Race)
|
||||
ci, _ := classInfo(c.Class)
|
||||
var b strings.Builder
|
||||
b.WriteString("✨ **LEVEL UP** ✨\n\n")
|
||||
if line := dndLevelUpFlavorLine(); line != "" {
|
||||
b.WriteString("_" + line + "_\n\n")
|
||||
}
|
||||
|
||||
if len(events) == 1 {
|
||||
ev := events[0]
|
||||
b.WriteString(fmt.Sprintf("You are now a **Level %d %s %s**.\n", ev.NewLevel, ri.Display, ci.Display))
|
||||
b.WriteString(fmt.Sprintf(" HP: %d → %d (+%d)\n", c.HPMax-ev.HPGain, c.HPMax, ev.HPGain))
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("You crossed **%d** levels in one go!\n", len(events)))
|
||||
for _, ev := range events {
|
||||
b.WriteString(fmt.Sprintf(" → Level %d (+%d HP)\n", ev.NewLevel, ev.HPGain))
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("\nFinal: **Level %d %s %s** with %d HP.\n",
|
||||
c.Level, ri.Display, ci.Display, c.HPMax))
|
||||
}
|
||||
|
||||
if c.Level >= dndMaxLevel {
|
||||
b.WriteString("\n_You've reached the level cap._")
|
||||
} else {
|
||||
next := dndXPToNextLevel(c.Level)
|
||||
b.WriteString(fmt.Sprintf("\nNext level: %d / %d XP.\n", c.XP, next))
|
||||
}
|
||||
|
||||
// Subclass selection cue: design doc specs a prompt at L5. Mechanics
|
||||
// arrive in a future phase; for now the level-up DM mentions it so the
|
||||
// player isn't surprised when it lands.
|
||||
for _, ev := range events {
|
||||
if ev.NewLevel == 5 {
|
||||
b.WriteString("\n🎯 _Subclass selection unlocks at L5 — coming in a future update._")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err := p.SendDM(userID, b.String()); err != nil {
|
||||
slog.Error("dnd: level-up DM failed", "user", userID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ── XP grant amounts ─────────────────────────────────────────────────────────
|
||||
|
||||
// Combat XP formulas. Tuned so a L1 player needs ~3 wins per level early
|
||||
// and many more at high levels.
|
||||
const (
|
||||
dndArenaXPPerThreat = 12 // arena win XP = threat * this
|
||||
dndArenaXPMin = 30 // arena win XP floor (low-threat fights still pay)
|
||||
dndDungeonXPPerTier = 60 // dungeon win XP = tier^1.4 * this, roughly
|
||||
dndLossXPFraction = 0.25
|
||||
dndNearDeathXPBonus = 1.25 // multiplier for clutch wins
|
||||
)
|
||||
|
||||
// arenaCombatXP returns the D&D XP to grant for an arena combat outcome.
|
||||
func arenaCombatXP(result CombatResult, threatLevel int) int {
|
||||
base := dndArenaXPPerThreat * threatLevel
|
||||
if base < dndArenaXPMin {
|
||||
base = dndArenaXPMin
|
||||
}
|
||||
if result.PlayerWon {
|
||||
if result.NearDeath {
|
||||
return int(float64(base) * dndNearDeathXPBonus)
|
||||
}
|
||||
return base
|
||||
}
|
||||
return int(float64(base) * dndLossXPFraction)
|
||||
}
|
||||
|
||||
// dungeonCombatXP returns the D&D XP to grant for a dungeon combat outcome.
|
||||
// Quadratic-ish scaling so high-tier dungeons feel meaningfully more rewarding.
|
||||
func dungeonCombatXP(result CombatResult, tier int) int {
|
||||
if tier < 1 {
|
||||
tier = 1
|
||||
}
|
||||
base := dndDungeonXPPerTier * tier * tier / 2 // T1=30, T3=270, T5=750
|
||||
if base < dndArenaXPMin {
|
||||
base = dndArenaXPMin
|
||||
}
|
||||
if result.PlayerWon {
|
||||
if result.NearDeath {
|
||||
return int(float64(base) * dndNearDeathXPBonus)
|
||||
}
|
||||
return base
|
||||
}
|
||||
return int(float64(base) * dndLossXPFraction)
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gogobee/internal/db"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func TestDnDXPToNextLevel(t *testing.T) {
|
||||
cases := []struct{ level, want int }{
|
||||
{1, 300}, // L1→L2: 300
|
||||
{2, 600}, // L2→L3: 900-300
|
||||
{4, 1000}, // L4→L5: 2700-1700
|
||||
{6, 2200}, // L6→L7: 6500-4300
|
||||
{19, 11000}, // L19→L20: 85000-74000
|
||||
{20, 0}, // capped
|
||||
{0, 300}, // clamp to 1
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := dndXPToNextLevel(c.level); got != c.want {
|
||||
t.Errorf("dndXPToNextLevel(%d) = %d, want %d", c.level, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDnDXPTableMonotonic(t *testing.T) {
|
||||
// Each level threshold must strictly exceed the previous.
|
||||
for i := 1; i < len(dndXPTable); i++ {
|
||||
if dndXPTable[i] <= dndXPTable[i-1] {
|
||||
t.Errorf("dndXPTable[%d]=%d not > dndXPTable[%d]=%d",
|
||||
i, dndXPTable[i], i-1, dndXPTable[i-1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArenaCombatXP(t *testing.T) {
|
||||
winLow := arenaCombatXP(CombatResult{PlayerWon: true}, 1)
|
||||
if winLow < 30 {
|
||||
t.Errorf("low-threat win XP = %d, want ≥ 30 (floor)", winLow)
|
||||
}
|
||||
winHigh := arenaCombatXP(CombatResult{PlayerWon: true}, 20)
|
||||
if winHigh != 240 {
|
||||
t.Errorf("threat-20 win XP = %d, want 240", winHigh)
|
||||
}
|
||||
winND := arenaCombatXP(CombatResult{PlayerWon: true, NearDeath: true}, 20)
|
||||
if winND != 300 { // 240 * 1.25
|
||||
t.Errorf("threat-20 near-death win XP = %d, want 300", winND)
|
||||
}
|
||||
loss := arenaCombatXP(CombatResult{PlayerWon: false}, 20)
|
||||
if loss != 60 { // 240 * 0.25
|
||||
t.Errorf("threat-20 loss XP = %d, want 60", loss)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDungeonCombatXP(t *testing.T) {
|
||||
if got := dungeonCombatXP(CombatResult{PlayerWon: true}, 1); got != 30 {
|
||||
t.Errorf("T1 win XP = %d, want 30 (floor)", got)
|
||||
}
|
||||
if got := dungeonCombatXP(CombatResult{PlayerWon: true}, 5); got != 750 {
|
||||
t.Errorf("T5 win XP = %d, want 750", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGrantDnDXP_NoOpOnMissingChar — the function should silently no-op
|
||||
// when the player has no D&D character.
|
||||
func TestGrantDnDXP_NoOpOnMissingChar(t *testing.T) {
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
events, err := p.grantDnDXP(id.UserID("@nobody:nowhere.invalid"), 1000)
|
||||
if err != nil {
|
||||
t.Fatalf("grantDnDXP on missing char: %v", err)
|
||||
}
|
||||
if len(events) != 0 {
|
||||
t.Errorf("got %d events on missing char, want 0", len(events))
|
||||
}
|
||||
}
|
||||
|
||||
// TestGrantDnDXP_LevelUpCascade — grant a huge XP amount and verify that
|
||||
// multiple level-ups happen and HP/level/AC update consistently.
|
||||
func TestGrantDnDXP_LevelUpCascade(t *testing.T) {
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
|
||||
// Build a fresh L1 D&D char in the test DB.
|
||||
uid := id.UserID("@xp_test:example")
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 1,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
ArmorClass: 16,
|
||||
}
|
||||
conMod := abilityModifier(c.CON)
|
||||
c.HPMax = computeMaxHP(c.Class, conMod, c.Level)
|
||||
c.HPCurrent = c.HPMax
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Grant 3000 XP — should push from L1 to L4 (300+600+900=1800 < 3000 < 2700+900=3600).
|
||||
// L1→L2: 300, total used 300, remaining 2700
|
||||
// L2→L3: 600, total used 900, remaining 2100
|
||||
// L3→L4: 800 (1700-900), total used 1700, remaining 1300
|
||||
// L4→L5: 1000 (2700-1700), total used 2700, remaining 300
|
||||
// Should land at L5 with 300 XP carryover.
|
||||
p := &AdventurePlugin{}
|
||||
events, err := p.grantDnDXP(uid, 3000)
|
||||
if err != nil {
|
||||
t.Fatalf("grantDnDXP: %v", err)
|
||||
}
|
||||
if len(events) != 4 {
|
||||
t.Errorf("got %d level-ups, want 4 (L2,L3,L4,L5)", len(events))
|
||||
}
|
||||
|
||||
got, err := LoadDnDCharacter(uid)
|
||||
if err != nil || got == nil {
|
||||
t.Fatalf("load post-grant: %v", err)
|
||||
}
|
||||
if got.Level != 5 {
|
||||
t.Errorf("level = %d, want 5", got.Level)
|
||||
}
|
||||
if got.XP != 300 {
|
||||
t.Errorf("xp carryover = %d, want 300", got.XP)
|
||||
}
|
||||
// Fighter d10 + CON+2 at L1 = 12. Per-level after: 6+2 = 8. L5 = 12 + 4*8 = 44.
|
||||
if got.HPMax != 44 {
|
||||
t.Errorf("L5 HPMax = %d, want 44", got.HPMax)
|
||||
}
|
||||
// Each level-up bumps HPCurrent by the gain. Started at full (12), gained
|
||||
// 8 four times = 12+32 = 44. So HPCurrent = HPMax = 44.
|
||||
if got.HPCurrent != got.HPMax {
|
||||
t.Errorf("HPCurrent = %d, want HPMax = %d", got.HPCurrent, got.HPMax)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGrantDnDXP_CapsAtL20 — XP overflow at level 20 is clamped.
|
||||
func TestGrantDnDXP_CapsAtL20(t *testing.T) {
|
||||
src := "/home/reala-misaki/git/gogobee/data/gogobee.db"
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
t.Skip("prod db not present")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
dst := filepath.Join(dir, "gogobee.db")
|
||||
in, _ := os.Open(src)
|
||||
defer in.Close()
|
||||
out, _ := os.Create(dst)
|
||||
defer out.Close()
|
||||
io.Copy(out, in)
|
||||
|
||||
db.Close()
|
||||
if err := db.Init(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(db.Close)
|
||||
|
||||
uid := id.UserID("@cap_test:example")
|
||||
c := &DnDCharacter{
|
||||
UserID: uid, Race: RaceHuman, Class: ClassFighter, Level: 19,
|
||||
STR: 16, DEX: 13, CON: 14, INT: 8, WIS: 10, CHA: 12,
|
||||
ArmorClass: 16,
|
||||
}
|
||||
c.HPMax = 100
|
||||
c.HPCurrent = 100
|
||||
if err := SaveDnDCharacter(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := &AdventurePlugin{}
|
||||
if _, err := p.grantDnDXP(uid, 999999); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := LoadDnDCharacter(uid)
|
||||
if got.Level != dndMaxLevel {
|
||||
t.Errorf("level = %d, want %d", got.Level, dndMaxLevel)
|
||||
}
|
||||
if got.XP != 0 {
|
||||
t.Errorf("XP at cap = %d, want 0 (overflow dropped)", got.XP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyClassPassives(t *testing.T) {
|
||||
cases := []struct {
|
||||
class DnDClass
|
||||
wantDmgBonus float64
|
||||
wantAtkBonusAdd int
|
||||
wantAutoCrit bool
|
||||
wantHealItem int
|
||||
}{
|
||||
{ClassFighter, 0.05, 0, false, 0},
|
||||
{ClassRogue, 0, 0, true, 0},
|
||||
{ClassMage, 0, 1, false, 0},
|
||||
{ClassCleric, 0, 0, false, 5},
|
||||
{ClassRanger, 0.05, 1, false, 0},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
stats := CombatStats{AttackBonus: 5}
|
||||
mods := CombatModifiers{}
|
||||
applyClassPassives(&stats, &mods, &DnDCharacter{Class: tc.class})
|
||||
if mods.DamageBonus != tc.wantDmgBonus {
|
||||
t.Errorf("%s: DamageBonus=%v, want %v", tc.class, mods.DamageBonus, tc.wantDmgBonus)
|
||||
}
|
||||
if stats.AttackBonus-5 != tc.wantAtkBonusAdd {
|
||||
t.Errorf("%s: AttackBonus add=%d, want %d", tc.class, stats.AttackBonus-5, tc.wantAtkBonusAdd)
|
||||
}
|
||||
if mods.AutoCritFirst != tc.wantAutoCrit {
|
||||
t.Errorf("%s: AutoCritFirst=%v, want %v", tc.class, mods.AutoCritFirst, tc.wantAutoCrit)
|
||||
}
|
||||
if mods.HealItem != tc.wantHealItem {
|
||||
t.Errorf("%s: HealItem=%d, want %d", tc.class, mods.HealItem, tc.wantHealItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -841,7 +841,9 @@ func (p *HoldemPlugin) doShowdown(game *HoldemGame) {
|
||||
|
||||
// Post end announcement to room and DM each player.
|
||||
endAnn := renderEndAnnouncement(results, game)
|
||||
p.SendMessage(game.RoomID, endAnn)
|
||||
if gameHasPublicRoom(game) {
|
||||
p.SendMessage(game.RoomID, endAnn)
|
||||
}
|
||||
p.broadcastDM(game, endAnn)
|
||||
|
||||
// Settle balances.
|
||||
@@ -874,7 +876,9 @@ func (p *HoldemPlugin) finishHand(game *HoldemGame) {
|
||||
// Award pot to last remaining player.
|
||||
ann, winnerID := awardPotToLastPlayer(game)
|
||||
if ann != "" {
|
||||
p.SendMessage(game.RoomID, ann)
|
||||
if gameHasPublicRoom(game) {
|
||||
p.SendMessage(game.RoomID, ann)
|
||||
}
|
||||
p.broadcastDM(game, ann)
|
||||
}
|
||||
|
||||
@@ -980,18 +984,22 @@ func (p *HoldemPlugin) sendTurnNotifications(game *HoldemGame) {
|
||||
}
|
||||
}
|
||||
|
||||
// broadcastDM delivers msg to each player's channel — their DM room in
|
||||
// multiplayer, or game.RoomID directly in solo-vs-bot (where the room IS
|
||||
// the player's DM). Deduplicated by room so callers that also post to
|
||||
// game.RoomID for spectators (see gameHasPublicRoom) don't cause the solo
|
||||
// player to see the message twice.
|
||||
func (p *HoldemPlugin) broadcastDM(game *HoldemGame, msg string) {
|
||||
sent := map[id.RoomID]bool{}
|
||||
first := true
|
||||
for _, pl := range game.Players {
|
||||
if pl.IsNPC || pl.State == PlayerSatOut {
|
||||
continue
|
||||
}
|
||||
// Skip players whose DM room IS the game room — they already saw
|
||||
// the message via the public-room post (solo-vs-bot case, where
|
||||
// game.RoomID == player's DM).
|
||||
if pl.DMRoomID == game.RoomID {
|
||||
if sent[pl.DMRoomID] {
|
||||
continue
|
||||
}
|
||||
sent[pl.DMRoomID] = true
|
||||
if !first {
|
||||
// Jitter 150–400ms between sends to avoid bursts on the Matrix server.
|
||||
time.Sleep(150*time.Millisecond + time.Duration(rand.IntN(250))*time.Millisecond)
|
||||
@@ -1001,6 +1009,17 @@ func (p *HoldemPlugin) broadcastDM(game *HoldemGame, msg string) {
|
||||
}
|
||||
}
|
||||
|
||||
// gameHasPublicRoom reports whether game.RoomID is a separate public room
|
||||
// (multiplayer) rather than a player's own DM (solo-vs-bot).
|
||||
func gameHasPublicRoom(g *HoldemGame) bool {
|
||||
for _, pl := range g.Players {
|
||||
if !pl.IsNPC && pl.DMRoomID == g.RoomID {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// --- NPC ---
|
||||
|
||||
func (p *HoldemPlugin) npcAct(game *HoldemGame) {
|
||||
|
||||
@@ -69,7 +69,8 @@ func runShowdown(g *HoldemGame) ([]showdownResult, map[id.UserID]int64) {
|
||||
for _, e := range evaluated {
|
||||
p := g.Players[e.seatIdx]
|
||||
won := winnings[p.UserID]
|
||||
line := renderShowdownLine(p.DisplayName, p.Hole, e.name, won)
|
||||
desc := describeMadeHand(e.name, p.Hole, g.Community)
|
||||
line := renderShowdownLine(p.DisplayName, p.Hole, desc, won)
|
||||
showdownLines = append(showdownLines, showdownResult{line: line})
|
||||
}
|
||||
|
||||
|
||||
@@ -664,9 +664,15 @@ func rewriteTipWithLLM(host, model string, ctx holdemTipContext, base string) (s
|
||||
return "", fmt.Errorf("empty response")
|
||||
}
|
||||
if !rewriteKeepsAction(base, tip) {
|
||||
slog.Warn("holdem: tip rewrite rejected (vocabulary)",
|
||||
"base", base, "rewrite", tip,
|
||||
"street", ctx.Street.String(), "to_call", ctx.ToCall)
|
||||
return "", fmt.Errorf("rewrite changed action vocabulary")
|
||||
}
|
||||
if reason := rewriteSemanticProblem(ctx, tip); reason != "" {
|
||||
slog.Warn("holdem: tip rewrite rejected (semantic)",
|
||||
"reason", reason, "base", base, "rewrite", tip,
|
||||
"street", ctx.Street.String(), "to_call", ctx.ToCall)
|
||||
return "", fmt.Errorf("rewrite semantic drift: %s", reason)
|
||||
}
|
||||
return tip, nil
|
||||
|
||||
@@ -690,7 +690,12 @@ func IsDMRoom(roomID id.RoomID, userID id.UserID) bool {
|
||||
}
|
||||
|
||||
// SendDM sends a direct message to a user. Reuses existing DM room if available.
|
||||
// No-op when the Matrix client is nil (which happens in unit tests that
|
||||
// construct plugins without a real client).
|
||||
func (b *Base) SendDM(userID id.UserID, text string) error {
|
||||
if b == nil || b.Client == nil {
|
||||
return nil
|
||||
}
|
||||
roomID, err := b.GetDMRoom(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user