mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Added randomly generated quest challenges to the random standard quest world
This commit is contained in:
195
forge-gui/src/main/java/forge/quest/QuestChallengeGenerator.java
Normal file
195
forge-gui/src/main/java/forge/quest/QuestChallengeGenerator.java
Normal file
@@ -0,0 +1,195 @@
|
||||
package forge.quest;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import forge.deck.DeckgenUtil;
|
||||
import forge.game.GameFormat;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class QuestChallengeGenerator {
|
||||
|
||||
public static QuestEventChallengeList generateChallenges(){
|
||||
Map<String,QuestEventChallenge> challenges = new HashMap<>();
|
||||
int id = 0;
|
||||
for (int i=0;i<5;++i) {
|
||||
QuestEventChallenge qc = getFormatChallenge(FModel.getFormats().getModern());
|
||||
qc.setId(new Integer(id).toString());
|
||||
qc.setCreditsReward(1000);
|
||||
qc.setWinsReqd(MyRandom.getRandom().nextInt(5));
|
||||
qc.setDifficulty(QuestEventDifficulty.MEDIUM);
|
||||
qc.setCardReward("1 multicolor rare");
|
||||
challenges.put(Integer.toString(id),qc);
|
||||
id++;
|
||||
}
|
||||
for (int i=0;i<5;++i) {
|
||||
QuestEventChallenge qc = getAIHeadstartChallenge(1);
|
||||
qc.setId(new Integer(id).toString());
|
||||
qc.setCreditsReward(1000);
|
||||
qc.setCardReward("1 multicolor rare");
|
||||
qc.setWinsReqd(MyRandom.getRandom().nextInt(5));
|
||||
qc.setDifficulty(QuestEventDifficulty.EASY);
|
||||
challenges.put(Integer.toString(id),qc);
|
||||
id++;
|
||||
}
|
||||
for (int i=0;i<5;++i) {
|
||||
QuestEventChallenge qc = getFormatChallenge(FModel.getFormats().get("Legacy"));
|
||||
qc.setId(new Integer(id).toString());
|
||||
qc.setCreditsReward(5000);
|
||||
qc.setCardReward("2 multicolor rares");
|
||||
qc.setWinsReqd(MyRandom.getRandom().nextInt(25));
|
||||
qc.setDifficulty(QuestEventDifficulty.HARD);
|
||||
challenges.put(Integer.toString(id),qc);
|
||||
id++;
|
||||
}
|
||||
for (int i=0;i<5;++i) {
|
||||
QuestEventChallenge qc = getAIHeadstartChallenge(2);
|
||||
qc.setId(new Integer(id).toString());
|
||||
qc.setCreditsReward(5000);
|
||||
qc.setCardReward("2 multicolor rares");
|
||||
qc.setWinsReqd(MyRandom.getRandom().nextInt(25));
|
||||
qc.setDifficulty(QuestEventDifficulty.MEDIUM);
|
||||
challenges.put(Integer.toString(id),qc);
|
||||
id++;
|
||||
}
|
||||
for (int i=0;i<5;++i) {
|
||||
QuestEventChallenge qc = getFormatChallenge(FModel.getFormats().get("Vintage"));
|
||||
qc.setId(new Integer(id).toString());
|
||||
qc.setCreditsReward(10000);
|
||||
qc.setCardReward("3 multicolor rares");
|
||||
qc.setWinsReqd(MyRandom.getRandom().nextInt(50));
|
||||
qc.setDifficulty(QuestEventDifficulty.EXPERT);
|
||||
challenges.put(Integer.toString(id),qc);
|
||||
id++;
|
||||
}
|
||||
for (int i=0;i<5;++i) {
|
||||
QuestEventChallenge qc = getAIHeadstartChallenge(3);
|
||||
qc.setId(new Integer(id).toString());
|
||||
qc.setCreditsReward(10000);
|
||||
qc.setCardReward("3 multicolor rares");
|
||||
qc.setWinsReqd(MyRandom.getRandom().nextInt(50));
|
||||
qc.setDifficulty(QuestEventDifficulty.HARD);
|
||||
challenges.put(Integer.toString(id),qc);
|
||||
id++;
|
||||
}
|
||||
return new QuestEventChallengeList(challenges);
|
||||
}
|
||||
|
||||
public static QuestEventChallenge getFormatChallenge(GameFormat format){
|
||||
QuestEventChallenge qc = new QuestEventChallenge();
|
||||
|
||||
qc.setEventDeck(DeckgenUtil.buildLDACArchetypeDeck(format,true));
|
||||
qc.setTitle(format.getName() + " " + qc.getEventDeck().getName() + " challenge");
|
||||
qc.setName(format.getName() + " " + qc.getEventDeck().getName() + " challenge");
|
||||
qc.setOpponentName(qc.getEventDeck().getName());
|
||||
qc.setDescription("Take on a " + format.getName() + " format deck");
|
||||
qc.setOpponentName(qc.getEventDeck().getName());
|
||||
qc.setRepeatable(true);
|
||||
return qc;
|
||||
}
|
||||
|
||||
public static QuestEventChallenge getAIHeadstartChallenge(int extras){
|
||||
QuestEventChallenge qc = new QuestEventChallenge();
|
||||
|
||||
qc.setEventDeck(DeckgenUtil.buildLDACArchetypeDeck(FModel.getFormats().getStandard(),true));
|
||||
qc.setTitle(qc.getEventDeck().getName() + " headstart challenge");
|
||||
qc.setName(qc.getEventDeck().getName() + " headstart challenge");
|
||||
qc.setOpponentName(qc.getEventDeck().getName());
|
||||
qc.setDescription("The AI gets a bit of a headstart...");
|
||||
ArrayList<String> cards = new ArrayList<>();
|
||||
for(int i=0; i < extras; ++i) {
|
||||
cards.add(qc.getEventDeck().getMain().toFlatList().get(
|
||||
MyRandom.getRandom().nextInt(qc.getEventDeck().getMain().toFlatList().size())).getName());
|
||||
}
|
||||
qc.setAiExtraCards(cards);
|
||||
qc.setOpponentName(qc.getEventDeck().getName());
|
||||
qc.setRepeatable(true);
|
||||
return qc;
|
||||
}
|
||||
|
||||
public static class QuestEventChallengeList implements IStorage<QuestEventChallenge>{
|
||||
|
||||
private Map<String,QuestEventChallenge> challenges;
|
||||
|
||||
public QuestEventChallengeList(Map<String, QuestEventChallenge> list){
|
||||
challenges = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullPath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuestEventChallenge get(String id) {
|
||||
return challenges.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuestEventChallenge find(Predicate<QuestEventChallenge> condition) {
|
||||
for(QuestEventChallenge challenge:challenges.values()){
|
||||
if(condition.apply(challenge)){
|
||||
return challenge;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getItemNames() {
|
||||
List<String> names = new ArrayList<>();
|
||||
for(QuestEventChallenge challenge:challenges.values()){
|
||||
names.add(challenge.getName());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String id) {
|
||||
return challenges.containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return challenges.keySet().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(QuestEventChallenge item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
challenges.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorage<IStorage<QuestEventChallenge>> getFolders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorage<QuestEventChallenge> tryGetFolder(String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorage<QuestEventChallenge> getFolderOrCreate(String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "QuestChallenges";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<QuestEventChallenge> iterator() {
|
||||
return challenges.values().iterator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,6 +418,9 @@ public class QuestController {
|
||||
* @return QuestEventManager
|
||||
*/
|
||||
public IStorage<QuestEventChallenge> getChallenges() {
|
||||
if (getWorld().getName().equals(QuestWorld.STANDARDWORLDNAME)){
|
||||
allChallenges = QuestChallengeGenerator.generateChallenges();
|
||||
}
|
||||
if (this.allChallenges == null) {
|
||||
resetChallengesManager();
|
||||
}
|
||||
@@ -455,6 +458,10 @@ public class QuestController {
|
||||
public void resetChallengesManager() {
|
||||
QuestWorld world = getWorld();
|
||||
String path;
|
||||
if (world.getName().equals(QuestWorld.STANDARDWORLDNAME)){
|
||||
allChallenges = QuestChallengeGenerator.generateChallenges();
|
||||
return;
|
||||
}
|
||||
if (world == null || !world.isCustom()){
|
||||
path = world == null || world.getChallengesDir() == null ? ForgeConstants.DEFAULT_CHALLENGES_DIR : ForgeConstants.QUEST_WORLD_DIR + world.getChallengesDir();
|
||||
}else{
|
||||
@@ -543,6 +550,8 @@ public class QuestController {
|
||||
maxChallenges = 5;
|
||||
}
|
||||
|
||||
maxChallenges = 5;
|
||||
|
||||
// Generate IDs as needed.
|
||||
if (achievements.getCurrentChallenges().size() < maxChallenges) {
|
||||
for (final QuestEventChallenge qc : allChallenges) {
|
||||
|
||||
Reference in New Issue
Block a user