using System; using System.Collections.Generic; using UnityEngine; namespace TKS.OutGame { /// 맹장 토벌전 세이브(기기 세이브 모드 · 서버 모드 = GET /tks/modes/raid 응답으로 덮는다). [Serializable] public class RaidState { public int week; public string entryDay = ""; public List entries = new List(); public long mainDamage; public long subDamage; public long score; public List milestones = new List(); public List shopBought = new List(); [Tooltip("토벌 훈장(raid_coin · 서버 모드 = 재화에서 온다)")] public int coins; [Tooltip("서버가 준 이번 주 메인 · 서브 · 순위(서버 모드)")] public bool serverView; public string main = ""; public string sub = ""; public int rank; public int rankTotal; public int mainHp; public int subHp; } /// /// 맹장 토벌전 규칙(기기 세이브 모드 · 서버 `domain/warlord.rules.ts` 와 같은 일정 · 횟수 · 점수 · 누적 단계 · 훈장 상점) — 순위 보상은 서버 모드만(실제 유저 순위). /// 값은 전부 표(RaidData · raid_rewards · raid_shop · content_modes_config raid.*). /// public static class RaidRules { public const string Kind = "raid2"; static void Roll(SaveData d, DateTime nowUtc) { var s = d.raid; if (s.serverView) return; // 서버 모드 = 서버가 주 · 날을 넘긴다 int week; string main, sub; RaidData.Schedule(nowUtc, out week, out main, out sub); if (s.week != week) { s.week = week; s.mainDamage = s.subDamage = s.score = 0; s.milestones.Clear(); s.shopBought.Clear(); } s.main = main; s.sub = sub; var day = EconomyRules.DayKey(nowUtc); if (s.entryDay != day) { s.entryDay = day; s.entries.Clear(); } } public static string BossOf(SaveData d, string slot, DateTime nowUtc) { Roll(d, nowUtc); return slot == RaidData.Main ? d.raid.main : d.raid.sub; } /// 맹장 토벌전 해금 스테이지 키(표 raid.unlock_stage · 연무장 잠김 안내 · 허브 이름표 조건). public static string UnlockStage { get { return ContentTables.Str(RaidData.Mode, "unlock_stage"); } } public static bool Unlocked(SaveData d) { if (d.raid.serverView) return true; if (TestOptions.UnlockAllStages && !SaveStore.MemoryOnly) return true; // 플레이 테스트 「전 스테이지 열기」 = 컨텐츠 해금도 무시(연의 전기 ScenarioModeRules 와 같음 · 메모리 세이브 테스트 · 캡처는 원래 판정 · PD 2026-11-18 「맹장 토벌전 · 투기장이 제대로 안 보임」) int ch, st; if (!ArenaRules.ParseStageKey(UnlockStage, out ch, out st)) return true; var s = d.Stage(ch, st, false); return s != null && s.clears > 0; } public static int Used(SaveData d, string slot, DateTime nowUtc) { Roll(d, nowUtc); return Counts.Get(d.raid.entries, slot); } public static string Can(SaveData d, string slot, bool practice, DateTime nowUtc) { if (ArenaRules.Settling(d, ArenaRules.Raid, nowUtc)) return ArenaRules.SettleNotice; if (!Unlocked(d)) return ContentTables.Str(RaidData.Mode, "unlock_stage") + " 클리어 뒤 열림"; if (string.IsNullOrEmpty(BossOf(d, slot, nowUtc))) return "오늘은 맹장이 없습니다"; if (practice) return ContentTables.Str(RaidData.Mode, "practice") == "unlimited" ? null : "연습 없음"; int limit = RaidData.EntryLimit(slot); if (Used(d, slot, nowUtc) >= limit) return "오늘 기록 도전 " + limit + "회 완료"; return null; } /// 입장 — 기록 도전은 자리마다 하루 횟수 1 사용(연습은 세지 않음). public static string Enter(SaveData d, string slot, bool practice, DateTime nowUtc) { var why = Can(d, slot, practice, nowUtc); if (why != null) return why; if (!practice) Counts.Add(d.raid.entries, slot, 1); return null; } /// 끝(기기 세이브 모드) — 피해(상한 n_hp) → 주간 점수 → 누적 단계 보상. public static ModeResult Result(OutGameData db, SaveData d, string slot, bool practice, string bossId, long damage, List lines, DateTime nowUtc, System.Random rng) { var b = RaidData.Get(bossId); var m = new ModeResult { kind = Kind, win = true, title = "맹장 토벌전 — " + (b != null ? b.nameKo : bossId) + (practice ? " (연습)" : "") }; if (lines != null) m.lines.AddRange(lines); if (practice) return m; Roll(d, nowUtc); long cap = b != null && b.hpCap > 0 ? b.hpCap : long.MaxValue; damage = Math.Min(cap, Math.Max(0, damage)); if (slot == RaidData.Main) d.raid.mainDamage += damage; else d.raid.subDamage += damage; d.raid.score = (long)Math.Floor(d.raid.mainDamage * RaidData.ScoreMult(RaidData.Main) + d.raid.subDamage * RaidData.ScoreMult(RaidData.Sub) + 1e-6); int play = ContentTables.Has(RaidData.Mode, "play_awaken_stone") ? ContentTables.Int(RaidData.Mode, "play_awaken_stone") : 0; // 기록 도전 1회마다 각성석(PD 2026-11-24) if (play > 0 && db.Awaken != null) { AwakenRules.AddGoods(d, db.Awaken.StoneKey, play); m.lines.Add(GoodsRules.NameOf(db, db.Awaken.StoneKey) + " +" + play); } m.lines.Add("이번 주 점수 " + d.raid.score.ToString("N0") + " (메인 " + d.raid.mainDamage.ToString("N0") + " × " + RaidData.ScoreMult(RaidData.Main) + " + 서브 " + d.raid.subDamage.ToString("N0") + ")"); foreach (var r in ContentTables.Rows(RaidData.Rewards)) { if (r.S("e_kind") != "milestone") continue; int step = r.I("n_step"); if (r.I("n_score_min") <= 0 || d.raid.score < r.I("n_score_min") || d.raid.milestones.Contains(step)) continue; d.raid.milestones.Add(step); m.lines.Add(r.S("s_band_ko") + " 달성 — " + GivePrize(db, d, r, rng)); } return m; } /// 보상 1줄(보옥 · 토벌 훈장 · 각성석 · 상자 「등급:수」) 지급 → 받은 것 글. static string GivePrize(OutGameData db, SaveData d, ContentRow r, System.Random rng) { var got = new List(); int gem = r.I("n_gem"), coin = r.I("n_raid_coin"), stone = r.I("n_awaken_stone"); if (gem > 0) { d.gem += gem; got.Add("보옥 +" + gem); } if (stone > 0 && db.Awaken != null) { AwakenRules.AddGoods(d, db.Awaken.StoneKey, stone); got.Add(GoodsRules.NameOf(db, db.Awaken.StoneKey) + " +" + stone); } if (coin > 0) { d.raid.coins += coin; got.Add("토벌 훈장 +" + coin); } foreach (var kv in ContentTables.ParseMap(r.S("s_chest"))) for (int i = 0; i < Mathf.RoundToInt(kv.Value); i++) { var id = TreasureRules.AddChest(db, d, kv.Key, rng); if (id != null) got.Add(db.Chests.Get(id).nameKo); } return string.Join(" · ", got.ToArray()); } // ---------- 훈장 상점 ---------- public static int Bought(SaveData d, string item, DateTime nowUtc) { Roll(d, nowUtc); return Counts.Get(d.raid.shopBought, item); } /// 구매(기기 세이브 모드) — 품목 · 고르는 것 = ShopRules(raid_shop · 진영 비서 = 진영 · 불멸 장비 = 「병종:부위」 · 보물 조각 = 보유 보물). public static string Buy(OutGameData db, SaveData d, string item, string pick, DateTime nowUtc, System.Random rng) { return ShopRules.Buy(db, d, ShopRules.RaidCoin, item, pick, nowUtc, rng); } } }