com.megacrit.cardcrawl.helpers.RelicLibrary Java Examples

The following examples show how to use com.megacrit.cardcrawl.helpers.RelicLibrary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SuperRareRelicPatch.java    From StSLib with MIT License 6 votes vote down vote up
public static String Postfix(String __result, AbstractRelic.RelicTier tier)
{
    if (depth == 0 && RelicLibrary.getRelic(__result) instanceof SuperRareRelic) {
        RelicTools.returnRelicToPool(tier, __result);
        ++depth;
        __result = AbstractDungeon.returnRandomRelicKey(tier);
        --depth;
    }

    return __result;
}
 
Example #2
Source File: SuperRareRelicPatch.java    From StSLib with MIT License 5 votes vote down vote up
public static String Postfix(String __result, AbstractRelic.RelicTier tier)
{
    if (depth == 0 && RelicLibrary.getRelic(__result) instanceof SuperRareRelic) {
        RelicTools.returnRelicToPool(tier, __result);
        ++depth;
        __result = AbstractDungeon.returnEndRandomRelicKey(tier);
        --depth;
    }

    return __result;
}
 
Example #3
Source File: DeckOfManyThingsEvent.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
@Override
protected void buttonEffect(int i) { // This is the event:
    switch (screenNum) {
        case 0: // While you are on screen number 0 (The starting screen)
            switch (i) {
                case 0: // If you press button the first button (Button at index 0), in this case: Inspiration.
                    this.imageEventText.updateBodyText(DESCRIPTIONS[1]); // Update the text of the event
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]); // 1. Change the first button to the [Leave] button
                    this.imageEventText.clearRemainingOptions(); // 2. and remove all others
                    screenNum = 1; // Screen set the screen number to 1. Once we exit the switch (i) statement,
                    // we'll still continue the switch (screenNum) statement. It'll find screen 1 and do it's actions
                    // (in our case, that's the final screen, but you can chain as many as you want like that)

                    AbstractRelic relicToAdd = RelicLibrary.starterList.get(AbstractDungeon.relicRng.random(RelicLibrary.starterList.size() - 1)).makeCopy();
                    // Get a random starting relic

                    AbstractDungeon.getCurrRoom().spawnRelicAndObtain((float)(Settings.WIDTH / 2), (float)(Settings.HEIGHT / 2), relicToAdd);


                    break; // Onto screen 1 we go.
                case 1: // If you press button the second button (Button at index 1), in this case: Deinal

                    CardCrawlGame.screenShake.shake(ScreenShake.ShakeIntensity.MED, ScreenShake.ShakeDur.MED, false);
                    // Shake the screen
                    CardCrawlGame.sound.play("BLUNT_FAST");  // Play a hit sound
                    AbstractDungeon.player.decreaseMaxHealth(healthdamage); // Lose max HP
                    if (CardGroup.getGroupWithoutBottledCards(AbstractDungeon.player.masterDeck.getPurgeableCards()).size() > 0) {
                        // If you have cards you can remove - remove a card
                        AbstractDungeon.gridSelectScreen.open(
                                CardGroup.getGroupWithoutBottledCards(
                                        AbstractDungeon.player.masterDeck.getPurgeableCards()),
                                1, OPTIONS[6], false, false, false, true);
                    }

                    this.imageEventText.updateBodyText(DESCRIPTIONS[2]);
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]);
                    this.imageEventText.clearRemainingOptions();
                    screenNum = 1;

                    // Same as before. A note here is that you can also do
                    // imageEventText.clearAllDialogs();
                    // imageEventText.setDialogOption(OPTIONS[1]);
                    // imageEventText.setDialogOption(OPTIONS[4]);
                    // (etc.)
                    // And that would also just set them into slot 0, 1, 2... in order, just like what we do in the very beginning

                    break; // Onto screen 1 we go.
                case 2: // If you press button the third button (Button at index 2), in this case: Acceptance

                    AbstractCard c = new Apotheosis().makeCopy();
                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(c, (float) (Settings.WIDTH / 2), (float) (Settings.HEIGHT / 2)));

                    this.imageEventText.updateBodyText(DESCRIPTIONS[3]);
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]);
                    this.imageEventText.clearRemainingOptions();
                    screenNum = 1;
                    break;
                case 3: // If you press button the fourth button (Button at index 3), in this case: TOUCH
                    imageEventText.loadImage("stsjorbsmodResources/images/events/IdentityCrisisEvent2.png"); // Change the shown image
                    // Other than that, this option doesn't do anything special.
                    this.imageEventText.updateBodyText(DESCRIPTIONS[4]);
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]);
                    this.imageEventText.clearRemainingOptions();
                    screenNum = 1;
                    break;
            }
            break;
        case 1: // Welcome to screenNum = 1;
            switch (i) {
                case 0: // If you press the first (and this should be the only) button,
                    openMap(); // You'll open the map and end the event.
                    break;
            }
            break;
    }
}
 
Example #4
Source File: RelicTools.java    From StSLib with MIT License 4 votes vote down vote up
public static boolean returnRelicToPool(String relicID)
{
    AbstractRelic.RelicTier tier = RelicLibrary.getRelic(relicID).tier;
    return returnRelicToPool(tier, relicID);
}
 
Example #5
Source File: DefaultInsertPatch.java    From StS-DefaultModBase with MIT License 4 votes vote down vote up
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {// All the locator has and needs is an override of the Locate method
    // In simple terms, the locator works like this:
    // We give is something to match with, and it returns the line number that it finds the ting on,
    // inside the method which we specified wayyyy early on in our @SpirePatch annotation.
    // The Locate method is of type int[] - it returns an array of ints. These ints are actually the matching line numbers.
    
    // This is where we open up the https://github.com/kiooeht/ModTheSpire/wiki/Matcher documentation.
    
    // The line in the original method, "return !RelicLibrary.getRelic(retVal).canSpawn() ? returnEndRandomRelicKey(tier) : retVal;"
    // is just a simple ternary operator, check out http://www.cafeaulait.org/course/week2/43.html
    // or https://stackoverflow.com/questions/8898590/short-form-for-java-if-statement or simply ask google.
    // if you can't spawn the relic(note the "!"), grab a new relic from the end of the list instead
    // (call the returnEndRandomRelicKey() method) - otherwise return the relic.
    
    // We want to insert our code immediately above it so we'll need to use a matcher against something in that line.
    // We have a few of options for this 1 particular line. Before you proceed, read the docs and see how many you can personally spot.
    
    // 1. RelicLibrary.getRelic - is calling the the getRelic() method of the RelicLibrary class.
    // (You can also see that by Ctrl+clicking on getRelic)
    // 2. getRelic(retVal).canSpawn() - is calling the canSpawn() method of the AbstractRelic class.
    // (get relic() returns an AbstractRelic so we just use canSpawn() directly from it to check if we can spawn it)
    // 3. returnEndRandomRelicKey(tier) - is calling the returnEndRandomRelicKey method of the AbstractDungeon class.
    // At the end of the day, all three of these are MethodCallMatchers.
    
    /*
     * BUT WAIT!
     * Did you know that the third option is *actually* on a completely different line than the first one?
     * Decompiling the code with a different decompiler shows that the last line is actually a lot more like this:
     *
     * if (!RelicLibrary.getRelic(retVal).canSpawn()) {
     *      return returnEndRandomRelicKey(tier);
     * }
     *  return retVal;
     *
     *  Which means that if we use the third matcher we will insert code inside the if statement, while if we use 1. or 2. - just outside of it.
     *
     *  Follow this guide to learn how to decompile your game.
     *  https://github.com/daviscook477/BaseMod/wiki/Decompiling-Your-Game
     *  Essentially - you would want to use JD-GUI and Luyten *both* to get a precise look.
     *  (You can 100% still totally use the IntelliJ for quick-referencing code, it is still very fast and convenient)
     *
     *  On a sidenote, you should enable debug lines in intelliJ both for bugfixing and seeing what thing is *really* on what line
     *  To do so:
     * 1. Ctrl+Shift+A
     * 2. Registry
     * 3. Scroll down and set decompiler.dump.original.lines to true
     */
    
    // A good way to choose, usually, would be to pick the matcher least likely to appear elsewhere in the code of the method
    // i.e. the rarest one. In this case, it doesn't really matter as it's 3 of the same matcher, and none of their methods
    // ever appear again anywhere else, so let's just go for the first one:
    // As the documentation says, put the Class type and the method name (as a string) as your parameters:
    
    Matcher finalMatcher = new Matcher.MethodCallMatcher(RelicLibrary.class, "getRelic");
    
    // Now we just have to return the line number corresponding to that particular method call.
    // We have 2 options:
    // 1. findInOrder - Returns the first line number that matches the description of the matcher
    // (i.e. the very first time it finds RelicLibrary.getRelic() in the method we're patching.)
    
    // 2. findAllInOrder - Returns an array of ints - all of the line numbers matching the description.
    // (This is, for example, if the method we're patching had used "RelicLibrary.getRelic()" 3 different times,
    // and we want to insert our code right before ALL of the matches, or before a particular one of them.)
    
    // In our case "RelicLibrary.getRelic()" is called only once, in that particular return statement, so we can just return it.
    return LineFinder.findInOrder(ctMethodToPatch, finalMatcher);
    
    // If we wanted to use findAllInOrder instead, we would do it like this:
    // return new int[]{LineFinder.findAllInOrder(ctMethodToPatch, finalMatcher)[0]};
    // The [0] in this case indicates the index of the line number in the array (in the order they were found)
    // The first (and for us, only) instance of "RelicLibrary.getRelic()" would be at index 0. The second at index 1, and so on.
    
    // Finally, if we wanted to insert our code before *every* line with a match, we would just skip the index and return the whole list of lines:
    // return LineFinder.findAllInOrder(ctMethodToPatch, finalMatcher)
}
 
Example #6
Source File: IdentityCrisisEvent.java    From StS-DefaultModBase with MIT License 4 votes vote down vote up
@Override
protected void buttonEffect(int i) { // This is the event:
    switch (screenNum) {
        case 0: // While you are on screen number 0 (The starting screen)
            switch (i) {
                case 0: // If you press button the first button (Button at index 0), in this case: Inspiration.
                    this.imageEventText.updateBodyText(DESCRIPTIONS[1]); // Update the text of the event
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]); // 1. Change the first button to the [Leave] button
                    this.imageEventText.clearRemainingOptions(); // 2. and remove all others
                    screenNum = 1; // Screen set the screen number to 1. Once we exit the switch (i) statement,
                    // we'll still continue the switch (screenNum) statement. It'll find screen 1 and do it's actions
                    // (in our case, that's the final screen, but you can chain as many as you want like that)

                    AbstractRelic relicToAdd = RelicLibrary.starterList.get(AbstractDungeon.relicRng.random(RelicLibrary.starterList.size() - 1)).makeCopy();
                    // Get a random starting relic

                    AbstractDungeon.getCurrRoom().spawnRelicAndObtain((float)(Settings.WIDTH / 2), (float)(Settings.HEIGHT / 2), relicToAdd);


                    break; // Onto screen 1 we go.
                case 1: // If you press button the second button (Button at index 1), in this case: Deinal

                    CardCrawlGame.screenShake.shake(ScreenShake.ShakeIntensity.MED, ScreenShake.ShakeDur.MED, false);
                    // Shake the screen
                    CardCrawlGame.sound.play("BLUNT_FAST");  // Play a hit sound
                    AbstractDungeon.player.decreaseMaxHealth(healthdamage); // Lose max HP
                    if (CardGroup.getGroupWithoutBottledCards(AbstractDungeon.player.masterDeck.getPurgeableCards()).size() > 0) {
                        // If you have cards you can remove - remove a card
                        AbstractDungeon.gridSelectScreen.open(
                                CardGroup.getGroupWithoutBottledCards(
                                        AbstractDungeon.player.masterDeck.getPurgeableCards()),
                                1, OPTIONS[6], false, false, false, true);
                    }

                    this.imageEventText.updateBodyText(DESCRIPTIONS[2]);
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]);
                    this.imageEventText.clearRemainingOptions();
                    screenNum = 1;

                    // Same as before. A note here is that you can also do
                    // imageEventText.clearAllDialogs();
                    // imageEventText.setDialogOption(OPTIONS[1]);
                    // imageEventText.setDialogOption(OPTIONS[4]);
                    // (etc.)
                    // And that would also just set them into slot 0, 1, 2... in order, just like what we do in the very beginning

                    break; // Onto screen 1 we go.
                case 2: // If you press button the third button (Button at index 2), in this case: Acceptance

                    AbstractCard c = new Apotheosis().makeCopy();
                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(c, (float) (Settings.WIDTH / 2), (float) (Settings.HEIGHT / 2)));

                    this.imageEventText.updateBodyText(DESCRIPTIONS[3]);
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]);
                    this.imageEventText.clearRemainingOptions();
                    screenNum = 1;
                    break;
                case 3: // If you press button the fourth button (Button at index 3), in this case: TOUCH
                    imageEventText.loadImage("theDefaultResources/images/events/IdentityCrisisEvent2.png"); // Change the shown image
                    // Other than that, this option doesn't do anything special.
                    this.imageEventText.updateBodyText(DESCRIPTIONS[4]);
                    this.imageEventText.updateDialogOption(0, OPTIONS[5]);
                    this.imageEventText.clearRemainingOptions();
                    screenNum = 1;
                    break;
            }
            break;
        case 1: // Welcome to screenNum = 1;
            switch (i) {
                case 0: // If you press the first (and this should be the only) button,
                    openMap(); // You'll open the map and end the event.
                    break;
            }
            break;
    }
}