Merge pull request #4413 from deathbeam/cleanup-raids-plugin

Add support for preserving raids scouter inside raid + fix checking for raids state on plugin state changes
This commit is contained in:
Tomas Slusny
2018-08-06 21:55:55 +02:00
committed by GitHub
2 changed files with 109 additions and 105 deletions

View File

@@ -77,6 +77,17 @@ public interface RaidsConfig extends Config
@ConfigItem( @ConfigItem(
position = 4, position = 4,
keyName = "scoutOverlayInRaid",
name = "Show scout overlay inside raid",
description = "Keep the overlay active while inside raid"
)
default boolean scoutOverlayInRaid()
{
return false;
}
@ConfigItem(
position = 5,
keyName = "whitelistedRooms", keyName = "whitelistedRooms",
name = "Whitelisted rooms", name = "Whitelisted rooms",
description = "Display whitelisted rooms in green on the overlay. Separate with comma (full name)" description = "Display whitelisted rooms in green on the overlay. Separate with comma (full name)"
@@ -87,7 +98,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 5, position = 6,
keyName = "blacklistedRooms", keyName = "blacklistedRooms",
name = "Blacklisted rooms", name = "Blacklisted rooms",
description = "Display blacklisted rooms in red on the overlay. Separate with comma (full name)" description = "Display blacklisted rooms in red on the overlay. Separate with comma (full name)"
@@ -98,7 +109,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 6, position = 7,
keyName = "enableRotationWhitelist", keyName = "enableRotationWhitelist",
name = "Enable rotation whitelist", name = "Enable rotation whitelist",
description = "Enable the rotation whitelist" description = "Enable the rotation whitelist"
@@ -109,7 +120,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 7, position = 8,
keyName = "whitelistedRotations", keyName = "whitelistedRotations",
name = "Whitelisted rotations", name = "Whitelisted rotations",
description = "Warn when boss rotation doesn't match a whitelisted one. Add rotations like [tekton, muttadile, guardians]" description = "Warn when boss rotation doesn't match a whitelisted one. Add rotations like [tekton, muttadile, guardians]"
@@ -120,7 +131,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 8, position = 9,
keyName = "enableLayoutWhitelist", keyName = "enableLayoutWhitelist",
name = "Enable layout whitelist", name = "Enable layout whitelist",
description = "Enable the layout whitelist" description = "Enable the layout whitelist"
@@ -131,7 +142,7 @@ public interface RaidsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 9, position = 10,
keyName = "whitelistedLayouts", keyName = "whitelistedLayouts",
name = "Whitelisted layouts", name = "Whitelisted layouts",
description = "Warn when layout doesn't match a whitelisted one. Add layouts like CFSCPPCSCF separated with comma" description = "Warn when layout doesn't match a whitelisted one. Add layouts like CFSCPPCSCF separated with comma"

View File

@@ -85,11 +85,6 @@ public class RaidsPlugin extends Plugin
private static final String SPLIT_REGEX = "\\s*,\\s*"; private static final String SPLIT_REGEX = "\\s*,\\s*";
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]"); private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]");
private RaidsTimer timer;
@Getter
private boolean inRaidChambers;
@Inject @Inject
private ChatMessageManager chatMessageManager; private ChatMessageManager chatMessageManager;
@@ -117,20 +112,25 @@ public class RaidsPlugin extends Plugin
@Inject @Inject
private SpriteManager spriteManager; private SpriteManager spriteManager;
@Getter
private final ArrayList<String> roomWhitelist = new ArrayList<>();
@Getter
private final ArrayList<String> roomBlacklist = new ArrayList<>();
@Getter
private final ArrayList<String> rotationWhitelist = new ArrayList<>();
@Getter
private final ArrayList<String> layoutWhitelist = new ArrayList<>();
@Getter @Getter
private Raid raid; private Raid raid;
@Getter @Getter
private ArrayList<String> roomWhitelist = new ArrayList<>(); private boolean inRaidChambers;
@Getter private RaidsTimer timer;
private ArrayList<String> roomBlacklist = new ArrayList<>();
@Getter
private ArrayList<String> rotationWhitelist = new ArrayList<>();
@Getter
private ArrayList<String> layoutWhitelist = new ArrayList<>();
@Provides @Provides
RaidsConfig provideConfig(ConfigManager configManager) RaidsConfig provideConfig(ConfigManager configManager)
@@ -149,14 +149,8 @@ public class RaidsPlugin extends Plugin
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
overlayManager.add(pointsOverlay); overlayManager.add(pointsOverlay);
if (client.getGameState() == GameState.LOGGED_IN)
{
inRaidChambers = client.getVar(Varbits.IN_RAID) == 1;
updateInfoBoxState();
}
updateLists(); updateLists();
checkRaidPresence(true);
} }
@Override @Override
@@ -164,40 +158,28 @@ public class RaidsPlugin extends Plugin
{ {
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(pointsOverlay); overlayManager.remove(pointsOverlay);
infoBoxManager.removeInfoBox(timer);
if (timer != null) inRaidChambers = false;
{ raid = null;
infoBoxManager.removeInfoBox(timer); timer = null;
}
} }
@Subscribe @Subscribe
public void onConfigChanged(ConfigChanged event) public void onConfigChanged(ConfigChanged event)
{ {
if (!event.getGroup().equals("raids"))
{
return;
}
if (event.getKey().equals("raidsTimer")) if (event.getKey().equals("raidsTimer"))
{ {
updateInfoBoxState(); updateInfoBoxState();
return;
} }
if (event.getKey().equals("whitelistedRooms")) updateLists();
{ checkRaidPresence(true);
updateList(roomWhitelist, config.whitelistedRooms());
}
if (event.getKey().equals("blacklistedRooms"))
{
updateList(roomBlacklist, config.blacklistedRooms());
}
if (event.getKey().equals("whitelistedRotations"))
{
updateList(rotationWhitelist, config.whitelistedRotations());
}
if (event.getKey().equals("whitelistedLayouts"))
{
updateList(layoutWhitelist, config.whitelistedLayouts());
}
} }
@Subscribe @Subscribe
@@ -219,47 +201,7 @@ public class RaidsPlugin extends Plugin
@Subscribe @Subscribe
public void onVarbitChange(VarbitChanged event) public void onVarbitChange(VarbitChanged event)
{ {
boolean setting = client.getVar(Varbits.IN_RAID) == 1; checkRaidPresence(false);
if (inRaidChambers != setting)
{
inRaidChambers = setting;
updateInfoBoxState();
if (inRaidChambers)
{
raid = buildRaid();
if (raid == null)
{
log.debug("Failed to build raid");
return;
}
Layout layout = layoutSolver.findLayout(raid.toCode());
if (layout == null)
{
log.debug("Could not find layout match");
return;
}
raid.updateLayout(layout);
RotationSolver.solve(raid.getCombatRooms());
overlay.setScoutOverlayShown(true);
}
else if (!config.scoutOverlayAtBank())
{
overlay.setScoutOverlayShown(false);
raid = null;
}
}
if (client.getVar(VarPlayer.IN_RAID_PARTY) == -1)
{
overlay.setScoutOverlayShown(false);
raid = null;
}
} }
@Subscribe @Subscribe
@@ -321,23 +263,74 @@ public class RaidsPlugin extends Plugin
} }
} }
private void checkRaidPresence(boolean force)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
boolean setting = client.getVar(Varbits.IN_RAID) == 1;
if (force || inRaidChambers != setting)
{
inRaidChambers = setting;
updateInfoBoxState();
if (inRaidChambers)
{
raid = buildRaid();
if (raid == null)
{
log.debug("Failed to build raid");
return;
}
Layout layout = layoutSolver.findLayout(raid.toCode());
if (layout == null)
{
log.debug("Could not find layout match");
return;
}
raid.updateLayout(layout);
RotationSolver.solve(raid.getCombatRooms());
overlay.setScoutOverlayShown(true);
}
else if (!config.scoutOverlayAtBank())
{
overlay.setScoutOverlayShown(false);
}
}
// If we left party raid was started or we left raid
if (client.getVar(VarPlayer.IN_RAID_PARTY) == -1 && (!inRaidChambers || !config.scoutOverlayInRaid()))
{
overlay.setScoutOverlayShown(false);
}
}
private void updateInfoBoxState() private void updateInfoBoxState()
{ {
if (timer != null) if (timer == null)
{ {
if (inRaidChambers && config.raidsTimer()) return;
{ }
infoBoxManager.addInfoBox(timer);
}
else
{
infoBoxManager.removeInfoBox(timer);
}
if (!inRaidChambers) if (inRaidChambers && config.raidsTimer())
{ {
timer = null; infoBoxManager.addInfoBox(timer);
} }
else
{
infoBoxManager.removeInfoBox(timer);
}
if (!inRaidChambers)
{
timer = null;
} }
} }
@@ -372,7 +365,7 @@ public class RaidsPlugin extends Plugin
} }
} }
public int getRotationMatches() int getRotationMatches()
{ {
String rotation = raid.getRotationString().toLowerCase(); String rotation = raid.getRotationString().toLowerCase();
String[] bosses = rotation.split(SPLIT_REGEX); String[] bosses = rotation.split(SPLIT_REGEX);