Skip to content

Commit

Permalink
attack styles: use client enum for looking up weapon attack styles
Browse files Browse the repository at this point in the history
enum_3098 maps from weapon type -> enum of attack style -> struct

Use this enum to pull our the attack styles. The current styles are: [Casting, Aggressive, Ranging, Longrange, Defensive, Controlled, Accurate, Other].
Defensive is used for defensive casting, Other seems to be for no style.
  • Loading branch information
Adam- committed Mar 21, 2024
1 parent cdfc401 commit 7d91afa
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 205 deletions.
6 changes: 6 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/EnumID.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ public final class EnumID
* val: struct slayer task
*/
public static final int SLAYER_TASK = 5008;

/**
* key: weapon type
* val: enum
*/
public static final int WEAPON_STYLES = 3908;
}
2 changes: 2 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/ParamID.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ public final class ParamID
public static final int NPC_DEATH_HIDER_EXCLUDE = 1799;

public static final int SLAYER_TASK_NAME = 1801;

public static final int ATTACK_STYLE_NAME = 1407;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.EnumID;
import net.runelite.api.GameState;
import net.runelite.api.ParamID;
import net.runelite.api.ScriptID;
import net.runelite.api.Skill;
import net.runelite.api.StructComposition;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
import net.runelite.api.events.GameTick;
Expand All @@ -54,7 +57,7 @@
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import static net.runelite.client.plugins.attackstyles.AttackStyle.CASTING;
import static net.runelite.client.plugins.attackstyles.AttackStyle.DEFENSIVE;
import static net.runelite.client.plugins.attackstyles.AttackStyle.DEFENSIVE_CASTING;
import static net.runelite.client.plugins.attackstyles.AttackStyle.OTHER;
import net.runelite.client.ui.overlay.OverlayManager;
Expand All @@ -71,7 +74,8 @@ public class AttackStylesPlugin extends Plugin
private AttackStyle prevAttackStyle;
private final Set<Skill> warnedSkills = EnumSet.noneOf(Skill.class);
private boolean warnedSkillSelected;
private final Table<WeaponType, Integer, Boolean> widgetsToHide = HashBasedTable.create();
// Weapon type, component, hidden
private final Table<Integer, Integer, Boolean> widgetsToHide = HashBasedTable.create();

@Inject
private Client client;
Expand Down Expand Up @@ -125,8 +129,11 @@ protected void startUp() throws Exception
protected void shutDown()
{
overlayManager.remove(overlay);
updateWidgetsToHide(false);
processWidgets();
clientThread.invokeLater(() ->
{
updateWidgetsToHide(false);
processWidgets();
});
hideWidget(client.getWidget(ComponentID.COMBAT_AUTO_RETALIATE), false);
warnedSkills.clear();
}
Expand Down Expand Up @@ -156,14 +163,9 @@ public void onScriptPostFired(ScriptPostFired scriptPostFired)
*/
private void processWidgets()
{
WeaponType equippedWeaponType = WeaponType.getWeaponType(equippedWeaponTypeVarbit);

if (widgetsToHide.containsRow(equippedWeaponType))
for (int componentId : widgetsToHide.row(equippedWeaponTypeVarbit).keySet())
{
for (int componentId : widgetsToHide.row(equippedWeaponType).keySet())
{
hideWidget(client.getWidget(componentId), widgetsToHide.get(equippedWeaponType, componentId));
}
hideWidget(client.getWidget(componentId), widgetsToHide.get(equippedWeaponTypeVarbit, componentId));
}
hideWidget(client.getWidget(ComponentID.COMBAT_AUTO_RETALIATE), config.hideAutoRetaliate());
}
Expand Down Expand Up @@ -202,28 +204,32 @@ public void onConfigChanged(ConfigChanged event)
if (event.getGroup().equals("attackIndicator"))
{
boolean enabled = Boolean.TRUE.toString().equals(event.getNewValue());
switch (event.getKey())
clientThread.invokeLater(() ->
{
case "warnForDefensive":
updateWarnedSkills(enabled, Skill.DEFENCE);
break;
case "warnForAttack":
updateWarnedSkills(enabled, Skill.ATTACK);
break;
case "warnForStrength":
updateWarnedSkills(enabled, Skill.STRENGTH);
break;
case "warnForRanged":
updateWarnedSkills(enabled, Skill.RANGED);
break;
case "warnForMagic":
updateWarnedSkills(enabled, Skill.MAGIC);
break;
case "removeWarnedStyles":
updateWidgetsToHide(enabled);
break;
}
clientThread.invokeLater(this::processWidgets);
switch (event.getKey())
{
case "warnForDefensive":
updateWarnedSkills(enabled, Skill.DEFENCE);
break;
case "warnForAttack":
updateWarnedSkills(enabled, Skill.ATTACK);
break;
case "warnForStrength":
updateWarnedSkills(enabled, Skill.STRENGTH);
break;
case "warnForRanged":
updateWarnedSkills(enabled, Skill.RANGED);
break;
case "warnForMagic":
updateWarnedSkills(enabled, Skill.MAGIC);
break;
case "removeWarnedStyles":
updateWidgetsToHide(enabled);
break;
}
updateWarning();
processWidgets();
});
}
}

Expand Down Expand Up @@ -256,19 +262,55 @@ private void resetWarnings()

private void updateAttackStyle(int equippedWeaponType, int attackStyleIndex, int castingMode)
{
AttackStyle[] attackStyles = WeaponType.getWeaponType(equippedWeaponType).getAttackStyles();
AttackStyle[] attackStyles = getWeaponTypeStyles(equippedWeaponType);
if (attackStyleIndex < attackStyles.length)
{
// from script4525
// Even though the client has 5 attack styles for Staffs, only attack styles 0-4 are used, with an additional
// casting mode set for defensive casting
if (attackStyleIndex == 4)
{
attackStyleIndex += castingMode;
}

attackStyle = attackStyles[attackStyleIndex];
if (attackStyle == null)
{
attackStyle = OTHER;
}
else if ((attackStyle == CASTING) && (castingMode == 1))
}
}

private AttackStyle[] getWeaponTypeStyles(int weaponType)
{
// from script4525
int weaponStyleEnum = client.getEnum(EnumID.WEAPON_STYLES).getIntValue(weaponType);
int[] weaponStyleStructs = client.getEnum(weaponStyleEnum).getIntVals();

AttackStyle[] styles = new AttackStyle[weaponStyleStructs.length];
int i = 0;
for (int style : weaponStyleStructs)
{
StructComposition attackStyleStruct = client.getStructComposition(style);
String attackStyleName = attackStyleStruct.getStringValue(ParamID.ATTACK_STYLE_NAME);

AttackStyle attackStyle = AttackStyle.valueOf(attackStyleName.toUpperCase());
if (attackStyle == OTHER)
{
// "Other" is used for no style
++i;
continue;
}

// "Defensive" is used for Defensive and also Defensive casting
if (i == 5 && attackStyle == DEFENSIVE)
{
attackStyle = DEFENSIVE_CASTING;
}

styles[i++] = attackStyle;
}
return styles;
}

private void updateWarnedSkills(boolean enabled, Skill skill)
Expand All @@ -281,7 +323,6 @@ private void updateWarnedSkills(boolean enabled, Skill skill)
{
warnedSkills.remove(skill);
}
updateWarning();
}

// update the 'warned skill selected' flag and also rebuild the hide widgets table
Expand All @@ -304,13 +345,7 @@ private void updateWarning()

private void updateWidgetsToHide(boolean enabled)
{
WeaponType equippedWeaponType = WeaponType.getWeaponType(equippedWeaponTypeVarbit);
if (equippedWeaponType == null)
{
return;
}

AttackStyle[] attackStyles = equippedWeaponType.getAttackStyles();
AttackStyle[] attackStyles = getWeaponTypeStyles(equippedWeaponTypeVarbit);

// Iterate over attack styles
for (int i = 0; i < attackStyles.length; i++)
Expand All @@ -331,35 +366,31 @@ private void updateWidgetsToHide(boolean enabled)
}
}

// Magic staves defensive casting mode
if (attackStyle == DEFENSIVE_CASTING || !enabled)
{
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_DEFENSIVE_SPELL_BOX, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_DEFENSIVE_SPELL_ICON, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_DEFENSIVE_SPELL_SHIELD, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_DEFENSIVE_SPELL_TEXT, enabled && warnedSkill);
}

// Remove appropriate combat option
switch (i)
{
case 0:
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_STYLE_ONE, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_STYLE_ONE, enabled && warnedSkill);
break;
case 1:
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_STYLE_TWO, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_STYLE_TWO, enabled && warnedSkill);
break;
case 2:
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_STYLE_THREE, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_STYLE_THREE, enabled && warnedSkill);
break;
case 3:
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_STYLE_FOUR, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_STYLE_FOUR, enabled && warnedSkill);
break;
case 4:
widgetsToHide.put(equippedWeaponType, ComponentID.COMBAT_SPELLS, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_SPELLS, enabled && warnedSkill);
break;
case 5:
// Magic staves defensive casting mode
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_DEFENSIVE_SPELL_BOX, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_DEFENSIVE_SPELL_ICON, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_DEFENSIVE_SPELL_SHIELD, enabled && warnedSkill);
widgetsToHide.put(equippedWeaponTypeVarbit, ComponentID.COMBAT_DEFENSIVE_SPELL_TEXT, enabled && warnedSkill);
break;
default:
// 5 can be defensive casting
}
}
}
Expand All @@ -379,7 +410,7 @@ Set<Skill> getWarnedSkills()
}

@VisibleForTesting
Table<WeaponType, Integer, Boolean> getHiddenWidgets()
Table<Integer, Integer, Boolean> getHiddenWidgets()
{
return widgetsToHide;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 7d91afa

Please sign in to comment.