Skip to content

Commit

Permalink
feat: Spell Recast Functions [skip ci] (#2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonkeyBlaster committed May 5, 2024
1 parent 81337ca commit f216c38
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ private void registerAllFunctions() {
registerFunction(new CombatFunctions.AreaDamageAverageFunction());
registerFunction(new CombatFunctions.AreaDamagePerSecondFunction());
registerFunction(new CombatFunctions.BlocksAboveGroundFunction());
registerFunction(new CombatFunctions.LastSpellNameFunction());
registerFunction(new CombatFunctions.LastSpellRepeatCountFunction());
registerFunction(new CombatFunctions.TicksSinceLastSpellFunction());

registerFunction(new CombatXpFunctions.CappedLevelFunction());
registerFunction(new CombatXpFunctions.CappedXpFunction());
Expand Down
60 changes: 60 additions & 0 deletions common/src/main/java/com/wynntils/functions/CombatFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,64 @@ protected List<String> getAliases() {
return List.of("agl", "above_ground_level");
}
}

public static class LastSpellNameFunction extends Function<String> {
@Override
public String getValue(FunctionArguments arguments) {
return arguments.getArgument("burst").getBooleanValue()
? Models.Spell.getLastBurstSpellName()
: Models.Spell.getLastSpellName();
}

@Override
public FunctionArguments.Builder getArgumentsBuilder() {
return new FunctionArguments.OptionalArgumentBuilder(
List.of(new FunctionArguments.Argument<>("burst", Boolean.class, false)));
}

@Override
protected List<String> getAliases() {
return List.of("recast_name");
}
}

public static class LastSpellRepeatCountFunction extends Function<Integer> {
@Override
public Integer getValue(FunctionArguments arguments) {
return arguments.getArgument("burst").getBooleanValue()
? Models.Spell.getRepeatedBurstSpellCount()
: Models.Spell.getRepeatedSpellCount();
}

@Override
public FunctionArguments.Builder getArgumentsBuilder() {
return new FunctionArguments.OptionalArgumentBuilder(
List.of(new FunctionArguments.Argument<>("burst", Boolean.class, false)));
}

@Override
protected List<String> getAliases() {
return List.of("recast_count");
}
}

public static class TicksSinceLastSpellFunction extends Function<Integer> {
@Override
public Integer getValue(FunctionArguments arguments) {
return arguments.getArgument("burst").getBooleanValue()
? Models.Spell.getTicksSinceCastBurst()
: Models.Spell.getTicksSinceCast();
}

@Override
public FunctionArguments.Builder getArgumentsBuilder() {
return new FunctionArguments.OptionalArgumentBuilder(
List.of(new FunctionArguments.Argument<>("burst", Boolean.class, false)));
}

@Override
protected List<String> getAliases() {
return List.of("recast_ticks");
}
}
}
81 changes: 80 additions & 1 deletion common/src/main/java/com/wynntils/models/spells/SpellModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2023.
* Copyright © Wynntils 2023-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.models.spells;
Expand All @@ -10,13 +10,15 @@
import com.wynntils.core.text.StyledText;
import com.wynntils.handlers.item.event.ItemRenamedEvent;
import com.wynntils.mc.event.SubtitleSetTextEvent;
import com.wynntils.mc.event.TickEvent;
import com.wynntils.models.spells.actionbar.SpellSegment;
import com.wynntils.models.spells.event.SpellEvent;
import com.wynntils.models.spells.event.SpellSegmentUpdateEvent;
import com.wynntils.models.spells.type.PartialSpellSource;
import com.wynntils.models.spells.type.SpellDirection;
import com.wynntils.models.spells.type.SpellFailureReason;
import com.wynntils.models.spells.type.SpellType;
import com.wynntils.models.worlds.event.WorldStateEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -30,10 +32,17 @@ public class SpellModel extends Model {
private static final Pattern SPELL_TITLE_PATTERN = Pattern.compile(
"§a([LR]|Right|Left)§7-§[a7](?:§n)?([LR?]|Right|Left)§7-§r§[a7](?:§n)?([LR?]|Right|Left)§r");
private static final Pattern SPELL_CAST = Pattern.compile("^§7(.*) spell cast! §3\\[§b-([0-9]+) ✺§3\\]$");
private static final int SPELL_COST_RESET_TICKS = 60;

private final SpellSegment spellSegment = new SpellSegment();

private SpellDirection[] lastSpell = SpellDirection.NO_SPELL;
private String lastBurstSpellName = "";
private String lastSpellName = "";
private int repeatedBurstSpellCount = 0;
private int repeatedSpellCount = 0;
private int ticksSinceCastBurst = 0;
private int ticksSinceCast = 0;

public SpellModel() {
super(List.of());
Expand Down Expand Up @@ -106,6 +115,76 @@ public void onSubtitleSetText(SubtitleSetTextEvent e) {
}
}

@SubscribeEvent
public void onSpellCast(SpellEvent.Cast e) {
ticksSinceCastBurst = 0;
ticksSinceCast = 0;

if (e.getSpellType().getName().equals(lastBurstSpellName)) {
repeatedBurstSpellCount++;
} else {
repeatedBurstSpellCount = 1;
}
if (e.getSpellType().getName().equals(lastSpellName)) {
repeatedSpellCount++;
} else {
repeatedSpellCount = 1;
}

lastBurstSpellName = e.getSpellType().getName();
lastSpellName = e.getSpellType().getName();
}

@SubscribeEvent
public void onTick(TickEvent e) {
if (!lastBurstSpellName.isEmpty()) {
ticksSinceCastBurst++;
}
if (!lastSpellName.isEmpty()) {
ticksSinceCast++;
}

if (ticksSinceCastBurst >= SPELL_COST_RESET_TICKS) {
lastBurstSpellName = "";
repeatedBurstSpellCount = 0;
ticksSinceCastBurst = 0;
}
}

@SubscribeEvent
public void onWorldStateChange(WorldStateEvent e) {
lastBurstSpellName = "";
lastSpellName = "";
repeatedBurstSpellCount = 0;
repeatedSpellCount = 0;
ticksSinceCastBurst = 0;
ticksSinceCast = 0;
}

public String getLastBurstSpellName() {
return lastBurstSpellName;
}

public String getLastSpellName() {
return lastSpellName;
}

public int getRepeatedBurstSpellCount() {
return repeatedBurstSpellCount;
}

public int getRepeatedSpellCount() {
return repeatedSpellCount;
}

public int getTicksSinceCastBurst() {
return ticksSinceCastBurst;
}

public int getTicksSinceCast() {
return ticksSinceCast;
}

private static SpellDirection[] getSpellFromMatcher(MatchResult spellMatcher) {
int size = 1;
for (; size < 3; ++size) {
Expand Down
9 changes: 9 additions & 0 deletions common/src/main/resources/assets/wynntils/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,12 @@
"function.wynntils.lastHarvestResourceType.name": "Last Harvest Resource Type",
"function.wynntils.lastMythic.description": "The last mythic that you found in a loot chest.",
"function.wynntils.lastMythic.name": "Last Mythic",
"function.wynntils.lastSpellName.argument.burst": "Should only the last spell in the current burst be returned?",
"function.wynntils.lastSpellName.description": "The name of the last spell cast",
"function.wynntils.lastSpellName.name": "Last Spell Name",
"function.wynntils.lastSpellRepeatCount.argument.burst": "Should only the last spell in the current burst be returned?",
"function.wynntils.lastSpellRepeatCount.description": "The number of times the last spell has been cast in a row in the current burst",
"function.wynntils.lastSpellRepeatCount.name": "Last Spell Repeat Count",
"function.wynntils.level.description": "Your current combat level",
"function.wynntils.level.name": "Lvl",
"function.wynntils.liquidEmerald.description": "Amount of money liquid emeralds in inventory",
Expand Down Expand Up @@ -1718,6 +1724,9 @@
"function.wynntils.stopwatchZero.name": "Stopwatch Zero",
"function.wynntils.ticks.description": "The number of ticks since world start",
"function.wynntils.ticks.name": "Ticks",
"function.wynntils.ticksSinceLastSpell.argument.burst": "Should only the last spell in the current burst be returned?",
"function.wynntils.ticksSinceLastSpell.description": "The number of ticks since the last spell was cast",
"function.wynntils.ticksSinceLastSpell.name": "Ticks Since Last Spell",
"function.wynntils.tokenGatekeeper.argument.gatekeeperNumber": "The Gatekeeper Number",
"function.wynntils.tokenGatekeeper.description": "The number of tokens collected to get past a gatekeeper",
"function.wynntils.tokenGatekeeper.name": "Gatekeeper Tokens",
Expand Down

0 comments on commit f216c38

Please sign in to comment.