ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Scenario/ScenarioModeRules.cs

165 lines
7.4 KiB
C#
Raw Normal View History

컨텐츠 모드 4종 구현 — 보급전 · 맹장 토벌전 · 연의 전기 · 투기장(교대 조작) · 더미 UI (PD 2026-11-17~18) - 전투 규칙 플러그인 ModeBattleRules(BattleMode.rules) + 훅(피해 · 처치 · 기믹 파괴 · 밀려 막힘 · 턴 시작 · 승패 · 제한 턴 · 출전 자리 · 고정 편성 · 바람 조준 · 교대 조작 · 좁힌 전장) - 표 = Resources/ContentModes/*.csv(기획 tables 사본 · 실행 중 읽음) · 적 수치 기준 = 게임 스테이지 적(common.enemy_ref) - ① 보급전 4곳(병법 훈련 조건 · 과제 · 별 / 군량고 / 연병장 허수아비 / 황건 삼형제) · 판정 · 보상 · 소탕 · 그날 완료 · 주간 도장 · 옛 던전 id 기록 이전 - ③ 맹장 7명(기본 공격 · 패턴 예고 · 기세 · 협공 · 벽 충돌 · 빈틈 · 딸린 것 · 철수) · 일정 · 점수 · 누적 단계 · 훈장 상점 - ② 연의 전기 15편(고정 편성 · 타격 횟수 기준 적 세기 · 조건 21 · 불 번짐 · 수공 · 바람 · 원군 · 연전 · 돌진) · 보상 · 주역 조각 - ④ 투기장 교대 조작(AlternateStep) · 12x18 전장 · 시즌 지형 · 점수 · 등급 · 상대 3 - 서버 /tks/modes/* 연결 · gimmicks.csv 5줄(granary · lowland · dry_grass · warship · camp) · Fable QA 11건 반영 - 테스트: 전체 189 중 187 통과 · 실패 2(보스 판 첫 프레임 · 보물 상자 크기 = 기존 실패로 추정) · 기믹 행 수 기대값 21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 16:03:13 +00:00
using System;
using System.Collections.Generic;
using UnityEngine;
namespace TKS.OutGame
{
/// <summary>연의 전기 편 1개의 진행(연의 = normal · 열전 = hard · [승리, 도전 1, 도전 2]).</summary>
[Serializable]
public class ScenarioEpisode
{
public string id = "";
public bool[] normal = new bool[3];
public bool[] hard = new bool[3];
public bool allStar;
}
[Serializable]
public class ScenarioState
{
public List<ScenarioEpisode> episodes = new List<ScenarioEpisode>();
[Tooltip("보유하지 않은 영웅의 조각(주역 조각 · 모아서 획득 · 필요 수 = 추후)")]
public List<CountEntry> heroShards = new List<CountEntry>();
public bool serverView;
public List<string> serverUnlocked = new List<string>();
public ScenarioEpisode Get(string id, bool create)
{
foreach (var e in episodes)
if (e.id == id) return e;
if (!create) return null;
var n = new ScenarioEpisode { id = id };
episodes.Add(n);
return n;
}
}
/// <summary>
/// 연의 전기 규칙(기기 세이브 모드 · 서버 `/tks/modes/scenario` 와 같은 보상) — 입장 군량 scenario.stamina_cost · 지면 refund_on_lose_pct 환급 ·
/// 첫 승리 reward_normal / reward_hard · 도전 조건마다 *_challenge_gem · 6개 모두 reward_all_star · 주역 조각 = 보유 여부와 관계없이(reward_hero_shard always).
/// </summary>
public static class ScenarioModeRules
{
public const string Kind = "scenario";
const string M = "scenario";
public static List<ContentRow> Battles()
{
var res = new List<ContentRow>(ContentTables.Rows("scenario_battles"));
res.Sort((a, b) => a.I("n_no").CompareTo(b.I("n_no")));
return res;
}
public static bool Unlocked(SaveData d, ContentRow b)
{
if (d.scenario.serverView) return d.scenario.serverUnlocked.Contains(b.S("s_id"));
int ch, st;
if (!ArenaRules.ParseStageKey(b.S("s_unlock_stage"), out ch, out st)) return true;
var s = d.Stage(ch, st, false);
return s != null && s.clears > 0;
}
public static bool HardOpen(SaveData d, string id)
{
var e = d.scenario.Get(id, false);
return e != null && e.normal[0];
}
public static string Can(OutGameData db, SaveData d, string id, bool hard, DateTime nowUtc)
{
var b = ContentTables.Find("scenario_battles", "s_id", id);
if (b == null) return "없는 편";
if (b.I("n_no") == 0) return "서장 = 1장 학습 판(본편 1-1 ~ 1-3)";
if (!Unlocked(d, b)) return b.S("s_unlock_ko") + " 뒤 열림";
if (hard && !HardOpen(d, id)) return "열전 = 연의를 이긴 뒤";
EconomyRules.TickStamina(db, d, nowUtc);
int cost = ContentTables.Int(M, "stamina_cost");
if (d.stamina < cost) return "군량이 부족합니다 — 필요 " + cost;
return null;
}
/// <summary>입장 = 군량 사용.</summary>
public static string Enter(OutGameData db, SaveData d, string id, bool hard, DateTime nowUtc)
{
var why = Can(db, d, id, hard, nowUtc);
if (why != null) return why;
EconomyRules.SpendStamina(db, d, ContentTables.Int(M, "stamina_cost"), nowUtc);
return null;
}
/// <summary>끝(기기 세이브 모드) — 보상 · 진행 기록 · 지면 군량 환급.</summary>
public static ModeResult Result(OutGameData db, SaveData d, string id, bool hard, bool win, bool[] challenges, List<string> lines, DateTime nowUtc, System.Random rng)
{
var b = ContentTables.Find("scenario_battles", "s_id", id);
var m = new ModeResult { kind = Kind, win = win, title = (b != null ? b.S("s_title_ko") : id) + (hard ? " (열전)" : " (연의)") };
if (lines != null) m.lines.AddRange(lines);
if (!win)
{
int back = Mathf.RoundToInt(ContentTables.Int(M, "stamina_cost") * ContentTables.Num(M, "refund_on_lose_pct") / 100f);
if (back > 0) EconomyRules.AddStamina(db, d, back, nowUtc);
m.lines.Add("패배 — 군량 " + back + " 환급");
return m;
}
var e = d.scenario.Get(id, true);
var st = hard ? e.hard : e.normal;
var got = new List<string>();
if (!st[0]) GiveParts(db, d, b, ContentTables.Str(M, hard ? "reward_hard" : "reward_normal"), rng, got);
else if (ContentTables.Str(M, "reward_hero_shard") == "always") // 다시 이겨도 주역 조각(보유 여부 무관 · 양 = 첫 승리 꾸러미의 shard)
foreach (var kv in ContentTables.ParseMap(ContentTables.Str(M, hard ? "reward_hard" : "reward_normal")))
if (kv.Key == "shard") GiveShard(d, b, Mathf.RoundToInt(kv.Value), db, got);
st[0] = true;
int gem = ContentTables.Int(M, hard ? "reward_hard_challenge_gem" : "reward_normal_challenge_gem");
for (int i = 0; i < 2 && challenges != null && i < challenges.Length; i++)
if (challenges[i] && !st[i + 1])
{
st[i + 1] = true;
d.gem += gem;
got.Add("도전 " + (i + 1) + " 보옥 +" + gem);
}
if (!e.allStar && Array.TrueForAll(e.normal, x => x) && Array.TrueForAll(e.hard, x => x))
{
e.allStar = true;
GiveParts(db, d, b, ContentTables.Str(M, "reward_all_star"), rng, got);
}
if (got.Count > 0) m.lines.Add(string.Join(" · ", got.ToArray()));
return m;
}
static void GiveParts(OutGameData db, SaveData d, ContentRow b, string parts, System.Random rng, List<string> got)
{
foreach (var kv in ContentTables.ParseMap(parts))
{
int n = Mathf.RoundToInt(kv.Value);
if (kv.Key == "gem")
{
d.gem += n;
got.Add("보옥 +" + n);
}
else if (kv.Key == "gold")
{
d.gold += n;
got.Add("골드 +" + n);
}
else if (kv.Key == "shard") GiveShard(d, b, n, db, got);
else if (kv.Key.EndsWith("_chest"))
for (int i = 0; i < n; i++)
{
var c = TreasureRules.AddChest(db, d, kv.Key.Substring(0, kv.Key.Length - "_chest".Length), rng);
if (c != null) got.Add(db.Chests.Get(c).nameKo);
}
}
}
static void GiveShard(SaveData d, ContentRow b, int n, OutGameData db, List<string> got)
{
if (b == null || n <= 0) return;
string hero = b.S("s_reward_hero");
var h = d.Hero(hero);
if (h != null) h.shards += n;
else Counts.Add(d.scenario.heroShards, hero, n); // 보유하지 않은 영웅 = 따로 모은다(얻는 데 드는 수 = 추후)
var def = db.Heroes.Get(hero);
got.Add((def != null ? def.nameKo : hero) + " 조각 +" + n);
}
}
}