Search in sources :

Example 1 with Artifact

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

the class Bones method get.

public static Item get() {
    if (depth == -1) {
        try {
            Bundle bundle = FileUtils.bundleFromFile(BONES_FILE);
            depth = bundle.getInt(LEVEL);
            item = (Item) bundle.get(ITEM);
            return get();
        } catch (IOException e) {
            return null;
        }
    } else {
        // heroes who are challenged cannot find bones
        if (depth == Dungeon.depth && Dungeon.challenges == 0) {
            FileUtils.deleteFile(BONES_FILE);
            depth = 0;
            // Enforces artifact uniqueness
            if (item instanceof Artifact) {
                if (Generator.removeArtifact(((Artifact) item).getClass())) {
                    try {
                        // generates a new artifact of the same type, always +0
                        Artifact artifact = (Artifact) item.getClass().newInstance();
                        artifact.cursed = true;
                        artifact.cursedKnown = true;
                        return artifact;
                    } catch (Exception e) {
                        ShatteredPixelDungeon.reportException(e);
                        return new Gold(item.price());
                    }
                } else {
                    return new Gold(item.price());
                }
            }
            if (item.isUpgradable()) {
                item.cursed = true;
                item.cursedKnown = true;
                if (item.isUpgradable()) {
                    // caps at +3
                    if (item.level() > 3) {
                        item.degrade(item.level() - 3);
                    }
                    item.levelKnown = false;
                }
            }
            item.reset();
            return item;
        } else {
            return null;
        }
    }
}
Also used : Gold(com.shatteredpixel.shatteredpixeldungeon.items.Gold) Bundle(com.watabou.utils.Bundle) IOException(java.io.IOException) Artifact(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact) IOException(java.io.IOException)

Example 2 with Artifact

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

the class RegularLevel method createItems.

@Override
protected void createItems() {
    // drops 3/4/5 items 60%/30%/10% of the time
    int nItems = 3 + Random.chances(new float[] { 6, 3, 1 });
    for (int i = 0; i < nItems; i++) {
        Heap.Type type = null;
        switch(Random.Int(20)) {
            case 0:
                type = Heap.Type.SKELETON;
                break;
            case 1:
            case 2:
            case 3:
            case 4:
                type = Heap.Type.CHEST;
                break;
            case 5:
                type = Dungeon.depth > 1 ? Heap.Type.MIMIC : Heap.Type.CHEST;
                break;
            default:
                type = Heap.Type.HEAP;
        }
        int cell = randomDropCell();
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
        Item toDrop = Generator.random();
        if (toDrop == null)
            continue;
        if ((toDrop instanceof Artifact && Random.Int(2) == 0) || (toDrop.isUpgradable() && Random.Int(4 - toDrop.level()) == 0)) {
            Heap dropped = drop(toDrop, cell);
            if (heaps.get(cell) == dropped) {
                dropped.type = Heap.Type.LOCKED_CHEST;
                addItemToSpawn(new GoldenKey(Dungeon.depth));
            }
        } else {
            drop(toDrop, cell).type = type;
        }
    }
    for (Item item : itemsToSpawn) {
        int cell = randomDropCell();
        drop(item, cell).type = Heap.Type.HEAP;
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
    }
    Item item = Bones.get();
    if (item != null) {
        int cell = randomDropCell();
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
        drop(item, cell).type = Heap.Type.REMAINS;
    }
    // guide pages
    Collection<String> allPages = Document.ADVENTURERS_GUIDE.pages();
    ArrayList<String> missingPages = new ArrayList<>();
    for (String page : allPages) {
        if (!Document.ADVENTURERS_GUIDE.hasPage(page)) {
            missingPages.add(page);
        }
    }
    // these are dropped specially
    missingPages.remove(Document.GUIDE_INTRO_PAGE);
    missingPages.remove(Document.GUIDE_SEARCH_PAGE);
    int foundPages = allPages.size() - (missingPages.size() + 2);
    // chance to find a page scales with pages missing and depth
    if (missingPages.size() > 0 && Random.Float() < (Dungeon.depth / (float) (foundPages + 1))) {
        GuidePage p = new GuidePage();
        p.page(missingPages.get(0));
        int cell = randomDropCell();
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
        drop(p, cell);
    }
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) GoldenKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey) GuidePage(com.shatteredpixel.shatteredpixeldungeon.items.journal.GuidePage) ArrayList(java.util.ArrayList) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap) Artifact(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact)

Example 3 with Artifact

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

the class Generator method randomArtifact.

// enforces uniqueness of artifacts throughout a run.
public static Artifact randomArtifact() {
    try {
        Category cat = Category.ARTIFACT;
        int i = Random.chances(cat.probs);
        // if no artifacts are left, return null
        if (i == -1) {
            return null;
        }
        Class<? extends Artifact> art = (Class<? extends Artifact>) cat.classes[i];
        if (removeArtifact(art)) {
            Artifact artifact = art.newInstance();
            artifact.random();
            return artifact;
        } else {
            return null;
        }
    } catch (Exception e) {
        ShatteredPixelDungeon.reportException(e);
        return null;
    }
}
Also used : Artifact(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact)

Example 4 with Artifact

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

the class WaterOfTransmutation method changeArtifact.

private Artifact changeArtifact(Artifact a) {
    Artifact n = Generator.randomArtifact();
    if (n != null && !Challenges.isItemBlocked(n)) {
        n.cursedKnown = a.cursedKnown;
        n.cursed = a.cursed;
        n.levelKnown = a.levelKnown;
        n.transferUpgrade(a.visiblyUpgraded());
    }
    return n;
}
Also used : Artifact(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact)

Aggregations

Artifact (com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact)4 Gold (com.shatteredpixel.shatteredpixeldungeon.items.Gold)1 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)1 Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)1 GuidePage (com.shatteredpixel.shatteredpixeldungeon.items.journal.GuidePage)1 GoldenKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey)1 Bundle (com.watabou.utils.Bundle)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1