kingmert 0 Опубликовано 10 февраля, 2019 (изменено) i add the code its working l2jfrozen i need to add and Reward when the event finsihed and spawn the characters can help someone ????? Спойлер public class EventMonumentStatuet { public static EventMonumentStatuet _instance; public static L2Spawn PVP_SPAWN; public boolean inPeriodOk = true; private Map<Integer, int[]> startup_players; private PreparedStatement statement; public EventMonumentStatuet() { startup_players = new FastMap(); } public static EventMonumentStatuet getInstance() { if (_instance == null) { _instance = new EventMonumentStatuet(); } return _instance; } public void htmlPVPnpc(L2PcInstance pl) {} public void spawnStatuets() { spawnNpcPVP(); } private static void spawnNpcPVP() { L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(Config.NPC_TEMPLATE_ID_PVP); try { PVP_SPAWN = new L2Spawn(tmpl); PVP_SPAWN.setLocx(83215); PVP_SPAWN.setLocy(148393); PVP_SPAWN.setLocz(-3373); PVP_SPAWN.setAmount(1); PVP_SPAWN.setRespawnDelay(1); SpawnTable.getInstance().addNewSpawn(PVP_SPAWN, false); PVP_SPAWN.init(); PVP_SPAWN.getLastSpawn().getStatus().setCurrentHp(999999999.0D); PVP_SPAWN.getLastSpawn().isAggressive(); PVP_SPAWN.getLastSpawn().Monument_Npc_PVP = true; PVP_SPAWN.getLastSpawn().decayMe(); PVP_SPAWN.getLastSpawn().spawnMe(PVP_SPAWN.getLastSpawn().getX(), PVP_SPAWN.getLastSpawn().getY(), PVP_SPAWN.getLastSpawn().getZ()); PVP_SPAWN.getLastSpawn().broadcastPacket(new MagicSkillUser(PVP_SPAWN.getLastSpawn(), PVP_SPAWN.getLastSpawn(), 1034, 1, 1, 1)); System.out.println("[EventMonumentStatuet]:Statue pvp spawned."); } catch (Exception e) { System.out.println("[EventMonumentStatuet]:Fail to spawn statue pvp."); } } public void reloadAllNpc() { unspawnNpcPVP(); PVP_SPAWN = null; spawnNpcPVP(); } private static void unspawnNpcPVP() { if ((PVP_SPAWN == null) || (PVP_SPAWN.getLastSpawn() == null)) { return; } PVP_SPAWN.getLastSpawn().deleteMe(); PVP_SPAWN.stopRespawn(); SpawnTable.getInstance().deleteSpawn(PVP_SPAWN, true); } public void onEnterPlayer(L2PcInstance pl) { if ((inPeriodOk) && (startup_players.get(Integer.valueOf(pl.getObjectId())) == null)) { int[] stats = { pl.getObjectId(), pl.getPvpKills() }; startup_players.put(Integer.valueOf(pl.getObjectId()), stats); storeInDataInfo(pl); } } public void ConfiguratePereiod() { String hour = Config.RATE_HOUR_STATUET_REFRESH.split(":")[0]; String minutes = Config.RATE_HOUR_STATUET_REFRESH.split(":")[1]; int h = 0;int m = 0; long timeL = 0L; try { h = Integer.valueOf(hour).intValue(); m = Integer.valueOf(minutes).intValue(); Calendar currentTime = Calendar.getInstance(); Calendar testStartTime = Calendar.getInstance(); testStartTime.setLenient(true); testStartTime.set(11, h); testStartTime.set(12, m); testStartTime.set(13, 0); if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis()) { testStartTime.add(5, 1); } timeL = testStartTime.getTimeInMillis() - currentTime.getTimeInMillis(); ThreadPoolManager.getInstance().scheduleGeneral(new refreshStatuet(), timeL); System.out.println("[EventMonumentStatuet]Periodo to refresh statuet: " + testStartTime.getTime()); } catch (Exception e) { System.out.println("[EventMonumentStatuet]:ConfiguratePereiod()]Fail to load period"); e.printStackTrace(); } } private void storeInDataInfo(L2PcInstance pl) { Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("INSERT INTO monuments_startup (obj_id, pvp) VALUES (?, ? )"); statement.setInt(1, pl.getObjectId()); statement.setInt(2, pl.getPvpKills()); statement.execute(); statement.close(); } catch (Exception e) { System.out.println("[EventMonumentStatuet]Error in store!"); e.printStackTrace(); } finally { CloseUtil.close(con); con = null; } } public void load() { Connection con = null; String SQL = "SELECT obj_id, pvp FROM monuments_startup ORDER BY obj_id"; if (startup_players.isEmpty()) { startup_players.clear(); } try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(SQL); ResultSet rs = statement.executeQuery(); while (rs.next()) { int obj_id = rs.getInt("obj_id"); int pvp = rs.getInt("pvp"); int[] stats = { obj_id, pvp }; startup_players.put(Integer.valueOf(obj_id), stats); } statement.close(); rs.close(); System.out.println("[EventMonumentStatuet]Loaded " + startup_players.size() + " competitors."); } catch (Exception e) { System.out.println("[EventMonumentStatuet]Error in load competitors!"); e.printStackTrace(); } finally { CloseUtil.close(con); con = null; } } public void StartNewPeriod() { String monuments_startup_del = "TRUNCATE TABLE monuments_startup"; Connection con = null; statement = null; try { System.out.println("[EventMonumentStatuet]Delete all elements from table monuments_startup."); con = L2DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement(monuments_startup_del); statement.execute(); try { statement.close(); CloseUtil.close(con); con = null; statement = null; monuments_startup_del = null; } catch (Exception e) {} startup_players.clear(); } catch (Exception e) { System.out.println("[EventMonumentStatuet]Error in delete all elements from table monuments_startup."); e.printStackTrace(); } finally { try { statement.close(); CloseUtil.close(con); con = null; statement = null; monuments_startup_del = null; } catch (Exception e) {} } System.out.println("[EventMonumentStatuet]Adding all objects online."); int[] stats = new int[3]; for (L2PcInstance pl : L2World.getInstance().getAllPlayers()) { stats[0] = pl.getObjectId(); stats[1] = pl.getPvpKills(); startup_players.put(Integer.valueOf(pl.getObjectId()), stats); storeInDataInfo(pl); } System.out.println("[EventMonumentStatuet]Added " + startup_players.size() + " objects online."); } private class refreshStatuet implements Runnable { public refreshStatuet() {} public void run() { EventMonumentStatuet.this.inPeriodOk = false; EventMonumentStatuet.this.CalculateWins(); EventMonumentStatuet.this.StartNewPeriod(); EventMonumentStatuet.this.inPeriodOk = true; } } public void CalculateWins() { if (startup_players.size() <= 1) { System.out.println("[EventMonumentStatuet]:No participants in event, no statue formed."); return; } Connection con = null; String SQL = "SELECT obj_Id, pvpkills FROM characters WHERE"; int count = 0; for (int[] a : startup_players.values()) { SQL = SQL + (count == 0 ? " obj_Id=" + a[0] : new StringBuilder().append(" or obj_Id=").append(a[0]).toString()); count++; } int pvp_maior = 0; int[] obj_pvp = { 0, 0 }; System.out.println("[EventMonumentStatuet]:Calculando player wins."); try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(SQL); ResultSet rs = statement.executeQuery(); while (rs.next()) { int obj_id = rs.getInt("obj_id"); int pvp = rs.getInt("pvpkills"); int[] dados = (int[])startup_players.get(Integer.valueOf(obj_id)); int diference_pvp = pvp - dados[1]; if (diference_pvp > pvp_maior) { pvp_maior = diference_pvp; obj_pvp[0] = obj_id; obj_pvp[1] = diference_pvp; } } statement.close(); rs.close(); System.out.println("[EventMonumentStatuet]:Wins a pvp player:" + obj_pvp[0] + " with " + obj_pvp[1] + " differ."); } catch (Exception e) { System.out.println("[EventMonumentStatuet]Error in createPvpStatuet!"); e.printStackTrace(); } finally { CloseUtil.close(con); con = null; } createStatuet(obj_pvp); } private void createStatuet( int[] dados_pvp) { Connection con = null; Map<Integer, Items> items_mp_pvp = null; Map<Integer, Items> items_mp_pk = null; L2Item item = null; System.out.println("[EventMonumentStatuet]: Creating map items for: " + dados_pvp[0]); if (dados_pvp[0] != 0) { String SQL = "SELECT item_id, enchant_level FROM items WHERE owner_id=" + dados_pvp[0] + " AND loc='PAPERDOLL'"; items_mp_pvp = new FastMap(); try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement st = con.prepareStatement(SQL); ResultSet rs = st.executeQuery(); while (rs.next()) { int item_id = rs.getInt("item_id"); int enchant_level = rs.getInt("enchant_level"); item = ItemTable.getInstance().getTemplate(item_id); if (item != null) { if (item.getType2() == 0) { items_mp_pvp.put(Integer.valueOf(items_mp_pvp.size() + 1), new Weapon(item_id, enchant_level, item.getBodyPart())); } else if (item.getType2() == 2) { items_mp_pvp.put(Integer.valueOf(items_mp_pvp.size() + 1), new Acessory(item_id, item.getBodyPart())); } else if (item.getType2() == 1) { items_mp_pvp.put(Integer.valueOf(items_mp_pvp.size() + 1), new ArmororShield(item_id, item.getBodyPart())); } } } st.close(); st = null; rs.close(); rs = null; System.out.println("[EventMonumentStatuet]:Map Items pvp created with " + items_mp_pvp.size() + " items."); } catch (Exception e) { System.out.println("[EventMonumentStatuet]: Error in createStatuet 1:"); e.printStackTrace(); } finally { CloseUtil.close(con); con = null; } } if ((items_mp_pvp != null)) { System.out.println("[EventMonumentStatuet]:Calling data from the statue new MonumentCreator()"); MonumentCreator alpha = new MonumentCreator(); if (dados_pvp[0] != 0) { int[] dados_pvp_int = new int[3]; dados_pvp_int[0] = dados_pvp[0]; dados_pvp_int[1] = 1; dados_pvp_int[2] = dados_pvp[1]; alpha.create(dados_pvp_int, items_mp_pvp); alpha = null; } CustomNpcInstanceManager.getInstance().reload(); reloadAllNpc(); } } public class Items { int _item_id; int _slot; public Items(int item_id, int slot) { _item_id = item_id; _slot = slot; } public int getItemId() { return _item_id; } public int getItemSlot() { return _slot; } } public class Weapon extends EventMonumentStatuet.Items { int _enchant; public Weapon(int item_id, int enchant, int slot) { super(item_id, slot); System.out.println("Added weapon slot:" + slot); _enchant = enchant; } public int getItemEnchant() { return _enchant; } } public class ArmororShield extends EventMonumentStatuet.Items { public ArmororShield(int item_id, int slot) { super(item_id, slot); } } public class Acessory extends EventMonumentStatuet.Items { public Acessory(int item_id, int slot) { super(item_id, slot); } } } Изменено 11 февраля, 2019 пользователем JoeyTribbiani Поделиться сообщением Ссылка на сообщение Поделиться на другие сайты