From 8fb8061ee13575869a5a7e67554700e3479c316c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 6 Sep 2017 23:28:41 -0400 Subject: [PATCH] v0.6.2: Code for well water now supports more than one well at a time --- .../actors/blobs/Blob.java | 12 ++- .../actors/blobs/WaterOfAwareness.java | 10 +-- .../actors/blobs/WaterOfHealth.java | 9 ++- .../actors/blobs/WaterOfTransmutation.java | 24 +++--- .../actors/blobs/WellWater.java | 76 +++++++------------ .../levels/rooms/special/MagicWellRoom.java | 13 +--- 6 files changed, 61 insertions(+), 83 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java index 7acccef2e..b35c005ae 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java @@ -217,17 +217,21 @@ public class Blob extends Actor { return null; } - @SuppressWarnings("unchecked") public static T seed( int cell, int amount, Class type ) { + return seed(cell, amount, type, Dungeon.level); + } + + @SuppressWarnings("unchecked") + public static T seed( int cell, int amount, Class type, Level level ) { try { - T gas = (T)Dungeon.level.blobs.get( type ); + T gas = (T)level.blobs.get( type ); if (gas == null) { gas = type.newInstance(); - Dungeon.level.blobs.put( type, gas ); + level.blobs.put( type, gas ); } - gas.seed( Dungeon.level, cell, amount ); + gas.seed( level, cell, amount ); return gas; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java index 7e3bbadd7..15a83c2ea 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java @@ -31,7 +31,6 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Identification; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes.Landmark; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -70,8 +69,6 @@ public class WaterOfAwareness extends WellWater { GLog.p( Messages.get(this, "procced") ); - Notes.remove( Landmark.WELL_OF_AWARENESS ); - return true; } @@ -85,12 +82,15 @@ public class WaterOfAwareness extends WellWater { emitter.parent.add( new Identification( DungeonTilemap.tileCenterToWorld( pos ) ) ); - Notes.remove( Landmark.WELL_OF_AWARENESS ); - return item; } } + @Override + protected Landmark record() { + return Landmark.WELL_OF_AWARENESS; + } + @Override public void use( BlobEmitter emitter ) { super.use( emitter ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfHealth.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfHealth.java index bace7dec9..a192489de 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfHealth.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfHealth.java @@ -32,7 +32,6 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShaftParticle; import com.shatteredpixel.shatteredpixeldungeon.items.DewVial; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfHealing; -import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes.Landmark; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; @@ -58,8 +57,6 @@ public class WaterOfHealth extends WellWater { GLog.p( Messages.get(this, "procced") ); - Notes.remove( Landmark.WELL_OF_HEALTH ); - return true; } @@ -67,13 +64,17 @@ public class WaterOfHealth extends WellWater { protected Item affectItem( Item item ) { if (item instanceof DewVial && !((DewVial)item).isFull()) { ((DewVial)item).fill(); - Notes.remove( Landmark.WELL_OF_HEALTH ); return item; } return null; } + @Override + protected Landmark record() { + return Landmark.WELL_OF_HEALTH; + } + @Override public void use( BlobEmitter emitter ) { super.use( emitter ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfTransmutation.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfTransmutation.java index 3db644fe7..9e8e02efa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfTransmutation.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfTransmutation.java @@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Generator; @@ -40,7 +41,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon; import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog; -import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes.Landmark; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; @@ -70,25 +70,31 @@ public class WaterOfTransmutation extends WellWater { } else { item = null; } - - if (item != null) { - Notes.remove( Landmark.WELL_OF_TRANSMUTATION ); - - //incase a never-seen item pops out - if (item.isIdentified()){ - Catalog.setSeen(item.getClass()); - } + + //incase a never-seen item pops out + if (item != null&& item.isIdentified()){ + Catalog.setSeen(item.getClass()); } return item; } + @Override + protected boolean affectHero(Hero hero) { + return false; + } + @Override public void use( BlobEmitter emitter ) { super.use( emitter ); emitter.start( Speck.factory( Speck.CHANGE ), 0.2f, 0 ); } + + @Override + protected Landmark record() { + return Landmark.WELL_OF_TRANSMUTATION; + } private MagesStaff changeStaff( MagesStaff staff ){ Class wandClass = staff.wandClass(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java index 193836b5b..fa629b28a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java @@ -26,54 +26,46 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; -import com.shatteredpixel.shatteredpixeldungeon.journal.Notes.Landmark; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; -import com.watabou.utils.Bundle; import com.watabou.utils.PathFinder; import com.watabou.utils.Random; -public class WellWater extends Blob { +public abstract class WellWater extends Blob { protected int pos; @Override - public void restoreFromBundle( Bundle bundle ) { - super.restoreFromBundle( bundle ); - - if (volume > 0) - for (int i=0; i < cur.length; i++) { - if (cur[i] > 0) { - pos = i; - break; + protected void evolve() { + int cell; + boolean seen = false; + for (int i=area.top-1; i <= area.bottom; i++) { + for (int j = area.left-1; j <= area.right; j++) { + cell = j + i* Dungeon.level.width(); + if (Dungeon.level.insideMap(cell)) { + off[cell] = cur[cell]; + volume += off[cell]; + if (off[cell] > 0 && Dungeon.level.visited[cell]) { + seen = true; + } } } - } - - @Override - protected void evolve() { - volume = off[pos] = cur[pos]; - area.union(pos%Dungeon.level.width(), pos/Dungeon.level.width()); - - if (Dungeon.visible[pos]) { - if (this instanceof WaterOfAwareness) { - Notes.add( Landmark.WELL_OF_AWARENESS ); - } else if (this instanceof WaterOfHealth) { - Notes.add( Notes.Landmark.WELL_OF_HEALTH ); - } else if (this instanceof WaterOfTransmutation) { - Notes.add( Landmark.WELL_OF_TRANSMUTATION ); - } + } + if (seen){ + Notes.add(record()); + } else { + Notes.remove(record()); } } - protected boolean affect() { - + protected boolean affect( int pos ) { + Heap heap; if (pos == Dungeon.hero.pos && affectHero( Dungeon.hero )) { - volume = off[pos] = cur[pos] = 0; + cur[pos] = 0; return true; } else if ((heap = Dungeon.level.heaps.get( pos )) != null) { @@ -95,7 +87,7 @@ public class WellWater extends Blob { } heap.sprite.link(); - volume = off[pos] = cur[pos] = 0; + cur[pos] = 0; return true; @@ -118,25 +110,11 @@ public class WellWater extends Blob { } } - protected boolean affectHero( Hero hero ) { - return false; - } + protected abstract boolean affectHero( Hero hero ); - protected Item affectItem( Item item ) { - return null; - } + protected abstract Item affectItem( Item item ); - @Override - public void seed( Level level, int cell, int amount ) { - super.seed(level, cell, amount); - - cur[pos] = 0; - pos = cell; - volume = cur[pos] = amount; - - area.setEmpty(); - area.union(cell%level.width(), cell/level.width()); - } + protected abstract Notes.Landmark record(); public static void affectCell( int cell ) { @@ -146,8 +124,8 @@ public class WellWater extends Blob { WellWater water = (WellWater)Dungeon.level.blobs.get( waterClass ); if (water != null && water.volume > 0 && - water.pos == cell && - water.affect()) { + water.cur[cell] > 0 && + water.affect( cell )) { Level.set( cell, Terrain.EMPTY_WELL ); GameScene.updateMap( cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/MagicWellRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/MagicWellRoom.java index 7d761b37e..07cdc96a6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/MagicWellRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/MagicWellRoom.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.WaterOfAwareness; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.WaterOfHealth; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.WaterOfTransmutation; @@ -57,17 +56,7 @@ public class MagicWellRoom extends SpecialRoom { SpecialRoom.disableGuaranteedWell(); } - WellWater water = (WellWater)level.blobs.get( waterClass ); - if (water == null) { - try { - water = waterClass.newInstance(); - } catch (Exception e) { - ShatteredPixelDungeon.reportException(e); - return; - } - } - water.seed( level, c.x + level.width() * c.y, 1 ); - level.blobs.put( waterClass, water ); + WellWater.seed(c.x + level.width() * c.y, 1, waterClass, level); entrance().set( Door.Type.REGULAR ); }