Exemple #1
0
  private void matchClients() {
    final TIntArrayList ids = new TIntArrayList(clients.size());

    clients.forEachEntry(
        new TIntObjectProcedure<ClientInfo>() {
          @Override
          public boolean execute(int id, ClientInfo client) {
            if (client.readyForGame()) ids.add(id);
            return true;
          }
        });

    if (ids.size() < 2) return;

    ids.sort();

    for (int i = 0; i < ids.size(); i += 2) {
      int idOne = ids.get(i);
      int idTwo = ids.get(i + 1);

      ClientInfo clientOne = clients.remove(idOne);
      ClientInfo clientTwo = clients.remove(idTwo);

      if (clientOne.getAddress().equals(clientTwo.getAddress())
          && clientOne.getPort() == clientTwo.getPort()) {
        if (clientOne.getLastPingTime() > clientTwo.getLastPingTime()) {
          clients.put(idOne, clientOne);
        } else {
          clients.put(idTwo, clientTwo);
        }
        continue;
      }

      boolean isHost = isHost(clientOne, clientTwo);

      NetworkGameInfo networkGameInfo;
      if (isHost) {
        networkGameInfo =
            new NetworkGameInfo(
                idOne,
                clientOne,
                clientTwo,
                clientOne.getRequestedBoard(),
                clientOne.getRequestedSpeed());
      } else {
        networkGameInfo =
            new NetworkGameInfo(
                idTwo,
                clientTwo,
                clientOne,
                clientTwo.getRequestedBoard(),
                clientTwo.getRequestedSpeed());
      }
      games.put(idOne, networkGameInfo);
      games.put(idTwo, networkGameInfo);

      System.out.println("Made game for " + idOne + " and " + idTwo + " " + networkGameInfo);
    }
  }
  public void loadBorderPoints() throws IOException {
    Iterator<Entry<RouteRegion, BinaryMapIndexReader>> it = reverseMap.entrySet().iterator();
    int sleft = Math.min(startX, targetX);
    int sright = Math.max(startX, targetX);
    int stop = Math.min(startY, targetY);
    int sbottom = Math.max(startY, targetY);
    // one tile of 12th zoom around (?)
    int zoomAround = 10;
    int distAround = 1 << (31 - zoomAround);
    leftBorderBoundary = sleft - distAround;
    rightBorderBoundary = sright + distAround;
    SearchRequest<RouteDataBorderLinePoint> req =
        BinaryMapIndexReader.buildSearchRouteBorderRequest(sleft, sright, stop, sbottom);
    while (it.hasNext()) {
      Entry<RouteRegion, BinaryMapIndexReader> entry = it.next();
      entry.getValue().searchBorderPoints(req, entry.getKey());
    }
    TIntObjectHashMap<RouteDataBorderLine> lines =
        new TIntObjectHashMap<RoutingContext.RouteDataBorderLine>();
    for (RouteDataBorderLinePoint p : req.getSearchResults()) {
      if (config.router.acceptLine(p) && p.x > leftBorderBoundary && p.x < rightBorderBoundary) {
        if (!lines.containsKey(p.y)) {
          RouteDataBorderLine line = new RouteDataBorderLine(p.y);
          lines.put(p.y, line);
          RouteDataBorderLinePoint lft = new RouteDataBorderLinePoint(p.region);
          lft.y = p.y;
          lft.id = Long.MIN_VALUE;
          lft.x = leftBorderBoundary;
          line.borderPoints.add(lft);
          RouteDataBorderLinePoint rht = new RouteDataBorderLinePoint(p.region);
          rht.y = p.y;
          rht.id = Long.MIN_VALUE;
          rht.x = rightBorderBoundary;
          line.borderPoints.add(rht);
        }
        lines.get(p.y).borderPoints.add(p);
      }
    }
    borderLines = lines.values(new RouteDataBorderLine[lines.size()]);
    Arrays.sort(borderLines);
    borderLineCoordinates = new int[borderLines.length];
    for (int i = 0; i < borderLineCoordinates.length; i++) {
      borderLineCoordinates[i] = borderLines[i].borderLine;
      // FIXME borders approach
      // not less then 14th zoom
      if (i > 0 && borderLineCoordinates[i - 1] >> 17 == borderLineCoordinates[i] >> 17) {
        throw new IllegalStateException();
      }
      System.out.println(
          "Line "
              + (borderLineCoordinates[i] >> 17)
              + " points "
              + borderLines[i].borderPoints.size() /* + " " +borderLines[i].borderPoints*/);
    }

    updateDistanceForBorderPoints(startX, startY, true);
    updateDistanceForBorderPoints(targetX, targetY, false);
  }
 public KeyphrasesMeasureTracer(String name, double weight) {
   super(name, weight);
   if (weight < 0.0) {
     sLogger_.error("Weight should not be < 0");
   }
   synchronized (id2word) {
     if (id2word.size() == 0) {
       sLogger_.debug("Reading all word ids for tracing.");
       id2word = getAllWordIds();
       sLogger_.debug("Reading all word ids for tracing done.");
     }
   }
   keyphrases = new LinkedList<KeyphrasesMeasureTracer.keyphraseTracingObject>();
 }
Exemple #4
0
  /*
   * (non-Javadoc)
   *
   * @see org.jmangos.commons.dataholder.DataLoadService#reload()
   */
  @Override
  public void reload() {

    // Don't replace directly becouse the players can't query quest while
    // it's loading!
    logger.info("Loading quest templates to temoary store.");
    final List<QuestPrototype> questPrototypeList =
        this.questPrototypeService.readQuestPrototypes();
    TIntObjectHashMap<QuestPrototype> tempQuestMap = new TIntObjectHashMap<QuestPrototype>();
    for (final QuestPrototype quest : questPrototypeList) {
      tempQuestMap.put(quest.getEntry(), quest);
    }
    logger.info("Loaded " + tempQuestMap.size() + " quests. Replacing new old Quests with newer");
    this.questMap = tempQuestMap;
    tempQuestMap = null;
  }
Exemple #5
0
 private ShuttleWayEvent getNextFloor() {
   int floors = _floors.size() - 1;
   if (!_moveBack) {
     _currentWay++;
     if (_currentWay > floors) {
       _currentWay = floors - 1;
       _moveBack = true;
     }
   } else {
     _currentWay--;
     if (_currentWay < 0) {
       _currentWay = 1;
       _moveBack = false;
     }
   }
   return _floors.get(_currentWay);
 }
Exemple #6
0
  @Override
  public void run() {
    System.out.println("GameMatcher Started");
    while (true) {
      System.out.println(
          "Running match cycle: currentID=" + currentID + " numClients=" + clients.size());

      writeLock.lock();
      removeStaleClients();
      matchClients();
      synchronized (clients) {
        running = false;
        writeLock.unlock();
        try {
          clients.wait();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
 public int size() {
   return bindplistData.size();
 }
Exemple #8
0
 public int size() {
   return skillPanels.size();
 }
 public void report() {
   _log.info("Loaded: " + _transformations.size() + " transformations.");
 }
  /** Method load. */
  private void load() {
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setValidating(false);
      factory.setIgnoringComments(true);
      File file = new File(Config.DATAPACK_ROOT, "data/xml/other/cursed_weapons.xml");

      if (!file.exists()) {
        return;
      }

      Document doc = factory.newDocumentBuilder().parse(file);

      for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) {
        if ("list".equals(n.getNodeName())) {
          for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) {
            if ("item".equals(d.getNodeName())) {
              NamedNodeMap attrs = d.getAttributes();
              int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
              int skillId = Integer.parseInt(attrs.getNamedItem("skillId").getNodeValue());
              String name = "Unknown cursed weapon";

              if (attrs.getNamedItem("name") != null) {
                name = attrs.getNamedItem("name").getNodeValue();
              } else if (ItemHolder.getInstance().getTemplate(id) != null) {
                name = ItemHolder.getInstance().getTemplate(id).getName();
              }

              if (id == 0) {
                continue;
              }

              CursedWeapon cw = new CursedWeapon(id, skillId, name);

              for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling()) {
                if ("dropRate".equals(cd.getNodeName())) {
                  cw.setDropRate(
                      Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue()));
                } else if ("duration".equals(cd.getNodeName())) {
                  attrs = cd.getAttributes();
                  cw.setDurationMin(Integer.parseInt(attrs.getNamedItem("min").getNodeValue()));
                  cw.setDurationMax(Integer.parseInt(attrs.getNamedItem("max").getNodeValue()));
                } else if ("durationLost".equals(cd.getNodeName())) {
                  cw.setDurationLost(
                      Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue()));
                } else if ("disapearChance".equals(cd.getNodeName())) {
                  cw.setDisapearChance(
                      Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue()));
                } else if ("stageKills".equals(cd.getNodeName())) {
                  cw.setStageKills(
                      Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue()));
                } else if ("transformationId".equals(cd.getNodeName())) {
                  cw.setTransformationId(
                      Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue()));
                } else if ("transformationTemplateId".equals(cd.getNodeName())) {
                  cw.setTransformationTemplateId(
                      Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue()));
                } else if ("transformationName".equals(cd.getNodeName())) {
                  cw.setTransformationName(cd.getAttributes().getNamedItem("val").getNodeValue());
                }
              }

              _cursedWeaponsMap.put(id, cw);
            }
          }
        }
      }

      _cursedWeapons = _cursedWeaponsMap.values(new CursedWeapon[_cursedWeaponsMap.size()]);
    } catch (Exception e) {
      _log.error("CursedWeaponsManager: Error parsing cursed_weapons file. " + e);
    }
  }
 /** @return */
 public int size() {
   return _datatable.size();
 }