HearthSim / Hearthstone-Deck-Tracker

A deck tracker and deck manager for Hearthstone on Windows
https://hsreplay.net/downloads/
4.61k stars 1.11k forks source link

[Plugin development] Visual Studio complains EntityInfo is not serializable #4394

Closed z7oka closed 2 years ago

z7oka commented 2 years ago

I am coding a simple plugin here's the important snippet

internal List<Entity> Entities =>
    Helper.DeepClone<Dictionary<int, Entity>>(CoreAPI.Game.Entities).Values.ToList<Entity>();
internal int countDeadMinions => Entities.Where(x => x.Card.Type == "Minion" && x.IsInZone(Zone.GRAVEYARD)).Count();

I am counting the number of minion in the GRAVEYARD on every turn start, after some debugging I found out that any mention of Entities is throwing a Serialization exception. Visual Studio complained EntityInfo is not Serializable. After adding the tag, it worked.

Am I developing the plugin correctly? is this the right way to access CoreAPI.Game.Entities ?

iceberk commented 2 years ago

I got the same error when trying to launch sample plugin. Try this instead of using DeepClone: internal List<Entity> Entities => CoreAPI.Game.Entities.Values.Select(x => x.Clone()).ToList();

z7oka commented 2 years ago

Thanks @iceberk for the workaround/correct usage. I'll close it for now and reopen when I test it locally if I still get the same error.