Search in sources :

Example 1 with Bag

use of com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag in project shattered-pixel-dungeon-gdx by 00-Evan.

the class DisintegrationTrap method activate.

@Override
public void activate() {
    Char target = Actor.findChar(pos);
    // find the closest char that can be aimed at
    if (target == null) {
        for (Char ch : Actor.chars()) {
            Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
            if (bolt.collisionPos == ch.pos && (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))) {
                target = ch;
            }
        }
    }
    Heap heap = Dungeon.level.heaps.get(pos);
    if (heap != null)
        heap.explode();
    if (target != null) {
        if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[target.pos]) {
            Sample.INSTANCE.play(Assets.SND_RAY);
            ShatteredPixelDungeon.scene().add(new Beam.DeathRay(DungeonTilemap.tileCenterToWorld(pos), target.sprite.center()));
        }
        target.damage(Math.max(target.HT / 5, Random.Int(target.HP / 2, 2 * target.HP / 3)), this);
        if (target == Dungeon.hero) {
            Hero hero = (Hero) target;
            if (!hero.isAlive()) {
                Dungeon.fail(getClass());
                GLog.n(Messages.get(this, "ondeath"));
            } else {
                Item item = hero.belongings.randomUnequipped();
                Bag bag = hero.belongings.backpack;
                // bags do not protect against this trap
                if (item instanceof Bag) {
                    bag = (Bag) item;
                    item = Random.element(bag.items);
                }
                if (item == null || item.level() > 0 || item.unique)
                    return;
                if (!item.stackable) {
                    item.detachAll(bag);
                    GLog.w(Messages.get(this, "one", item.name()));
                } else {
                    int n = Random.NormalIntRange(1, (item.quantity() + 1) / 2);
                    for (int i = 1; i <= n; i++) item.detach(bag);
                    GLog.w(Messages.get(this, "some", item.name()));
                }
            }
        }
    }
}
Also used : Beam(com.shatteredpixel.shatteredpixeldungeon.effects.Beam) Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Ballistica(com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica) Hero(com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero) Bag(com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap)

Example 2 with Bag

use of com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag in project shattered-pixel-dungeon-gdx by 00-Evan.

the class ScrollOfRemoveCurse method uncurse.

public static boolean uncurse(Hero hero, Item... items) {
    boolean procced = false;
    for (Item item : items) {
        if (item != null && item.cursed) {
            item.cursed = false;
            procced = true;
        }
        if (item instanceof Weapon) {
            Weapon w = (Weapon) item;
            if (w.hasCurseEnchant()) {
                w.enchant(null);
                w.cursed = false;
                procced = true;
            }
        }
        if (item instanceof Armor) {
            Armor a = (Armor) item;
            if (a.hasCurseGlyph()) {
                a.inscribe(null);
                a.cursed = false;
                procced = true;
            }
        }
        if (item instanceof Bag) {
            for (Item bagItem : ((Bag) item).items) {
                if (bagItem != null && bagItem.cursed) {
                    bagItem.cursed = false;
                    procced = true;
                }
            }
        }
    }
    if (procced) {
        hero.sprite.emitter().start(ShadowParticle.UP, 0.05f, 10);
        // for ring of might
        hero.updateHT(false);
    }
    return procced;
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) Armor(com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor) WndBag(com.shatteredpixel.shatteredpixeldungeon.windows.WndBag) Bag(com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag) Weapon(com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon)

Example 3 with Bag

use of com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Belongings method resurrect.

public void resurrect(int depth) {
    for (Item item : backpack.items.toArray(new Item[0])) {
        if (item instanceof Key) {
            if (((Key) item).depth == depth) {
                item.detachAll(backpack);
            }
        } else if (item.unique) {
            item.detachAll(backpack);
            // you keep the bag itself, not its contents.
            if (item instanceof Bag) {
                ((Bag) item).clear();
            }
            item.collect();
        } else if (!item.isEquipped(owner)) {
            item.detachAll(backpack);
        }
    }
    if (weapon != null) {
        weapon.cursed = false;
        weapon.activate(owner);
    }
    if (armor != null) {
        armor.cursed = false;
        armor.activate(owner);
    }
    if (misc1 != null) {
        misc1.cursed = false;
        misc1.activate(owner);
    }
    if (misc2 != null) {
        misc2.cursed = false;
        misc2.activate(owner);
    }
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) Bag(com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag) IronKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey) SkeletonKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey) GoldenKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey) Key(com.shatteredpixel.shatteredpixeldungeon.items.keys.Key)

Aggregations

Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)3 Bag (com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag)3 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)1 Hero (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero)1 Beam (com.shatteredpixel.shatteredpixeldungeon.effects.Beam)1 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)1 Armor (com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor)1 GoldenKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey)1 IronKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey)1 Key (com.shatteredpixel.shatteredpixeldungeon.items.keys.Key)1 SkeletonKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey)1 Weapon (com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon)1 Ballistica (com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)1 WndBag (com.shatteredpixel.shatteredpixeldungeon.windows.WndBag)1