v0.9.3: improved logic for allies moving with you into boss arenas

This commit is contained in:
Evan Debenham 2021-05-09 13:45:20 -04:00
parent 82ce389a48
commit 9412eb81f4
3 changed files with 35 additions and 21 deletions

View File

@ -72,6 +72,7 @@ import com.watabou.utils.Reflection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
public abstract class Mob extends Char { public abstract class Mob extends Char {
@ -1055,6 +1056,10 @@ public abstract class Mob extends Char {
private static ArrayList<Mob> heldAllies = new ArrayList<>(); private static ArrayList<Mob> heldAllies = new ArrayList<>();
public static void holdAllies( Level level ){ public static void holdAllies( Level level ){
holdAllies(level, Dungeon.hero.pos);
}
public static void holdAllies( Level level, int holdFromPos ){
heldAllies.clear(); heldAllies.clear();
for (Mob mob : level.mobs.toArray( new Mob[0] )) { for (Mob mob : level.mobs.toArray( new Mob[0] )) {
//preserve the ghost no matter where they are //preserve the ghost no matter where they are
@ -1066,7 +1071,7 @@ public abstract class Mob extends Char {
//preserve intelligent allies if they are near the hero //preserve intelligent allies if they are near the hero
} else if (mob.alignment == Alignment.ALLY } else if (mob.alignment == Alignment.ALLY
&& mob.intelligentAlly && mob.intelligentAlly
&& Dungeon.level.distance(Dungeon.hero.pos, mob.pos) <= 3){ && Dungeon.level.distance(holdFromPos, mob.pos) <= 5){
level.mobs.remove( mob ); level.mobs.remove( mob );
heldAllies.add(mob); heldAllies.add(mob);
} }
@ -1074,6 +1079,10 @@ public abstract class Mob extends Char {
} }
public static void restoreAllies( Level level, int pos ){ public static void restoreAllies( Level level, int pos ){
restoreAllies(level, pos, -1);
}
public static void restoreAllies( Level level, int pos, int gravitatePos ){
if (!heldAllies.isEmpty()){ if (!heldAllies.isEmpty()){
ArrayList<Integer> candidatePositions = new ArrayList<>(); ArrayList<Integer> candidatePositions = new ArrayList<>();
@ -1082,7 +1091,19 @@ public abstract class Mob extends Char {
candidatePositions.add(i+pos); candidatePositions.add(i+pos);
} }
} }
Collections.shuffle(candidatePositions);
//gravitate pos sets a preferred location for allies to be closer to
if (gravitatePos == -1) {
Collections.shuffle(candidatePositions);
} else {
Collections.sort(candidatePositions, new Comparator<Integer>() {
@Override
public int compare(Integer t1, Integer t2) {
return Dungeon.level.distance(gravitatePos, t1) -
Dungeon.level.distance(gravitatePos, t2);
}
});
}
for (Mob ally : heldAllies) { for (Mob ally : heldAllies) {
level.mobs.add(ally); level.mobs.add(ally);
@ -1093,6 +1114,7 @@ public abstract class Mob extends Char {
} else { } else {
ally.pos = pos; ally.pos = pos;
} }
if (ally.sprite != null) ally.sprite.place(ally.pos);
} }
} }

View File

@ -270,14 +270,10 @@ public class NewCityBossLevel extends Level {
public void seal() { public void seal() {
super.seal(); super.seal();
for (Mob m : mobs){ //moves intelligent allies with the hero, preferring closer pos to entrance door
//bring the first ally with you int doorPos = pointToCell(new Point(arena.left + arena.width()/2, arena.bottom));
if (m.alignment == Char.Alignment.ALLY && !m.properties().contains(Char.Property.IMMOVABLE)){ Mob.holdAllies(this, doorPos);
m.pos = Dungeon.hero.pos + (Random.Int(2) == 0 ? +1 : -1); Mob.restoreAllies(this, Dungeon.hero.pos, doorPos);
m.sprite.place(m.pos);
break;
}
}
DwarfKing boss = new DwarfKing(); DwarfKing boss = new DwarfKing();
boss.state = boss.WANDERING; boss.state = boss.WANDERING;

View File

@ -384,14 +384,10 @@ public class PrisonBossLevel extends Level {
set(pointToCell(tenguCellDoor), Terrain.LOCKED_DOOR); set(pointToCell(tenguCellDoor), Terrain.LOCKED_DOOR);
GameScene.updateMap(pointToCell(tenguCellDoor)); GameScene.updateMap(pointToCell(tenguCellDoor));
for (Mob m : mobs){ //moves intelligent allies with the hero, preferring closer pos to cell door
//bring the first ally with you int doorPos = pointToCell(tenguCellDoor);
if (m.alignment == Char.Alignment.ALLY && !m.properties().contains(Char.Property.IMMOVABLE)){ Mob.holdAllies(this, doorPos);
m.pos = pointToCell(tenguCellDoor); //they should immediately walk out of the door Mob.restoreAllies(this, Dungeon.hero.pos, doorPos);
m.sprite.place(m.pos);
break;
}
}
tengu.state = tengu.HUNTING; tengu.state = tengu.HUNTING;
tengu.pos = tenguPos; tengu.pos = tenguPos;