Beispiel #1
0
  /** Method load. */
  public static void load() {
    VoteList.clear();

    try {
      File file = new File(Config.DATAPACK_ROOT, "data/xml/other/vote.xml");
      DocumentBuilderFactory factory2 = DocumentBuilderFactory.newInstance();
      factory2.setValidating(false);
      factory2.setIgnoringComments(true);
      Document doc2 = factory2.newDocumentBuilder().parse(file);

      for (Node n2 = doc2.getFirstChild(); n2 != null; n2 = n2.getNextSibling()) {
        if ("list".equals(n2.getNodeName())) {
          for (Node d2 = n2.getFirstChild(); d2 != null; d2 = d2.getNextSibling()) {
            if ("vote".equals(d2.getNodeName())) {
              Vote v = new Vote();
              v.id = Integer.parseInt(d2.getAttributes().getNamedItem("id").getNodeValue());
              v.maxPerAccount =
                  Integer.parseInt(d2.getAttributes().getNamedItem("maxPerAccount").getNodeValue());
              v.name = d2.getAttributes().getNamedItem("name").getNodeValue();
              v.active =
                  Boolean.parseBoolean(d2.getAttributes().getNamedItem("active").getNodeValue());

              for (Node i = d2.getFirstChild(); i != null; i = i.getNextSibling()) {
                if ("variant".equals(i.getNodeName())) {
                  v.variants.put(
                      Integer.parseInt(i.getAttributes().getNamedItem("id").getNodeValue()),
                      i.getAttributes().getNamedItem("desc").getNodeValue());
                }
              }

              VoteList.put(v.id, v);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    try (Connection con = DatabaseFactory.getInstance().getConnection(); ) {

      PreparedStatement st = con.prepareStatement("SELECT * FROM vote");
      ResultSet rs = st.executeQuery();

      while (rs.next()) {
        Vote v = VoteList.get(rs.getInt("id"));

        if (v != null) {
          String HWID = rs.getString("HWID");
          Integer[] rez = v.results.get(HWID);
          v.results.put(HWID, ArrayUtils.add(rez, rs.getInt("vote")));
        }
      }
      rs.close();
      st.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #2
0
  /**
   * Method vote.
   *
   * @param command String
   * @param activeChar Player
   * @param args String
   * @return boolean
   */
  @SuppressWarnings("unchecked")
  private boolean vote(String command, Player activeChar, String args) {
    if ((args != null) && !args.isEmpty()) {
      String[] param = args.split(" ");

      if ((param.length >= 2) && Util.isNumber(param[0]) && Util.isNumber(param[1])) {
        String playerId = activeChar.getAccountName();
        Vote v = VoteList.get(Integer.parseInt(param[0]));

        if ((v == null) || !v.active) {
          return false;
        }

        int var = Integer.parseInt(param[1]);
        Integer[] alreadyResults = v.results.get(playerId);

        if (alreadyResults == null) {
          v.results.put(playerId, new Integer[] {var});
          mysql.set(
              "INSERT IGNORE INTO vote (`id`, `HWID`, `vote`) VALUES (?,?,?)",
              param[0],
              playerId,
              param[1]);
        } else if (alreadyResults.length < v.maxPerAccount) {
          for (int id : alreadyResults) {
            if (id == var) {
              show("Error: you have already voted for this entry.", activeChar);
              return false;
            }
          }

          v.results.put(playerId, ArrayUtils.add(alreadyResults, var));
          mysql.set(
              "INSERT IGNORE INTO vote (`id`, `HWID`, `vote`) VALUES (?,?,?)",
              param[0],
              playerId,
              param[1]);
        } else {
          show("Error: you have reached votes limit.", activeChar);
          return false;
        }
      }
    }

    int count = 0;
    StringBuilder html = new StringBuilder("!Vote Manager:\n<br>");
    String playerId = activeChar.getAccountName();

    for (Entry<Integer, Vote> e : VoteList.entrySet()) {
      if (e.getValue().active) {
        count++;
        html.append(e.getValue().name).append(":<br>");
        Integer[] already = e.getValue().results.get(playerId);

        if ((already != null) && (already.length >= e.getValue().maxPerAccount)) {
          html.append("You have already voted.<br>");
        } else {
          Entry<Integer, String>[] variants = new Entry[e.getValue().variants.size()];
          int i = 0;

          for (Entry<Integer, String> variant : e.getValue().variants.entrySet()) {
            variants[i] = variant;
            i++;
          }

          shuffle(variants);
          variants:
          for (Entry<Integer, String> variant : variants) {
            if (already != null) {
              for (Integer et : already) {
                if (et.equals(variant.getKey())) {
                  continue variants;
                }
              }
            }

            html.append(
                "[user_vote "
                    + e.getValue().id
                    + " "
                    + variant.getKey()
                    + "|"
                    + variant.getValue()
                    + "]<br1>");
          }

          html.append("<br>");
        }
      }
    }

    if (count == 0) {
      html.append("No active votes now.");
    }

    show(html.toString(), activeChar);
    return true;
  }
Beispiel #3
0
/**
 * @author Mobius
 * @version $Revision: 1.0 $
 */
public final class YehanBrother extends Fighter {
  private long _spawnTimer = 0;
  private static final int[] _minions = ArrayUtils.createAscendingArray(22509, 22512);

  /**
   * Constructor for YehanBrother.
   *
   * @param actor NpcInstance
   */
  public YehanBrother(NpcInstance actor) {
    super(actor);
  }

  /** Method onEvtSpawn. */
  @Override
  protected void onEvtSpawn() {
    super.onEvtSpawn();
    _spawnTimer = System.currentTimeMillis();
  }

  /**
   * Method getBrother.
   *
   * @return NpcInstance
   */
  private NpcInstance getBrother() {
    final NpcInstance actor = getActor();
    int brotherId = 0;

    if (actor.getId() == 25665) {
      brotherId = 25666;
    } else if (actor.getId() == 25666) {
      brotherId = 25665;
    }

    for (NpcInstance npc : actor.getReflection().getNpcs()) {
      if (npc.getId() == brotherId) {
        return npc;
      }
    }

    return null;
  }

  /** Method thinkAttack. */
  @Override
  protected void thinkAttack() {
    final NpcInstance actor = getActor();
    final NpcInstance brother = getBrother();

    if (!brother.isDead() && !actor.isInRange(brother, 300)) {
      actor.altOnMagicUseTimer(getActor(), SkillTable.getInstance().getInfo(6371, 1));
    } else {
      removeInvul(actor);
    }

    if ((_spawnTimer + 40000) < System.currentTimeMillis()) {
      _spawnTimer = System.currentTimeMillis();
      final NpcInstance mob =
          actor
              .getReflection()
              .addSpawnWithoutRespawn(
                  _minions[Rnd.get(_minions.length)], Location.findAroundPosition(actor, 300), 0);
      mob.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, actor.getAggressionTarget(), 1000);
    }

    super.thinkAttack();
  }

  /**
   * Method removeInvul.
   *
   * @param npc NpcInstance
   */
  private void removeInvul(NpcInstance npc) {
    for (Effect e : npc.getEffectList().getAllEffects()) {
      if (e.getSkill().getId() == 6371) {
        e.exit();
      }
    }
  }
}