From 5b8e36876cd08154a8640af43fcbdb822ad819ac Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Mon, 14 Oct 2019 09:26:14 -0300 Subject: [PATCH] Don't deactivate the portal if a gem wasn't purified Signed-off-by: Chris Cromer --- src/main/java/cl/cromer/azaraka/Canvas.java | 2 +- src/main/java/cl/cromer/azaraka/object/Player.java | 12 ++++++++---- src/main/java/cl/cromer/azaraka/object/Portal.java | 12 +++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/cl/cromer/azaraka/Canvas.java b/src/main/java/cl/cromer/azaraka/Canvas.java index 433f8cb..138ab53 100644 --- a/src/main/java/cl/cromer/azaraka/Canvas.java +++ b/src/main/java/cl/cromer/azaraka/Canvas.java @@ -369,7 +369,7 @@ public class Canvas extends java.awt.Canvas implements Constants { } } - ArrayList gems = player.getInventoryGems(); + ArrayList gems = player.getInventoryGems(false); for (Gem gem : gems) { gem.drawAnimation(graphicBuffer, xPixels, 8); xPixels = xPixels + 3 + (gem.getAnimationWidth()); diff --git a/src/main/java/cl/cromer/azaraka/object/Player.java b/src/main/java/cl/cromer/azaraka/object/Player.java index 8e32993..f8d918f 100644 --- a/src/main/java/cl/cromer/azaraka/object/Player.java +++ b/src/main/java/cl/cromer/azaraka/object/Player.java @@ -82,7 +82,7 @@ public class Player extends Object implements Constants { */ public void keyPressed(int keyCode) { if (getScene().isDoorOpen()) { - ArrayList gems = getInventoryGems(); + ArrayList gems = getInventoryGems(true); if (gems.size() < 2) { getScene().openDoor(false); } @@ -485,13 +485,17 @@ public class Player extends Object implements Constants { /** * Get the gems the player has * + * @param all Whether or not to return the gems that are still in transition to inventory * @return Returns an array of the gems the player is carrying */ - public ArrayList getInventoryGems() { + public ArrayList getInventoryGems(boolean all) { ArrayList gems = new ArrayList<>(); for (Object object : carrying) { - if (object instanceof Gem && object.getCell().getObjectOnTop() == null) { - // Only count the gem as in inventory once it stops showing + if (object instanceof Gem) { + if (!all && object.getCell().getObjectOnTop() != null) { + // Only count the gem as in inventory once it stops showing + continue; + } gems.add((Gem) object); } } diff --git a/src/main/java/cl/cromer/azaraka/object/Portal.java b/src/main/java/cl/cromer/azaraka/object/Portal.java index f7ea7f7..d383544 100644 --- a/src/main/java/cl/cromer/azaraka/object/Portal.java +++ b/src/main/java/cl/cromer/azaraka/object/Portal.java @@ -92,15 +92,21 @@ public class Portal extends Object implements Constants { */ public void purifyGems() { if (state == State.ACTIVE) { - ArrayList gems = getScene().getCanvas().getPlayer().getInventoryGems(); + ArrayList gems = getScene().getCanvas().getPlayer().getInventoryGems(true); + boolean purified = false; for (Gem gem : gems) { if (gem.getState() == Gem.State.TAINTED) { gem.setState(Gem.State.PURIFIED); getScene().getCanvas().getPlayer().gainHealth(2); + if (!purified) { + purified = true; + } } } - setState(State.INACTIVE); - playPortalSound(); + if (purified) { + setState(State.INACTIVE); + playPortalSound(); + } if (gems.size() == 2) { getScene().openDoor(true); }