修复商品的物品列表无限叠加问题

This commit is contained in:
milimoe 2025-01-21 02:09:35 +08:00
parent 7dea8032c2
commit a520f7e9b6
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
2 changed files with 8 additions and 6 deletions

View File

@ -89,17 +89,19 @@ namespace Milimoe.FunGame.Core.Entity
public class Goods public class Goods
{ {
public long Id { get; set; } public long Id { get; set; } = 0;
public List<Item> Items { get; } public List<Item> Items { get; } = [];
public string Name { get; set; } public string Name { get; set; } = "";
public string Description { get; set; } public string Description { get; set; } = "";
public Dictionary<string, double> Prices { get; } = []; public Dictionary<string, double> Prices { get; } = [];
public int Stock { get; set; } public int Stock { get; set; }
public Goods() { }
public Goods(long id, Item item, int stock, string name, string description, Dictionary<string, double>? prices = null) public Goods(long id, Item item, int stock, string name, string description, Dictionary<string, double>? prices = null)
{ {
Id = id; Id = id;
Items = [item]; Items.Add(item);
Stock = stock; Stock = stock;
Name = name; Name = name;
Description = description; Description = description;

View File

@ -9,7 +9,7 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
{ {
public override Goods NewInstance() public override Goods NewInstance()
{ {
return new Goods(0, Factory.GetItem(), 0, "", ""); return new Goods();
} }
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref Goods result, Dictionary<string, object> convertingContext) public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref Goods result, Dictionary<string, object> convertingContext)