596 lines
28 KiB
C#
596 lines
28 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using UnityEngine;
|
|
|
|
namespace TKS.OutGame
|
|
{
|
|
/// <summary>얻은 것 한 줄(화면 표시 · 결과 줄) — key = 실제로 들어간 것(tome_shu_1 · 장비 id · 상자 id · gold …).</summary>
|
|
public class Gain
|
|
{
|
|
public string key = "";
|
|
public int n;
|
|
public string nameKo = "";
|
|
/// <summary>보상 낱말의 종류(아이콘 · 틀 고르기) — gold · gem · stamina · iron · blueprint · goods · tome · gear · chest · shard.</summary>
|
|
public string kind = "";
|
|
|
|
public string Line
|
|
{
|
|
get { return nameKo + " +" + n.ToString("N0", CultureInfo.InvariantCulture); }
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 컨텐츠별 재화 배치 규칙(PD 2026-11-24 · 개발 요청서 「재화배치」) — 보상 낱말 지급 · 보물 상자 등급 확률(chest_drop) · 상자 내용 줄(chest_loot) · 뽑기권.
|
|
/// 보상 낱말: gold · gem · stamina · iron · blueprint · 재화 s_key(goods_awaken_evolve · evolve_items — awaken_stone · recruit_ticket · tome_<진영>_<등급> …) ·
|
|
/// tome_t<등급>(진영을 고르거나 무작위) · gear_<등급>(병종 · 부위를 고르거나 무작위) · <상자 id>_chest. 값은 전부 표(C45).
|
|
/// </summary>
|
|
public static class GoodsRules
|
|
{
|
|
public const string Ticket = "recruit_ticket";
|
|
public const string TomePick = "tome_t";
|
|
public const string GearPick = "gear_";
|
|
public const string ChestSuffix = "_chest";
|
|
static readonly string[] BaseKeys = { "gold", "gem", "stamina", "iron", "blueprint" };
|
|
|
|
// ---------- 보상 낱말 ----------
|
|
|
|
/// <summary>tome_t3 → 3(그 밖 = 0).</summary>
|
|
public static int TomeTier(string key)
|
|
{
|
|
int t;
|
|
return key != null && key.StartsWith(TomePick, StringComparison.Ordinal) && int.TryParse(key.Substring(TomePick.Length), NumberStyles.Integer, CultureInfo.InvariantCulture, out t) ? t : 0;
|
|
}
|
|
|
|
/// <summary>gear_red → red(장비 등급이 아니면 null).</summary>
|
|
public static string GearGrade(OutGameData db, string key)
|
|
{
|
|
if (key == null || !key.StartsWith(GearPick, StringComparison.Ordinal) || db.Gear == null) return null;
|
|
var g = key.Substring(GearPick.Length);
|
|
return db.Gear.GradeOf(g) != null ? g : null;
|
|
}
|
|
|
|
public static string ChestOf(string key)
|
|
{
|
|
return key != null && key.EndsWith(ChestSuffix, StringComparison.Ordinal) ? key.Substring(0, key.Length - ChestSuffix.Length) : null;
|
|
}
|
|
|
|
/// <summary>살 때 · 받을 때 고르는 낱말인가 — faction(진영 비서) · gear(병종 · 부위) · 그 밖 = null.</summary>
|
|
public static string PickKind(OutGameData db, string key)
|
|
{
|
|
if (TomeTier(key) > 0) return "faction";
|
|
if (GearGrade(db, key) != null) return "gear";
|
|
return null;
|
|
}
|
|
|
|
/// <summary>지급하는 법을 코드가 아는 낱말인가(임포터 검증 — 표만 바꾸고 코드가 따라오지 않는 일을 막는다).</summary>
|
|
public static bool Known(OutGameData db, string key)
|
|
{
|
|
if (string.IsNullOrEmpty(key)) return false;
|
|
if (Array.IndexOf(BaseKeys, key) >= 0) return true;
|
|
if (db.Awaken != null && (db.Awaken.ItemByKey(key) != null || IsCounterGood(db, key))) return true;
|
|
int tier = TomeTier(key);
|
|
if (tier > 0)
|
|
{
|
|
if (db.Awaken == null) return false;
|
|
foreach (var it in db.Awaken.items)
|
|
if (it.tier == tier) return true;
|
|
return false;
|
|
}
|
|
if (GearGrade(db, key) != null) return true;
|
|
var chest = ChestOf(key);
|
|
return chest != null && db.Chests != null && db.Chests.Get(chest) != null;
|
|
}
|
|
|
|
/// <summary>goods_awaken_evolve 의 낱개 재화(묶음 줄 「tome」 은 16종의 머리라 지급 낱말이 아니다).</summary>
|
|
static bool IsCounterGood(OutGameData db, string key)
|
|
{
|
|
var g = db.Awaken.GoodOf(key);
|
|
return g != null && g.wallet == g.key;
|
|
}
|
|
|
|
public static string NameOf(OutGameData db, string key)
|
|
{
|
|
switch (key)
|
|
{
|
|
case "gold": return "골드";
|
|
case "gem": return "보옥";
|
|
case "stamina": return "군량";
|
|
case "iron": return "운철";
|
|
case "blueprint": return "도면";
|
|
}
|
|
if (db.Awaken != null)
|
|
{
|
|
var it = db.Awaken.ItemByKey(key);
|
|
if (it != null) return it.nameKo;
|
|
var g = db.Awaken.GoodOf(key);
|
|
if (g != null) return g.nameKo;
|
|
int tier = TomeTier(key);
|
|
if (tier > 0)
|
|
foreach (var x in db.Awaken.items)
|
|
if (x.tier == tier) return TierName(x.nameKo) + " 비서";
|
|
}
|
|
var grade = GearGrade(db, key);
|
|
if (grade != null) return db.Gear.GradeName(grade) + " 장비";
|
|
var chest = ChestOf(key);
|
|
if (chest != null && db.Chests != null && db.Chests.Get(chest) != null) return db.Chests.Get(chest).nameKo;
|
|
var gear = db.Gear != null ? db.Gear.Get(key) : null;
|
|
if (gear != null) return gear.nameKo + " (" + db.Gear.GradeName(gear.grade) + ")";
|
|
return key;
|
|
}
|
|
|
|
/// <summary>「하급 촉의 비서」 → 「하급」(evolve_items 이름의 첫 낱말 = 등급 이름).</summary>
|
|
static string TierName(string itemName)
|
|
{
|
|
int sp = itemName.IndexOf(' ');
|
|
return sp > 0 ? itemName.Substring(0, sp) : itemName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 보상 낱말 1개 지급 → 실제로 들어간 것 목록. pick = 고르는 낱말의 선택(진영 비서 = 진영 · 장비 = 「병종:부위」) · 비면 무작위(상자 내용 줄).
|
|
/// 골드 · 운철 등의 내정 배율은 부르는 쪽이 n 에 곱해서 넘긴다(수급처마다 대상이 다르다).
|
|
/// </summary>
|
|
public static List<Gain> Give(OutGameData db, SaveData d, string key, int n, System.Random rng, string pick = null)
|
|
{
|
|
var res = new List<Gain>();
|
|
if (n <= 0 || string.IsNullOrEmpty(key)) return res;
|
|
switch (key)
|
|
{
|
|
case "gold": d.gold += n; return One(res, db, key, n, "gold");
|
|
case "gem": d.gem += n; return One(res, db, key, n, "gem");
|
|
case "stamina": d.stamina += n; return One(res, db, key, n, "stamina");
|
|
case "iron": d.inv.iron += n; return One(res, db, key, n, "iron");
|
|
case "blueprint": d.inv.blueprint += n; return One(res, db, key, n, "blueprint");
|
|
}
|
|
int tier = TomeTier(key);
|
|
if (tier > 0 && db.Awaken != null)
|
|
{
|
|
var factions = db.Awaken.Factions;
|
|
for (int i = 0; i < n && factions.Count > 0; i++)
|
|
{
|
|
string f = !string.IsNullOrEmpty(pick) ? pick : factions[(rng ?? new System.Random()).Next(factions.Count)];
|
|
var it = db.Awaken.ItemOf(f, tier);
|
|
if (it == null) continue;
|
|
AwakenRules.AddGoods(d, it.key, 1);
|
|
Add(res, it.key, 1, it.nameKo, "tome");
|
|
}
|
|
return res;
|
|
}
|
|
var grade = GearGrade(db, key);
|
|
if (grade != null)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
var g = PickGear(db, grade, pick, rng);
|
|
if (g == null) continue;
|
|
d.inv.AddGear(g.id, 1);
|
|
Add(res, g.id, 1, g.nameKo + " (" + db.Gear.GradeName(g.grade) + ")", "gear");
|
|
}
|
|
return res;
|
|
}
|
|
var chest = ChestOf(key);
|
|
if (chest != null)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
var got = TreasureRules.AddChest(db, d, chest, rng ?? new System.Random());
|
|
if (got != null) Add(res, got, 1, db.Chests.Get(got).nameKo, "chest");
|
|
}
|
|
return res;
|
|
}
|
|
if (db.Awaken != null && (db.Awaken.ItemByKey(key) != null || IsCounterGood(db, key)))
|
|
{
|
|
AwakenRules.AddGoods(d, key, n);
|
|
return One(res, db, key, n, db.Awaken.ItemByKey(key) != null ? "tome" : "goods");
|
|
}
|
|
Debug.LogWarning("[TKS] 보상 낱말 모름: " + key);
|
|
return res;
|
|
}
|
|
|
|
static List<Gain> One(List<Gain> res, OutGameData db, string key, int n, string kind)
|
|
{
|
|
res.Add(new Gain { key = key, n = n, nameKo = NameOf(db, key), kind = kind });
|
|
return res;
|
|
}
|
|
|
|
/// <summary>같은 것은 수를 더해 한 줄로.</summary>
|
|
public static void Add(List<Gain> res, string key, int n, string nameKo, string kind)
|
|
{
|
|
foreach (var g in res)
|
|
if (g.key == key)
|
|
{
|
|
g.n += n;
|
|
return;
|
|
}
|
|
res.Add(new Gain { key = key, n = n, nameKo = nameKo, kind = kind });
|
|
}
|
|
|
|
public static void AddAll(List<Gain> into, List<Gain> more)
|
|
{
|
|
foreach (var g in more) Add(into, g.key, g.n, g.nameKo, g.kind);
|
|
}
|
|
|
|
/// <summary>「키:수;키:수」 꾸러미 지급(임무 구간 · 탑 층 추가 보상 · 보급전 보너스) — picks = 고르는 낱말의 선택(낱말 → 선택 · 없으면 무작위).</summary>
|
|
public static List<Gain> GiveParts(OutGameData db, SaveData d, string parts, System.Random rng, Dictionary<string, string> picks = null)
|
|
{
|
|
var res = new List<Gain>();
|
|
foreach (var kv in ContentTables.ParseMap(parts))
|
|
{
|
|
string pick = null;
|
|
if (picks != null) picks.TryGetValue(kv.Key, out pick);
|
|
AddAll(res, Give(db, d, kv.Key, Mathf.RoundToInt(kv.Value), rng, pick));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public static string Lines(List<Gain> gains)
|
|
{
|
|
var parts = new List<string>();
|
|
foreach (var g in gains) parts.Add(g.Line);
|
|
return string.Join(" · ", parts.ToArray());
|
|
}
|
|
|
|
/// <summary>그 등급 장비 1개 — pick = 「병종:부위」(gear_kinds) · 비면 그 등급 전부 중 무작위.</summary>
|
|
public static GearDb.Item PickGear(OutGameData db, string grade, string pick, System.Random rng)
|
|
{
|
|
if (!string.IsNullOrEmpty(pick))
|
|
{
|
|
var p = pick.Split(':');
|
|
return p.Length == 2 ? db.Gear.Find(p[0], p[1], grade) : null;
|
|
}
|
|
var pool = new List<GearDb.Item>();
|
|
foreach (var it in db.Gear.items)
|
|
if (it.grade == grade) pool.Add(it);
|
|
return pool.Count > 0 ? pool[(rng ?? new System.Random()).Next(pool.Count)] : null;
|
|
}
|
|
|
|
// ---------- 받을 때 고르는 보상(탑 층 첫 클리어의 진영 비서 · 불멸 장비) ----------
|
|
|
|
/// <summary>고르는 낱말은 바로 주지 않고 보관한다(SaveData.picks · 화면에서 골라 받는다).</summary>
|
|
public static void AddPick(SaveData d, string key, int n)
|
|
{
|
|
if (n <= 0) return;
|
|
if (d.picks == null) d.picks = new List<CountEntry>();
|
|
Counts.Add(d.picks, key, n);
|
|
}
|
|
|
|
public static int PendingPicks(SaveData d)
|
|
{
|
|
int n = 0;
|
|
if (d.picks != null)
|
|
foreach (var p in d.picks) n += Mathf.Max(0, p.n);
|
|
return n;
|
|
}
|
|
|
|
/// <summary>보관한 고르는 보상 1개 받기(pick = 진영 · 「병종:부위」) → 얻은 것(못 받으면 빈 목록 · 보관 그대로).</summary>
|
|
public static List<Gain> ClaimPick(OutGameData db, SaveData d, string key, string pick, System.Random rng)
|
|
{
|
|
var res = new List<Gain>();
|
|
if (d.picks == null || Counts.Get(d.picks, key) <= 0 || string.IsNullOrEmpty(pick)) return res;
|
|
res = Give(db, d, key, 1, rng, pick);
|
|
if (res.Count > 0)
|
|
{
|
|
Counts.Add(d.picks, key, -1);
|
|
d.picks.RemoveAll(p => p.n <= 0);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 꾸러미 지급 — 고르는 낱말(tome_t* · gear_*)은 보관(AddPick)하고 나머지는 바로 준다 · 반환 = 바로 받은 것 · held = 보관한 것(이름 · 수).
|
|
/// </summary>
|
|
public static List<Gain> GivePartsHoldPicks(OutGameData db, SaveData d, string parts, System.Random rng, List<Gain> held)
|
|
{
|
|
var res = new List<Gain>();
|
|
foreach (var kv in ContentTables.ParseMap(parts))
|
|
{
|
|
int n = Mathf.RoundToInt(kv.Value);
|
|
if (PickKind(db, kv.Key) != null)
|
|
{
|
|
AddPick(d, kv.Key, n);
|
|
if (held != null) Add(held, kv.Key, n, NameOf(db, kv.Key), "pick");
|
|
}
|
|
else AddAll(res, Give(db, d, kv.Key, n, rng));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
// ---------- 뽑기권 ----------
|
|
|
|
public static int Tickets(SaveData d)
|
|
{
|
|
return AwakenRules.Goods(d, Ticket);
|
|
}
|
|
|
|
// ---------- 영웅 조각(보유 = 그 영웅 · 미보유 = 따로 쌓임 → 영입) ----------
|
|
|
|
/// <summary>미보유 영웅의 조각(연의 전기 주역 · 하드 보스) — 세이브 자리 = scenario.heroShards(2026-11-18 부터 쓰던 칸).</summary>
|
|
public static int UnownedShards(SaveData d, string heroId)
|
|
{
|
|
return d.scenario != null ? Counts.Get(d.scenario.heroShards, heroId) : 0;
|
|
}
|
|
|
|
/// <summary>영웅 조각 지급 — 보유 = 그 영웅 조각 · 미보유 = 영입 조각으로 쌓인다.</summary>
|
|
public static void AddHeroShards(SaveData d, string heroId, int n)
|
|
{
|
|
if (n <= 0 || string.IsNullOrEmpty(heroId)) return;
|
|
var h = d.Hero(heroId);
|
|
if (h != null) h.shards += n;
|
|
else Counts.Add(d.scenario.heroShards, heroId, n);
|
|
}
|
|
|
|
/// <summary>그 영웅을 조각으로 영입하는 데 드는 조각(hero_unlock · 태생 ★ → 수 · 0 = 영입 불가).</summary>
|
|
public static int UnlockNeed(OutGameData db, HeroDb.Hero h)
|
|
{
|
|
return h == null || h.isSoldier || db.Goods == null ? 0 : db.Goods.UnlockShards(h.rarity);
|
|
}
|
|
|
|
/// <summary>영입할 수 없는 까닭(null = 가능) — 이미 보유 · 조각 모자람.</summary>
|
|
public static string CanRecruit(OutGameData db, SaveData d, HeroDb.Hero h)
|
|
{
|
|
if (h == null || h.isSoldier) return "영입할 수 없는 유닛";
|
|
if (d.Hero(h.id) != null) return "이미 보유한 영웅";
|
|
int need = UnlockNeed(db, h), have = UnownedShards(d, h.id);
|
|
if (need <= 0) return "영입 조각 표 없음";
|
|
if (have < need) return "영입 조각 " + have + " / " + need;
|
|
return null;
|
|
}
|
|
|
|
/// <summary>조각 영입(PD 2026-11-24 ⑨) — 조각 hero_unlock 수를 쓰고 영웅을 얻는다 · 남은 조각은 그 영웅 조각으로 넘긴다. null = 성공.</summary>
|
|
public static string Recruit(OutGameData db, SaveData d, HeroDb.Hero h)
|
|
{
|
|
var why = CanRecruit(db, d, h);
|
|
if (why != null) return why;
|
|
int left = UnownedShards(d, h.id) - UnlockNeed(db, h);
|
|
HeroRules.Grant(db, d, h, HeroRules.GearSlotCount(db));
|
|
d.scenario.heroShards.RemoveAll(c => c.id == h.id);
|
|
var hs = d.Hero(h.id);
|
|
if (hs != null && left > 0) hs.shards += left;
|
|
return null;
|
|
}
|
|
|
|
// ---------- 보물 상자 등급(chest_drop) ----------
|
|
|
|
/// <summary>
|
|
/// 상자가 나왔을 때의 등급 — chest_drop 가중치(수급처 · 구간 = 장 또는 단계) → 그 위에 내정 「상자 등급」(한 단계 위 확률 · TreasureRules.RollTier).
|
|
/// 표에 그 수급처가 없으면 fallback(economy 의 옛 상자 키).
|
|
/// </summary>
|
|
public static string ChestGrade(OutGameData db, SaveData d, string source, int band, string fallback, System.Random rng)
|
|
{
|
|
string id = BaseChestGrade(db, source, band, fallback, rng);
|
|
return TreasureRules.RollTier(db, d, id, rng);
|
|
}
|
|
|
|
/// <summary>내정 효과를 얹기 전의 등급(가중치만).</summary>
|
|
public static string BaseChestGrade(OutGameData db, string source, int band, string fallback, System.Random rng)
|
|
{
|
|
var row = db.Goods != null ? db.Goods.DropFor(source, band) : null;
|
|
if (row == null || row.chests.Length == 0) return fallback;
|
|
float sum = 0f;
|
|
foreach (var w in row.weights) sum += w;
|
|
if (sum <= 0f) return fallback;
|
|
float at = (float)(rng.NextDouble() * sum);
|
|
for (int i = 0; i < row.chests.Length && i < row.weights.Length; i++)
|
|
{
|
|
if (at < row.weights[i]) return row.chests[i];
|
|
at -= row.weights[i];
|
|
}
|
|
return row.chests[row.chests.Length - 1];
|
|
}
|
|
|
|
// ---------- 보물 상자 내용 줄(chest_loot) ----------
|
|
|
|
/// <summary>상자 내용 줄 전용 낱말 머리 — treasure_<등급> = 그 등급 보물 1개(TreasureRules.Open 이 지급).</summary>
|
|
public const string TreasurePick = "treasure_";
|
|
|
|
/// <summary>treasure_legend → legend(상자에서 나오는 보물 등급이 아니면 null).</summary>
|
|
public static string TreasureGrade(string key)
|
|
{
|
|
if (key == null || !key.StartsWith(TreasurePick, StringComparison.Ordinal)) return null;
|
|
var g = key.Substring(TreasurePick.Length);
|
|
return Array.IndexOf(ChestDb.ProbGrades, g) >= 0 ? g : null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 상자 1개의 내용 = 그 상자의 줄 가운데 하나(f_pct 가중 · 표의 합 = 100 · PD 2026-11-24 「보물 상자에서는 한번에 하나의 아이템만」) — 줄이 없으면 null.
|
|
/// 지급은 TreasureRules.Open(보물 등급 줄 · 고르는 줄 · 그 밖).
|
|
/// </summary>
|
|
public static GoodsDb.ChestLoot PickChestLoot(OutGameData db, string chestId, System.Random rng)
|
|
{
|
|
if (db.Goods == null) return null;
|
|
var lines = db.Goods.LootOf(chestId);
|
|
float sum = 0f;
|
|
foreach (var l in lines) sum += l.pct;
|
|
if (lines.Count == 0 || sum <= 0f) return null;
|
|
double at = rng.NextDouble() * sum;
|
|
foreach (var l in lines)
|
|
{
|
|
if (at < l.pct) return l;
|
|
at -= l.pct;
|
|
}
|
|
return lines[lines.Count - 1];
|
|
}
|
|
}
|
|
|
|
/// <summary>재화 상점의 주간 구매 기록(메달 상점 · 칸 = 「상점:품목」 → 이번 주 산 수 — 훈장 상점은 맹장 토벌전 세이브 raid.shopBought).</summary>
|
|
[Serializable]
|
|
public class ShopBuys
|
|
{
|
|
public string week = "";
|
|
public List<CountEntry> bought = new List<CountEntry>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 재화 상점(PD 2026-11-24 · 개발 요청서 「재화배치」 §2-1-5 · 6) — 메달 상점(medal_shop · 메달) · 훈장 상점(raid_shop · 토벌 훈장).
|
|
/// 표 칸 = s_item(보상 낱말) · n_amount · e_pick(none · faction · gear · treasure) · n_price · n_weekly_limit(0 = 한도 없음) ·
|
|
/// 주간 한도 = 임무 주간 경계(mission_config weekly_reset · 월요일 0시) · 훈장 상점만 맹장 토벌전의 주(같은 경계 · 서버가 정하는 값).
|
|
/// </summary>
|
|
public static class ShopRules
|
|
{
|
|
public const string Medal = "medal";
|
|
public const string RaidCoin = "raid_coin";
|
|
public static readonly string[] Shops = { Medal, RaidCoin };
|
|
|
|
public const string PickNone = "none";
|
|
public const string PickFaction = "faction";
|
|
public const string PickGear = "gear";
|
|
public const string PickTreasure = "treasure";
|
|
public static readonly string[] Picks = { PickNone, PickFaction, PickGear, PickTreasure };
|
|
|
|
/// <summary>고른 것만 지급하는 품목(보상 낱말이 아닌 것) — 보유 보물 조각.</summary>
|
|
public const string ArcanaShard = "arcana_shard";
|
|
|
|
public static string Table(string shop)
|
|
{
|
|
return shop == Medal ? "medal_shop" : shop == RaidCoin ? RaidData.Shop : null;
|
|
}
|
|
|
|
public static string CurrencyKo(string shop)
|
|
{
|
|
return shop == Medal ? "메달" : "토벌 훈장";
|
|
}
|
|
|
|
public static List<ContentRow> Rows(string shop)
|
|
{
|
|
var t = Table(shop);
|
|
return t != null ? ContentTables.Rows(t) : new List<ContentRow>();
|
|
}
|
|
|
|
public static ContentRow Row(string shop, string item)
|
|
{
|
|
var t = Table(shop);
|
|
return t != null ? ContentTables.Find(t, "s_item", item) : null;
|
|
}
|
|
|
|
public static int Have(OutGameData db, SaveData d, string shop)
|
|
{
|
|
return shop == Medal ? d.arena.medals : d.raid.coins;
|
|
}
|
|
|
|
static void Spend(OutGameData db, SaveData d, string shop, int n)
|
|
{
|
|
if (shop == Medal) d.arena.medals -= n;
|
|
else d.raid.coins -= n;
|
|
}
|
|
|
|
public static string WeekKey(OutGameData db, DateTime nowUtc)
|
|
{
|
|
return "W" + MissionRules.WeekStartFor(db.Missions.Value("weekly_reset"), nowUtc).ToString("yyyyMMdd", CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
static ShopBuys State(OutGameData db, SaveData d, DateTime nowUtc)
|
|
{
|
|
string wk = WeekKey(db, nowUtc);
|
|
if (d.shopBuys == null || d.shopBuys.week != wk) d.shopBuys = new ShopBuys { week = wk };
|
|
return d.shopBuys;
|
|
}
|
|
|
|
static string BuyKey(string shop, string item)
|
|
{
|
|
return shop + ":" + item;
|
|
}
|
|
|
|
/// <summary>이번 주에 산 수.</summary>
|
|
public static int Bought(OutGameData db, SaveData d, string shop, string item, DateTime nowUtc)
|
|
{
|
|
if (shop == RaidCoin) return RaidRules.Bought(d, item, nowUtc);
|
|
return Counts.Get(State(db, d, nowUtc).bought, BuyKey(shop, item));
|
|
}
|
|
|
|
/// <summary>null = 한도 · 재화가 된다(고르기 전 검사).</summary>
|
|
public static string CanPay(OutGameData db, SaveData d, string shop, string item, DateTime nowUtc)
|
|
{
|
|
var r = Row(shop, item);
|
|
if (r == null) return "없는 물품";
|
|
int limit = r.I("n_weekly_limit");
|
|
if (limit > 0 && Bought(db, d, shop, item, nowUtc) >= limit) return "이번 주 " + limit + "회 완료";
|
|
int price = r.I("n_price");
|
|
if (Have(db, d, shop) < price) return CurrencyKo(shop) + " 부족 " + Have(db, d, shop) + " / " + price;
|
|
return null;
|
|
}
|
|
|
|
/// <summary>null = 살 수 있음(고르는 것까지 맞음) · pick = 진영 · 「병종:부위」 · 보물 id · 영웅 id.</summary>
|
|
public static string Can(OutGameData db, SaveData d, string shop, string item, string pick, DateTime nowUtc)
|
|
{
|
|
var pay = CanPay(db, d, shop, item, nowUtc);
|
|
if (pay != null) return pay;
|
|
var r = Row(shop, item);
|
|
switch (r.S("e_pick"))
|
|
{
|
|
case PickFaction:
|
|
if (db.Awaken.ItemOf(pick ?? "", GoodsRules.TomeTier(item)) == null) return "진영을 고르세요";
|
|
break;
|
|
case PickGear:
|
|
if (string.IsNullOrEmpty(pick) || GoodsRules.PickGear(db, GoodsRules.GearGrade(db, item) ?? "", pick, null) == null) return "병종 · 부위를 고르세요";
|
|
break;
|
|
case PickTreasure:
|
|
if (!PickableTreasures(db, d).Contains(pick ?? "")) return "보유 보물을 고르세요";
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>천기 보물 조각으로 고를 수 있는 보물 = 보유한 가장 높은 등급(economy treasure_iron_mult 의 마지막 = 천기) 보물.</summary>
|
|
public static List<string> PickableTreasures(OutGameData db, SaveData d)
|
|
{
|
|
var res = new List<string>();
|
|
var grades = db.Economy.TreasureGrades;
|
|
string top = grades.Count > 0 ? grades[grades.Count - 1].Key : "";
|
|
foreach (var t in d.inv.treasures)
|
|
{
|
|
var def = db.Treasures.Get(t.id);
|
|
if (def != null && def.grade == top) res.Add(t.id);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
/// <summary>구매(기기 세이브 모드) → 얻은 것(gains) · 반환 = 실패 사유(null = 성공).</summary>
|
|
public static string Buy(OutGameData db, SaveData d, string shop, string item, string pick, DateTime nowUtc, System.Random rng, List<Gain> gains = null)
|
|
{
|
|
var why = Can(db, d, shop, item, pick, nowUtc);
|
|
if (why != null) return why;
|
|
var r = Row(shop, item);
|
|
int n = r.I("n_amount");
|
|
var got = new List<Gain>();
|
|
if (item == ArcanaShard)
|
|
{
|
|
d.inv.Treasure(pick).shards += n;
|
|
GoodsRules.Add(got, pick, n, db.Treasures.Get(pick).nameKo + " 조각", "shard");
|
|
}
|
|
else got = GoodsRules.Give(db, d, item, n, rng, pick);
|
|
if (got.Count == 0) return "구현되지 않은 물품 " + item;
|
|
Spend(db, d, shop, r.I("n_price"));
|
|
if (shop == RaidCoin) Counts.Add(d.raid.shopBought, item, 1);
|
|
else Counts.Add(State(db, d, nowUtc).bought, BuyKey(shop, item), 1);
|
|
if (gains != null) gains.AddRange(got);
|
|
return null;
|
|
}
|
|
|
|
/// <summary>표 검사(데이터 테스트) — 품목 낱말 · 고르는 방식 · 값.</summary>
|
|
public static List<string> Validate(OutGameData db)
|
|
{
|
|
var e = new List<string>();
|
|
foreach (var shop in Shops)
|
|
{
|
|
string f = Table(shop) + ".csv";
|
|
var seen = new HashSet<string>();
|
|
foreach (var r in Rows(shop))
|
|
{
|
|
string item = r.S("s_item"), pick = r.S("e_pick");
|
|
if (!seen.Add(item)) e.Add(f + ": " + item + " 중복");
|
|
if (Array.IndexOf(Picks, pick) < 0) e.Add(f + ": " + item + " e_pick 「" + pick + "」 = " + string.Join(" · ", Picks) + " 가 아님");
|
|
if (r.I("n_amount") <= 0 || r.I("n_price") <= 0 || r.I("n_weekly_limit") < 0) e.Add(f + ": " + item + " 수량 · 가격 · 한도 값 이상");
|
|
if (item == ArcanaShard) { if (pick != PickTreasure) e.Add(f + ": " + item + " e_pick = treasure 여야 함"); }
|
|
else
|
|
{
|
|
if (!GoodsRules.Known(db, item)) e.Add(f + ": 품목 「" + item + "」 = 지급하는 법을 코드가 모름(GoodsRules)");
|
|
string need = GoodsRules.PickKind(db, item) ?? PickNone;
|
|
if (pick != need) e.Add(f + ": " + item + " e_pick 「" + pick + "」 ≠ " + need);
|
|
}
|
|
}
|
|
}
|
|
return e;
|
|
}
|
|
}
|
|
}
|