v0.6.2: Code for well water now supports more than one well at a time

This commit is contained in:
Evan Debenham 2017-09-06 23:28:41 -04:00
parent 4a8373246b
commit 8fb8061ee1
6 changed files with 61 additions and 83 deletions

View File

@ -217,17 +217,21 @@ public class Blob extends Actor {
return null;
}
@SuppressWarnings("unchecked")
public static<T extends Blob> T seed( int cell, int amount, Class<T> type ) {
try {
T gas = (T)Dungeon.level.blobs.get( type );
if (gas == null) {
gas = type.newInstance();
Dungeon.level.blobs.put( type, gas );
return seed(cell, amount, type, Dungeon.level);
}
gas.seed( Dungeon.level, cell, amount );
@SuppressWarnings("unchecked")
public static<T extends Blob> T seed( int cell, int amount, Class<T> type, Level level ) {
try {
T gas = (T)level.blobs.get( type );
if (gas == null) {
gas = type.newInstance();
level.blobs.put( type, gas );
}
gas.seed( level, cell, amount );
return gas;

View File

@ -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 );

View File

@ -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 );

View File

@ -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;
@ -71,25 +71,31 @@ public class WaterOfTransmutation extends WellWater {
item = null;
}
if (item != null) {
Notes.remove( Landmark.WELL_OF_TRANSMUTATION );
//incase a never-seen item pops out
if (item.isIdentified()){
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<?extends Wand> wandClass = staff.wandClass();

View File

@ -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;
}
}
}
@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 );
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;
}
}
}
}
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 );

View File

@ -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 );
}