game: fixed miss watchers from second side of transformable cards (closes #11329);

This commit is contained in:
Oleg Agafonov 2023-11-06 10:40:05 +04:00
parent 710b79b46d
commit dfbd6627e5
5 changed files with 99 additions and 11 deletions

View file

@ -318,8 +318,11 @@ public abstract class GameImpl implements Game {
card = ((PermanentCard) card).getCard();
}
// init each card by parts... if you add new type here then getInitAbilities must be
// implemented too (it allows to split abilities between card and parts)
// usage hints:
// - each card and parts must be initialized here before usage
// - it add card/part to starting zone, assign abilities and init watchers
// - warning, if you add new type here then getInitAbilities must be
// implemented too (it allows to split abilities between card and parts)
// main card
card.setOwnerId(ownerId);
@ -348,6 +351,14 @@ public abstract class GameImpl implements Game {
Card spellCard = ((AdventureCard) card).getSpellCard();
spellCard.setOwnerId(ownerId);
addCardToState(spellCard);
} else if (card.isTransformable() && card.getSecondCardFace() != null) {
Card nightCard = card.getSecondCardFace();
nightCard.setOwnerId(ownerId);
addCardToState(nightCard);
} else if (card.getMeldsToClazz() != null) {
// meld card will be added and init on meld effect resolve, so ignore it here
// TODO: rework meld logic cause card with watchers must be added on game init
// (possible bugs: miss watcher related data in meld cards/rules/hints)
}
}
}

View file

@ -634,16 +634,23 @@ public class GameState implements Serializable, Copyable<GameState> {
return this.turnMods;
}
/**
* Find game scope watcher
*/
public <T extends Watcher> T getWatcher(Class<T> watcherClass) {
return watcherClass.cast(watchers.get(watcherClass.getSimpleName()));
return getWatcher(watcherClass, null);
}
/**
* Find card/player scope watcher
*/
public <T extends Watcher> T getWatcher(Class<T> watcherClass, UUID uuid) {
return watcherClass.cast(watchers.get(watcherClass.getSimpleName(), uuid.toString()));
String watcherKey = (uuid == null ? "" : uuid.toString()) + watcherClass.getSimpleName();
return watcherClass.cast(getWatcher(watcherKey));
}
public <T extends Watcher> T getWatcher(Class<T> watcherClass, String prefix) {
return watcherClass.cast(watchers.get(watcherClass.getSimpleName(), prefix));
public Watcher getWatcher(String key) {
return watchers.get(key);
}
public SpecialActions getSpecialActions() {

View file

@ -12,7 +12,7 @@ import java.util.HashMap;
*/
public class Watchers extends HashMap<String, Watcher> {
private static Logger logger = LogManager.getLogger(Watcher.class.getSimpleName());
private static final Logger logger = LogManager.getLogger(Watcher.class.getSimpleName());
public Watchers() {
}
@ -39,15 +39,12 @@ public class Watchers extends HashMap<String, Watcher> {
this.values().forEach(Watcher::reset);
}
public Watcher get(String key, String id) {
return get(id + key);
}
@Override
public Watcher get(Object key) {
if (containsKey(key)) {
return super.get(key);
}
// can't add game exeption here because it's an easy way to ruin any game with bugged card
logger.error(key + " not found in watchers", new Throwable());
return null;
}