use of com.shatteredpixel.shatteredpixeldungeon.actors.Char in project shattered-pixel-dungeon-gdx by 00-Evan.
the class Mimic method spawnAt.
public static Mimic spawnAt(int pos, List<Item> items) {
if (Dungeon.level.pit[pos])
return null;
Char ch = Actor.findChar(pos);
if (ch != null) {
ArrayList<Integer> candidates = new ArrayList<>();
for (int n : PathFinder.NEIGHBOURS8) {
int cell = pos + n;
if ((Dungeon.level.passable[cell] || Dungeon.level.avoid[cell]) && Actor.findChar(cell) == null) {
candidates.add(cell);
}
}
if (candidates.size() > 0) {
int newPos = Random.element(candidates);
Actor.addDelayed(new Pushing(ch, ch.pos, newPos), -1);
ch.pos = newPos;
Dungeon.level.press(newPos, ch);
} else {
return null;
}
}
Mimic m = new Mimic();
m.items = new ArrayList<>(items);
m.adjustStats(Dungeon.depth);
m.pos = pos;
m.state = m.HUNTING;
GameScene.add(m, 1);
m.sprite.turnTo(pos, Dungeon.hero.pos);
if (Dungeon.level.heroFOV[m.pos]) {
CellEmitter.get(pos).burst(Speck.factory(Speck.STAR), 10);
Sample.INSTANCE.play(Assets.SND_MIMIC);
}
// generate an extra reward for killing the mimic
Item reward = null;
do {
switch(Random.Int(5)) {
case 0:
reward = new Gold().random();
break;
case 1:
reward = Generator.randomMissile();
break;
case 2:
reward = Generator.randomArmor();
break;
case 3:
reward = Generator.randomWeapon();
break;
case 4:
reward = Generator.random(Generator.Category.RING);
break;
}
} while (reward == null || Challenges.isItemBlocked(reward));
m.items.add(reward);
return m;
}
use of com.shatteredpixel.shatteredpixeldungeon.actors.Char in project shattered-pixel-dungeon-gdx by 00-Evan.
the class Skeleton method die.
@Override
public void die(Object cause) {
super.die(cause);
if (cause == Chasm.class)
return;
boolean heroKilled = false;
for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) {
Char ch = findChar(pos + PathFinder.NEIGHBOURS8[i]);
if (ch != null && ch.isAlive()) {
int damage = Math.max(0, damageRoll() - (ch.drRoll() / 2));
ch.damage(damage, this);
if (ch == Dungeon.hero && !ch.isAlive()) {
heroKilled = true;
}
}
}
if (Dungeon.level.heroFOV[pos]) {
Sample.INSTANCE.play(Assets.SND_BONES);
}
if (heroKilled) {
Dungeon.fail(getClass());
GLog.n(Messages.get(this, "explo_kill"));
}
}
use of com.shatteredpixel.shatteredpixeldungeon.actors.Char in project shattered-pixel-dungeon-gdx by 00-Evan.
the class LloydsBeacon method execute.
@Override
public void execute(Hero hero, String action) {
super.execute(hero, action);
if (action == AC_SET || action == AC_RETURN) {
if (Dungeon.bossLevel()) {
hero.spend(LloydsBeacon.TIME_TO_USE);
GLog.w(Messages.get(this, "preventing"));
return;
}
for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) {
Char ch = Actor.findChar(hero.pos + PathFinder.NEIGHBOURS8[i]);
if (ch != null && ch.alignment == Char.Alignment.ENEMY) {
GLog.w(Messages.get(this, "creatures"));
return;
}
}
}
if (action == AC_ZAP) {
curUser = hero;
int chargesToUse = Dungeon.depth > 20 ? 2 : 1;
if (!isEquipped(hero)) {
GLog.i(Messages.get(Artifact.class, "need_to_equip"));
QuickSlotButton.cancel();
} else if (charge < chargesToUse) {
GLog.i(Messages.get(this, "no_charge"));
QuickSlotButton.cancel();
} else {
GameScene.selectCell(zapper);
}
} else if (action == AC_SET) {
returnDepth = Dungeon.depth;
returnPos = hero.pos;
hero.spend(LloydsBeacon.TIME_TO_USE);
hero.busy();
hero.sprite.operate(hero.pos);
Sample.INSTANCE.play(Assets.SND_BEACON);
GLog.i(Messages.get(this, "return"));
} else if (action == AC_RETURN) {
if (returnDepth == Dungeon.depth) {
ScrollOfTeleportation.appear(hero, returnPos);
Dungeon.level.press(returnPos, hero);
Dungeon.observe();
GameScene.updateFog();
} else {
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null)
buff.detach();
InterlevelScene.mode = InterlevelScene.Mode.RETURN;
InterlevelScene.returnDepth = returnDepth;
InterlevelScene.returnPos = returnPos;
Game.switchScene(InterlevelScene.class);
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.actors.Char in project shattered-pixel-dungeon-gdx by 00-Evan.
the class CellSelector method onClick.
@Override
protected void onClick(NoosaInputProcessor.Touch touch) {
if (dragging) {
dragging = false;
} else {
PointF p = Camera.main.screenToCamera((int) touch.current.x, (int) touch.current.y);
for (Char mob : Dungeon.level.mobs.toArray(new Mob[0])) {
if (mob.sprite != null && mob.sprite.overlapsPoint(p.x, p.y)) {
select(mob.pos);
return;
}
}
for (Heap heap : Dungeon.level.heaps.values()) {
if (heap.sprite != null && heap.sprite.overlapsPoint(p.x, p.y)) {
select(heap.pos);
return;
}
}
select(((DungeonTilemap) target).screenToTile((int) touch.current.x, (int) touch.current.y, true));
}
}
use of com.shatteredpixel.shatteredpixeldungeon.actors.Char in project shattered-pixel-dungeon-gdx by 00-Evan.
the class PitfallTrap method activate.
@Override
public void activate() {
Heap heap = Dungeon.level.heaps.get(pos);
if (heap != null) {
for (Item item : heap.items) {
Dungeon.dropToChasm(item);
}
heap.sprite.kill();
GameScene.discard(heap);
Dungeon.level.heaps.remove(pos);
}
Char ch = Actor.findChar(pos);
if (ch == Dungeon.hero) {
Chasm.heroFall(pos);
} else if (ch != null) {
Chasm.mobFall((Mob) ch);
}
}
Aggregations