diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java index 268f3441a..9f0b8ee77 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java @@ -93,6 +93,14 @@ public class Bee extends Mob { this.potHolder = potHolder.id(); } + public int potPos(){ + return potPos; + } + + public int potHolderID(){ + return potHolder; + } + @Override public int attackSkill( Char target ) { return defenseSkill; @@ -115,16 +123,16 @@ public class Bee extends Mob { @Override protected Char chooseEnemy() { //if the pot is no longer present, default to regular AI behaviour - if (alignment == Alignment.ALLY || (potHolder == -1 && potPos == -1)) + if (alignment == Alignment.ALLY || (potHolder == -1 && potPos == -1)){ return super.chooseEnemy(); - + //if something is holding the pot, target that - else if (Actor.findById(potHolder) != null) - return (Char)Actor.findById(potHolder); - + }else if (Actor.findById(potHolder) != null){ + return (Char) Actor.findById(potHolder); + //if the pot is on the ground - else { - + }else { + //try to find a new enemy in these circumstances if (enemy == null || !enemy.isAlive() || state == WANDERING || Dungeon.level.distance(enemy.pos, potPos) > 3 diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java index 9d3e25a0c..935198d4c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java @@ -96,7 +96,7 @@ public class Thief extends Mob { if (item != null) { Dungeon.level.drop( item, pos ).sprite.drop(); //updates position - if (item instanceof Honeypot.ShatteredPot) ((Honeypot.ShatteredPot)item).setHolder( this ); + if (item instanceof Honeypot.ShatteredPot) ((Honeypot.ShatteredPot)item).dropPot( this, pos ); item = null; } super.rollToDropLoot(); @@ -151,7 +151,7 @@ public class Thief extends Mob { } else { this.item = item.detach( hero.belongings.backpack ); if ( item instanceof Honeypot.ShatteredPot) - ((Honeypot.ShatteredPot)item).setHolder(this); + ((Honeypot.ShatteredPot)item).pickupPot(this); } return true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java index 168f24edc..659320a83 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java @@ -122,7 +122,7 @@ public class Honeypot extends Item { bee.sprite.parent.add( new AlphaTweener( bee.sprite, 1, 0.15f ) ); Sample.INSTANCE.play( Assets.SND_BEE ); - return new ShatteredPot().setBee( bee ); + return new ShatteredPot(); } else { return this; } @@ -148,56 +148,77 @@ public class Honeypot extends Item { { image = ItemSpriteSheet.SHATTPOT; - stackable = false; - } - - private int myBee; - private int beeDepth; - - public Item setBee(Char bee){ - myBee = bee.id(); - beeDepth = Dungeon.depth; - return this; + stackable = true; } @Override public boolean doPickUp(Hero hero) { if ( super.doPickUp(hero) ){ - setHolder( hero ); + pickupPot( hero ); return true; - }else + } else { return false; + } } @Override public void doDrop(Hero hero) { super.doDrop(hero); - updateBee( hero.pos, null ); + dropPot(hero, hero.pos); } @Override protected void onThrow(int cell) { super.onThrow(cell); - updateBee( cell, null ); + dropPot(curUser, cell); } - public void setHolder(Char holder){ - updateBee(holder.pos, holder ); + public void pickupPot(Char holder){ + for (Bee bee : findBees(holder.pos)){ + updateBee(bee, -1, holder); + } + } + + public void dropPot( Char holder, int dropPos ){ + for (Bee bee : findBees(holder)){ + updateBee(bee, dropPos, null); + } } - public void goAway(){ - updateBee( -1, null); - } - - private void updateBee( int cell, Char holder){ - //important, as ids are not unique between depths. - if (Dungeon.depth != beeDepth) - return; - - Bee bee = (Bee)Actor.findById( myBee ); + private void updateBee( Bee bee, int cell, Char holder ){ if (bee != null && bee.alignment == Char.Alignment.ENEMY) bee.setPotInfo( cell, holder ); } + + //returns up to quantity bees which match the current pot Pos + private ArrayList findBees( int potPos ){ + ArrayList bees = new ArrayList<>(); + for (Char c : Actor.chars()){ + if (c instanceof Bee && ((Bee) c).potPos() == potPos){ + bees.add((Bee) c); + if (bees.size() >= quantity) { + break; + } + } + } + + return bees; + } + + //returns up to quantity bees which match the current pot holder + private ArrayList findBees( Char potHolder ){ + ArrayList bees = new ArrayList<>(); + for (Char c : Actor.chars()){ + if (c instanceof Bee && ((Bee) c).potHolderID() == potHolder.id()){ + bees.add((Bee) c); + if (bees.size() >= quantity) { + break; + } + } + } + + return bees; + } @Override public boolean isUpgradable() { @@ -209,21 +230,5 @@ public class Honeypot extends Item { return true; } - private static final String MYBEE = "mybee"; - private static final String BEEDEPTH = "beedepth"; - - @Override - public void storeInBundle(Bundle bundle) { - super.storeInBundle(bundle); - bundle.put( MYBEE, myBee ); - bundle.put( BEEDEPTH, beeDepth ); - } - - @Override - public void restoreFromBundle(Bundle bundle) { - super.restoreFromBundle(bundle); - myBee = bundle.getInt( MYBEE ); - beeDepth = bundle.getInt( BEEDEPTH ); - } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretHoneypotRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretHoneypotRoom.java index 3b09e00c2..71881e1f7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretHoneypotRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretHoneypotRoom.java @@ -52,7 +52,6 @@ public class SecretHoneypotRoom extends SecretRoom { bee.pos = level.pointToCell(brokenPotPos); level.mobs.add( bee ); - pot.setBee(bee); bee.setPotInfo(level.pointToCell(brokenPotPos), null); placeItem(new Honeypot(), level);