Improved watcher copy support of Cards fields (example: Abandoned Sarcophagus, see 43dbaf405b);

This commit is contained in:
Oleg Agafonov 2021-08-01 03:32:16 +04:00
parent df07ad4418
commit 790aef9c37

View file

@ -1,5 +1,6 @@
package mage.watchers; package mage.watchers;
import mage.cards.Cards;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -133,6 +134,14 @@ public abstract class Watcher implements Serializable {
PlayerList list = e.getValue().copy(); PlayerList list = e.getValue().copy();
target.put(e.getKey(), list); target.put(e.getKey(), list);
} }
} else if (valueType.getTypeName().endsWith("Cards")) {
Map<Object, Cards> source = (Map<Object, Cards>) field.get(this);
Map<Object, Cards> target = (Map<Object, Cards>) field.get(watcher);
target.clear();
for (Map.Entry<Object, Cards> e : source.entrySet()) {
Cards list = e.getValue().copy();
target.put(e.getKey(), list);
}
} else if (valueType.getTypeName().contains("List")) { } else if (valueType.getTypeName().contains("List")) {
Map<Object, List<Object>> source = (Map<Object, List<Object>>) field.get(this); Map<Object, List<Object>> source = (Map<Object, List<Object>>) field.get(this);
Map<Object, List<Object>> target = (Map<Object, List<Object>>) field.get(watcher); Map<Object, List<Object>> target = (Map<Object, List<Object>>) field.get(watcher);