FunGame-Core/Entity/System/Inventory.cs
milimoe c55e9262cc
.NET 9;库存、物品相关更新;伤害乘算修改 (#101)
* 添加 SQL 文件

* 完善库存的显示;从用户类中移除余额;使用 Guid 关联物品与其技能;取消特效类的伤害乘区,改为加算

* 升级 .NET 9

* 回合数在获取到下一个角色时累加

* 更新 .NET9 的工作流
2024-11-15 00:52:49 +08:00

100 lines
3.2 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.Text;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Model;
namespace Milimoe.FunGame.Core.Entity
{
public class Inventory
{
/// <summary>
/// 库存 ID 与用户 ID 绑定
/// </summary>
public long Id => User.Id;
/// <summary>
/// 库存的名称,默认为 “<see cref="User.Username"/>的库存”;可更改
/// </summary>
public string Name { get; set; } = "";
/// <summary>
/// 库存属于哪个玩家
/// </summary>
public User User { get; }
/// <summary>
/// 玩家持有 <see cref="EquilibriumConstant.InGameCurrency"/> 的数量
/// </summary>
public double Credits { get; set; } = 0;
/// <summary>
/// 玩家持有 <see cref="EquilibriumConstant.InGameMaterial"/> 的数量
/// </summary>
public double Materials { get; set; } = 0;
/// <summary>
/// 玩家拥有的角色
/// </summary>
public HashSet<Character> Characters { get; } = [];
/// <summary>
/// 玩家拥有的物品
/// </summary>
public HashSet<Item> Items { get; } = [];
internal Inventory(User user)
{
User = user;
Name = user.Username + "的库存";
}
public override string ToString()
{
return Name + $"{User}";
}
public string ToString(bool showAll)
{
StringBuilder builder = new();
builder.AppendLine($"☆★☆ {Name} ☆★☆");
builder.AppendLine($"{General.GameplayEquilibriumConstant.InGameCurrency}{Credits:0.00}");
builder.AppendLine($"{General.GameplayEquilibriumConstant.InGameMaterial}{Materials:0.00}");
builder.AppendLine($"======= 角色 =======");
Character[] characters = [.. Characters];
for (int i = 1; i <= characters.Length; i++)
{
Character character = characters[i - 1];
if (showAll)
{
builder.AppendLine($"===== 第 {i} 个角色 =====");
builder.AppendLine($"{character.GetInfo(false)}");
}
else
{
builder.AppendLine($"{i}. {character.ToStringWithLevelWithOutUser()}");
}
}
builder.AppendLine($"======= 物品 =======");
Item[] items = [.. Items];
for (int i = 1; i <= items.Length; i++)
{
Item item = items[i - 1];
if (showAll)
{
builder.AppendLine($"===== 第 {i} 个物品 =====");
}
else
{
builder.AppendLine($"{i}. [{ItemSet.GetQualityTypeName(item.QualityType)}|{ItemSet.GetItemTypeName(item.ItemType)}] {item.Name}");
}
builder.AppendLine($"{item.ToStringInventory(showAll).Trim()}");
if (showAll) builder.AppendLine();
}
return builder.ToString();
}
}
}