v0.7.5: fixed an animation cancel bug that let players open containers/doors remotely and without keys

This commit is contained in:
Evan Debenham 2019-09-12 19:31:36 -04:00
parent f0a44e8578
commit 388e16b53c
2 changed files with 48 additions and 30 deletions

View File

@ -1546,32 +1546,45 @@ public class Hero extends Char {
int doorCell = ((HeroAction.Unlock)curAction).dst;
int door = Dungeon.level.map[doorCell];
if (door == Terrain.LOCKED_DOOR){
Notes.remove(new IronKey(Dungeon.depth));
Level.set( doorCell, Terrain.DOOR );
} else {
Notes.remove(new SkeletonKey(Dungeon.depth));
Level.set( doorCell, Terrain.UNLOCKED_EXIT );
}
GameScene.updateKeyDisplay();
if (Dungeon.level.adjacent(pos, doorCell)) {
boolean hasKey = true;
if (door == Terrain.LOCKED_DOOR) {
hasKey = Notes.remove(new IronKey(Dungeon.depth));
if (hasKey) Level.set(doorCell, Terrain.DOOR);
} else {
hasKey = Notes.remove(new SkeletonKey(Dungeon.depth));
if (hasKey) Level.set(doorCell, Terrain.UNLOCKED_EXIT);
}
Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT );
GameScene.updateMap( doorCell );
spend( Key.TIME_TO_UNLOCK );
if (hasKey) {
GameScene.updateKeyDisplay();
Level.set(doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT);
GameScene.updateMap(doorCell);
spend(Key.TIME_TO_UNLOCK);
}
}
} else if (curAction instanceof HeroAction.OpenChest) {
Heap heap = Dungeon.level.heaps.get( ((HeroAction.OpenChest)curAction).dst );
if (heap.type == Type.SKELETON || heap.type == Type.REMAINS) {
Sample.INSTANCE.play( Assets.SND_BONES );
} else if (heap.type == Type.LOCKED_CHEST){
Notes.remove(new GoldenKey(Dungeon.depth));
} else if (heap.type == Type.CRYSTAL_CHEST){
Notes.remove(new CrystalKey(Dungeon.depth));
if (Dungeon.level.adjacent(pos, heap.pos)){
boolean hasKey = true;
if (heap.type == Type.SKELETON || heap.type == Type.REMAINS) {
Sample.INSTANCE.play( Assets.SND_BONES );
} else if (heap.type == Type.LOCKED_CHEST){
hasKey = Notes.remove(new GoldenKey(Dungeon.depth));
} else if (heap.type == Type.CRYSTAL_CHEST){
hasKey = Notes.remove(new CrystalKey(Dungeon.depth));
}
if (hasKey) {
GameScene.updateKeyDisplay();
heap.open(this);
spend(Key.TIME_TO_UNLOCK);
}
}
GameScene.updateKeyDisplay();
heap.open( this );
spend( Key.TIME_TO_UNLOCK );
}
curAction = null;

View File

@ -191,38 +191,43 @@ public class Notes {
}
}
public static void add( Landmark landmark ) {
public static boolean add( Landmark landmark ) {
LandmarkRecord l = new LandmarkRecord( landmark, Dungeon.depth );
if (!records.contains(l)) {
records.add(new LandmarkRecord(landmark, Dungeon.depth));
boolean result = records.add(new LandmarkRecord(landmark, Dungeon.depth));
Collections.sort(records);
return result;
}
return false;
}
public static void remove( Landmark landmark ) {
records.remove( new LandmarkRecord(landmark, Dungeon.depth) );
public static boolean remove( Landmark landmark ) {
return records.remove( new LandmarkRecord(landmark, Dungeon.depth) );
}
public static void add( Key key ){
public static boolean add( Key key ){
KeyRecord k = new KeyRecord(key);
if (!records.contains(k)){
records.add(k);
boolean result = records.add(k);
Collections.sort(records);
return result;
} else {
k = (KeyRecord) records.get(records.indexOf(k));
k.quantity(k.quantity() + key.quantity());
return true;
}
}
public static void remove( Key key ){
public static boolean remove( Key key ){
KeyRecord k = new KeyRecord( key );
if (records.contains(k)){
k = (KeyRecord) records.get(records.indexOf(k));
k.quantity(k.quantity() - key.quantity());
if (k.quantity() <= 0){
records.remove(k);
return records.remove(k);
}
}
return false;
}
public static int keyCount( Key key ){