Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver405
- diff --git config/players.properties config/players.properties
- index 99e7087..863c6c5 100644
- --- config/players.properties
- +++ config/players.properties
- @@ -259,6 +259,22 @@
- # Store buffs/debuffs on user logout. Default: True
- StoreSkillCooltime = True
- +
- +
- +#==========================================================================
- +# RANDOM CRAFT SYSTEM NPC - ID - CONSUME - REFRESH - CREATE - ITEMS
- +#==========================================================================
- +
- +RandomCraftItemId = 57
- +
- +RandomCraftConsumeRefresh = 50000
- +
- +RandromCraftConsumeCreate = 300000
- +
- +
- +
- +
- +
- # DressMe system.
- AllowDressMeSystem = True
- diff --git java/Base/Data/IconTable.java java/Base/Data/IconTable.java
- new file mode 100644
- index 0000000..fdce5d7
- --- /dev/null
- +++ java/Base/Data/IconTable.java
- @@ -0,0 +1,62 @@
- +package Base.Data;
- +
- +import java.io.File;
- +import java.util.HashMap;
- +import java.util.Map;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +
- +public class IconTable extends XMLDocument
- +{
- + private static final Map<Integer, String> itemIcons = new HashMap<>();
- +
- + public IconTable()
- + {
- + load();
- + }
- +
- + @Override
- + protected void load()
- + {
- + loadDocument("./data/xml/icons.xml");
- + LOG.info("Loaded " + itemIcons.size() + " icons.");
- + }
- +
- + @Override
- + protected void parseDocument(Document doc, File f)
- + {
- + // First element is never read.
- + final Node n = doc.getFirstChild();
- +
- + for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
- + {
- + if (!"icon".equalsIgnoreCase(o.getNodeName()))
- + {
- + continue;
- + }
- +
- + final NamedNodeMap attrs = o.getAttributes();
- + final int itemId = Integer.valueOf(attrs.getNamedItem("Id").getNodeValue());
- + final String value = String.valueOf(attrs.getNamedItem("value").getNodeValue());
- +
- + itemIcons.put(itemId, value);
- + }
- + }
- +
- + public String getIcon(int id)
- + {
- + return itemIcons.get(id) == null ? "icon.noimage" : itemIcons.get(id);
- + }
- +
- + public static IconTable getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final IconTable _instance = new IconTable();
- + }
- +}
- diff --git java/Base/Data/XMLDocument.java java/Base/Data/XMLDocument.java
- new file mode 100644
- index 0000000..7ba3079
- --- /dev/null
- +++ java/Base/Data/XMLDocument.java
- @@ -0,0 +1,119 @@
- +package Base.Data;
- +
- +import java.io.File;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilderFactory;
- +import javax.xml.transform.OutputKeys;
- +import javax.xml.transform.Transformer;
- +import javax.xml.transform.TransformerException;
- +import javax.xml.transform.TransformerFactory;
- +import javax.xml.transform.dom.DOMSource;
- +import javax.xml.transform.stream.StreamResult;
- +
- +import net.sf.l2j.commons.data.StatSet;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +
- +/**
- + * An XML document, relying on a static and single DocumentBuilderFactory.
- + */
- +public abstract class XMLDocument
- +{
- + protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
- +
- + protected Document document;
- +
- + private static final DocumentBuilderFactory BUILDER;
- + static
- + {
- + BUILDER = DocumentBuilderFactory.newInstance();
- + BUILDER.setValidating(false);
- + BUILDER.setIgnoringComments(true);
- + }
- +
- + abstract protected void load();
- +
- + abstract protected void parseDocument(Document doc, File f);
- +
- + public void loadDocument(String filePath)
- + {
- + loadDocument(new File(filePath));
- + }
- +
- + public void writeDocument(Document doc, String fileName)
- + {
- + try
- + {
- + TransformerFactory transformerFactory = TransformerFactory.newInstance();
- + Transformer transformer = transformerFactory.newTransformer();
- + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- + transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- +
- + DOMSource source = new DOMSource(doc);
- + StreamResult result = new StreamResult(new File(fileName));
- +
- + transformer.transform(source, result);
- + LOG.info("XML file saved to " + fileName);
- + }
- + catch (TransformerException e)
- + {
- + LOG.warning("Error saving XML file: " + e.getMessage());
- + }
- + }
- +
- + /**
- + * Parse an entire directory or file if found.
- + * @param file
- + */
- + public void loadDocument(File file)
- + {
- + if (!file.exists())
- + {
- + LOG.severe("The following file or directory doesn't exist: " + file.getName());
- + return;
- + }
- +
- + if (file.isDirectory())
- + {
- + for (File f : file.listFiles())
- + {
- + loadDocument(f);
- + }
- + }
- + else if (file.isFile())
- + {
- + try
- + {
- + parseDocument(BUILDER.newDocumentBuilder().parse(file), file);
- + }
- + catch (Exception e)
- + {
- + LOG.log(Level.SEVERE, "Error loading XML file " + file.getName(), e);
- + }
- + }
- + }
- +
- + public Document getDocument()
- + {
- + return document;
- + }
- +
- + /**
- + * This method parses the content of a NamedNodeMap and feed the given StatsSet.
- + * @param attrs : The NamedNodeMap to parse.
- + * @param set : The StatsSet to feed.
- + */
- + public static void parseAndFeed(NamedNodeMap attrs, StatSet set)
- + {
- + for (int i = 0; i < attrs.getLength(); i++)
- + {
- + final Node attr = attrs.item(i);
- + set.set(attr.getNodeName(), attr.getNodeValue());
- + }
- + }
- +}
- diff --git java/Base/RandomCraft/RandomCraftItem.java java/Base/RandomCraft/RandomCraftItem.java
- new file mode 100644
- index 0000000..088d66f
- --- /dev/null
- +++ java/Base/RandomCraft/RandomCraftItem.java
- @@ -0,0 +1,50 @@
- +package Base.RandomCraft;
- +
- +import net.sf.l2j.gameserver.data.xml.ItemData;
- +import net.sf.l2j.gameserver.model.item.kind.Item;
- +
- +public class RandomCraftItem
- +{
- + private int id;
- + private int cantidad;
- + private double probabilidad;
- + private boolean announce;
- +
- + public RandomCraftItem(int id, int cantidad, double probabilidad, boolean announce)
- + {
- + this.id = id;
- + this.cantidad = cantidad;
- + this.probabilidad = probabilidad;
- + this.announce = announce;
- + }
- +
- + public int getId()
- + {
- + return id;
- + }
- +
- + public int getCantidad()
- + {
- + return cantidad;
- + }
- +
- + public double getProbabilidad()
- + {
- + return probabilidad;
- + }
- +
- + public boolean getAnnounce()
- + {
- + return announce;
- + }
- +
- + public String getIcon()
- + {
- + return getItem().getIcon();
- + }
- +
- + public Item getItem()
- + {
- + return ItemData.getInstance().getTemplate(id);
- + }
- +}
- diff --git java/Base/RandomCraft/RandomCraftXML.java java/Base/RandomCraft/RandomCraftXML.java
- new file mode 100644
- index 0000000..0f2672d
- --- /dev/null
- +++ java/Base/RandomCraft/RandomCraftXML.java
- @@ -0,0 +1,80 @@
- +package Base.RandomCraft;
- +
- +import java.io.File;
- +import java.util.HashMap;
- +import java.util.Map;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +
- +import Base.Data.XMLDocument;
- +
- +public class RandomCraftXML extends XMLDocument
- +{
- + private Map<Integer, RandomCraftItem> items;
- +
- + public RandomCraftXML()
- + {
- + items = new HashMap<>();
- + load();
- + }
- +
- + public static RandomCraftXML getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final RandomCraftXML INSTANCE = new RandomCraftXML();
- + }
- +
- + @Override
- + protected void load()
- + {
- + loadDocument("./data/xml/RandomCraft.xml");
- + LOG.info("RandomCraftItemData: Loaded " + items.size() + " items.");
- + }
- +
- + @Override
- + protected void parseDocument(Document doc, File file)
- + {
- + try
- + {
- + final Node root = doc.getFirstChild();
- +
- + for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling())
- + {
- + if (!"item".equalsIgnoreCase(node.getNodeName()))
- + {
- + continue;
- + }
- +
- + NamedNodeMap attrs = node.getAttributes();
- + int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
- + int cantidad = Integer.parseInt(attrs.getNamedItem("count").getNodeValue());
- + double probabilidad = Double.parseDouble(attrs.getNamedItem("chance").getNodeValue());
- + boolean announce = Boolean.parseBoolean(attrs.getNamedItem("announce").getNodeValue());
- +
- + RandomCraftItem item = new RandomCraftItem(id, cantidad, probabilidad, announce);
- + items.put(id, item);
- + }
- + }
- + catch (Exception e)
- + {
- + // LOG.warning("RandomCraftItemData: Error while loading items: " + e);
- + e.printStackTrace();
- + }
- + }
- +
- + public Map<Integer, RandomCraftItem> getItems()
- + {
- + return items;
- + }
- +
- + public RandomCraftItem getItemById(int id)
- + {
- + return items.get(id);
- + }
- +}
- diff --git java/net/sf/l2j/Config.java java/net/sf/l2j/Config.java
- index a0fde2e..30397a1 100644
- --- java/net/sf/l2j/Config.java
- +++ java/net/sf/l2j/Config.java
- @@ -49,6 +49,16 @@
- // Clans settings
- // --------------------------------------------------
- +
- +
- + public static int RANDOM_CRAFT_ITEM_ID_CONSUME;
- + public static int RANDOM_CRAFT_ITEM_CONSUME_REFRESH;
- + public static int RANDOM_CRAFT_ITEM_CONSUME_CREATE;
- +
- +
- +
- +
- +
- /** Clans */
- public static int CLAN_JOIN_DAYS;
- public static int CLAN_CREATE_DAYS;
- @@ -963,6 +973,13 @@
- HP_REGEN_MULTIPLIER = players.getProperty("HpRegenMultiplier", 1.);
- MP_REGEN_MULTIPLIER = players.getProperty("MpRegenMultiplier", 1.);
- CP_REGEN_MULTIPLIER = players.getProperty("CpRegenMultiplier", 1.);
- +
- + RANDOM_CRAFT_ITEM_ID_CONSUME = players.getProperty("RandomCraftItemId", 57);
- +
- + RANDOM_CRAFT_ITEM_CONSUME_REFRESH = players.getProperty("RandomCraftConsumeRefresh", 50000);
- +
- + RANDOM_CRAFT_ITEM_CONSUME_CREATE = players.getProperty("RandromCraftConsumeCreate", 300000);
- +
- PLAYER_SPAWN_PROTECTION = players.getProperty("PlayerSpawnProtection", 0);
- PLAYER_FAKEDEATH_UP_PROTECTION = players.getProperty("PlayerFakeDeathUpProtection", 5);
- RESPAWN_RESTORE_HP = players.getProperty("RespawnRestoreHP", 0.7);
- diff --git java/net/sf/l2j/gameserver/GameServer.java java/net/sf/l2j/gameserver/GameServer.java
- index 29763e0..e7cc44c 100644
- --- java/net/sf/l2j/gameserver/GameServer.java
- +++ java/net/sf/l2j/gameserver/GameServer.java
- @@ -102,6 +102,8 @@
- import net.sf.l2j.util.DeadLockDetector;
- import net.sf.l2j.util.IPv4Filter;
- +import Base.Data.IconTable;
- +import Base.RandomCraft.RandomCraftXML;
- import Base.Skin.DressMeData;
- public class GameServer
- @@ -266,6 +268,11 @@
- StringUtil.printSection("Spawns");
- SpawnManager.getInstance().spawn();
- + IconTable.getInstance();
- +
- + StringUtil.printSection("RandomCraft - Terius");
- + RandomCraftXML.getInstance();
- +
- StringUtil.printSection("Handlers");
- LOGGER.info("Loaded {} admin command handlers.", AdminCommandHandler.getInstance().size());
- LOGGER.info("Loaded {} chat handlers.", ChatHandler.getInstance().size());
- diff --git java/net/sf/l2j/gameserver/model/actor/Player.java java/net/sf/l2j/gameserver/model/actor/Player.java
- index 8610748..35bca86 100644
- --- java/net/sf/l2j/gameserver/model/actor/Player.java
- +++ java/net/sf/l2j/gameserver/model/actor/Player.java
- @@ -228,6 +228,7 @@
- import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
- import net.sf.l2j.gameserver.taskmanager.WaterTaskManager;
- +import Base.RandomCraft.RandomCraftItem;
- import Base.Skin.DressMeData;
- /**
- @@ -319,6 +320,8 @@
- protected int _activeClass;
- protected int _classIndex;
- + private List<RandomCraftItem> generatedCraftItems;
- +
- private final Map<Integer, SubClass> _subClasses = new ConcurrentSkipListMap<>();
- private final ReentrantLock _subclassLock = new ReentrantLock();
- @@ -7368,6 +7371,8 @@
- return false;
- }
- +
- +
- @Override
- public void unpolymorph()
- {
- @@ -7375,6 +7380,25 @@
- sendPacket(new UserInfo(this));
- }
- +
- + public List<RandomCraftItem> getGeneratedCraftItems()
- + {
- + return generatedCraftItems;
- + }
- +
- + public void setGeneratedCraftItems(List<RandomCraftItem> items)
- + {
- + generatedCraftItems = items;
- + }
- +
- + public void clearGeneratedCraftItems()
- + {
- + generatedCraftItems.clear();
- + }
- +
- +
- +
- +
- @Override
- public void addKnownObject(WorldObject object)
- {
- diff --git java/net/sf/l2j/gameserver/model/actor/instance/RandomCraft.java java/net/sf/l2j/gameserver/model/actor/instance/RandomCraft.java
- new file mode 100644
- index 0000000..2be171d
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/model/actor/instance/RandomCraft.java
- @@ -0,0 +1,524 @@
- +package net.sf.l2j.gameserver.model.actor.instance;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.ArrayList;
- +import java.util.LinkedList;
- +import java.util.List;
- +import java.util.Map;
- +import java.util.Random;
- +
- +import net.sf.l2j.commons.pool.ConnectionPool;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.model.World;
- +import net.sf.l2j.gameserver.model.actor.Npc;
- +import net.sf.l2j.gameserver.model.actor.Player;
- +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
- +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
- +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
- +import net.sf.l2j.gameserver.network.serverpackets.ItemList;
- +import net.sf.l2j.gameserver.network.serverpackets.MoveToPawn;
- +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- +import Base.RandomCraft.RandomCraftItem;
- +import Base.RandomCraft.RandomCraftXML;
- +
- +/**
- + * @author Terius
- + */
- +
- +public class RandomCraft extends Npc
- +{
- + private boolean hasGeneratedItems;
- + List<RandomCraftItem> items = new LinkedList<>();
- +
- + public RandomCraft(int objectId, NpcTemplate template)
- + {
- + super(objectId, template);
- + setHasGeneratedItems(false);
- + }
- +
- +
- + @Override
- + public void onInteract(Player player)
- + {
- + // Rotate the player to face the instance
- + player.sendPacket(new MoveToPawn(player, this, Npc.INTERACTION_DISTANCE));
- +
- + if (hasRandomAnimation())
- + {
- + onRandomAnimation(1);
- + }
- +
- + loadGeneratedItems(player);
- +
- + showHtmlWindow(player);
- +
- + // Enviar ActionFailed al jugador para evitar quedarse atascado
- + player.sendPacket(ActionFailed.STATIC_PACKET);
- + }
- +
- +
- +
- +
- + @Override
- + public void onBypassFeedback(Player player, String command)
- + {
- + if (command.startsWith("refresh"))
- + {
- + // Verifique si el jugador tiene el artículo requerido (ID 57) y la cantidad (50000)
- + ItemInstance item57 = player.getInventory().getItemByItemId(Config.RANDOM_CRAFT_ITEM_ID_CONSUME);
- + if (item57 != null && item57.getCount() >= Config.RANDOM_CRAFT_ITEM_CONSUME_REFRESH)
- + {
- + // Cargue al jugador el artículo requerido (ID 57) y la cantidad (50000)
- + player.getInventory().destroyItemByItemId("Random Craft", Config.RANDOM_CRAFT_ITEM_ID_CONSUME, Config.RANDOM_CRAFT_ITEM_CONSUME_REFRESH, player, this);
- +
- + generateItems(player);
- +
- + player.sendPacket(new ItemList(player, true));
- +
- + showHtmlWindow(player);
- +
- + // Almacene los elementos generados en la base de datos para el jugador
- + saveGeneratedItems(player);
- + }
- + else
- + {
- + player.sendMessage("Necesitas al menos 50000 Adena para actualizar Random Craft.");
- + }
- + }
- + else if (command.startsWith("create"))
- + {
- + // Eliminar los elementos generados para el jugador de la tabla RandomCraftItem
- + deleteGeneratedItems(player);
- +
- + createItem(player);
- +
- + // showHtmlWindow(player);
- + }
- +
- + else if (command.startsWith("back"))
- + {
- +
- + showHtmlWindow(player);
- + }
- +
- + }
- +
- + private void generateItems(Player player)
- + {
- + List<RandomCraftItem> items = new LinkedList<>();
- + RandomCraftXML randomCraftXML = RandomCraftXML.getInstance();
- + Map<Integer, RandomCraftItem> craftItems = randomCraftXML.getItems();
- +
- + // Genera 4 elementos únicos para cada jugador en función de la probabilidad
- + List<Integer> selectedItems = new ArrayList<>();
- + while (selectedItems.size() < 4)
- + {
- + int itemId = getRandomItem(craftItems);
- + if (!selectedItems.contains(itemId))
- + {
- + selectedItems.add(itemId);
- + items.add(craftItems.get(itemId));
- + }
- + }
- +
- + // Asignar los elementos generados al jugador
- + player.setGeneratedCraftItems(items);
- + setHasGeneratedItems(true);
- +
- + }
- +
- + private static void deleteGeneratedItems(Player player)
- + {
- + try (Connection con = ConnectionPool.getConnection();
- + PreparedStatement stmt = con.prepareStatement("DELETE FROM RandomCraftItem WHERE object_id = ?"))
- + {
- + stmt.setInt(1, player.getObjectId());
- + stmt.execute();
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + private static void saveGeneratedItems(Player player)
- + {
- + try (Connection con = ConnectionPool.getConnection();
- + PreparedStatement stmt = con.prepareStatement("DELETE FROM RandomCraftItem WHERE object_id = ?"))
- + {
- + stmt.setInt(1, player.getObjectId());
- + stmt.execute();
- +
- + try (PreparedStatement insertStmt = con.prepareStatement("INSERT INTO RandomCraftItem (object_id, item_id, amount, chance, announce) VALUES (?, ?, ?, ?, ?)"))
- + {
- + insertStmt.setInt(1, player.getObjectId());
- + List<RandomCraftItem> items = player.getGeneratedCraftItems();
- + if (items != null)
- + {
- + for (RandomCraftItem item : items)
- + {
- + insertStmt.setInt(2, item.getId());
- + insertStmt.setInt(3, item.getCantidad());
- + insertStmt.setDouble(4, item.getProbabilidad());
- + insertStmt.setBoolean(5, item.getAnnounce());
- + insertStmt.addBatch(); // Agregar la consulta al lote (batch)
- + }
- + insertStmt.executeBatch(); // Ejecutar el lote de consultas
- + }
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + private void loadGeneratedItems(Player player)
- + {
- + try (Connection con = ConnectionPool.getConnection();
- + PreparedStatement stmt = con.prepareStatement("SELECT item_id, amount, chance, announce FROM RandomCraftItem WHERE object_id = ?"))
- + {
- + stmt.setInt(1, player.getObjectId());
- +
- + try (ResultSet rset = stmt.executeQuery())
- + {
- + List<RandomCraftItem> items = new LinkedList<>();
- + while (rset.next())
- + {
- + int itemId = rset.getInt("item_id");
- + int amount = rset.getInt("amount");
- + int chance = rset.getInt("chance");
- + boolean announce = rset.getBoolean("announce");
- + RandomCraftItem item = new RandomCraftItem(itemId, amount, chance, announce);
- + items.add(item);
- + }
- +
- + player.setGeneratedCraftItems(items);
- + setHasGeneratedItems(!items.isEmpty());
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + private static int getRandomItem(Map<Integer, RandomCraftItem> craftItems)
- + {
- + // Calcular la suma de probabilidad total
- + double totalProbability = 0;
- + for (RandomCraftItem item : craftItems.values())
- + {
- + totalProbability += item.getProbabilidad();
- + }
- +
- + // Generar un valor aleatorio entre 0 y la probabilidad total
- + Random random = new Random();
- + double randomValue = random.nextDouble() * totalProbability;
- +
- + // Seleccione el elemento en función de la probabilidad
- + double cumulativeProbability = 0;
- + for (RandomCraftItem item : craftItems.values())
- + {
- + cumulativeProbability += item.getProbabilidad();
- + if (randomValue <= cumulativeProbability)
- + {
- + return item.getId();
- + }
- + }
- +
- + // Si no se selecciona ningún artÃculo, devolver un artÃculo al azar
- + List<Integer> itemIds = new ArrayList<>(craftItems.keySet());
- + int index = random.nextInt(itemIds.size());
- + return itemIds.get(index);
- + }
- +
- + private void createItem(Player player)
- + {
- + // Comprueba si la lista de elementos está vacía
- + List<RandomCraftItem> items = player.getGeneratedCraftItems();
- + if (items == null || items.isEmpty())
- + {
- + player.sendMessage("Necesita actualizar para poder crear un elemento aleatorio.");
- + return;
- + }
- +
- + // Obtén un elemento aleatorio de la lista de elementos generados
- + Random random = new Random();
- + int index = random.nextInt(items.size());
- + RandomCraftItem craftItem = items.get(index);
- +
- + // Carga al jugador el artículo con ID 57 y cantidad 300000
- + ItemInstance item57 = player.getInventory().getItemByItemId(Config.RANDOM_CRAFT_ITEM_ID_CONSUME);
- + if (item57 != null && item57.getCount() >= Config.RANDOM_CRAFT_ITEM_CONSUME_CREATE)
- + {
- + player.getInventory().destroyItemByItemId("Random Craft", Config.RANDOM_CRAFT_ITEM_ID_CONSUME, Config.RANDOM_CRAFT_ITEM_CONSUME_CREATE, player, this);
- +
- + // Da el artículo al jugador
- + ItemInstance itemInstance = player.getInventory().addItem("Random Craft", craftItem.getId(), craftItem.getCantidad(), player, this);
- + if (itemInstance != null)
- + {
- + player.sendPacket(new ItemList(player, true));
- +
- + // Envía un mensaje al jugador con el nombre del artículo y la cantidad.
- + String message = "¡Felicidades! Has recibido " + craftItem.getItem().getName() + " (Cantidad: " + craftItem.getCantidad() + ")";
- + player.sendMessage(message);
- +
- + // Obtén el nombre del jugador que creó el elemento
- + String creatorName = player.getName();
- +
- + // Comprueba si el artículo tiene announce en true en el archivo XML
- + if (craftItem.getAnnounce())
- + {
- +
- + for (Player players : World.getInstance().getPlayers())
- + {
- +
- + String text = creatorName + " Ha Crafteado: " + craftItem.getItem().getName() + " En el RandomCraft System";
- +
- + players.sendPacket(new ExShowScreenMessage(text, 12000));
- +
- + }
- +
- + }
- +
- + // Borra la lista de elementos para el jugador
- + player.clearGeneratedCraftItems();
- + setHasGeneratedItems(false);
- +
- + // Muestra la ventana de felicitaciones con el item ganador
- + showCongratulationsWindow(player, craftItem);
- +
- + return;
- + }
- + }
- +
- + player.sendMessage("Necesitas al menos 300000 Adena para crear un elemento aleatorio.");
- + }
- +
- + private void showHtmlWindow(Player player)
- + {
- + StringBuilder html = new StringBuilder();
- + html.append("<html><body>");
- + html.append("<center>Bienvenido a Random Craft System!</center>");
- + html.append("<br>");
- + html.append("<center>Podras Crear 1 item entre los 4 que salgan random!</center>");
- + html.append("<br>");
- + html.append("<center>Les Deseo Mucha Suerte</center>");
- + html.append("<br>");
- + html.append("<br>");
- +
- + List<RandomCraftItem> items = player.getGeneratedCraftItems();
- + if (items == null || items.isEmpty())
- + {
- + html.append("<center>La Lista Esta Vacia Dale a Refresh</center>");
- + }
- + else
- + {
- + // Generar los iconos de los artículos en forma horizontal
- + for (RandomCraftItem item : items)
- + {
- + html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
- + html.append("<div align=center>");
- + html.append("<table>");
- + html.append("<tr>");
- + html.append("<td>");
- + html.append("<img src=").append(item.getIcon()).append(" width=32 height=32>");
- + html.append("</td>");
- + html.append("<td width=260>");
- + html.append("<font color=LEVEL>").append(item.getItem().getName()).append("</font>");
- +
- + html.append("</td>");
- + html.append("</tr>");
- + html.append("</table>");
- + html.append("</div>");
- + html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
- + html.append("<br>");
- + }
- + }
- +
- + html.append("<br>");
- + html.append("<br>");
- + html.append("<center>");
- + html.append("<table>");
- + html.append("<tr>");
- + html.append("<td width=75 height=21>");
- + html.append("<button value=\"Refresh\" action=\"bypass -h npc_").append(getObjectId()).append("_refresh\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">");
- + html.append("</td>");
- + html.append("<td width=75 height=21>");
- + html.append("<button value=\"Create\" action=\"bypass -h npc_").append(getObjectId()).append("_create\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">");
- + html.append("</td>");
- + html.append("</tr>");
- + html.append("</table>");
- + html.append("</center>");
- +
- + html.append("</body></html>");
- +
- + showHtmlWindow(player, html.toString());
- + }
- +
- + private void showHtmlWindow(Player player, String htmlContent)
- + {
- + NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- + html.setHtml(htmlContent);
- +
- + player.sendPacket(html);
- + }
- +
- + private void showCongratulationsWindow(Player player, RandomCraftItem craftItem)
- + {
- + StringBuilder html = new StringBuilder();
- +
- + html.append("<html><body>");
- + html.append("<center>Felicidades, has ganado un item</center>");
- + html.append("<br>");
- + html.append("<center>¡Has recibido</center>");
- + html.append("<br>");
- + html.append("<br>");
- + html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
- + html.append("<center>");
- + html.append("<table>");
- + html.append("<tr>");
- + html.append("<td>");
- + html.append("<img src=").append(craftItem.getIcon()).append(" width=32 height=32>");
- + html.append("</td>");
- + html.append("<td width=260>");
- + html.append("<font color=LEVEL>").append(craftItem.getItem().getName()).append("</font>");
- + html.append("</td>");
- + html.append("</tr>");
- + html.append("</table>");
- + html.append("</center>");
- + html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
- + html.append("<br>");
- + html.append("<br>");
- + html.append("<br>");
- + html.append("<br>");
- + html.append("<center>");
- + html.append("<button value=\"Back\" action=\"bypass -h npc_").append(getObjectId()).append("_back\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">");
- + html.append("</center>");
- + html.append("</body></html>");
- +
- + showHtmlWindow(player, html.toString());
- + }
- +
- + /**
- + * @return the hasGeneratedItems
- + */
- + public boolean isHasGeneratedItems()
- + {
- + return hasGeneratedItems;
- + }
- +
- + /**
- + * @param hasGeneratedItems the hasGeneratedItems to set
- + */
- + public void setHasGeneratedItems(boolean hasGeneratedItems)
- + {
- + this.hasGeneratedItems = hasGeneratedItems;
- + }
- +}
- diff --git java/net/sf/l2j/gameserver/model/item/kind/Item.java java/net/sf/l2j/gameserver/model/item/kind/Item.java
- index 9c641b1..054e694 100644
- --- java/net/sf/l2j/gameserver/model/item/kind/Item.java
- +++ java/net/sf/l2j/gameserver/model/item/kind/Item.java
- @@ -34,6 +34,8 @@
- import net.sf.l2j.gameserver.skills.basefuncs.FuncTemplate;
- import net.sf.l2j.gameserver.skills.conditions.Condition;
- +import Base.Data.IconTable;
- +
- /**
- * This container contains all informations concerning an item (weapon, armor, etc).
- */
- @@ -531,6 +533,16 @@
- return _defaultAction;
- }
- +
- + public String getIcon()
- + {
- + return IconTable.getInstance().getIcon(getItemId());
- + }
- +
- +
- +
- +
- +
- /**
- * Returns the name of the item
- * @return String
- diff --git server/gameserver/data/xml/RandomCraft.xml server/gameserver/data/xml/RandomCraft.xml
- new file mode 100644
- index 0000000..ff31b12
- --- /dev/null
- +++ server/gameserver/data/xml/RandomCraft.xml
- @@ -0,0 +1,38 @@
- +<?xml version="1.0" encoding="UTF-8"?>
- +<rewards>
- + <item id="5644" count="1" chance="25" announce="false"/>
- + <item id="5704" count="1" chance="25" announce="false"/>
- + <item id="5706" count="1" chance="25" announce="false"/>
- + <item id="5709" count="1" chance="10" announce="false"/>
- + <item id="5714" count="1" chance="10" announce="false"/>
- + <item id="5715" count="1" chance="10" announce="false"/>
- + <item id="5720" count="1" chance="10" announce="false"/>
- + <item id="5727" count="1" chance="10" announce="false"/>
- + <item id="5765" count="1" chance="15" announce="false"/>
- + <item id="5766" count="1" chance="15" announce="false"/>
- + <item id="5767" count="1" chance="15" announce="false"/>
- + <item id="5768" count="1" chance="15" announce="false"/>
- + <item id="5769" count="1" chance="15" announce="false"/>
- + <item id="5770" count="1" chance="20" announce="false"/>
- + <item id="5771" count="1" chance="15" announce="false"/>
- + <item id="5772" count="1" chance="15" announce="false"/>
- + <item id="5773" count="1" chance="15" announce="false"/>
- + <item id="5774" count="1" chance="15" announce="false"/>
- + <item id="5775" count="1" chance="15" announce="false"/>
- + <item id="5776" count="1" chance="15" announce="false"/>
- + <item id="5777" count="1" chance="15" announce="false"/>
- + <item id="5778" count="1" chance="15" announce="false"/>
- + <item id="5779" count="1" chance="15" announce="false"/>
- + <item id="5780" count="1" chance="20" announce="false"/>
- + <item id="5781" count="1" chance="20" announce="false"/>
- + <item id="5782" count="1" chance="20" announce="false"/>
- + <item id="5783" count="1" chance="20" announce="false"/>
- + <item id="5784" count="1" chance="20" announce="false"/>
- + <item id="5785" count="1" chance="20" announce="false"/>
- + <item id="5787" count="1" chance="20" announce="false"/>
- + <item id="6367" count="1" chance="25" announce="false"/>
- + <item id="6372" count="1" chance="25" announce="false"/>
- + <item id="6373" count="1" chance="2" announce="true"/>
- + <item id="6374" count="1" chance="2" announce="true"/>
- + <item id="6375" count="1" chance="2" announce="true"/>
- + <item id="6376" count="1" chance="2" announce="true"/>
- + <item id="6377" count="1" chance="2" announce="true"/>
- + <item id="6378" count="1" chance="2" announce="true"/>
- + <item id="6379" count="1" chance="2" announce="true"/>
- + <item id="6380" count="1" chance="2" announce="true"/>
- + <item id="6381" count="1" chance="2" announce="true"/>
- + <item id="6382" count="1" chance="2" announce="true"/>
- + <item id="6383" count="1" chance="2" announce="true"/>
- + <item id="6384" count="1" chance="2" announce="true"/>
- + <item id="6385" count="1" chance="2" announce="true"/>
- + <item id="6386" count="1" chance="2" announce="true"/>
- + <item id="6392" count="1" chance="10" announce="false"/>
- + <item id="6582" count="1" chance="2" announce="true"/>
- + <item id="6587" count="1" chance="2" announce="true"/>
- + <item id="6590" count="1" chance="2" announce="true"/>
- + <item id="6594" count="1" chance="2" announce="true"/>
- + <item id="6597" count="1" chance="2" announce="true"/>
- + <item id="6599" count="1" chance="2" announce="true"/>
- + <item id="6604" count="1" chance="2" announce="true"/>
- + <item id="6606" count="1" chance="2" announce="true"/>
- + <item id="6609" count="1" chance="2" announce="true"/>
- +</rewards>
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement