ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Trade/TradeData.cs

149 lines
6.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Globalization;
namespace TKS.OutGame
{
/// <summary>
/// 거래 상품 표(PD 2026-11-26 · 기획 `tables/_trade_v1` 사본 · Resources/ContentModes/trade_*.csv · 실행 중에 읽음) — 값은 전부 표(C45 · 가격 = trade_price_tiers 만 바꾸면 됨).
/// 게임 사본에만 덧붙인 칸(값 아님 · 코드 열쇠): packages n_open_chapter · s_popup_stage · s_art · s_banner / monthly l_perks · s_art / pass_growth s_open · s_art / gem · gold s_art.
/// 상품 id(구글 플레이) = tks_&lt;s_id&gt;.
/// </summary>
public static class TradeData
{
public const string Packages = "trade_packages";
public const string Monthly = "trade_monthly";
public const string PassGrowth = "trade_pass_growth";
public const string PassRewards = "trade_pass_rewards";
public const string Spend = "trade_spend_rewards";
public const string ShopDaily = "trade_shop_daily";
public const string Gems = "trade_gem_products";
public const string Golds = "trade_gold_products";
public const string Tiers = "trade_price_tiers";
public const string Config = "trade_config";
/// <summary>보옥 환산표(가치 배수 표시용 · 기획 value_conv 사본).</summary>
public const string ValueConv = "trade_value_conv";
public static readonly string[] Tables = { Packages, Monthly, PassGrowth, PassRewards, Spend, ShopDaily, Gems, Golds, Tiers, Config, ValueConv };
/// <summary>꾸러미의 보옥 환산(value_conv n_gem_value × 수 · 표에 없는 낱말 = 0).</summary>
public static float GemValue(string parts)
{
float v = 0f;
foreach (var kv in Items(parts))
{
var r = ContentTables.Find(ValueConv, "s_key", kv.Key);
if (r != null) v += r.F("n_gem_value") * kv.Value;
}
return v;
}
/// <summary>가치 배수 = 보옥 환산 ÷ (가격 ÷ 1000 × value_gem_per_krw1000) · 0 = 계산 못 함.</summary>
public static float ValueMult(float gemValue, int krw)
{
float per = Cfg("value_gem_per_krw1000", 100f);
return krw > 0 && per > 0f ? gemValue / (krw / 1000f * per) : 0f;
}
/// <summary>글자 표(로컬라이징 키 · UiText).</summary>
public const string TextTable = "UI/Trade/trade_text";
/// <summary>그림 경로(요청서 4절 · 그림 세션 약속) — 배너 · 카드 · 권 · 월정액 · 팝업 / 아이콘.</summary>
public const string ArtDir = "UI/Trade/art/";
public const string IconDir = "UI/Trade/icons/";
public const string ProductPrefix = "tks_";
// 묶음(packages s_group) · 초기화(s_reset)
public const string GFirst = "first", GAdFree = "adfree", GDaily = "daily", GWeekly = "weekly", GMonthly = "monthly", GChapter = "chapter";
public const string RNone = "none", RDaily = "daily", RWeekly = "weekly", RMonthly = "monthly";
public const string CurGold = "gold", CurGem = "gem", CurAd = "ad";
public static List<ContentRow> Rows(string table) { return ContentTables.Rows(table); }
public static ContentRow Package(string id) { return ContentTables.Find(Packages, "s_id", id); }
public static ContentRow MonthlyRow(string id) { return ContentTables.Find(Monthly, "s_id", id); }
public static ContentRow Pass(string id) { return ContentTables.Find(PassGrowth, "s_pass", id); }
public static ContentRow Gem(string id) { return ContentTables.Find(Gems, "s_id", id); }
public static ContentRow Gold(string id) { return ContentTables.Find(Golds, "s_id", id); }
public static string ProductId(string sid) { return ProductPrefix + sid; }
/// <summary>가격 단계 → 원화(표시 · 누적 결제 · 0 = 없는 단계).</summary>
public static int Krw(string tier)
{
var r = ContentTables.Find(Tiers, "s_tier", tier);
return r != null ? r.I("n_krw") : 0;
}
public static float Usd(string tier)
{
var r = ContentTables.Find(Tiers, "s_tier", tier);
return r != null ? r.F("n_usd") : 0f;
}
public static float Cfg(string key, float def)
{
var r = ContentTables.Find(Config, "key", key);
float v;
return r != null && ContentTables.TryNum(r.S("value"), out v) ? v : def;
}
public static int CfgInt(string key, int def)
{
return (int)Math.Round(Cfg(key, def));
}
/// <summary>상품 하나(s_id) → 종류(pkg · monthly · pass · gem · null).</summary>
public static string KindOf(string sid)
{
if (Package(sid) != null) return "pkg";
if (MonthlyRow(sid) != null) return "monthly";
if (Pass(sid) != null) return "pass";
if (Gem(sid) != null) return "gem";
return null;
}
/// <summary>결제 상품의 가격 단계(없으면 "").</summary>
public static string TierOf(string sid)
{
var r = Package(sid) ?? MonthlyRow(sid) ?? Gem(sid);
if (r != null) return r.S("s_tier");
var p = Pass(sid);
return p != null ? p.S("s_tier") : "";
}
public static int PriceKrw(string sid)
{
return Krw(TierOf(sid));
}
/// <summary>「키:수;키:수|키:수」 → 날(|)별 꾸러미 문자열(첫 결제 = 3일 · 그 밖 = 1개).</summary>
public static List<string> Days(string items)
{
var res = new List<string>();
if (string.IsNullOrEmpty(items)) return res;
foreach (var p in items.Split('|')) res.Add(p.Trim());
return res;
}
/// <summary>꾸러미 → (키, 수) 순서 목록(같은 키 = 합침 없음 · 표 순서 그대로).</summary>
public static List<KeyValuePair<string, int>> Items(string parts)
{
var res = new List<KeyValuePair<string, int>>();
if (string.IsNullOrEmpty(parts)) return res;
foreach (var part in parts.Split(';', '|'))
{
var kv = part.Split(':');
if (kv.Length != 2) continue;
int n;
if (!int.TryParse(kv[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out n)) continue;
res.Add(new KeyValuePair<string, int>(kv[0].Trim(), n));
}
return res;
}
/// <summary>「키:수;키:수」 → 사전(혜택 l_perks).</summary>
public static Dictionary<string, float> Map(string s)
{
return ContentTables.ParseMap(s);
}
}
}