Deck-based AI hints metadata + predefined sideboarding plan support (#5113)

* - Support for AI hints in deck metadata.
- Support for pre-planned sideboarding using an AI hint.

* - Fix imports.

* - NPE prevention for cases when the AI has no sideboard.
This commit is contained in:
Agetian
2024-04-24 07:56:01 +03:00
committed by GitHub
parent b4b8d05260
commit 9f13d36799
4 changed files with 111 additions and 42 deletions

View File

@@ -48,6 +48,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
private final Set<String> tags = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
// Supports deferring loading a deck until we actually need its contents. This works in conjunction with
// the lazy card load feature to ensure we don't need to load all cards on start up.
private final Set<String> aiHints = new TreeSet<>();
private Map<String, List<String>> deferredSections = null;
private Map<String, List<String>> loadedSections = null;
private String lastCardArtPreferenceUsed = "";
@@ -207,6 +208,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
result.parts.put(kv.getKey(), cp);
cp.addAll(kv.getValue());
}
result.setAiHints(StringUtils.join(aiHints, " | "));
}
/*
@@ -536,6 +538,29 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
return allCards;
}
public void setAiHints(String aiHintsInfo) {
if (aiHintsInfo == null || aiHintsInfo.trim().equals("")) {
return;
}
String[] hints = aiHintsInfo.split("\\|");
for (String hint : hints) {
aiHints.add(hint.trim());
}
}
public Set<String> getAiHints() {
return aiHints;
}
public String getAiHint(String name) {
for (String aiHint : aiHints) {
if (aiHint.toLowerCase().startsWith(name.toLowerCase() + "$")) {
return aiHint.substring(aiHint.indexOf("$") + 1).trim();
}
}
return "";
}
public UnplayableAICards getUnplayableAICards() {
if (unplayableAI == null) {
unplayableAI = new UnplayableAICards(this);

View File

@@ -45,6 +45,7 @@ public class DeckFileHeader {
private static final String PLAYER = "Player";
private static final String CSTM_POOL = "Custom Pool";
private static final String PLAYER_TYPE = "PlayerType";
public static final String AI_HINTS = "AiHints";
private final DeckFormat deckType;
private final boolean customPool;
@@ -55,6 +56,7 @@ public class DeckFileHeader {
private final Set<String> tags;
private final boolean intendedForAi;
private final String aiHints;
/**
* @return the intendedForAi
@@ -63,6 +65,13 @@ public class DeckFileHeader {
return intendedForAi;
}
/**
* @return the AI hints
*/
public String getAiHints() {
return aiHints;
}
/**
* TODO: Write javadoc for Constructor.
*
@@ -75,6 +84,7 @@ public class DeckFileHeader {
this.deckType = DeckFormat.smartValueOf(kvPairs.get(DeckFileHeader.DECK_TYPE), DeckFormat.Constructed);
this.customPool = kvPairs.getBoolean(DeckFileHeader.CSTM_POOL);
this.intendedForAi = "computer".equalsIgnoreCase(kvPairs.get(DeckFileHeader.PLAYER)) || "ai".equalsIgnoreCase(kvPairs.get(DeckFileHeader.PLAYER_TYPE));
this.aiHints = kvPairs.get(DeckFileHeader.AI_HINTS);
this.tags = new TreeSet<>();
String rawTags = kvPairs.get(DeckFileHeader.TAGS);

View File

@@ -53,6 +53,9 @@ public class DeckSerializer {
if (!d.getTags().isEmpty()) {
out.add(TextUtil.concatNoSpace(DeckFileHeader.TAGS,"=", StringUtils.join(d.getTags(), DeckFileHeader.TAGS_SEPARATOR)));
}
if (!d.getAiHints().isEmpty()) {
out.add(TextUtil.concatNoSpace(DeckFileHeader.AI_HINTS, "=", StringUtils.join(d.getAiHints(), " | ")));
}
for(Entry<DeckSection, CardPool> s : d) {
out.add(TextUtil.enclosedBracket(s.getKey().toString()));
@@ -77,6 +80,7 @@ public class DeckSerializer {
Deck d = new Deck(dh.getName());
d.setComment(dh.getComment());
d.setAiHints(dh.getAiHints());
d.getTags().addAll(dh.getTags());
d.setDeferredSections(sections);
return d;