Skip to content

Commit

Permalink
Merge pull request #30 from Skrelpoid/develop
Browse files Browse the repository at this point in the history
Add Custom Mode Mod for BetterRewards
  • Loading branch information
Skrelpoid authored Mar 27, 2022
2 parents 7c5edf2 + 39350ce commit f0134a7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/main/java/skrelpoid/betterrewards/BetterRewardsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.evacipated.cardcrawl.modthespire.lib.SpireConfig;
import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractEvent;
import com.megacrit.cardcrawl.events.GenericEventDialog;
Expand All @@ -26,6 +27,8 @@
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.relics.Circlet;
import com.megacrit.cardcrawl.rooms.ShopRoom;
import com.megacrit.cardcrawl.screens.custom.CustomMod;
import com.megacrit.cardcrawl.screens.custom.CustomModeScreen;
import com.megacrit.cardcrawl.screens.options.DropdownMenu;
import com.megacrit.cardcrawl.screens.runHistory.RunHistoryScreen;
import com.megacrit.cardcrawl.screens.stats.RunData;
Expand Down Expand Up @@ -59,6 +62,7 @@ public class BetterRewardsMod implements PostInitializeSubscriber {
public static boolean isGettingRewards = false;
public static boolean alreadyGotRewards = false;
public static boolean isFunMode = false;
public static CustomMod customMod;
public static RunData lastRun;

public static ArrayList<AbstractShopItem> shopItems;
Expand Down Expand Up @@ -388,6 +392,23 @@ private static void loadSettings() {
isFunMode = config.getBool("isFunMode");
}

public static void addCustomModeMods(CustomModeScreen screen, CustomMod sealedMod, CustomMod draftMod) {
customMod = new CustomMod("BetterRewards", "b", false);
customMod.name = "BetterRewards";
customMod.description = "Get the Better Rewards event at the start of your run";
String label = FontHelper.colorString("[" + customMod.name + "]", customMod.color) + " " + customMod.description;
ReflectionHacks.setPrivate(customMod, CustomMod.class, "label", label);
float height = -FontHelper.getSmartHeight(FontHelper.charDescFont, label, 1050.0F * Settings.scale, 32.0F * Settings.scale) + 70.0F * Settings.scale;
ReflectionHacks.setPrivate(customMod, CustomMod.class, "height", height);
customMod.setMutualExclusionPair(sealedMod);
customMod.setMutualExclusionPair(draftMod);
ReflectionHacks.<List<CustomMod>>getPrivate(screen, CustomModeScreen.class, "modList").add(customMod);
}

public static boolean isCustomModEnabled() {
return customMod.selected || (!Settings.isDailyRun && !Settings.isTrial);
}

// TODO FIX rewardsscreen in shop sometimes forces player to leave for now
// fixed by not giving relics that show reward screen
// could be really fixed by patching proceed button
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package skrelpoid.betterrewards.patches;


import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher.MethodCallMatcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertLocator;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.screens.custom.CustomMod;
import com.megacrit.cardcrawl.screens.custom.CustomModeScreen;
import com.megacrit.cardcrawl.unlock.UnlockTracker;

import javassist.CtBehavior;
import skrelpoid.betterrewards.BetterRewardsMod;

public class CustomModeScreenPatches {

@SpirePatch(clz = CustomModeScreen.class, method = "initializeMods")
public static class AddCustomModeModPatch {
@SpireInsertPatch(locator = Locator.class, localvars = { "sealedMod", "draftMod" })
public static void Insert(CustomModeScreen screen, CustomMod sealedMod, CustomMod draftMod) {
BetterRewardsMod.addCustomModeMods(screen, sealedMod, draftMod);
}

private static class Locator extends SpireInsertLocator {

@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
return LineFinder.findInOrder(ctMethodToPatch,
new MethodCallMatcher(UnlockTracker.class, "isAchievementUnlocked"));
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class AddBetterRewardsButton {
@SpirePostfixPatch
public static void Postfix(NeowRoom room, boolean b) {
BetterRewardsMod.isNeowDone = b;
if (!Settings.isDailyRun && !Settings.isTrial && !BetterRewardsMod.isNeowDone && BetterRewardsMod.shouldShowButton) {
if (BetterRewardsMod.isCustomModEnabled() && !BetterRewardsMod.isNeowDone && BetterRewardsMod.shouldShowButton) {
BetterRewardsMod.shouldShowButton = false;
BetterRewardsMod.button = RoomEventDialog.optionList.size();
room.event.roomEventText.addDialogOption("[Turn Around]");
Expand Down Expand Up @@ -81,8 +81,9 @@ public static void Prefix(AbstractEvent e, int buttonPressed) {
}

// screenNum = 0, 1 or 2 mean talk option
// 10 is only ok for trial (Custom Mode) I think
private static boolean acceptableScreenNum(int sn) {
return sn == 0 || sn == 1 || sn == 2;
return sn == 0 || sn == 1 || sn == 2 || (Settings.isTrial && sn == 10);
}

private static void maybeStartRewards(AbstractEvent e, int buttonPressed, Field screenNumField, int sn)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/ModTheSpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "BetterRewards",
"author_list": ["Skrelpoid"],
"description": "Adds an option to Neow where instead of getting standard rewards, you get rewards based on the score of your last run in a special shop.",
"version": "4.4.0",
"version": "4.5.0",
"sts_version": "12-22-2020",
"mts_version": "3.15.0",
"dependencies": ["basemod"],
Expand Down

0 comments on commit f0134a7

Please sign in to comment.