Search in sources :

Example 1 with XORShiftRandom

use of util.XORShiftRandom in project ultimate-java by pantinor.

the class TestJaxb method testNibbles.

// @Test
public void testNibbles() throws Exception {
    byte[] data = new byte[4];
    data[1] = (byte) 0x85;
    int x = (data[1] >> 4) & 0x0f;
    int y = data[1] & 0x0f;
    int z = x;
    Random rand = new XORShiftRandom();
    for (int j = 0; j < 10; j++) {
        int v = 99 + (rand.nextInt(256) & 119);
        int f = v;
    }
}
Also used : Random(java.util.Random) XORShiftRandom(util.XORShiftRandom) XORShiftRandom(util.XORShiftRandom)

Example 2 with XORShiftRandom

use of util.XORShiftRandom in project ultimate-java by pantinor.

the class CombatScreen method holeUp.

public static void holeUp(Maps contextMap, final int x, final int y, final BaseScreen rs, final Context context, CreatureSet cs, final TextureAtlas sa, boolean inn) {
    Ultima4.hud.add("Hole up & Camp!");
    if (!inn && context.getCurrentMap().getCity() != null) {
        Ultima4.hud.add("Only outside or in the dungeon!");
        return;
    }
    if (context.getTransportContext() != TransportContext.FOOT) {
        Ultima4.hud.add("Only on foot!");
        return;
    }
    // make sure everyone's asleep
    for (int i = 0; i < context.getParty().getMembers().size(); i++) {
        context.getParty().getMember(i).putToSleep();
    }
    Ultima4.hud.add("Resting");
    final Maps campMap;
    TiledMap tmap;
    if (contextMap == Maps.WORLD) {
        campMap = Maps.CAMP_CON;
    } else if (inn) {
        campMap = Maps.INN_CON;
    } else {
        campMap = Maps.CAMP_DNG;
    }
    tmap = new UltimaTiledMapLoader(campMap, sa, campMap.getMap().getWidth(), campMap.getMap().getHeight(), tilePixelWidth, tilePixelHeight).load();
    context.setCurrentTiledMap(tmap);
    final CombatScreen sc = new CombatScreen(rs, context, contextMap, campMap.getMap(), tmap, null, cs, sa);
    mainGame.setScreen(sc);
    final int CAMP_HEAL_INTERVAL = 5;
    Random rand = new XORShiftRandom();
    SequenceAction seq = Actions.action(SequenceAction.class);
    for (int i = 0; i < CAMP_HEAL_INTERVAL; i++) {
        seq.addAction(Actions.delay(1f));
        seq.addAction(Actions.run(new Runnable() {

            public void run() {
                Ultima4.hud.append(" .");
            }
        }));
    }
    if (!inn && rand.nextInt(8) == 0) {
        seq.addAction(Actions.run(new Runnable() {

            public void run() {
                Ultima4.hud.add("Ambushed!");
                sc.setAmbushingMonsters(rs, x, y, sa);
            }
        }));
    } else {
        seq.addAction(Actions.run(new Runnable() {

            @Override
            public void run() {
                for (int i = 0; i < context.getParty().getMembers().size(); i++) {
                    context.getParty().getMember(i).wakeUp();
                }
                /* Make sure we've waited long enough for camping to be effective */
                boolean healed = false;
                if (((context.getParty().getSaveGame().moves / CAMP_HEAL_INTERVAL) >= 0x10000) || (((context.getParty().getSaveGame().moves / CAMP_HEAL_INTERVAL) & 0xffff) != context.getParty().getSaveGame().lastcamp)) {
                    for (int i = 0; i < context.getParty().getMembers().size(); i++) {
                        PartyMember m = context.getParty().getMember(i);
                        m.getPlayer().mp = m.getPlayer().getMaxMp();
                        if ((m.getPlayer().hp < m.getPlayer().hpMax) && m.heal(HealType.CAMPHEAL)) {
                            healed = true;
                        }
                    }
                }
                Ultima4.hud.add(healed ? "Party Healed!" : "No effect.");
                context.getParty().getSaveGame().lastcamp = (context.getParty().getSaveGame().moves / 5) & 0xffff;
                sc.end();
            }
        }));
        if (inn && contextMap == Maps.SKARABRAE && rand.nextInt(3) == 0) {
            // show isaac
            for (Person p : context.getCurrentMap().getCity().getPeople()) {
                if (p.getId() == 10) {
                    p.setRemovedFromMap(false);
                    p.setStart_x(27);
                    p.setX(27);
                    p.setStart_y(12);
                    p.setY(12);
                    p.setMovement(ObjectMovementBehavior.WANDER);
                }
            }
        }
    }
    sc.getStage().addAction(seq);
}
Also used : Random(java.util.Random) XORShiftRandom(util.XORShiftRandom) PartyMember(objects.Party.PartyMember) UltimaTiledMapLoader(util.UltimaTiledMapLoader) XORShiftRandom(util.XORShiftRandom) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Person(objects.Person) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)

Example 3 with XORShiftRandom

use of util.XORShiftRandom in project ultimate-java by pantinor.

the class StartScreen method initQuestionTree.

/**
 * Initializes the question tree. The tree starts off with the first eight
 * entries set to the numbers 0-7 in a random order.
 */
public static void initQuestionTree() {
    for (int i = 0; i < 8; i++) {
        questionTree[i] = i;
    }
    // shuffle the first 8 virtue slots, the last 8 slots are for the answers
    Random rand = new XORShiftRandom();
    for (int i = 0; i < 8; i++) {
        int r = rand.nextInt(8);
        int tmp = questionTree[r];
        questionTree[r] = questionTree[i];
        questionTree[i] = tmp;
    }
    answerInd = 8;
    if (questionTree[0] > questionTree[1]) {
        int tmp = questionTree[0];
        questionTree[0] = questionTree[1];
        questionTree[1] = tmp;
    }
}
Also used : Random(java.util.Random) XORShiftRandom(util.XORShiftRandom) XORShiftRandom(util.XORShiftRandom)

Example 4 with XORShiftRandom

use of util.XORShiftRandom in project ultimate-java by pantinor.

the class BaseMap method searchLocation.

public ItemMapLabels searchLocation(BaseScreen screen, Party p, int x, int y, int z) {
    SaveGame sg = p.getSaveGame();
    if (labels == null) {
        return null;
    }
    Label tmp = null;
    for (Label l : labels) {
        if (l.getX() == x && l.getY() == y && l.getZ() == z) {
            tmp = l;
        }
    }
    if (tmp == null) {
        return null;
    }
    int expPoints = 0;
    ItemMapLabels label = ItemMapLabels.valueOf(ItemMapLabels.class, tmp.getName());
    boolean added = false;
    int conditions = label.getConditions();
    if ((conditions & SC_NEWMOONS) > 0 && !(GameScreen.trammelphase == 0 && GameScreen.feluccaphase == 0)) {
        return null;
    }
    if ((conditions & SC_FULLAVATAR) > 0) {
        for (int i = 0; i < 8; i++) {
            if (sg.karma[i] != 0) {
                return null;
            }
        }
    }
    if ((conditions & SC_REAGENTDELAY) > 0 && (sg.moves & 0xF0) == sg.lastreagent) {
        return null;
    }
    switch(label) {
        case bell:
            if ((sg.items & Item.BELL.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.BELL.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            added = true;
            break;
        case blackstone:
            if ((sg.stones & Stone.BLACK.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.BLACK.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case bluestone:
            if ((sg.stones & Stone.BLUE.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.BLUE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case book:
            if ((sg.items & Item.BOOK.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.BOOK.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            added = true;
            break;
        case candle:
            if ((sg.items & Item.CANDLE.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.CANDLE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            added = true;
            break;
        case compassionrune:
            if ((sg.runes & Virtue.COMPASSION.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.COMPASSION.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case greenstone:
            if ((sg.stones & Stone.GREEN.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.GREEN.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case honestyrune:
            if ((sg.runes & Virtue.HONESTY.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.HONESTY.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case honorrune:
            if ((sg.runes & Virtue.HONOR.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.HONOR.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case horn:
            if ((sg.items & Item.HORN.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.HORN.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            added = true;
            break;
        case humilityrune:
            if ((sg.runes & Virtue.HUMILITY.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.HUMILITY.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case justicerune:
            if ((sg.runes & Virtue.JUSTICE.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.JUSTICE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case orangestone:
            if ((sg.stones & Stone.ORANGE.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.ORANGE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case purplestone:
            if ((sg.stones & Stone.PURPLE.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.PURPLE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case redstone:
            if ((sg.stones & Stone.RED.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.RED.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case sacrificerune:
            if ((sg.runes & Virtue.SACRIFICE.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.SACRIFICE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case skull:
            if ((sg.items & Item.SKULL.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.SKULL.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            added = true;
            break;
        case spiritualityrune:
            if ((sg.runes & Virtue.SPIRITUALITY.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.SPIRITUALITY.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case valorrune:
            if ((sg.runes & Virtue.VALOR.getLoc()) > 0) {
                break;
            }
            sg.runes |= Virtue.VALOR.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 100;
            added = true;
            break;
        case wheel:
            if ((sg.items & Item.WHEEL.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.WHEEL.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            added = true;
            break;
        case whitestone:
            if ((sg.stones & Stone.WHITE.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.WHITE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case yellowstone:
            if ((sg.stones & Stone.YELLOW.getLoc()) > 0) {
                break;
            }
            sg.stones |= Stone.YELLOW.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            added = true;
            break;
        case mysticarmor:
            if (sg.armor[ArmorType.MYSTICROBE.ordinal()] > 0) {
                break;
            }
            // all party members would have it
            sg.armor[ArmorType.MYSTICROBE.ordinal()] += 8;
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case mysticswords:
            if (sg.weapons[WeaponType.MYSTICSWORD.ordinal()] > 0) {
                break;
            }
            sg.weapons[WeaponType.MYSTICSWORD.ordinal()] += 8;
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case mandrake1:
        case mandrake2:
            sg.reagents[Reagent.MANDRAKE.ordinal()] += new XORShiftRandom().nextInt(8) + 2;
            if (sg.reagents[Reagent.MANDRAKE.ordinal()] > 99) {
                sg.reagents[Reagent.MANDRAKE.ordinal()] = 99;
            }
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case nightshade1:
        case nightshade2:
            sg.reagents[Reagent.NIGHTSHADE.ordinal()] += new XORShiftRandom().nextInt(8) + 2;
            if (sg.reagents[Reagent.NIGHTSHADE.ordinal()] > 99) {
                sg.reagents[Reagent.NIGHTSHADE.ordinal()] = 99;
            }
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case telescope:
            if (screen instanceof GameScreen) {
                GameScreen gameScreen = (GameScreen) screen;
                gameScreen.peerTelescope();
            }
            break;
        case balloon:
            break;
        case lockelake:
            break;
        case maskofminax:
            if ((sg.items & Item.MASK_MINAX.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.MASK_MINAX.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case rageofgod:
            if ((sg.items & Item.RAGE_GOD.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.RAGE_GOD.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case ironrunemold:
            if ((sg.items & Item.RUNE_MOLD.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.RUNE_MOLD.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case blackironore:
            if ((sg.items & Item.IRON_ORE.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.IRON_ORE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case magicparchment:
            if ((sg.items & Item.PARCH.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.PARCH.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case greedrune:
            if ((sg.items & Item.GREED_RUNE.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.GREED_RUNE.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 200;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        case songhumility:
            if ((sg.items & Item.SONG_HUM.getLoc()) > 0) {
                break;
            }
            sg.items |= Item.SONG_HUM.getLoc();
            p.adjustKarma(KarmaAction.FOUND_ITEM);
            expPoints = 400;
            sg.lastreagent = sg.moves & 0xF0;
            added = true;
            break;
        default:
            break;
    }
    if (expPoints > 0) {
        p.getMember(0).awardXP(expPoints);
    }
    if (added) {
        return label;
    }
    return null;
}
Also used : GameScreen(ultima.GameScreen) XORShiftRandom(util.XORShiftRandom)

Aggregations

XORShiftRandom (util.XORShiftRandom)4 Random (java.util.Random)3 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)1 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)1 PartyMember (objects.Party.PartyMember)1 Person (objects.Person)1 GameScreen (ultima.GameScreen)1 UltimaTiledMapLoader (util.UltimaTiledMapLoader)1