传入 User 以便获取已购数量

This commit is contained in:
milimoe 2025-07-24 01:27:04 +08:00
parent 742936e260
commit 00429c2de0
Signed by: milimoe
GPG Key ID: 9554D37E4B8991D0
2 changed files with 20 additions and 2 deletions

View File

@ -40,6 +40,11 @@ namespace Milimoe.FunGame.Core.Entity
}
public override string ToString()
{
return ToString(null);
}
public string ToString(User? user = null)
{
StringBuilder builder = new();
builder.AppendLine($"{Id}. {Name}");
@ -48,7 +53,15 @@ namespace Milimoe.FunGame.Core.Entity
builder.AppendLine($"商品售价:{(Prices.Count > 0 ? string.Join("", Prices.Select(kv => $"{kv.Value} {kv.Key}")) : "")}");
builder.AppendLine($"包含物品:{string.Join("", Items.Select(i => $"[{ItemSet.GetQualityTypeName(i.QualityType)}|{ItemSet.GetItemTypeName(i.ItemType)}] {i.Name}"))}");
builder.AppendLine($"剩余库存:{(Stock == -1 ? "" : Stock)}");
if (Quota > 0) builder.AppendLine($"限购数量:{Quota}");
if (Quota > 0)
{
int buyCount = 0;
if (user != null)
{
UsersBuyCount.TryGetValue(user.Id, out buyCount);
}
builder.AppendLine($"限购数量:{Quota}(已购:{buyCount}");
}
return builder.ToString().Trim();
}

View File

@ -31,6 +31,11 @@ namespace Milimoe.FunGame.Core.Entity
}
public override string ToString()
{
return ToString(null);
}
public string ToString(User? user = null)
{
StringBuilder builder = new();
@ -66,7 +71,7 @@ namespace Milimoe.FunGame.Core.Entity
Goods[] goodsValid = [.. Goods.Values.Where(g => !g.ExpireTime.HasValue || g.ExpireTime.Value > DateTime.Now)];
foreach (Goods goods in goodsValid)
{
builder.AppendLine(goods.ToString());
builder.AppendLine(goods.ToString(user));
}
builder.AppendLine("提示:使用【商店查看+序号】查看物品详细信息,使用【商店购买+序号】购买物品(指令在 2 分钟内可用)。");
if (AutoRefresh)