v0.7.3b: refactored shattered honeypots, they are now stackable
This commit is contained in:
parent
8b97172557
commit
9dd77eedd3
|
@ -93,6 +93,14 @@ public class Bee extends Mob {
|
||||||
this.potHolder = potHolder.id();
|
this.potHolder = potHolder.id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int potPos(){
|
||||||
|
return potPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int potHolderID(){
|
||||||
|
return potHolder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int attackSkill( Char target ) {
|
public int attackSkill( Char target ) {
|
||||||
return defenseSkill;
|
return defenseSkill;
|
||||||
|
@ -115,15 +123,15 @@ public class Bee extends Mob {
|
||||||
@Override
|
@Override
|
||||||
protected Char chooseEnemy() {
|
protected Char chooseEnemy() {
|
||||||
//if the pot is no longer present, default to regular AI behaviour
|
//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();
|
return super.chooseEnemy();
|
||||||
|
|
||||||
//if something is holding the pot, target that
|
//if something is holding the pot, target that
|
||||||
else if (Actor.findById(potHolder) != null)
|
}else if (Actor.findById(potHolder) != null){
|
||||||
return (Char) Actor.findById(potHolder);
|
return (Char) Actor.findById(potHolder);
|
||||||
|
|
||||||
//if the pot is on the ground
|
//if the pot is on the ground
|
||||||
else {
|
}else {
|
||||||
|
|
||||||
//try to find a new enemy in these circumstances
|
//try to find a new enemy in these circumstances
|
||||||
if (enemy == null || !enemy.isAlive() || state == WANDERING
|
if (enemy == null || !enemy.isAlive() || state == WANDERING
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class Thief extends Mob {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
Dungeon.level.drop( item, pos ).sprite.drop();
|
Dungeon.level.drop( item, pos ).sprite.drop();
|
||||||
//updates position
|
//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;
|
item = null;
|
||||||
}
|
}
|
||||||
super.rollToDropLoot();
|
super.rollToDropLoot();
|
||||||
|
@ -151,7 +151,7 @@ public class Thief extends Mob {
|
||||||
} else {
|
} else {
|
||||||
this.item = item.detach( hero.belongings.backpack );
|
this.item = item.detach( hero.belongings.backpack );
|
||||||
if ( item instanceof Honeypot.ShatteredPot)
|
if ( item instanceof Honeypot.ShatteredPot)
|
||||||
((Honeypot.ShatteredPot)item).setHolder(this);
|
((Honeypot.ShatteredPot)item).pickupPot(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class Honeypot extends Item {
|
||||||
bee.sprite.parent.add( new AlphaTweener( bee.sprite, 1, 0.15f ) );
|
bee.sprite.parent.add( new AlphaTweener( bee.sprite, 1, 0.15f ) );
|
||||||
|
|
||||||
Sample.INSTANCE.play( Assets.SND_BEE );
|
Sample.INSTANCE.play( Assets.SND_BEE );
|
||||||
return new ShatteredPot().setBee( bee );
|
return new ShatteredPot();
|
||||||
} else {
|
} else {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -148,57 +148,78 @@ public class Honeypot extends Item {
|
||||||
|
|
||||||
{
|
{
|
||||||
image = ItemSpriteSheet.SHATTPOT;
|
image = ItemSpriteSheet.SHATTPOT;
|
||||||
stackable = false;
|
stackable = true;
|
||||||
}
|
|
||||||
|
|
||||||
private int myBee;
|
|
||||||
private int beeDepth;
|
|
||||||
|
|
||||||
public Item setBee(Char bee){
|
|
||||||
myBee = bee.id();
|
|
||||||
beeDepth = Dungeon.depth;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doPickUp(Hero hero) {
|
public boolean doPickUp(Hero hero) {
|
||||||
if ( super.doPickUp(hero) ){
|
if ( super.doPickUp(hero) ){
|
||||||
setHolder( hero );
|
pickupPot( hero );
|
||||||
return true;
|
return true;
|
||||||
}else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doDrop(Hero hero) {
|
public void doDrop(Hero hero) {
|
||||||
super.doDrop(hero);
|
super.doDrop(hero);
|
||||||
updateBee( hero.pos, null );
|
dropPot(hero, hero.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onThrow(int cell) {
|
protected void onThrow(int cell) {
|
||||||
super.onThrow(cell);
|
super.onThrow(cell);
|
||||||
updateBee( cell, null );
|
dropPot(curUser, cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHolder(Char holder){
|
public void pickupPot(Char holder){
|
||||||
updateBee(holder.pos, holder );
|
for (Bee bee : findBees(holder.pos)){
|
||||||
|
updateBee(bee, -1, holder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goAway(){
|
public void dropPot( Char holder, int dropPos ){
|
||||||
updateBee( -1, null);
|
for (Bee bee : findBees(holder)){
|
||||||
|
updateBee(bee, dropPos, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBee( int cell, Char holder){
|
private void updateBee( Bee bee, int cell, Char holder ){
|
||||||
//important, as ids are not unique between depths.
|
|
||||||
if (Dungeon.depth != beeDepth)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Bee bee = (Bee)Actor.findById( myBee );
|
|
||||||
if (bee != null && bee.alignment == Char.Alignment.ENEMY)
|
if (bee != null && bee.alignment == Char.Alignment.ENEMY)
|
||||||
bee.setPotInfo( cell, holder );
|
bee.setPotInfo( cell, holder );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//returns up to quantity bees which match the current pot Pos
|
||||||
|
private ArrayList<Bee> findBees( int potPos ){
|
||||||
|
ArrayList<Bee> 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<Bee> findBees( Char potHolder ){
|
||||||
|
ArrayList<Bee> 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
|
@Override
|
||||||
public boolean isUpgradable() {
|
public boolean isUpgradable() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -209,21 +230,5 @@ public class Honeypot extends Item {
|
||||||
return true;
|
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ public class SecretHoneypotRoom extends SecretRoom {
|
||||||
bee.pos = level.pointToCell(brokenPotPos);
|
bee.pos = level.pointToCell(brokenPotPos);
|
||||||
level.mobs.add( bee );
|
level.mobs.add( bee );
|
||||||
|
|
||||||
pot.setBee(bee);
|
|
||||||
bee.setPotInfo(level.pointToCell(brokenPotPos), null);
|
bee.setPotInfo(level.pointToCell(brokenPotPos), null);
|
||||||
|
|
||||||
placeItem(new Honeypot(), level);
|
placeItem(new Honeypot(), level);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user