Skip to content

Commit

Permalink
woodcutting: add new forestry events
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Oct 26, 2023
1 parent ba3109c commit 0e3a831
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,66 @@ default boolean forestryFloweringTreeNotification()
return true;
}

@ConfigItem(
position = 14,
keyName = "forestryPoachersNotification",
name = "Poachers notification",
description = "Configures whether to notify you of a Poachers event",
section = forestrySection
)
default boolean forestryPoachersNotification()
{
return true;
}

@ConfigItem(
position = 15,
keyName = "forestryPheasantControlNotification",
name = "Pheasant Control notification",
description = "Configures whether to notify you of a Pheasant Control event",
section = forestrySection
)
default boolean forestryPheasantControlNotification()
{
return true;
}

@ConfigItem(
position = 16,
keyName = "forestryBeeHiveNotification",
name = "Bee Hive notification",
description = "Configures whether to notify you of a Bee Hive event",
section = forestrySection
)
default boolean forestryBeeHiveNotification()
{
return true;
}

@ConfigItem(
position = 17,
keyName = "forestryEnchantmentRitualNotification",
name = "Enchantment Ritual notification",
description = "Configures whether to notify you of an Enchantment Ritual event",
section = forestrySection
)
default boolean forestryEnchantmentRitualNotification()
{
return true;
}

@ConfigItem(
position = 18,
keyName = "forestryFriendlyEntNotification",
name = "Friendly Ent notification",
description = "Configures whether to notify you of a Friendly Ent event",
section = forestrySection
)
default boolean forestryFriendlyEntNotification()
{
return true;
}

@ConfigItem(
position = 20,
keyName = "highlightGlowingRoots",
Expand Down Expand Up @@ -191,4 +251,52 @@ default boolean highlightFlowers()
{
return true;
}

@ConfigItem(
position = 23,
keyName = "highlightFoxTrap",
name = "Highlight fox trap",
description = "Highlights the fox trap during Poachers events",
section = forestrySection
)
default boolean highlightFoxTrap()
{
return true;
}

@ConfigItem(
position = 24,
keyName = "highlightPheasantNest",
name = "Highlight pheasant nest",
description = "Highlights the pheasant next during Pheasant Control events",
section = forestrySection
)
default boolean highlightPheasantNest()
{
return true;
}

@ConfigItem(
position = 25,
keyName = "highlightBeeHive",
name = "Highlight bee hive",
description = "Highlights the bee hive during Bee Hive events",
section = forestrySection
)
default boolean highlightBeeHive()
{
return true;
}

@ConfigItem(
position = 26,
keyName = "highlightRitualCircle",
name = "Highlight ritual circle",
description = "Highlights the Ritual Circle during Enchantment Ritual events",
section = forestrySection
)
default boolean highlightRitualCircle()
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public class WoodcuttingPlugin extends Plugin
private final List<GameObject> saplingIngredients = new ArrayList<>(5);
@Getter(AccessLevel.PACKAGE)
private final GameObject[] saplingOrder = new GameObject[3];
@Getter(AccessLevel.PACKAGE)
private NPC foxTrap;
@Getter(AccessLevel.PACKAGE)
private final List<GameObject> pheasantNests = new ArrayList<>(4);
@Getter(AccessLevel.PACKAGE)
private NPC freakyForester;
@Getter(AccessLevel.PACKAGE)
private NPC unfinishedBeeHive;
private final List<NPC> circles = new ArrayList<>(5);
private final List<NPC> entlings = new ArrayList<>(0);

@Getter(AccessLevel.PACKAGE)
private final List<TreeRespawn> respawns = new ArrayList<>();
Expand Down Expand Up @@ -347,6 +357,10 @@ public void onGameObjectSpawned(final GameObjectSpawned event)
case ObjectID.SPLINTERED_BARK:
saplingIngredients.add(gameObject);
break;
case ObjectID.PHEASANT_NEST:
case ObjectID.PHEASANT_NEST_49937:
pheasantNests.add(gameObject);
break;
}
}

Expand Down Expand Up @@ -395,6 +409,14 @@ public void onGameObjectDespawned(final GameObjectDespawned event)
log.debug("Struggling Sapling event is over");
}
break;
case ObjectID.PHEASANT_NEST:
case ObjectID.PHEASANT_NEST_49937:
pheasantNests.remove(object);
if (pheasantNests.isEmpty())
{
log.debug("Pheasant event is over");
}
break;
}
}

Expand All @@ -408,6 +430,11 @@ public void onGameStateChanged(final GameStateChanged event)
respawns.clear();
flowers.clear();
activeFlowers.clear();
foxTrap = null;
freakyForester = null;
unfinishedBeeHive = null;
circles.clear();
entlings.clear();
// fallthrough
case LOADING:
treeObjects.clear();
Expand Down Expand Up @@ -449,7 +476,8 @@ public void onAnimationChanged(final AnimationChanged event)
public void onNpcSpawned(NpcSpawned event)
{
NPC npc = event.getNpc();
if (isFloweringBush(npc.getId()))
var id = npc.getId();
if (isFloweringBush(id))
{
if (flowers.isEmpty() && config.forestryFloweringTreeNotification())
{
Expand All @@ -458,10 +486,57 @@ public void onNpcSpawned(NpcSpawned event)

flowers.add(npc);
}
else if (npc.getId() == NpcID.WOODCUTTING_LEPRECHAUN && config.forestryLeprechaunNotification())
else if (id == NpcID.WOODCUTTING_LEPRECHAUN && config.forestryLeprechaunNotification())
{
notifier.notify("A Leprechaun event spawned!");
}
else if (id == NpcID.FRIGHTENED_FOX && config.forestryPoachersNotification())
{
notifier.notify("A Poachers event spawned!");
}
else if (id == NpcID.FOX_TRAP)
{
foxTrap = npc;
}
else if (id == NpcID.FREAKY_FORESTER_12536)
{
freakyForester = npc;

if (config.forestryPheasantControlNotification())
{
notifier.notify("A Pheasant Control event has spawned!");
}
}
else if (id == NpcID.WILD_BEE_HIVE)
{
if (config.forestryBeeHiveNotification())
{
notifier.notify("A Bee Hive event has spawned!");
}
}
else if (id == NpcID.UNFINISHED_BEE_HIVE || id == NpcID.UNFINISHED_BEE_HIVE_12516)
{
unfinishedBeeHive = npc;
}
else if (id >= NpcID.RITUAL_CIRCLE_GREEN && id <= NpcID.RITUAL_CIRCLE_RED_12535)
{
circles.add(npc);
}
else if (id == NpcID.DRYAD_12519)
{
if (config.forestryEnchantmentRitualNotification())
{
notifier.notify("An Enchantment Ritual event has spawned!");
}
}
else if (id == NpcID.ENTLING)
{
entlings.add(npc);
if (entlings.size() == 1 && config.forestryFriendlyEntNotification())
{
notifier.notify("A Friendly Ent event has spawned!");
}
}
}

@Subscribe
Expand All @@ -479,6 +554,20 @@ public void onNpcDespawned(NpcDespawned event)
lastInteractFlower = null;
}
}
if (foxTrap == npc)
{
foxTrap = null;
}
if (freakyForester == npc)
{
freakyForester = null;
}
if (unfinishedBeeHive == npc)
{
unfinishedBeeHive = null;
}
circles.remove(npc);
entlings.remove(npc);
}

@Subscribe
Expand All @@ -505,4 +594,29 @@ private static boolean isFloweringBush(int npcId)
npcId == NpcID.FLOWERING_BUSH_GREEN ||
npcId == NpcID.FLOWERING_BUSH_BLUE;
}

NPC solveCircles()
{
int s = 0;
for (var npc : circles)
{
int off = npc.getId() - NpcID.RITUAL_CIRCLE_GREEN;
int shape = off / 4;
int color = off % 4;
int id = (16 << shape) | (1 << color);
s ^= id;
}
for (var npc : circles)
{
int off = npc.getId() - NpcID.RITUAL_CIRCLE_GREEN;
int shape = off / 4;
int color = off % 4;
int id = (16 << shape) | (1 << color);
if ((id & s) == id)
{
return npc;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public Dimension render(Graphics2D graphics)
renderForestryRoots(graphics);
renderForestrySapling(graphics);
renderForestryFlowers(graphics);
renderForestryPoachers(graphics);
renderForestryPheasants(graphics);
renderForestryBeeHive(graphics);
renderEnchantmentRitual(graphics);
return null;
}

Expand Down Expand Up @@ -220,6 +224,73 @@ private void renderForestryFlowers(Graphics2D graphics)
}
}

private void renderForestryPoachers(Graphics2D graphics)
{
if (plugin.getFoxTrap() != null && config.highlightFoxTrap())
{
var foxTrap = plugin.getFoxTrap();
var poly = foxTrap.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.RED);
}
}
}

private void renderForestryPheasants(Graphics2D graphics)
{
if (!plugin.getPheasantNests().isEmpty() && config.highlightPheasantNest())
{
for (var nest : plugin.getPheasantNests())
{
if (nest.getId() == ObjectID.PHEASANT_NEST_49937)
{
var poly = nest.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.GREEN);
}
}
}

var forester = plugin.getFreakyForester();
if (forester != null)
{
var poly = forester.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.GREEN);
}
}
}
}

private void renderForestryBeeHive(Graphics2D graphics)
{
if (plugin.getUnfinishedBeeHive() != null && config.highlightBeeHive())
{
var beehive = plugin.getUnfinishedBeeHive();
var poly = beehive.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.ORANGE);
}
}
}

private void renderEnchantmentRitual(Graphics2D graphics)
{
var solution = plugin.solveCircles();
if (solution != null && config.highlightRitualCircle())
{
var poly = solution.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.GREEN);
}
}
}

private void renderRedwoods(Graphics2D graphics)
{
if (plugin.getSession() == null || !config.showRedwoodTrees())
Expand Down

0 comments on commit 0e3a831

Please sign in to comment.