Esempio n. 1
0
 /**
  * Returns the map's weather. (default : 64x64 map have clouds)
  *
  * @param p_map
  * @return Weather
  */
 public Weather getWeather(Area p_map) {
   switch (p_map.getAtmosphere()) {
     case OUTSIDE:
     case CASTLE:
       return Weather.CLOUD;
     default:
       return Weather.USUAL;
   }
 }
  /**
   * @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;
  }
Esempio n. 3
0
 public BankMusic getMusicForMap(Area p_map) {
   Atmosphere atm = p_map.getAtmosphere();
   return atm.music;
 }