Esempio n. 1
0
 @Override
 public void createGame() {
   if (this._locked) {
     return;
   }
   this.removeInactiveTeams();
   int teamsSize = this.getPlayersInTeam() * 2;
   if (this._parties.size() < teamsSize || this._games.size() >= this.getMaxGamesCount()) {
     this.check();
     return;
   }
   FastList players = new FastList();
   this.setIsTemporaryLocked(true);
   try {
     for (RegistrationData team : this._parties) {
       if (team.isChosen() || players.size() >= teamsSize) continue;
       team.setIsChosen(true);
       players.add(team);
       if (players.size() < teamsSize) continue;
       this.launchGame(players.toArray(new RegistrationData[players.size()]), null);
       this.setIsTemporaryLocked(false);
       break;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   for (RegistrationData p : this._parties) {
     if (!p.isChosen()) continue;
     this._parties.remove(p);
   }
   this.setIsTemporaryLocked(false);
   this.check();
 }
Esempio n. 2
0
  /** notify all observers */
  public void notifyObservers(ObserverType type, Object... object) {
    List<ActionObserver> tempOnceused = Collections.emptyList();
    lock.lock();
    try {
      if (onceUsedObservers.size() > 0) {
        tempOnceused = new ArrayList<ActionObserver>();
        Iterator<ActionObserver> iterator = onceUsedObservers.iterator();
        while (iterator.hasNext()) {
          ActionObserver observer = iterator.next();
          if (observer.getObserverType().matchesObserver(type)) {
            if (observer.tryUse()) {
              tempOnceused.add(observer);
              iterator.remove();
            }
          }
        }
      }
    } finally {
      lock.unlock();
    }

    // notify outside of lock
    for (ActionObserver observer : tempOnceused) {
      notifyAction(type, observer, object);
    }

    if (observers.size() > 0) {
      for (ActionObserver observer : observers) {
        if (observer.getObserverType().matchesObserver(type)) {
          notifyAction(type, observer, object);
        }
      }
    }
  }
Esempio n. 3
0
  @Override
  protected final void writeImpl() {
    if (getClient().getActiveChar() == null) return;

    for (PartyMatchRoom room : PartyMatchRoomList.getInstance().getRooms()) {
      if (room.getMembersCount() < 1
          || room.getOwner() == null
          || room.getOwner().isOnline() == 0
          || room.getOwner().getPartyRoom() != room.getId()) {
        PartyMatchRoomList.getInstance().deleteRoom(room.getId());
        continue;
      }
      if (_loc > 0 && _loc != room.getLocation()) continue;
      if (_lim == 0
          && ((_cha.getLevel() < room.getMinLvl()) || (_cha.getLevel() > room.getMaxLvl())))
        continue;
      _rooms.add(room);
    }
    int count = 0;
    int size = _rooms.size();

    writeC(0x96);
    if (size > 0) writeD(1);
    else writeD(0);

    writeD(_rooms.size());
    while (size > count) {
      writeD(_rooms.get(count).getId());
      writeS(_rooms.get(count).getTitle());
      writeD(_rooms.get(count).getLocation());
      writeD(_rooms.get(count).getMinLvl());
      writeD(_rooms.get(count).getMaxLvl());
      writeD(_rooms.get(count).getMembersCount());
      writeD(_rooms.get(count).getMaxMembers());
      writeS(_rooms.get(count).getOwner().getName());
      count++;
    }
  }
  @Override
  protected final void writeImpl() {
    writeC(0x91);
    writeD(_id);
    writeD(_level);
    writeD(_spCost);
    writeD(_type.ordinal());

    writeD(_reqs.size());

    for (Req temp : _reqs) {
      writeD(temp.type);
      writeD(temp.itemId);
      writeQ(temp.count);
      writeD(temp.unk);
    }
  }
Esempio n. 5
0
  @Override
  protected final void writeImpl() {
    writeC(0xf3);
    writeD(_messageId);

    if (_info.isEmpty()) {
      writeD(0x00);
      writeD(_time);
      writeD(_requesterId);
    } else {
      writeD(_info.size());

      // TODO: Verify this i bet its same like SystemMessage
      for (CnfDlgData data : _info) {
        writeD(data.type);

        switch (data.type) {
          case TYPE_TEXT:
            writeS((String) data.value);
            break;
          case TYPE_NUMBER:
          case TYPE_NPC_NAME:
          case TYPE_ITEM_NAME:
            writeD((Integer) data.value);
            break;
          case TYPE_SKILL_NAME:
            writeD((Integer) data.value); // Skill Id
            writeD(_skillLvL); // Skill lvl
            break;
          case TYPE_ZONE_NAME:
            Integer[] array = (Integer[]) data.value;
            writeD(array[0]);
            writeD(array[1]);
            writeD(array[2]);
            break;
        }
      }
      if (_time != 0) {
        writeD(_time);
      }
      if (_requesterId != 0) {
        writeD(_requesterId);
      }
    }
  }
 /** @see l2.brick.gameserver.network.serverpackets.L2GameServerPacket#writeImpl() */
 @Override
 protected void writeImpl() {
   writeC(0xfe);
   writeH(0x92);
   FastList<Territory> territoryList = TerritoryWarManager.getInstance().getAllTerritories();
   writeD(territoryList.size()); // Territory Count
   for (Territory t : territoryList) {
     writeD(t.getTerritoryId()); // Territory Id
     writeS(
         CastleManager.getInstance().getCastleById(t.getCastleId()).getName().toLowerCase()
             + "_dominion"); // territory name
     writeS(t.getOwnerClan().getName());
     writeD(t.getOwnedWardIds().size()); // Emblem Count
     for (int i : t.getOwnedWardIds())
       writeD(i); // Emblem ID - should be in for loop for emblem count
     writeD(_warTime);
   }
 }
Esempio n. 7
0
  private AdditionalSkillTable() {
    for (int skillId : _exludeSkills) _skillList.add(skillId);

    _log.info("ExtraSkillTable: Loaded  " + _skillList.size() + " skills.");
  }
Esempio n. 8
0
 public PlayerInGame(FastList<String> players) {
   writeC(0x02);
   writeH(players.size());
   for (String pc : players) writeS(pc);
 }
 /**
  * Number of items in storage
  *
  * @return
  */
 public int size() {
   return storageItems.size();
 }
Esempio n. 10
0
 /** @return int */
 public int getNumberOfFreeSlots() {
   return limit - storageItems.size();
 }
Esempio n. 11
0
 public boolean isFull() {
   return storageItems.size() >= limit;
 }
Esempio n. 12
0
  /**
   * @see ru.catssoftware.gameserver.pathfinding.PathFinding#findPath(int, int, int, int, int, int,
   *     int, boolean)
   */
  @Override
  public List<AbstractNodeLoc> findPath(
      int x, int y, int z, int tx, int ty, int tz, int instanceId, boolean playable) {
    int gx = (x - L2World.MAP_MIN_X) >> 4;
    int gy = (y - L2World.MAP_MIN_Y) >> 4;
    if (!GeoData.getInstance().hasGeo(x, y)) {
      return null;
    }
    short gz = GeoData.getInstance().getHeight(x, y, z);
    int gtx = (tx - L2World.MAP_MIN_X) >> 4;
    int gty = (ty - L2World.MAP_MIN_Y) >> 4;
    if (!GeoData.getInstance().hasGeo(tx, ty)) {
      return null;
    }
    short gtz = GeoData.getInstance().getHeight(tx, ty, tz);
    CellNodeBuffer buffer =
        alloc(64 + (2 * Math.max(Math.abs(gx - gtx), Math.abs(gy - gty))), playable);
    if (buffer == null) {
      return null;
    }

    boolean debug = playable && Config.DEBUG_PATH;

    if (debug) {
      if (_debugItems == null) {
        _debugItems = new FastList<L2ItemInstance>();
      } else {
        for (L2ItemInstance item : _debugItems) {
          if (item == null) {
            continue;
          }
          item.decayMe();
        }

        _debugItems.clear();
      }
    }

    FastList<AbstractNodeLoc> path = null;
    try {
      CellNode result = buffer.findPath(gx, gy, gz, gtx, gty, gtz);

      if (debug) {
        for (CellNode n : buffer.debugPath()) {
          if (n.getCost() < 0) {
            dropDebugItem(1831, (int) (-n.getCost() * 10), n.getLoc());
          } else {
            // known nodes
            dropDebugItem(PcInventory.ADENA_ID, (int) (n.getCost() * 10), n.getLoc());
          }
        }
      }

      if (result == null) {
        _findFails++;
        return null;
      }

      path = constructPath(result);
    } catch (Exception e) {
      _log.log(Level.WARNING, "", e);
      return null;
    } finally {
      buffer.free();
    }

    if ((path.size() < 3) || (Config.MAX_POSTFILTER_PASSES <= 0)) {
      _findSuccess++;
      return path;
    }

    long timeStamp = System.currentTimeMillis();
    _postFilterUses++;
    if (playable) {
      _postFilterPlayableUses++;
    }

    int currentX, currentY, currentZ;
    ListIterator<AbstractNodeLoc> middlePoint, endPoint;
    AbstractNodeLoc locMiddle, locEnd;
    boolean remove;
    int pass = 0;
    do {
      pass++;
      _postFilterPasses++;

      remove = false;
      middlePoint = path.listIterator();
      endPoint = path.listIterator(1);
      locEnd = null;
      currentX = x;
      currentY = y;
      currentZ = z;

      while (endPoint.hasNext()) {
        locEnd = endPoint.next();
        locMiddle = middlePoint.next();
        if (GeoData.getInstance()
            .canMoveFromToTarget(
                currentX,
                currentY,
                currentZ,
                locEnd.getX(),
                locEnd.getY(),
                locEnd.getZ(),
                instanceId)) {
          middlePoint.remove();
          remove = true;
          if (debug) {
            dropDebugItem(735, 1, locMiddle);
          }
        } else {
          currentX = locMiddle.getX();
          currentY = locMiddle.getY();
          currentZ = locMiddle.getZ();
        }
      }
    }
    // only one postfilter pass for AI
    while (playable && remove && (path.size() > 2) && (pass < Config.MAX_POSTFILTER_PASSES));

    if (debug) {
      middlePoint = path.listIterator();
      while (middlePoint.hasNext()) {
        locMiddle = middlePoint.next();
        dropDebugItem(65, 1, locMiddle);
      }
    }

    _findSuccess++;
    _postFilterElapsed += System.currentTimeMillis() - timeStamp;
    return path;
  }
Esempio n. 13
0
  public void showHeroDiary(L2PcInstance activeChar, int heroclass, int charid, int page) {
    final int perpage = 10;

    if (_herodiary.containsKey(charid)) {
      List<StatsSet> _mainlist = _herodiary.get(charid);
      final NpcHtmlMessage DiaryReply = new NpcHtmlMessage();
      final String htmContent =
          HtmCache.getInstance()
              .getHtm(activeChar.getHtmlPrefix(), "data/html/olympiad/herodiary.htm");
      if ((htmContent != null) && _heroMessage.containsKey(charid)) {
        DiaryReply.setHtml(htmContent);
        DiaryReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
        DiaryReply.replace("%message%", _heroMessage.get(charid));
        DiaryReply.disableValidation();

        if (!_mainlist.isEmpty()) {
          FastList<StatsSet> _list = FastList.newInstance();
          _list.addAll(_mainlist);
          Collections.reverse(_list);

          boolean color = true;
          final StringBuilder fList = new StringBuilder(500);
          int counter = 0;
          int breakat = 0;
          for (int i = ((page - 1) * perpage); i < _list.size(); i++) {
            breakat = i;
            StatsSet _diaryentry = _list.get(i);
            StringUtil.append(fList, "<tr><td>");
            if (color) {
              StringUtil.append(fList, "<table width=270 bgcolor=\"131210\">");
            } else {
              StringUtil.append(fList, "<table width=270>");
            }
            StringUtil.append(
                fList,
                "<tr><td width=270><font color=\"LEVEL\">"
                    + _diaryentry.getString("date")
                    + ":xx</font></td></tr>");
            StringUtil.append(
                fList, "<tr><td width=270>" + _diaryentry.getString("action") + "</td></tr>");
            StringUtil.append(fList, "<tr><td>&nbsp;</td></tr></table>");
            StringUtil.append(fList, "</td></tr>");
            color = !color;
            counter++;
            if (counter >= perpage) {
              break;
            }
          }

          if (breakat < (_list.size() - 1)) {
            DiaryReply.replace(
                "%buttprev%",
                "<button value=\"Prev\" action=\"bypass _diary?class="
                    + heroclass
                    + "&page="
                    + (page + 1)
                    + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
          } else {
            DiaryReply.replace("%buttprev%", "");
          }

          if (page > 1) {
            DiaryReply.replace(
                "%buttnext%",
                "<button value=\"Next\" action=\"bypass _diary?class="
                    + heroclass
                    + "&page="
                    + (page - 1)
                    + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
          } else {
            DiaryReply.replace("%buttnext%", "");
          }

          DiaryReply.replace("%list%", fList.toString());

          FastList.recycle(_list);
        } else {
          DiaryReply.replace("%list%", "");
          DiaryReply.replace("%buttprev%", "");
          DiaryReply.replace("%buttnext%", "");
        }

        activeChar.sendPacket(DiaryReply);
      }
    }
  }
Esempio n. 14
0
 /**
  * Returns false if all resources are loaded, true otherwise.
  *
  * @return
  */
 public boolean hasNextToLoad() {
   return index < res.size();
 }
  public synchronized void start(L2PcInstance player, byte type, L2Npc npc) {
    boolean canPass = true;
    if (!player.isInParty()) {
      showHtmlFile(player, "data/html/seven_signs/rift/NoParty.htm", npc);
      return;
    }

    if (player.getParty().getPartyLeaderOID() != player.getObjectId()) {
      showHtmlFile(player, "data/html/seven_signs/rift/NotPartyLeader.htm", npc);
      return;
    }

    if (player.getParty().isInDimensionalRift()) {
      handleCheat(player, npc);
      return;
    }

    if (player.getParty().getMemberCount() < Config.RIFT_MIN_PARTY_SIZE) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      html.setFile(player.getHtmlPrefix(), "data/html/seven_signs/rift/SmallParty.htm");
      html.replace("%npc_name%", npc.getName());
      html.replace("%count%", Integer.toString(Config.RIFT_MIN_PARTY_SIZE));
      player.sendPacket(html);
      return;
    }

    // max parties inside is rooms count - 1
    if (!isAllowedEnter(type)) {
      player.sendMessage("Rift is full. Try later.");
      return;
    }

    for (L2PcInstance p : player.getParty().getPartyMembers())
      if (!checkIfInPeaceZone(p.getX(), p.getY(), p.getZ())) {
        canPass = false;
        break;
      }

    if (!canPass) {
      showHtmlFile(player, "data/html/seven_signs/rift/NotInWaitingRoom.htm", npc);
      return;
    }

    L2ItemInstance i;
    int count = getNeededItems(type);
    for (L2PcInstance p : player.getParty().getPartyMembers()) {
      i = p.getInventory().getItemByItemId(DIMENSIONAL_FRAGMENT_ITEM_ID);

      if (i == null) {
        canPass = false;
        break;
      }

      if (i.getCount() > 0) {
        if (i.getCount() < getNeededItems(type)) {
          canPass = false;
          break;
        }
      } else {
        canPass = false;
        break;
      }
    }

    if (!canPass) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      html.setFile(player.getHtmlPrefix(), "data/html/seven_signs/rift/NoFragments.htm");
      html.replace("%npc_name%", npc.getName());
      html.replace("%count%", Integer.toString(count));
      player.sendPacket(html);
      return;
    }

    for (L2PcInstance p : player.getParty().getPartyMembers()) {
      i = p.getInventory().getItemByItemId(DIMENSIONAL_FRAGMENT_ITEM_ID);
      if (!p.destroyItem("RiftEntrance", i, count, null, false)) {
        NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
        html.setFile(player.getHtmlPrefix(), "data/html/seven_signs/rift/NoFragments.htm");
        html.replace("%npc_name%", npc.getName());
        html.replace("%count%", Integer.toString(count));
        player.sendPacket(html);
        return;
      }
    }

    byte room;
    FastList<Byte> emptyRooms;
    do {
      emptyRooms = getFreeRooms(type);
      room = emptyRooms.get(Rnd.get(1, emptyRooms.size()) - 1);
    }
    // find empty room
    while (_rooms.get(type).get(room).ispartyInside());
    new DimensionalRift(player.getParty(), type, room);
  }
Esempio n. 16
0
 public void removeResidentialSkills(L2PcInstance player) {
   if (_residentialSkills != null && _residentialSkills.size() > 0) {
     for (L2Skill sk : _residentialSkills) player.removeSkill(sk, false);
   }
 }