attack styles: add defensive casting to weapon types for staffs
Fix race with accessing client vars on startUp
This commit is contained in:
@@ -35,8 +35,8 @@ import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
@@ -46,6 +46,7 @@ import net.runelite.api.widgets.Widget;
|
||||
import static net.runelite.api.widgets.WidgetID.COMBAT_GROUP_ID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
@@ -71,6 +72,9 @@ public class AttackStylesPlugin extends Plugin
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Inject
|
||||
private AttackStylesConfig config;
|
||||
|
||||
@@ -93,20 +97,28 @@ public class AttackStylesPlugin extends Plugin
|
||||
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
updateWarnedSkills(config.warnForAttack(), Skill.ATTACK);
|
||||
updateWarnedSkills(config.warnForStrength(), Skill.STRENGTH);
|
||||
updateWarnedSkills(config.warnForDefence(), Skill.DEFENCE);
|
||||
updateWarnedSkills(config.warnForRanged(), Skill.RANGED);
|
||||
updateWarnedSkills(config.warnForMagic(), Skill.MAGIC);
|
||||
updateAttackStyle(
|
||||
client.getVar(Varbits.EQUIPPED_WEAPON_TYPE),
|
||||
client.getVar(VarPlayer.ATTACK_STYLE),
|
||||
client.getVar(Varbits.DEFENSIVE_CASTING_MODE));
|
||||
updateWarning(false);
|
||||
processWidgets();
|
||||
clientThread.invokeLater(this::start);
|
||||
}
|
||||
}
|
||||
|
||||
private void start()
|
||||
{
|
||||
updateWarnedSkills(config.warnForAttack(), Skill.ATTACK);
|
||||
updateWarnedSkills(config.warnForStrength(), Skill.STRENGTH);
|
||||
updateWarnedSkills(config.warnForDefence(), Skill.DEFENCE);
|
||||
updateWarnedSkills(config.warnForRanged(), Skill.RANGED);
|
||||
updateWarnedSkills(config.warnForMagic(), Skill.MAGIC);
|
||||
attackStyleVarbit = client.getVar(VarPlayer.ATTACK_STYLE);
|
||||
equippedWeaponTypeVarbit = client.getVar(Varbits.EQUIPPED_WEAPON_TYPE);
|
||||
castingModeVarbit = client.getVar(Varbits.DEFENSIVE_CASTING_MODE);
|
||||
updateAttackStyle(
|
||||
equippedWeaponTypeVarbit,
|
||||
attackStyleVarbit,
|
||||
castingModeVarbit);
|
||||
updateWarning(false);
|
||||
processWidgets();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
@@ -133,11 +145,6 @@ public class AttackStylesPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
if (widgetsToHide == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
processWidgets();
|
||||
}
|
||||
|
||||
@@ -301,13 +308,14 @@ public class AttackStylesPlugin extends Plugin
|
||||
// Iterate over attack styles
|
||||
for (int i = 0; i < attackStyles.length; i++)
|
||||
{
|
||||
if (attackStyles[i] == null)
|
||||
AttackStyle attackStyle = attackStyles[i];
|
||||
if (attackStyle == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean warnedSkill = false;
|
||||
for (Skill skill : attackStyles[i].getSkills())
|
||||
for (Skill skill : attackStyle.getSkills())
|
||||
{
|
||||
if (warnedSkills.contains(skill))
|
||||
{
|
||||
@@ -317,12 +325,12 @@ public class AttackStylesPlugin extends Plugin
|
||||
}
|
||||
|
||||
// Magic staves defensive casting mode
|
||||
if (equippedWeaponType == WeaponType.TYPE_18)
|
||||
if (attackStyle == AttackStyle.DEFENSIVE_CASTING || !enabled)
|
||||
{
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_BOX, enabled && (warnedSkills.contains(Skill.DEFENCE) || warnedSkill));
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_ICON, enabled && (warnedSkills.contains(Skill.DEFENCE) || warnedSkill));
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_SHIELD, enabled && (warnedSkills.contains(Skill.DEFENCE) || warnedSkill));
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_TEXT, enabled && (warnedSkills.contains(Skill.DEFENCE) || warnedSkill));
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_BOX, enabled && warnedSkill);
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_ICON, enabled && warnedSkill);
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_SHIELD, enabled && warnedSkill);
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_DEFENSIVE_SPELL_TEXT, enabled && warnedSkill);
|
||||
}
|
||||
|
||||
// Remove appropriate combat option
|
||||
@@ -344,7 +352,7 @@ public class AttackStylesPlugin extends Plugin
|
||||
widgetsToHide.put(equippedWeaponType, WidgetInfo.COMBAT_SPELLS, enabled && warnedSkill);
|
||||
break;
|
||||
default:
|
||||
log.warn("Unreachable default case for equipped weapon type attack styles");
|
||||
// 5 can be defensive casting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ public enum WeaponType
|
||||
TYPE_15(CONTROLLED, CONTROLLED, CONTROLLED, DEFENSIVE),
|
||||
TYPE_16(ACCURATE, AGGRESSIVE, CONTROLLED, DEFENSIVE),
|
||||
TYPE_17(ACCURATE, AGGRESSIVE, AGGRESSIVE, DEFENSIVE),
|
||||
TYPE_18(ACCURATE, AGGRESSIVE, null, DEFENSIVE, CASTING),
|
||||
TYPE_18(ACCURATE, AGGRESSIVE, null, DEFENSIVE, CASTING, DEFENSIVE_CASTING),
|
||||
TYPE_19(RANGING, RANGING, null, LONGRANGE),
|
||||
TYPE_20(ACCURATE, CONTROLLED, null, DEFENSIVE),
|
||||
TYPE_21(ACCURATE, AGGRESSIVE, null, DEFENSIVE),
|
||||
TYPE_21(ACCURATE, AGGRESSIVE, null, DEFENSIVE, CASTING, DEFENSIVE_CASTING),
|
||||
TYPE_22(ACCURATE, AGGRESSIVE, AGGRESSIVE, DEFENSIVE),
|
||||
TYPE_23(CASTING, CASTING, null, DEFENSIVE_CASTING),
|
||||
TYPE_24(ACCURATE, AGGRESSIVE, CONTROLLED, DEFENSIVE),
|
||||
|
||||
Reference in New Issue
Block a user