Merging 1.7.5 Source: actors/ changes

This commit is contained in:
Evan Debenham 2015-01-30 15:32:32 -05:00
parent 894f7d9d06
commit c467cb966c
2 changed files with 87 additions and 32 deletions

View File

@ -20,6 +20,8 @@ package com.shatteredpixel.shatteredpixeldungeon.actors;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import android.util.SparseArray;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
@ -36,6 +38,8 @@ public abstract class Actor implements Bundlable {
private float time; private float time;
private int id = 0;
protected abstract boolean act(); protected abstract boolean act();
protected void spend( float time ) { protected void spend( float time ) {
@ -61,15 +65,32 @@ public abstract class Actor implements Bundlable {
protected void onRemove() {} protected void onRemove() {}
private static final String TIME = "time"; private static final String TIME = "time";
private static final String ID = "id";
@Override @Override
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
bundle.put( TIME, time ); bundle.put( TIME, time );
bundle.put( ID, id );
} }
@Override @Override
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
time = bundle.getFloat( TIME ); time = bundle.getFloat( TIME );
id = bundle.getInt( ID );
}
public int id() {
if (id > 0) {
return id;
} else {
int max = 0;
for (Actor a : all) {
if (a.id > max) {
max = a.id;
}
}
return (id = max + 1);
}
} }
// ********************** // **********************
@ -78,6 +99,8 @@ public abstract class Actor implements Bundlable {
private static HashSet<Actor> all = new HashSet<Actor>(); private static HashSet<Actor> all = new HashSet<Actor>();
private static Actor current; private static Actor current;
private static SparseArray<Actor> ids = new SparseArray<Actor>();
private static float now = 0; private static float now = 0;
private static Char[] chars = new Char[Level.LENGTH]; private static Char[] chars = new Char[Level.LENGTH];
@ -88,6 +111,8 @@ public abstract class Actor implements Bundlable {
Arrays.fill( chars, null ); Arrays.fill( chars, null );
all.clear(); all.clear();
ids.clear();
} }
public static void fixTime() { public static void fixTime() {
@ -203,8 +228,12 @@ public abstract class Actor implements Bundlable {
return; return;
} }
if (actor.id > 0) {
ids.put( actor.id, actor );
}
all.add( actor ); all.add( actor );
actor.time += time; // (+=) => (=) ? actor.time += time;
actor.onAdd(); actor.onAdd();
if (actor instanceof Char) { if (actor instanceof Char) {
@ -222,6 +251,10 @@ public abstract class Actor implements Bundlable {
if (actor != null) { if (actor != null) {
all.remove( actor ); all.remove( actor );
actor.onRemove(); actor.onRemove();
if (actor.id > 0) {
ids.remove( actor.id );
}
} }
} }
@ -229,6 +262,10 @@ public abstract class Actor implements Bundlable {
return chars[pos]; return chars[pos];
} }
public static Actor findById( int id ) {
return ids.get( id );
}
public static HashSet<Actor> all() { public static HashSet<Actor> all() {
return all; return all;
} }

View File

@ -35,11 +35,12 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.Camera;
import com.watabou.utils.Bundlable; import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.GameMath;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
public abstract class Char extends Actor { public abstract class Char extends Actor {
@ -65,7 +66,6 @@ public abstract class Char extends Actor {
protected float baseSpeed = 1; protected float baseSpeed = 1;
public boolean paralysed = false; public boolean paralysed = false;
public boolean pacified = false;
public boolean rooted = false; public boolean rooted = false;
public boolean flying = false; public boolean flying = false;
public int invisible = 0; public int invisible = 0;
@ -127,10 +127,24 @@ public abstract class Char extends Actor {
HeroSubClass.SNIPER ? 0 : Random.IntRange( 0, enemy.dr() ); HeroSubClass.SNIPER ? 0 : Random.IntRange( 0, enemy.dr() );
int dmg = damageRoll(); int dmg = damageRoll();
int effectiveDamage = Math.max( dmg - dr, 0 );; int effectiveDamage = Math.max( dmg - dr, 0 );
effectiveDamage = attackProc( enemy, effectiveDamage ); effectiveDamage = attackProc( enemy, effectiveDamage );
effectiveDamage = enemy.defenseProc( this, effectiveDamage ); effectiveDamage = enemy.defenseProc( this, effectiveDamage );
//game screen shakes for large amounts of damage dealt to/by the player.
//TODO: make sure this isn't distracting
float shake = 0f;
if (enemy == Dungeon.hero) {
shake = Math.max(effectiveDamage / (enemy.HT / 4),
(float) Math.pow(effectiveDamage / (enemy.HP / 2), 2));
} else if (this == Dungeon.hero && effectiveDamage >= enemy.HP) {
shake = (float) Math.pow(effectiveDamage / (enemy.HT / 2), 2);
}
if (shake > 1f)
Camera.main.shake( GameMath.gate( 1, shake, 5), 0.3f );
enemy.damage( effectiveDamage, this ); enemy.damage( effectiveDamage, this );
if (visibleFight) { if (visibleFight) {
@ -150,8 +164,9 @@ public abstract class Char extends Actor {
if (Dungeon.hero.killerGlyph != null) { if (Dungeon.hero.killerGlyph != null) {
Dungeon.fail( Utils.format( ResultDescriptions.GLYPH, Dungeon.hero.killerGlyph.name(), Dungeon.depth ) ); // FIXME
GLog.n( TXT_KILL, Dungeon.hero.killerGlyph.name() ); // Dungeon.fail( Utils.format( ResultDescriptions.GLYPH, Dungeon.hero.killerGlyph.name(), Dungeon.depth ) );
// GLog.n( TXT_KILL, Dungeon.hero.killerGlyph.name() );
} else { } else {
if ( this instanceof Yog ) { if ( this instanceof Yog ) {
@ -183,7 +198,7 @@ public abstract class Char extends Actor {
GLog.i( TXT_SMB_MISSED, enemy.name, defense, name ); GLog.i( TXT_SMB_MISSED, enemy.name, defense, name );
} }
Sample.INSTANCE.play( Assets.SND_MISS ); Sample.INSTANCE.play(Assets.SND_MISS);
} }
return false; return false;
@ -326,6 +341,15 @@ public abstract class Char extends Actor {
return null; return null;
} }
public boolean isCharmedBy( Char ch ) {
int chID = ch.id();
for (Buff b : buffs) {
if (b instanceof Charm && ((Charm)b).object == chID) {
return true;
}
}
return false;
}
public void add( Buff buff ) { public void add( Buff buff ) {
@ -450,16 +474,10 @@ public abstract class Char extends Actor {
public void move( int step ) { public void move( int step ) {
if (buff( Vertigo.class ) != null) { if (Level.adjacent( step, pos ) && buff( Vertigo.class ) != null) {
ArrayList<Integer> candidates = new ArrayList<Integer>(); step = pos + Level.NEIGHBOURS8[Random.Int( 8 )];
for (int dir : Level.NEIGHBOURS8) { if (!(Level.passable[step] || Level.avoid[step]) || Actor.findChar( step ) != null)
int p = pos + dir; return;
if ((Level.passable[p] || Level.avoid[p]) && Actor.findChar( p ) == null) {
candidates.add( p );
}
}
step = Random.element( candidates );
} }
if (Dungeon.level.map[pos] == Terrain.OPEN_DOOR) { if (Dungeon.level.map[pos] == Terrain.OPEN_DOOR) {