/** * Get the range, in pixel coordinates, taken for the point. * * @return Zone */ public Zone getZone(Area p_map) { if (zone == null) { Point p1 = new Point(px, py); Point p2 = new Point(2, 1); if (isBorder()) { if (p1.x == 0 || p1.x == p_map.getDim_x() - 1) { p1.y = 0; p2.y = p_map.getDim_y(); p2.x = 1; } else { p1.x = 0; p2.x = p_map.getDim_x(); } } else if (isVertical()) { p2.x = 1; p2.y = 2; } else if (isSingle()) { p2.x = 1; p2.y = 1; } zone = new Zone(16 * p1.x, 16 * p1.y, 16 * p2.x, 16 * p2.y); } return zone; }
/** * @param p_action * @return boolean */ public boolean render(ActionElement p_action) { boolean achieved = false; if (p_action.waiting) { waitForEndAction(p_action); achieved = p_action.done; } else { Perso perso = EngineZildo.persoManagement.getNamedPerso(p_action.who); if (perso != null) { scriptExec.involved.add(perso); // Note that this perso is concerned } Point location = p_action.location; if (p_action.delta && location != null) { Point currentPos = null; if (perso != null) { // Given position is a delta with current one (work ONLY with perso, not with camera) currentPos = new Point(perso.x, perso.y); } else if ("camera".equals(p_action.what)) { currentPos = ClientEngineZildo.mapDisplay.getCamera(); } else { Element elem = EngineZildo.spriteManagement.getNamedElement(p_action.what); currentPos = new Point(elem.x, elem.y); } if (currentPos == null) { throw new RuntimeException("We need valid 'who' or 'what' attribute"); } location = location.translate(currentPos.x, currentPos.y); } String text = p_action.text; switch (p_action.kind) { case pos: if (perso != null) { perso.x = location.x; perso.y = location.y; } else if ("camera".equals(p_action.what)) { ClientEngineZildo.mapDisplay.setCamera(location); ClientEngineZildo.mapDisplay.setFocusedEntity(null); } else { Element elem = EngineZildo.spriteManagement.getNamedElement(p_action.what); elem.x = location.x; elem.y = location.y; // TODO:the 'pushable' attribute shouldn't be set by this default way elem.setPushable(false); } achieved = true; break; case moveTo: if (perso != null) { perso.setGhost(true); perso.setTarget(location); perso.setForward(p_action.backward); perso.setSpeed(p_action.speed); perso.setOpen(p_action.open); perso.setUnstoppable(p_action.unstoppable); } else if ("camera".equals(p_action.what)) { ClientEngineZildo.mapDisplay.setTargetCamera(location); ClientEngineZildo.mapDisplay.setFocusedEntity(null); } break; case speak: String sentence = UIText.getGameText(text); EngineZildo.dialogManagement.launchDialog( SinglePlayer.getClientState(), null, new ScriptAction(sentence)); scriptExec.userEndedAction = false; break; case script: MouvementPerso script = MouvementPerso.fromInt(p_action.val); perso.setQuel_deplacement(script, true); String param = p_action.fx; if (param != null) { switch (script) { case ZONE: perso.setZone_deplacement( EngineZildo.mapManagement.range( perso.getX() - 16 * 5, perso.getY() - 16 * 5, perso.getX() + 16 * 5, perso.getY() + 16 * 5)); break; case OBSERVE: Perso persoToObserve = EngineZildo.persoManagement.getNamedPerso(param); perso.setFollowing(persoToObserve); break; } } achieved = true; break; case angle: if (perso.getTarget() != null) { return false; } perso.setAngle(Angle.fromInt(p_action.val)); achieved = true; break; case wait: count = p_action.val; break; case fadeIn: EngineZildo.askEvent( new ClientEvent(ClientEventNature.FADE_IN, FilterEffect.fromInt(p_action.val))); break; case fadeOut: EngineZildo.askEvent( new ClientEvent(ClientEventNature.FADE_OUT, FilterEffect.fromInt(p_action.val))); break; case clear: EngineZildo.askEvent(new ClientEvent(ClientEventNature.CLEAR)); achieved = true; break; case map: // Change current map EngineZildo.mapManagement.loadMap(p_action.text, false); ClientEngineZildo.mapDisplay.setCurrentMap(EngineZildo.mapManagement.getCurrentMap()); achieved = true; break; case focus: // Camera focus on given character Element toFocus = perso; if (p_action.what != null) { toFocus = EngineZildo.spriteManagement.getNamedElement(p_action.what); } if (toFocus == null) { ClientEngineZildo.mapDisplay.setFocusedEntity(null); } if (p_action.delta) { Point cameraLoc = new Point(toFocus.x - MapDisplay.CENTER_X, toFocus.y - MapDisplay.CENTER_Y); ClientEngineZildo.mapDisplay.setTargetCamera(cameraLoc); } ClientEngineZildo.mapDisplay.setFocusedEntity(toFocus); // If delta, we go smoothly to the target, except if it's explicitly asked to be // unblocking achieved = !p_action.delta || p_action.unblock; break; case spawn: // Spawn a new character if (p_action.who != null) { PersoDescription desc = PersoDescription.valueOf(p_action.text); Perso newOne = EngineZildo.persoManagement.createPerso( desc, location.x, location.y, 0, p_action.who, p_action.val); newOne.setSpeed(p_action.speed); newOne.setEffect(p_action.fx); newOne.initPersoFX(); EngineZildo.spriteManagement.spawnPerso(newOne); } else { // Spawn a new element if (EngineZildo.spriteManagement.getNamedElement(p_action.what) == null) { // Spawn only if doesn't exist yet SpriteDescription desc = SpriteDescription.Locator.findNamedSpr(p_action.text); Reverse rev = Reverse.fromInt(p_action.reverse); Rotation rot = Rotation.fromInt(p_action.rotation); Element elem = EngineZildo.spriteManagement.spawnElement( desc, location.x, location.y, 0, rev, rot); elem.setName(p_action.what); } } achieved = true; break; case impact: ImpactKind impactKind = ImpactKind.valueOf(p_action.text); EngineZildo.spriteManagement.spawnSprite( new ElementImpact(location.x, location.y, impactKind, null)); achieved = true; break; case animation: SpriteAnimation anim = SpriteAnimation.valueOf(p_action.text); Element animElem = EngineZildo.spriteManagement.spawnSpriteGeneric( anim, location.x, location.y, 0, null, null); if (p_action.what != null) { animElem.setName(p_action.what); } achieved = true; break; case take: // Someone takes an item if (p_action.who == null || "zildo".equalsIgnoreCase(p_action.who)) { // This is Zildo PersoZildo zildo = EngineZildo.persoManagement.getZildo(); if (p_action.val != 0) { zildo.pickGoodies(null, p_action.val); } else { zildo.pickItem(ItemKind.fromString(text), null); } } else if (perso != null) { // This is somebody else Element elem = EngineZildo.spriteManagement.getNamedElement(p_action.what); perso.addPersoSprites(elem); } achieved = true; break; case putDown: // Zildo loses an item PersoZildo zildo = EngineZildo.persoManagement.getZildo(); zildo.removeItem(ItemKind.fromString(text)); achieved = true; break; case mapReplace: EngineZildo.scriptManagement.addReplacedMapName(p_action.what, text); achieved = true; break; case exec: // Note : we can sequence scripts in an action tag. EngineZildo.scriptManagement.execute(text); break; case music: if (text == null) { // Stop music ? EngineZildo.soundManagement.broadcastSound((BankMusic) null, (Point) null); } else { BankMusic musicSnd = BankMusic.valueOf(text); EngineZildo.soundManagement.broadcastSound(musicSnd, (Point) null); } EngineZildo.soundManagement.setForceMusic(true); achieved = true; break; case sound: BankSound snd = BankSound.valueOf(text); EngineZildo.soundManagement.playSound(snd, null); achieved = true; break; case remove: Element toRemove; if (p_action.what != null) { toRemove = EngineZildo.spriteManagement.getNamedElement(p_action.what); } else { toRemove = perso; EngineZildo.persoManagement.removePerso((Perso) toRemove); } EngineZildo.spriteManagement.deleteSprite(toRemove); achieved = true; break; case markQuest: if (p_action.val == 1) { EngineZildo.scriptManagement.accomplishQuest(p_action.text, true); } else { EngineZildo.scriptManagement.resetQuest(p_action.text); } achieved = true; break; case attack: if (p_action.text != null) { Item weapon = new Item(ItemKind.fromString(text)); perso.setWeapon(weapon); perso.attack(); achieved = true; } break; case activate: Element toActivate = EngineZildo.spriteManagement.getNamedElement(p_action.what); ElementGear gearToActivate = (ElementGear) toActivate; gearToActivate.activate(p_action.activate); break; case tile: // Change tile on map Area area = EngineZildo.mapManagement.getCurrentMap(); Case c = area.get_mapcase(location.x, location.y + 4); if (p_action.back != -1) { c.setBackTile(new Tile(p_action.back, c)); } if (p_action.back2 != -1) { c.setBackTile2(new Tile(p_action.back2, c)); } if (p_action.fore != -1) { c.setForeTile(new Tile(p_action.fore, c)); } EngineZildo.mapManagement.getCurrentMap().set_mapcase(location.x, location.y + 4, c); achieved = true; break; case filter: switch (p_action.val) { case 0: // REGULAR ClientEngineZildo.ortho.setFilteredColor(new Vector3f(1, 1, 1)); break; case 1: // NIGHT ClientEngineZildo.ortho.setFilteredColor(Ortho.NIGHT_FILTER); break; case 2: // SEMI_NIGHT ClientEngineZildo.ortho.setFilteredColor(Ortho.SEMI_NIGHT_FILTER); break; } achieved = true; break; case end: new GameOverAction().launchAction(null); } p_action.done = achieved; p_action.waiting = !achieved; } return achieved; }
@Override public String toString() { return p.toString(); }
@Override public void parse(Element p_elem) { if (kind == null) { throw new RuntimeException("Action kind is unknown !"); } // Store XML element in order to read easier from ZEditor xmlElement = p_elem; // Read common attributes who = readAttribute("who"); what = readAttribute("what"); fx = readAttribute("fx"); unblock = isTrue("unblock"); speed = Float.valueOf("0" + p_elem.getAttribute("speed")); unstoppable = isTrue("unstoppable"); foreground = isTrue("foreground"); // Read less common ones String strPos = p_elem.getAttribute("pos"); String strAngle = p_elem.getAttribute("angle"); switch (kind) { case spawn: delta = isTrue("delta"); reverse = readInt("reverse"); rotation = readInt("rotation"); case animation: case impact: location = Point.fromString(strPos); if (!"".equals(strAngle)) { val = Integer.valueOf(strAngle); } case perso: text = readAttribute("type"); info = readAttribute("info"); break; case speak: text = readAttribute("text"); break; case sound: case map: case music: // String text = readAttribute("name"); break; case moveTo: backward = isTrue("backward"); open = isTrue("open"); case pos: // Position if (!strPos.isEmpty()) { location = Point.fromString(strPos); } delta = isTrue("delta"); z = readInt("z", -1); break; case script: text = readAttribute("text"); case angle: case wait: case zoom: case herospecial: val = readInt("value"); break; case fadeIn: case fadeOut: case filter: case end: // Integer val = readInt("type"); break; case focus: delta = isTrue("delta"); if (readAttribute("unblock") == null) { unblock = true; } break; case take: val = readInt("value"); case putDown: case attack: text = readAttribute("item"); break; case exec: text = p_elem.getAttribute("script"); break; case mapReplace: case zikReplace: text = p_elem.getAttribute("name"); break; case markQuest: text = readAttribute("name"); val = isTrue("value") ? 1 : 0; break; case visible: case activate: activate = isTrue("value"); break; case tile: location = Point.fromString(strPos); back = readInt("back", -1); back2 = readInt("back2", -1); fore = readInt("fore", -1); break; } }
public PointFixed(String str) { p = Point.fromString(str); }