ThreeKingdomsSlingshot/Assets/Scripts/OutGame/WanderRules.cs

153 lines
6.8 KiB
C#
Raw Normal View History

컨텐츠별 재화 배치 — 보물 상자 등급 확률 · 하드 난이도 · 등용권 · 상점 · 탑 소탕 · 영입 · 떠돌이 상인(PD 2026-11-24 「커밋 푸시 해」) 1차 · 2차(개발 요청서 「재화배치」 §1 ~ §3) - 새 표 chest_drop · chest_loot · hard_mode · hero_unlock(자산 GoodsDb) · medal_shop - 보물 상자 = 수급처별 등급 확률 + 내용 줄(운철 · 도면 · 보옥 · 진영 비서) · 스킬서 폐기 - 임무 · 보급전 · 투기장 · 토벌전 · 연의 전기 · 순찰 보상 교체 · 출정 첫 클리어 보옥 0 - 메달 · 훈장 상점(진영 비서 · 불멸 장비) · 출정 하드 난이도 · 영웅 조각 영입(40 · 50 · 60) · 탑 층 추가 보상 · 소탕 PD 2차 결정(요청서 §6) - 등용 포인트 삭제 · 「등용권」(구 뽑기권) · 중복 영웅 = 그 영웅 조각을 영입 수만큼(hero_unlock) - 천장 = 픽업 배너는 픽업 영웅 확정(gacha pity_pickup_featured) · 상시 배너 하루 1회 무료(픽업 제외) - 하드 하루 횟수 = 클리어했을 때만 차감 · 하드 월드맵 색 필터(밤) + 장 이름 띠 「· 하드」(UI/worldmap_hard) - 떠돌이 상인 = 영웅 조각을 날마다 칸별 확률로(★1 · ★2 골드 · ★3 보옥 · wander_shop · WanderRules) - 거래 > 보물 상자의 획득처 문구 정리 테스트: GoodsTests 19 · RecruitTests 9 · AwakenTests 6 · MissionTests 8 · GachaCutsceneTests 4 통과 서버 모드: 하드 · 메달 상점 · 탑 소탕 · 영입 · 떠돌이 상인은 막음(서버 규칙 없음) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 00:41:12 +00:00
using System;
using System.Collections.Generic;
namespace TKS.OutGame
{
/// <summary>떠돌이 상인이 오늘 내놓은 물품 1칸.</summary>
[Serializable]
public class WanderOffer
{
public string slot;
public string heroId;
public bool bought;
}
/// <summary>떠돌이 상인의 오늘 물품(날이 바뀌면 다시 굴린다).</summary>
[Serializable]
public class WanderState
{
public string day = "";
public List<WanderOffer> offers = new List<WanderOffer>();
}
/// <summary>
/// 떠돌이 상인(PD 2026-11-24 「상점의 영웅 조각 판매는 상시가 아니라 랜덤 · ★1 · ★2 영웅 조각 = 골드 · ★3 영웅 조각 = 보옥으로만」) — 표 wander_shop(ContentModes):
/// 칸(s_slot)마다 그날 나올 확률 f_appear_pct · 태생 ★ n_rarity 영웅 중 무작위 1명의 조각 n_amount 개 · 값 s_currency(gold · gem) n_price · 칸마다 하루 1번.
/// 대상 = 명장 등용 풀(gacha_pool in_pool)의 영웅(병사 제외) · 보유 = 그 영웅 조각 · 미보유 = 영입 조각(GoodsRules.AddHeroShards).
/// 날 경계 = EconomyRules.DayKey(승급 장비 상점과 같은 「매일 갱신」).
/// </summary>
public static class WanderRules
{
public const string Table = "wander_shop";
public const string Gold = "gold";
public const string Gem = "gem";
public static readonly string[] Currencies = { Gold, Gem };
public static List<ContentRow> Rows()
{
return ContentTables.Rows(Table);
}
public static ContentRow Row(string slot)
{
return ContentTables.Find(Table, "s_slot", slot);
}
/// <summary>그 태생 ★ 의 판매 대상 영웅(등용 풀 · 병사 제외).</summary>
public static List<HeroDb.Hero> Heroes(OutGameData db, int rarity)
{
var res = new List<HeroDb.Hero>();
foreach (var p in db.Gacha.pool)
{
if (!p.inPool) continue;
var h = db.Heroes.Get(p.heroId);
if (h != null && !h.isSoldier && h.rarity == rarity) res.Add(h);
}
return res;
}
/// <summary>오늘 물품을 새로 굴려야 하는가(처음 · 날이 바뀜).</summary>
public static bool NeedsRoll(SaveData d, DateTime nowUtc)
{
return d.wander == null || d.wander.day != EconomyRules.DayKey(nowUtc);
}
/// <summary>오늘의 물품(없을 수 있음) — 날이 바뀌었으면 칸마다 확률로 굴린다.</summary>
public static List<WanderOffer> Today(OutGameData db, SaveData d, DateTime nowUtc, System.Random rng)
{
if (NeedsRoll(d, nowUtc))
{
var st = new WanderState { day = EconomyRules.DayKey(nowUtc) };
foreach (var r in Rows())
{
if (rng.NextDouble() * 100.0 >= r.F("f_appear_pct")) continue;
var pool = Heroes(db, r.I("n_rarity"));
if (pool.Count == 0) continue;
st.offers.Add(new WanderOffer { slot = r.S("s_slot"), heroId = pool[rng.Next(pool.Count)].id });
}
d.wander = st;
}
return d.wander.offers;
}
static WanderOffer Offer(SaveData d, string slot)
{
if (d.wander != null)
foreach (var o in d.wander.offers)
if (o.slot == slot) return o;
return null;
}
/// <summary>null = 살 수 있음.</summary>
public static string Can(OutGameData db, SaveData d, string slot, DateTime nowUtc)
{
if (NeedsRoll(d, nowUtc)) return "오늘 물품이 아닙니다";
var o = Offer(d, slot);
var r = Row(slot);
if (o == null || r == null) return "없는 물품";
if (o.bought) return "이미 구매했습니다(칸마다 하루 1번)";
int price = r.I("n_price");
if (r.S("s_currency") == Gem)
{
if (d.gem < price) return "보옥 부족 " + d.gem + " / " + price;
}
else if (d.gold < price) return "골드 부족 " + d.gold + " / " + price;
return null;
}
/// <summary>구매(기기 세이브 모드) → 얻은 것(gains) · 반환 = 실패 사유(null = 성공).</summary>
public static string Buy(OutGameData db, SaveData d, string slot, DateTime nowUtc, List<Gain> gains = null)
{
var why = Can(db, d, slot, nowUtc);
if (why != null) return why;
var o = Offer(d, slot);
var r = Row(slot);
int price = r.I("n_price"), n = r.I("n_amount");
if (r.S("s_currency") == Gem) d.gem -= price;
else d.gold -= price;
GoodsRules.AddHeroShards(d, o.heroId, n);
o.bought = true;
if (gains != null)
{
var def = db.Heroes.Get(o.heroId);
GoodsRules.Add(gains, o.heroId, n, (def != null ? def.nameKo : o.heroId) + " 조각", "shard");
}
return null;
}
/// <summary>표 검사(데이터 테스트) — 칸 이름 · 태생 ★ · 확률 · 수량 · 값 · ★3 = 보옥 / ★1 · ★2 = 골드(PD 2026-11-24).</summary>
public static List<string> Validate(OutGameData db)
{
var e = new List<string>();
const string f = Table + ".csv";
var seen = new HashSet<string>();
var rows = Rows();
if (rows.Count == 0) e.Add(f + ": 줄 없음");
foreach (var r in rows)
{
string slot = r.S("s_slot"), cur = r.S("s_currency");
int rarity = r.I("n_rarity");
if (slot.Length == 0 || !seen.Add(slot)) e.Add(f + ": s_slot 「" + slot + "」 비었거나 중복");
if (rarity < 1 || rarity > 3) e.Add(f + ": " + slot + " n_rarity " + rarity + " = 1~3 이 아님");
else if (Heroes(db, rarity).Count == 0) e.Add(f + ": " + slot + " ★" + rarity + " 영웅이 등용 풀에 없음");
float pct = r.F("f_appear_pct");
if (pct < 0f || pct > 100f) e.Add(f + ": " + slot + " f_appear_pct " + pct + " = 0~100 이 아님");
if (r.I("n_amount") <= 0 || r.I("n_price") <= 0) e.Add(f + ": " + slot + " 수량 · 값 이상");
if (Array.IndexOf(Currencies, cur) < 0) e.Add(f + ": " + slot + " s_currency 「" + cur + "」 = gold · gem 이 아님");
else if ((rarity >= 3) != (cur == Gem)) e.Add(f + ": " + slot + " ★3 = 보옥 · ★1 · ★2 = 골드 여야 함");
}
return e;
}
}
}