Skip to content

Conversation

@tldyl
Copy link

@tldyl tldyl commented Nov 22, 2022

After add this feature, you can add a method to a class like this:

@SpirePatch(
        clz = RunicDome.class,
        method = SpirePatch.CLASS
)
public static class PatchRunicDome {
    //this will add onSpawnMonster(AbstractMonster) method to RunicDome
    @SpireMethod(returnType = void.class)
    public static void onSpawnMonster(AbstractRelic runicDome, AbstractMonster monster) {
        runicDome.flash();
        AbstractDungeon.actionManager.addToBottom(new RelicAboveCreatureAction(monster, runicDome));
    }
}

If another mod has already added this method, the method body will insert into the existing method.

@SpirePatch(
        clz = RunicDome.class,
        method = SpirePatch.CLASS
)
public static class TestConflict {
    private static final AbstractRelic mask = new CultistMask();

    @SpireMethod(returnType = void.class, onConflict = SpireMethod.PREFIX)
    public static void onSpawnMonster(AbstractRelic runicDome, AbstractMonster monster) {
        AbstractDungeon.actionManager.addToBottom(new RelicAboveCreatureAction(AbstractDungeon.player, runicDome));
        AbstractDungeon.actionManager.addToBottom(new SFXAction("VO_CULTIST_1A"));
        AbstractDungeon.actionManager.addToBottom(new TalkAction(true, mask.DESCRIPTIONS[1], 1.0F, 2.0F));
    }
}

I have been tested and it works.

@tldyl
Copy link
Author

tldyl commented Nov 22, 2022

You can add a method with return value to a class like this:

@SpirePatch(
        clz = Orichalcum.class,
        method = SpirePatch.CLASS
)
public static class TestReturnValue {
    @SpireMethod(returnType = float.class)
    public static void atDamageModify(AbstractRelic orichalcum, Object[] _retVal, float damage, AbstractCard c) {
        _retVal[0] = c.hasTag(AbstractCard.CardTags.STRIKE) ? damage + 3.0F : damage;
    }
}

@SpirePatch(
        clz = Orichalcum.class,
        method = SpirePatch.CLASS
)
public static class TestConflictWithReturnValue {
    @SpireMethod(returnType = float.class, onConflict = SpireMethod.PREFIX)
    public static void atDamageModify(AbstractRelic orichalcum, Object[] _retVal, float damage, AbstractCard c) {
        _retVal[0] = damage;
    }
}

I have been tested and it works.

@tldyl tldyl changed the base branch from master to develop November 29, 2022 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant