Skip to content

Commit

Permalink
OnLoseTempHp hook for powers and relics
Browse files Browse the repository at this point in the history
  • Loading branch information
kiooeht committed Nov 28, 2018
1 parent f8c8cf8 commit 8755429
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#### dev ####
* Powers
* `HealthBarRenderPower`
* `OnLoseTempHpPower`
* Relics
* `OnLoseTempHpRelic`

#### v1.8.1 ####
* Fix stun having incorrect intents the next turn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.evacipated.cardcrawl.mod.stslib.patches.tempHp;

import com.evacipated.cardcrawl.mod.stslib.patches.core.AbstractCreature.TempHPField;
import com.evacipated.cardcrawl.mod.stslib.powers.interfaces.OnLoseTempHpPower;
import com.evacipated.cardcrawl.mod.stslib.relics.OnLoseTempHpRelic;
import com.evacipated.cardcrawl.mod.stslib.vfx.combat.TempDamageNumberEffect;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.ScreenShake;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import javassist.CtBehavior;

import java.util.ArrayList;

@SpirePatch(
cls="com.megacrit.cardcrawl.characters.AbstractPlayer",
clz=AbstractPlayer.class,
method="damage"
)
public class PlayerDamage
Expand All @@ -30,6 +34,17 @@ public static void Insert(AbstractPlayer __instance, DamageInfo info, @ByRef int

int temporaryHealth = TempHPField.tempHp.get(__instance);
if (temporaryHealth > 0) {
for (AbstractPower power : __instance.powers) {
if (power instanceof OnLoseTempHpPower) {
damageAmount[0] = ((OnLoseTempHpPower) power).onLoseTempHp(info, damageAmount[0]);
}
}
for (AbstractRelic relic : __instance.relics) {
if (relic instanceof OnLoseTempHpRelic) {
damageAmount[0] = ((OnLoseTempHpRelic) relic).onLoseTempHp(info, damageAmount[0]);
}
}

hadBlock[0] = true;
CardCrawlGame.screenShake.shake(ScreenShake.ShakeIntensity.MED, ScreenShake.ShakeDur.SHORT, false);
if (temporaryHealth >= damageAmount[0]) {
Expand All @@ -45,16 +60,14 @@ public static void Insert(AbstractPlayer __instance, DamageInfo info, @ByRef int

TempHPField.tempHp.set(__instance, temporaryHealth);
}

System.out.println("Final damage: " + damageAmount[0]);
}

private static class Locator extends SpireInsertLocator
{
@Override
public int[] Locate(CtBehavior ctMethodToPatch) throws Exception
{
Matcher finalMatcher = new Matcher.MethodCallMatcher("com.megacrit.cardcrawl.characters.AbstractPlayer", "decrementBlock");
Matcher finalMatcher = new Matcher.MethodCallMatcher(AbstractPlayer.class, "decrementBlock");
return offset(LineFinder.findInOrder(ctMethodToPatch, new ArrayList<>(), finalMatcher), 1);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.evacipated.cardcrawl.mod.stslib.powers.interfaces;

import com.megacrit.cardcrawl.cards.DamageInfo;

public interface OnLoseTempHpPower
{
int onLoseTempHp(DamageInfo info, int damageAmount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.evacipated.cardcrawl.mod.stslib.relics;

import com.megacrit.cardcrawl.cards.DamageInfo;

public interface OnLoseTempHpRelic
{
int onLoseTempHp(DamageInfo info, int damageAmount);
}

0 comments on commit 8755429

Please sign in to comment.