/**
   * Initialize Zildo inventory and so on, with start values.
   *
   * @param p_zildo
   */
  public static void setUpZildo(PersoZildo p_zildo) {
    // p_zildo.addInventory(new Item(ItemKind.BOW));
    // p_zildo.addInventory(new Item(ItemKind.BOOMERANG));
    // p_zildo.addInventory(new Item(ItemKind.BOMB));
    p_zildo.setPv(p_zildo.getMaxpv());
    // p_zildo.setMoney(0);

    // p_zildo.setCountArrow(0);
    // p_zildo.setCountBomb(20);

  }
예제 #2
0
  @Override
  public void launchAction(ClientState p_clientState) {

    zildo.setDialoguingWith(seller);
    seller.setDialoguingWith(zildo);

    List<StoredItem> items = new ArrayList<StoredItem>();
    for (StoredItem sItem : sellingItems) {
      if (sItem.quantity != 0) {
        items.add(sItem);
      }
    }
    zildo.lookItems(new Inventory(items), 0, seller, sellDescription);

    p_clientState.dialogState.dialoguing = true;
  }
  /**
   * People killed another one.
   *
   * <p>
   *
   * <ul>
   *   <li>display message
   *   <li>update scores
   *   <li>drop Zildo's current weapon
   *   <li>respawn him
   * </ul>
   *
   * @param p_zildo
   * @param p_shooter
   */
  public void kill(PersoZildo p_zildo, Perso p_shooter) {
    ClientState clKilled = Server.getClientFromZildo(p_zildo);
    ClientState clShooter = null;
    if (p_shooter != null && p_shooter.isZildo()) {
      clShooter = Server.getClientFromZildo((PersoZildo) p_shooter);
    }
    displayDeathMessage(clKilled, clShooter);
    // Update scores
    clKilled.nDied++;
    if (clShooter != null) {
      clShooter.nKill++;
    }

    // Drop Zildo's weapon at his death point
    Item weapon = p_zildo.getWeapon();
    ItemKind k = weapon == null ? null : weapon.kind;
    if (k != null && k != ItemKind.SWORD) {
      EngineZildo.spriteManagement.spawnSprite(
          k.representation,
          (int) p_zildo.getX(),
          (int) p_zildo.getY(),
          false,
          Reverse.NOTHING,
          true);
    }

    // Steal money from the dead Zildo
    if (p_shooter != null && p_shooter.isZildo()) {
      int money = p_zildo.getMoney() / 2;
      p_zildo.setMoney(money);
      p_shooter.setMoney(p_shooter.getMoney() + money);
    }

    // Respawn Zildo
    EngineZildo.respawnClient(p_zildo);

    needToBroadcast = true;
  }
예제 #4
0
  /**
   * @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;
  }
 /** Call Circle filter to focus on Zildo. */
 private void circleOnZildo() {
   PersoZildo zildo = EngineZildo.persoManagement.getZildo();
   Point zildoPos = zildo.getCenteredScreenPosition();
   Zildo.pdPlugin.getFilter(CircleFilter.class).setCenter(zildoPos.x, zildoPos.y);
 }