|
| 1 | +package stsjorbsmod.patches; |
| 2 | + |
| 3 | +import com.evacipated.cardcrawl.modthespire.lib.*; |
| 4 | +import com.megacrit.cardcrawl.characters.AbstractPlayer; |
| 5 | +import com.megacrit.cardcrawl.dungeons.AbstractDungeon; |
| 6 | +import com.megacrit.cardcrawl.events.AbstractEvent; |
| 7 | +import com.megacrit.cardcrawl.events.shrines.Nloth; |
| 8 | +import com.megacrit.cardcrawl.random.Random; |
| 9 | +import com.megacrit.cardcrawl.relics.AbstractRelic; |
| 10 | +import javassist.CannotCompileException; |
| 11 | +import javassist.CtBehavior; |
| 12 | +import javassist.expr.ExprEditor; |
| 13 | +import javassist.expr.FieldAccess; |
| 14 | +import javassist.expr.MethodCall; |
| 15 | +import stsjorbsmod.JorbsMod; |
| 16 | +import stsjorbsmod.relics.FragileMindRelic; |
| 17 | + |
| 18 | +import java.util.ArrayList; |
| 19 | + |
| 20 | +public class NlothsGiftPatch { |
| 21 | + |
| 22 | + /** |
| 23 | + * This is called only by edited expressions in the main game. See the following SpirePatch. |
| 24 | + * |
| 25 | + * @param playerRelics ArrayList of AbstractRelic. This exactly matches the return type |
| 26 | + * @return ArrayList of AbstractRelics. This exactly matches the parameter type |
| 27 | + */ |
| 28 | + public static ArrayList<AbstractRelic> clonePlayerRelicsWithoutFragileMind(ArrayList<AbstractRelic> playerRelics) { |
| 29 | + ArrayList<AbstractRelic> relics = new ArrayList<>(playerRelics.size()); |
| 30 | + playerRelics.forEach(r -> { |
| 31 | + if (!FragileMindRelic.ID.equals(r.relicId)) { |
| 32 | + relics.add(r); |
| 33 | + } |
| 34 | + }); |
| 35 | + return relics; |
| 36 | + } |
| 37 | + |
| 38 | + public static class ClonePlayerRelicsWithoutFragileMind extends ExprEditor { |
| 39 | + @Override |
| 40 | + public void edit(FieldAccess fieldAccess) throws CannotCompileException { |
| 41 | + if (fieldAccess.getClassName().equals(AbstractPlayer.class.getName()) |
| 42 | + && fieldAccess.getFieldName().equals("relics")) { |
| 43 | + fieldAccess.replace("{ $_ = (" + NlothsGiftPatch.class.getName() + ".clonePlayerRelicsWithoutFragileMind($proceed())); }"); |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @SpirePatch(clz = AbstractDungeon.class, method = "getShrine") |
| 49 | + public static class AbstractDungeon_getShrine_NlothCheck { |
| 50 | + public static ExprEditor Instrument() { |
| 51 | + return new ClonePlayerRelicsWithoutFragileMind(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @SpirePatch(clz = Nloth.class, method = SpirePatch.CONSTRUCTOR) |
| 56 | + public static class Nloth_ctor_RemoveFragileMind { |
| 57 | + /** |
| 58 | + * Removes FragileMindRelic from the list of relics for N'loth to request. |
| 59 | + */ |
| 60 | + public static ExprEditor Instrument() { |
| 61 | + return new ClonePlayerRelicsWithoutFragileMind(); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments