Search in sources :

Example 1 with PartyMember

use of objects.Party.PartyMember in project ultimate-java by pantinor.

the class HealerService method nextDialog.

@Override
public boolean nextDialog() {
    switch(state) {
        case WAIT_NEED_HELP:
            displayToScreen(String.format(welcomeMessage, vendor.getName(), vendor.getOwner()));
            displayToScreen("\nAre you in need of help?");
            break;
        case WAIT_GIVE_BLOOD:
            displayToScreen("Art thou willing to give 100 pts of thy blood to aid others?");
            break;
        case GIVE_BLOOD:
            party.getMember(0).getPlayer().hp = party.getMember(0).getPlayer().hp - 100;
            party.adjustKarma(KarmaAction.DONATED_BLOOD);
            displayToScreen("Thou art a great help. We are in dire need!");
            break;
        case WAIT_WHICH_SERVICE:
            String list = "We can perform:\n\n";
            for (Item i : vendor.getInventoryItems()) {
                list += i.getChoice().toUpperCase() + " - " + i.getName() + " for " + i.getPrice() + "gp.\n";
            }
            list += "\nYour Need?";
            displayToScreen(list);
            break;
        case WAIT_WHO_SERVICE:
            displayToScreen("Who is in need?");
            break;
        case WAIT_PERFORM_SERVICE:
            displayToScreen(String.format("%s will cost thee %s gp.", currentSelectedItem.getDescription(), currentSelectedItem.getPrice()));
            displayToScreen("Wilt thou pay?");
            break;
        case PERFORM_SERVICE:
            if (currentCount <= 0 || currentCount > party.getSaveGame().members) {
                currentCount = 1;
            }
            PartyMember pm = party.getMember(currentCount - 1);
            if (pm == null) {
                break;
            }
            if (pm.heal(currentSelectedItem.getHealType())) {
                party.adjustGold(-currentSelectedItem.getPrice());
                // Sounds.play(Sound.MOONGATE);
                displayToScreen("There you are. Please be more careful next time.");
            } else {
                displayToScreen(SaveGame.pc(pm.getPlayer().name) + ", thou art not in need of such service.");
            }
            displayToScreen("Anything else?");
            state = ConvState.ANYTHING_ELSE;
            break;
        case FAREWELL:
            displayToScreen(String.format("%s says: May thy life be guarded by the powers of good.", vendor.getOwner()));
            return false;
        default:
            displayToScreen("I cannot help thee with that.");
            state = ConvState.WAIT_NEED_HELP;
            break;
    }
    return true;
}
Also used : PartyMember(objects.Party.PartyMember)

Example 2 with PartyMember

use of objects.Party.PartyMember 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 PartyMember

use of objects.Party.PartyMember in project ultimate-java by pantinor.

the class CombatScreen method preMove.

private boolean preMove(Creature active, Direction dir) {
    int x = active.currentX;
    int y = active.currentY;
    AttackVector next = null;
    if (dir == Direction.NORTH) {
        next = new AttackVector(x, y - 1);
    }
    if (dir == Direction.SOUTH) {
        next = new AttackVector(x, y + 1);
    }
    if (dir == Direction.EAST) {
        next = new AttackVector(x + 1, y);
    }
    if (dir == Direction.WEST) {
        next = new AttackVector(x - 1, y);
    }
    if (next.x > combatMap.getWidth() - 1 || next.x < 0 || next.y > combatMap.getHeight() - 1 || next.y < 0) {
        if (combatMap.getType() == MapType.dungeon && !party.isOKtoExitDirection(dir)) {
            log("Cannot exit in that direction!");
            Sounds.play(Sound.BLOCKED);
            return false;
        } else {
            PartyMember ap = party.getActivePartyMember();
            ap.fled = true;
            ap.combatMapExitDirection = dir;
            Sounds.play(Sound.FLEE);
            if (party.getAbleCombatPlayers() == 0) {
                end();
                return false;
            } else {
                int ni = party.getNextActiveIndex();
                Creature nextActivePlayer = party.getMember(ni).combatCr;
                cursor.setPos(nextActivePlayer.currentPos);
            }
        }
    } else {
        int mask = combatMap.getValidMovesMask(context, x, y);
        if (!Direction.isDirInMask(dir, mask)) {
            Sounds.play(Sound.BLOCKED);
            return false;
        }
    }
    return true;
}
Also used : Creature(objects.Creature) PartyMember(objects.Party.PartyMember)

Example 4 with PartyMember

use of objects.Party.PartyMember in project ultimate-java by pantinor.

the class CombatScreen method nearestPartyMember.

private PartyMember nearestPartyMember(int fromX, int fromY, DistanceWrapper dist, boolean ranged) {
    PartyMember opponent = null;
    int d = 0;
    int leastDist = 0xFFFF;
    boolean jinx = context.getAura().getType() == AuraType.JINX;
    for (int i = 0; i < party.getMembers().size(); i++) {
        PartyMember pm = party.getMember(i);
        if (pm.fled || pm.getPlayer().status == StatusType.DEAD) {
            continue;
        }
        if (!jinx) {
            if (ranged) {
                d = Utils.distance(MapBorderBehavior.fixed, combatMap.getWidth(), combatMap.getHeight(), fromX, fromY, pm.combatCr.currentX, pm.combatCr.currentY);
            } else {
                d = Utils.movementDistance(MapBorderBehavior.fixed, combatMap.getWidth(), combatMap.getHeight(), fromX, fromY, pm.combatCr.currentX, pm.combatCr.currentY);
            }
            /* skip target 50% of time if same distance */
            if (d < leastDist || (d == leastDist && rand.nextInt(2) == 0)) {
                opponent = pm;
                leastDist = d;
            }
        }
    }
    if (opponent != null) {
        dist.setVal(leastDist);
    }
    return opponent;
}
Also used : PartyMember(objects.Party.PartyMember)

Example 5 with PartyMember

use of objects.Party.PartyMember in project ultimate-java by pantinor.

the class CombatScreen method creatureAction.

/**
 * Return false if to remove from map.
 */
private boolean creatureAction(Creature creature) throws PartyDeathException {
    // accept no input starting now, re-enabled when creature actions are done
    Gdx.input.setInputProcessor(null);
    if (creature.getStatus() == StatusType.SLEEPING && rand.nextInt(16) == 0) {
        creature.setStatus(StatusType.GOOD);
    }
    if (creature.getStatus() == StatusType.SLEEPING) {
        return true;
    }
    if (creature.negates()) {
        context.setAura(AuraType.NEGATE, 2);
    }
    CombatAction action = null;
    if (creature.getTeleports() && rand.nextInt(100) <= 25) {
        action = CombatAction.TELEPORT;
    } else if (creature.getRanged() && rand.nextInt(100) <= 25) {
        action = CombatAction.RANGED;
    } else if (creature.castsSleep() && rand.nextInt(100) <= 25 && context.getAura().getType() != AuraType.NEGATE) {
        action = CombatAction.CAST_SLEEP;
    } else if (creature.getDamageStatus() == CreatureStatus.FLEEING) {
        action = CombatAction.FLEE;
    } else {
        action = CombatAction.ATTACK;
    }
    /* 
         * now find out who to do it to
         */
    DistanceWrapper dist = new DistanceWrapper(0);
    PartyMember target = nearestPartyMember(creature.currentX, creature.currentY, dist, action == CombatAction.RANGED);
    if (target == null) {
        return true;
    }
    if (action == CombatAction.ATTACK && dist.getVal() > 1) {
        action = CombatAction.ADVANCE;
    }
    if (creature.getCamouflage() && !hideOrShow(creature)) {
        return true;
    }
    switch(action) {
        case ATTACK:
            {
                Sounds.play(Sound.NPC_ATTACK);
                if (Utils.attackHit(creature, target) == AttackResult.HIT) {
                    Sounds.play(Sound.PC_STRUCK);
                    wounded = true;
                    if (!Utils.dealDamage(creature, target)) {
                        target = null;
                    }
                    if (target != null) {
                        if (creature.stealsFood() && rand.nextInt(8) == 0) {
                            Sounds.play(Sound.NEGATIVE_EFFECT);
                            party.adjustFood(-(rand.nextInt(10) * 1000));
                        }
                        if (creature.stealsGold() && rand.nextInt(8) == 0) {
                            Sounds.play(Sound.NEGATIVE_EFFECT);
                            party.adjustGold(-(rand.nextInt(40)));
                        }
                    }
                }
                break;
            }
        case CAST_SLEEP:
            {
                if (context.getAura().getType() == AuraType.NEGATE) {
                    log("Sleep spell negated.");
                } else {
                    log("Sleep!");
                    Sounds.play(Sound.SLEEP);
                    for (PartyMember p : party.getMembers()) {
                        if (rand.nextInt(2) == 0 && !p.isDisabled()) {
                            p.putToSleep();
                        }
                    }
                }
                break;
            }
        case TELEPORT:
            {
                // only wisp teleports
                boolean valid = false;
                int rx = 0, ry = 0, count = 0;
                while (!valid && count < 5) {
                    rx = rand.nextInt(combatMap.getWidth());
                    ry = rand.nextInt(combatMap.getHeight());
                    Tile t = combatMap.getTile(rx, ry);
                    if (t != null) {
                        valid = true;
                        TileRule rule = t.getRule();
                        if (rule != null && rule.has(TileAttrib.creatureunwalkable)) {
                            valid = false;
                        }
                    }
                    count++;
                }
                if (valid) {
                    moveCreature(action, creature, rx, ry);
                }
                break;
            }
        case RANGED:
            {
                // figure out which direction to fire the weapon
                int dirmask = Utils.getRelativeDirection(MapBorderBehavior.fixed, combatMap.getWidth(), combatMap.getHeight(), target.combatCr.currentX, target.combatCr.currentY, creature.currentX, creature.currentY);
                Sounds.play(Sound.NPC_ATTACK);
                List<AttackVector> path = Utils.getDirectionalActionPath(combatMap, dirmask, creature.currentX, creature.currentY, 1, 11, false, false, false);
                for (AttackVector v : path) {
                    if (rangedAttackAt(v, creature)) {
                        break;
                    }
                }
                break;
            }
        case FLEE:
        case ADVANCE:
            {
                if (StringUtils.equals("none", creature.getMovement())) {
                    // reapers do not move
                    return true;
                }
                moveCreature(action, creature, target.combatCr.currentX, target.combatCr.currentY);
                // is map OOB
                if (creature.currentX > combatMap.getWidth() - 1 || creature.currentX < 0 || creature.currentY > combatMap.getHeight() - 1 || creature.currentY < 0) {
                    log(String.format("%s Flees!", creature.getName()));
                    Sounds.play(Sound.EVADE);
                    if (creature.getGood()) {
                        party.adjustKarma(KarmaAction.SPARED_GOOD);
                    }
                    return false;
                }
                break;
            }
    }
    return true;
}
Also used : PartyMember(objects.Party.PartyMember) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) List(java.util.List)

Aggregations

PartyMember (objects.Party.PartyMember)24 PartyDeathException (util.PartyDeathException)9 Creature (objects.Creature)5 Tile (objects.Tile)5 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)4 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)4 DungeonTileModelInstance (util.DungeonTileModelInstance)4 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)3 Color (com.badlogic.gdx.graphics.Color)2 Vector3 (com.badlogic.gdx.math.Vector3)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 Person (objects.Person)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)1 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)1 Action (com.badlogic.gdx.scenes.scene2d.Action)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)1