use of objects.Tile 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;
}
use of objects.Tile in project ultimate-java by pantinor.
the class CombatScreen method keyUp.
@Override
public boolean keyUp(int keycode) {
PartyMember ap = party.getActivePartyMember();
Creature active = ap.combatCr;
try {
if (keycode == Keys.SPACE || ap.isDisabled()) {
log("Pass");
} else if (keycode == Keys.UP) {
if (preMove(active, Direction.NORTH)) {
active.currentY--;
active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
checkTileAffects(ap, active.currentX, active.currentY);
}
} else if (keycode == Keys.DOWN) {
if (preMove(active, Direction.SOUTH)) {
active.currentY++;
active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
checkTileAffects(ap, active.currentX, active.currentY);
}
} else if (keycode == Keys.RIGHT) {
if (preMove(active, Direction.EAST)) {
active.currentX++;
active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
checkTileAffects(ap, active.currentX, active.currentY);
}
} else if (keycode == Keys.LEFT) {
if (preMove(active, Direction.WEST)) {
active.currentX--;
active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
checkTileAffects(ap, active.currentX, active.currentY);
}
} else if (keycode == Keys.A) {
log("Attack: ");
Gdx.input.setInputProcessor(sip);
sip.setinitialKeyCode(keycode, combatMap, active.currentX, active.currentY);
return false;
} else if (keycode == Keys.C) {
log("Cast Spell (A-Z): ");
Gdx.input.setInputProcessor(new SpellInputProcessor(this, context, stage, active.currentX, active.currentY, ap));
return false;
} else if (keycode == Keys.U) {
Tile tile = combatMap.getTile(active.currentX, active.currentY);
if (// altar
tile.getIndex() == 74 || (party.getSaveGame().items & Item.RAGE_GOD.getLoc()) > 0 || (party.getSaveGame().items & Item.MASK_MINAX.getLoc()) > 0) {
// altar or rage of god
log("Use which item: ");
log("");
Gdx.input.setInputProcessor(sip);
sip.setinitialKeyCode(keycode, combatMap, active.currentX, active.currentY);
return false;
} else {
log("Nothing to use!");
}
} else if (keycode == Keys.R) {
Gdx.input.setInputProcessor(new ReadyWearInputAdapter(ap, true));
return false;
} else if (keycode == Keys.W) {
Gdx.input.setInputProcessor(new ReadyWearInputAdapter(ap, false));
return false;
} else if (keycode == Keys.G) {
getChest(party.getActivePlayer(), active.currentX, active.currentY);
return false;
} else if (keycode == Keys.Z) {
showZstats = showZstats + 1;
if (showZstats >= STATS_PLAYER1 && showZstats <= STATS_PLAYER8) {
if (showZstats > party.getMembers().size()) {
showZstats = STATS_WEAPONS;
}
}
if (showZstats > STATS_SPELLS) {
showZstats = STATS_NONE;
}
return false;
}
finishPlayerTurn();
} catch (PartyDeathException e) {
this.returnScreen.partyDeath();
}
return false;
}
use of objects.Tile in project ultimate-java by pantinor.
the class CombatScreen method getChest.
// for dungeon room chests only
public void getChest(int index, int x, int y) {
try {
Tile tile = combatMap.getTile(x, y);
if (tile != null && tile.getIndex() == 60) {
PartyMember pm = context.getParty().getMember(index);
context.getChestTrapHandler(pm);
log(String.format("The Chest Holds: %d Gold", context.getParty().getChestGold()));
replaceTile("dungeon_floor", x, y);
} else {
log("Not Here!");
}
} catch (PartyDeathException e) {
this.returnScreen.partyDeath();
}
}
use of objects.Tile in project ultimate-java by pantinor.
the class Context method saveGame.
public void saveGame(float x, float y, float z, Direction orientation, Maps map) {
if (map == Maps.WORLD) {
party.getSaveGame().x = (int) x;
party.getSaveGame().y = (int) y;
party.getSaveGame().dngx = (int) x;
party.getSaveGame().dngy = (int) y;
party.getSaveGame().dnglevel = 0;
party.getSaveGame().orientation = 0;
} else {
Portal p = Maps.WORLD.getMap().getPortal(map.getId());
party.getSaveGame().x = (int) x;
party.getSaveGame().y = (int) y;
party.getSaveGame().dngx = (p == null ? (int) x : p.getX());
party.getSaveGame().dngy = (p == null ? (int) y : p.getY());
party.getSaveGame().dnglevel = (int) z;
party.getSaveGame().orientation = orientation.getVal() - 1;
}
party.getSaveGame().location = map.getId();
Stage surfaceStage = Maps.WORLD.getMap().getSurfaceMapStage();
if (surfaceStage != null) {
party.getSaveGame().resetMonsters();
Drawable[] objects = new Drawable[24];
int count = 0;
for (Actor a : surfaceStage.getActors()) {
if (a instanceof Drawable) {
Drawable d = (Drawable) a;
objects[count] = d;
if (count > 23) {
break;
}
count++;
}
}
for (int i = 0; i < 24; i++) {
if (objects[i] != null) {
party.getSaveGame().objects_save_tileids[i] = (byte) objects[i].getTile().getIndex();
party.getSaveGame().objects_save_x[i] = (byte) objects[i].getCx();
party.getSaveGame().objects_save_y[i] = (byte) objects[i].getCy();
}
}
List<Creature> monsters = Maps.WORLD.getMap().getCreatures();
for (int i = 0; i < 8 && monsters.size() > i; i++) {
Tile tile = Ultima4.baseTileSet.getTileByName(monsters.get(i).getTile().toString());
if (tile == null) {
continue;
}
party.getSaveGame().monster_save_tileids[i] = (byte) tile.getIndex();
party.getSaveGame().monster_save_x[i] = (byte) monsters.get(i).currentX;
party.getSaveGame().monster_save_y[i] = (byte) monsters.get(i).currentY;
}
}
try {
party.getSaveGame().write(PARTY_SAV_BASE_FILENAME);
} catch (Exception e) {
e.printStackTrace();
}
try {
File file = new File("journal.save");
JAXBContext jaxbContext = JAXBContext.newInstance(JournalEntries.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(this.journalEntries, file);
} catch (Exception e) {
e.printStackTrace();
}
}
use of objects.Tile in project ultimate-java by pantinor.
the class Context method getCombatMapForTile.
public Maps getCombatMapForTile(Tile combatantTile, TransportContext transport, int x, int y) {
boolean fromShip = false;
boolean toShip = false;
Tile tileUnderneathAvatar = currentMap.getTile(x, y);
if (transport == TransportContext.SHIP) {
fromShip = true;
}
if (combatantTile.getRule() == TileRule.ship) {
toShip = true;
}
if (fromShip && toShip) {
return Maps.SHIPSHIP_CON;
}
if (toShip) {
return Maps.SHORSHIP_CON;
} else if (fromShip && tileUnderneathAvatar.getRule() == TileRule.water) {
return Maps.SHIPSEA_CON;
} else if (tileUnderneathAvatar.getRule() == TileRule.water) {
return Maps.SHORE_CON;
} else if (fromShip && tileUnderneathAvatar.getRule() != TileRule.water) {
return Maps.SHIPSHOR_CON;
}
if (tileUnderneathAvatar.getCombatMap() != null) {
return tileUnderneathAvatar.getCombatMap();
}
return Maps.BRICK_CON;
}
Aggregations