Skip to content

Commit

Permalink
Fragile mind nloths gift (#206)
Browse files Browse the repository at this point in the history
* N'loth should now both never trigger if the Wanderer only has starting two relics and never request Fragile Mind if the event triggers

* reformat

* rename a patch

* some updates to make redo some of the instrumentation

* oops

* cleanup

* test patch

* remove test patch after verification
  • Loading branch information
wang429 authored and dbjorge committed Nov 28, 2019
1 parent ff1b820 commit e323890
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/main/java/stsjorbsmod/patches/NlothsGiftPatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package stsjorbsmod.patches;

import com.evacipated.cardcrawl.modthespire.lib.*;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractEvent;
import com.megacrit.cardcrawl.events.shrines.Nloth;
import com.megacrit.cardcrawl.random.Random;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import javassist.CannotCompileException;
import javassist.CtBehavior;
import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess;
import javassist.expr.MethodCall;
import stsjorbsmod.JorbsMod;
import stsjorbsmod.relics.FragileMindRelic;

import java.util.ArrayList;

public class NlothsGiftPatch {

/**
* This is called only by edited expressions in the main game. See the following SpirePatch.
*
* @param playerRelics ArrayList of AbstractRelic. This exactly matches the return type
* @return ArrayList of AbstractRelics. This exactly matches the parameter type
*/
public static ArrayList<AbstractRelic> clonePlayerRelicsWithoutFragileMind(ArrayList<AbstractRelic> playerRelics) {
ArrayList<AbstractRelic> relics = new ArrayList<>(playerRelics.size());
playerRelics.forEach(r -> {
if (!FragileMindRelic.ID.equals(r.relicId)) {
relics.add(r);
}
});
return relics;
}

public static class ClonePlayerRelicsWithoutFragileMind extends ExprEditor {
@Override
public void edit(FieldAccess fieldAccess) throws CannotCompileException {
if (fieldAccess.getClassName().equals(AbstractPlayer.class.getName())
&& fieldAccess.getFieldName().equals("relics")) {
fieldAccess.replace("{ $_ = (" + NlothsGiftPatch.class.getName() + ".clonePlayerRelicsWithoutFragileMind($proceed())); }");
}
}
}

@SpirePatch(clz = AbstractDungeon.class, method = "getShrine")
public static class AbstractDungeon_getShrine_NlothCheck {
public static ExprEditor Instrument() {
return new ClonePlayerRelicsWithoutFragileMind();
}
}

@SpirePatch(clz = Nloth.class, method = SpirePatch.CONSTRUCTOR)
public static class Nloth_ctor_RemoveFragileMind {
/**
* Removes FragileMindRelic from the list of relics for N'loth to request.
*/
public static ExprEditor Instrument() {
return new ClonePlayerRelicsWithoutFragileMind();
}
}
}

0 comments on commit e323890

Please sign in to comment.