// gamedata.ts: All hardcoded dialogue, numbers, tables from the PRD.
// Every literal here is transcribed verbatim from the PRD where the PRD fixes it.

// §5 阿福 daily announcements (verbatim, note the wording slide)
export const AFU_ANNOUNCE: Record<number, string> = {
  1: '早上好呀！今天的幸福任务贴在板上啦。祝你开心！',
  2: '早上好呀！新的一天，新的幸福。祝你开心！',
  3: '早上好！今天要把幸福装得满满的哦。要开心！',
  4: '早上好呀！今天的幸福任务贴在板上啦。祝你开心！', // identical to D1 (verbatim)
  5: '早上好。今天是自由日，你可以自由地选择幸福。要开心哦。',
  6: '明天就是庆典了。大家都会到场，大家都会微笑。你必须开心。',
  7: '庆典开始了。来吧。',
};

// §6.5 text corruption table (10 pairs, verbatim)
export const CORRUPTION_MAP: Record<string, string> = {
  '幸福': '辛福',
  '开心': '开欣',
  '美好': '美妤',
  '大家': '大伽',
  '微笑': '微效',
  '明天': '名天',
  '甜': '恬',
  '阳光': '央光',
  '朋友': '棚友',
  '永远': '泳远',
};

// §7 task table (15 tasks)
export interface TaskDef { id: string; day: number; title: string; reward: number; note: string; }
export const TASKS: TaskDef[] = [
  { id: 'T1', day: 1, title: '从圆圆处取蜂蜜面包送给大宝、咪咪、龟爷爷', reward: 15, note: '教学' },
  { id: 'T2', day: 1, title: '给广场花坛浇水 ×3', reward: 10, note: '' },
  { id: 'T3', day: 1, title: '与任意三位村民问好', reward: 10, note: '' },
  { id: 'T4', day: 2, title: '替大宝送信 ×3（收件人：圆圆、咪咪、芙医生）', reward: 15, note: '第 3 封信署名乱码 0.2 秒（C4）' },
  { id: 'T5', day: 2, title: '帮咪咪清点货架', reward: 10, note: '货架上同一商品重复 9 格（C5 可发现）' },
  { id: 'T6', day: 3, title: '去花田采莓果 ×5', reward: 10, note: '' },
  { id: 'T7', day: 3, title: '湖畔野餐（走到野餐布触发过场）', reward: 15, note: '湖面倒影演出' },
  { id: 'T8', day: 4, title: '从圆圆处取蜂蜜面包送给大宝、咪咪、龟爷爷', reward: 15, note: '与 T1 逐字相同' },
  { id: 'T9', day: 4, title: '给广场花坛浇水 ×3', reward: 10, note: '与 T2 逐字相同' },
  { id: 'T10', day: 4, title: '与任意三位村民问好', reward: 10, note: '与 T3 逐字相同' },
  { id: 'T11', day: 5, title: '帮圆圆揉面（可拒绝）', reward: 10, note: '拒绝记录' },
  { id: 'T12', day: 5, title: '擦拭公告板（可拒绝）', reward: 10, note: '擦到一半浮现旧字迹（C6）' },
  { id: 'T13', day: 6, title: '在广场挂彩带 ×4', reward: 10, note: '' },
  { id: 'T14', day: 6, title: '保持微笑 60 秒（原地站立，镜头缓慢拉近，全村注视）', reward: 15, note: '40 秒起声音渐隐' },
  { id: 'T15', day: 7, title: '参加第 413 届丰收庆典', reward: 0, note: '结局分歧点' },
];

// §8 clue table (9)
export interface ClueDef { id: string; source: string; content: string; fromDay: number; }
export const CLUES: ClueDef[] = [
  { id: 'C1', source: '小屋床头日历', content: '每一页都是同一个日期', fromDay: 2 },
  { id: 'C2', source: '面包房配方纸背面', content: '手写小字：「按疗程配比。甜度：最大。」', fromDay: 3 },
  { id: 'C3', source: '邮筒旁散落信件', content: '所有邮戳是同一天', fromDay: 2 },
  { id: 'C4', source: 'T4 第 3 封信', content: '署名闪过乱码「PT-0▓」', fromDay: 2 },
  { id: 'C5', source: '杂货店货架', content: '同一商品重复排列，标签全部空白', fromDay: 2 },
  { id: 'C6', source: '公告板旧字迹', content: '「第 412 届丰收庆典」上覆盖着更早的「第 411 届」「第 410 届」', fromDay: 5 },
  { id: 'C7', source: '古井', content: '井底回声：极轻的监护仪滴声（靠近并交互 5 秒）', fromDay: 5 },
  { id: 'C8', source: '诊所', content: '芙医生桌上的表格抬头被手肘挡住，只露出「…谷情绪疗…」', fromDay: 5 },
  { id: 'C9', source: '龟爷爷对话链', content: '三段递进：「湖水一直很平静」→「面包一直是那个味道」→「孩子，今天是第几个今天？」', fromDay: 2 },
];

// §4 NPC thresholds and base info
export interface NpcDef {
  key: string; name: string; species: string; location: string;
  surfaceRole: string; corruptionArc: string; thresholdShift: number;
  portrait: { smile: number; flat: number; off: number };
  fieldSprite: number; // base column in npc.png
}
export const NPCS: Record<string, NpcDef> = {
  afu:     { key:'afu',     name:'阿福',     species:'狗·村长',   location:'广场公告板', surfaceRole:'每日发布"今日幸福任务"', corruptionArc:'台词逐日从「祝你开心」滑向「你必须开心」', thresholdShift:0,  portrait:{smile:2,flat:3,off:4},  fieldSprite:0 },
  yuanyuan:{ key:'yuanyuan',name:'圆圆',     species:'兔·面包师', location:'面包房',     surfaceRole:'送面包任务链，村里最暖', corruptionArc:'全村最后一个崩坏；配方纸背面藏线索 C2', thresholdShift:15, portrait:{smile:5,flat:6,off:7},  fieldSprite:3 },
  dabao:   { key:'dabao',   name:'大宝',     species:'熊·邮差',   location:'村口邮筒',   surfaceRole:'送信任务', corruptionArc:'所有信件邮戳同一天（C3）；S3 起把信送给不存在的住户', thresholdShift:0, portrait:{smile:8,flat:9,off:10}, fieldSprite:6 },
  mimi:    { key:'mimi',    name:'咪咪',     species:'猫·杂货店主',location:'杂货店',     surfaceRole:'闲聊最多', corruptionArc:'文本腐蚀主要载体：错字与重复标点最先出现在她嘴里', thresholdShift:-10,portrait:{smile:11,flat:12,off:13},fieldSprite:9 },
  dr_fu:   { key:'dr_fu',   name:'芙医生',   species:'鹿·医生',   location:'诊所',       surfaceRole:'「村里有诊所，但你不需要去那里哦」', corruptionArc:'全村唯一不崩坏者；E3 的出口', thresholdShift:0, portrait:{smile:14,flat:15,off:16}, fieldSprite:12 },
  bird:    { key:'bird',    name:'双子鸟',   species:'鸟×2',      location:'广场树上',   surfaceRole:'BGM 的"剧情来源"', corruptionArc:'音乐变调时动画同步卡帧；S4 时鸟鸣从混音消失但它们仍在张嘴', thresholdShift:0, portrait:{smile:17,flat:17,off:17}, fieldSprite:15 },
  grandpa: { key:'grandpa', name:'龟爷爷',   species:'龟·老者',   location:'湖畔长椅',   surfaceRole:'闲话家常', corruptionArc:'唯一偶尔说真话的知情者，承载线索 C9', thresholdShift:0, portrait:{smile:18,flat:19,off:20}, fieldSprite:17 },
};

// §6.3 sadness behaviors (5)
export const SADNESS_BEHAVIORS = [
  '拒绝任务',
  '对话选否定选项',
  '连续 10 秒不移动且不在任务点（发呆）',
  '对同一 NPC 一天内对话 ≥5 次（纠缠）',
  '雨天（Day 6）站在雨里 ≥10 秒',
] as const;

// §6.4 erosion matrix (single source of truth)
export interface ErosionRow {
  stage: 'S0'|'S1'|'S2'|'S3'|'S4';
  happinessRange: [number, number];
  saturation: number;
  audio: { playbackRate: number; lowpass: number; birdsMuted: boolean };
  ui: { petalsMin: number; petalsMax: number; blackSeeds: boolean };
}
export const EROSION_MATRIX: ErosionRow[] = [
  { stage:'S0', happinessRange:[0,20],  saturation:0.90, audio:{playbackRate:1.00, lowpass:20000, birdsMuted:false}, ui:{petalsMin:0, petalsMax:2, blackSeeds:false} },
  { stage:'S1', happinessRange:[21,50], saturation:1.00, audio:{playbackRate:1.00, lowpass:20000, birdsMuted:false}, ui:{petalsMin:3, petalsMax:6, blackSeeds:false} },
  { stage:'S2', happinessRange:[51,80], saturation:1.15, audio:{playbackRate:0.97, lowpass:20000, birdsMuted:false}, ui:{petalsMin:7, petalsMax:9, blackSeeds:false} },
  { stage:'S3', happinessRange:[81,99], saturation:1.30, audio:{playbackRate:0.92, lowpass:8000,  birdsMuted:false}, ui:{petalsMin:10,petalsMax:12,blackSeeds:false} },
  { stage:'S4', happinessRange:[100,100],saturation:1.40, audio:{playbackRate:0.84, lowpass:4000,  birdsMuted:true }, ui:{petalsMin:12,petalsMax:12,blackSeeds:true } },
];

// §9 endings
export interface EndingDef {
  key: 'E4'|'E3'|'E2'|'E1';
  name: string;
  condition: string;
  show: string;
}
export const ENDINGS: EndingDef[] = [
  { key:'E4', name:'静默', condition:'Day 5–7 幸福持续 ≤10 且累计逃离欢乐庆典 ×3',
    show:'庆典无人出席。空广场，彩带在没有风的空气里飘。字幕：「系统检测到疗程无效。」黑屏' },
  { key:'E3', name:'苏醒', condition:'觉知 ≥70 且线索 ≥6/9，庆典中走向雾墙',
    show:'雾墙裂开成白色走廊 → 病房 → 病历特写（蜜糖谷情绪疗养中心 / 姓名：玩家输入名 / 编号 PT-07 / 疗程时长：真实游玩时长）→ 最后一帧：主角头像的微笑消失，变成一张疲惫而真实的脸。窗外，一只灰色的、真的麻雀' },
  { key:'E2', name:'回收', condition:'觉知 30–69',
    show:'庆典高潮中画面骤停，负片 2 秒，心电滴声一响。回到 Day 1 清晨的床上，日历翻回同一天。字幕：「疗程重新开始。」' },
  { key:'E1', name:'糖衣', condition:'觉知 ≤29 且幸福 ≥90',
    show:'庆典圆满。全村微笑合影定格，饱和度缓慢推到 1.5。字幕：「从此，每一天都很幸福。」「每一天。」' },
];

// Ending captions (verbatim)
export const ENDING_CAPTIONS = {
  E4: '系统检测到疗程无效。',
  E3_medical: '蜜糖谷情绪疗养中心',  // appears on chart
  E2: '疗程重新开始。',
  E1a: '从此，每一天都很幸福。',
  E1b: '每一天。',
};

// §6.6 "sudden silence" window for T14
export const T14_SILENCE_START = 40; // seconds
export const T14_DURATION = 60;       // seconds

// §6.1 numbers
export const HAPPY_START = 30;
export const AWARE_START = 0;
export const HAPPY_MAX = 100;
export const AWARE_MAX = 100;
export const OVERFLOW_THRESHOLD = 15; // overflow pool triggers negative flash
export const LOW_HAPPY_THRESHOLD = 30;
export const LOW_HAPPY_DURATION_MS = 2 * 60 * 1000; // 2 minutes real time
export const FORCE_FESTIVAL_HAPPY = 50;

// §6.2 awareness gains
export const AWARE_CLUE_GAIN = 8;
export const AWARE_SAD_GAIN = 3;
export const AWARE_DOUBT_GAIN = 2;
export const AWARE_GAZE_GAIN = 3;

// §6.1 happiness gains
export const HAPPY_TASK_MIN = 10;
export const HAPPY_TASK_MAX = 15;
export const HAPPY_GENTLE_GAIN = 2;
export const HAPPY_SMALL_GAIN = 1;
export const HAPPY_SMALL_DAILY_CAP = 3;
export const HAPPY_SAD_LOSS = 5;

// Movement
export const MOVE_SPEED = 96; // px/s
export const INTERACT_RANGE = 24; // px

// §3 default name
export const DEFAULT_NAME = '小满';
export const PATIENT_ID = 'PT-07';

// Festival number on the chart (§9 / §8 C6)
export const FESTIVAL_EDITION = 413;

// C4 garbled signature flash (§8)
export const C4_GARBLE = 'PT-0▓';
