Noticias:

No tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

Menú Principal

Timed Items Disappear

Iniciado por Swarlog, Jul 26, 2025, 11:51 PM

Tema anterior - Siguiente tema

Swarlog

Con estos cambios, podemos indicarle que items queremos que cuando pase X tiempo se eliminen automáticamente. Muy bueno para servidores pvp, para que la gente siempre este actualizando sus equipos.

### Eclipse Workspace Patch 1.0
#P Dream_GameServer
Index: src/com/dream/game/model/itemcontainer/PcInventory.java
===================================================================
--- src/com/dream/game/model/itemcontainer/PcInventory.java (revision 1760)
+++ src/com/dream/game/model/itemcontainer/PcInventory.java (working copy)
@@ -28,8 +28,8 @@
import com.dream.game.datatables.SkillTable;
import com.dream.game.datatables.sql.ItemTable;
import com.dream.game.manager.FortSiegeManager;
+import com.dream.game.manager.TimedItemManager;
import com.dream.game.model.L2Object;
-import com.dream.game.model.TimedItemControl;
import com.dream.game.model.TradeList;
import com.dream.game.model.TradeList.TradeItem;
import com.dream.game.model.actor.instance.L2ItemInstance;
@@ -309,7 +309,6 @@
}
}
@Override
public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)
{
@@ -324,9 +323,9 @@
{
_ancientAdena = item;
}
+ if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
+ {
+ TimedItemManager.getInstance().setTimed(item);
+ }
return item;
}
@@ -348,9 +347,9 @@
{
_ancientAdena = item;
}
+ if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
+ {
+ TimedItemManager.getInstance().setTimed(item);
+ }
return item;
}
@@ -393,9 +392,9 @@
{
_ancientAdena = null;
}
+ if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
+ {
+ TimedItemManager.getInstance().destroy(item);
+ }
return item;
}
Index: src/com/dream/game/L2GameServer.java
===================================================================
--- src/com/dream/game/L2GameServer.java (revision 1760)
+++ src/com/dream/game/L2GameServer.java (working copy)
@@ -88,6 +88,7 @@
import com.dream.game.manager.RaidBossSpawnManager;
import com.dream.game.manager.RaidPointsManager;
import com.dream.game.manager.SiegeManager;
+import com.dream.game.manager.TimedItemManager;
import com.dream.game.manager.TownManager;
import com.dream.game.manager.ZoneManager;
import com.dream.game.manager.clanhallsiege.BanditStrongholdSiege;
@@ -369,7 +369,7 @@
CastleManorManager.getInstance();
L2Manor.getInstance();
AuctionManager.getInstance();
+ TimedItemManager.getInstance();
PartyRoomManager.getInstance();

Console.printSection("Olympiad");

Index: src/com/dream/Config.java
===================================================================
--- src/com/dream/Config.java (revision 1783)
+++ src/com/dream/Config.java (working copy)
@@ -91,6 +91,9 @@
public static boolean GRIDS_ALWAYS_ON;
public static String PROTECTED_ITEMS;
public static FastList LIST_PROTECTED_ITEMS = new FastList<>();
+ public static String TIMED_ITEMS;
+ public static FastList LIST_TIMED_ITEMS = new FastList<>();
+ public static int TIMED_ITEM_TIME;
public static Pattern CNAME_PATTERN;
public static Pattern PET_NAME_PATTERN;
public static Pattern CLAN_ALLY_NAME_PATTERN;
@@ -217,6 +220,14 @@
LIST_PROTECTED_ITEMS.add(Integer.parseInt(id.trim()));
}

+ TIMED_ITEMS = altSettings.getProperty("ListOfTimedItems");
+ TIMED_ITEM_TIME = Integer.parseInt(altSettings.getProperty("TimedItemTime", "2"));
+ LIST_TIMED_ITEMS = new FastList<>();
+ for (String id : TIMED_ITEMS.trim().split(","))
+ {
+ LIST_TIMED_ITEMS.add(Integer.parseInt(id.trim()));
+ }
+
DESTROY_DROPPED_PLAYER_ITEM = Boolean.parseBoolean(altSettings.getProperty("DestroyPlayerDroppedItem", "false"));
DESTROY_EQUIPABLE_PLAYER_ITEM = Boolean.parseBoolean(altSettings.getProperty("DestroyEquipableItem", "false"));
SAVE_DROPPED_ITEM = Boolean.parseBoolean(altSettings.getProperty("SaveDroppedItem", "false"));
Index: src/com/dream/game/manager/TimedItemManager.java
===================================================================
--- src/com/dream/game/manager/TimedItemManager.java (revision 0)
+++ src/com/dream/game/manager/TimedItemManager.java (working copy)
@@ -0,0 +1,331 @@
+package com.dream.game.manager;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javolution.util.FastMap;
+
+import org.apache.log4j.Logger;
+
+import com.dream.Config;
+import com.dream.L2DatabaseFactory;
+import com.dream.game.model.L2Object;
+import com.dream.game.model.actor.instance.L2ItemInstance;
+import com.dream.game.model.actor.instance.L2PcInstance;
+import com.dream.game.model.world.L2World;
+import com.dream.game.network.ExclusiveTask;
+import com.dream.game.network.SystemMessageId;
+import com.dream.game.network.serverpackets.ItemList;
+import com.dream.game.network.serverpackets.SystemMessage;
+
+public class TimedItemManager
+{
+ public final FastMap _timedItems = new FastMap<>();
+ private static Logger _log = Logger.getLogger(TimedItemManager.class);
+ private static Connection con;
+
+ public class Info
+ {
+ int _charId;
+ int _itemId;
+ long _activationTime;
+ }
+
+ public static final TimedItemManager getInstance()
+ {
+ return SingletonHolder._instance;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final TimedItemManager _instance = new TimedItemManager();
+ }
+
+ public TimedItemManager()
+ {
+ restore();
+ _startControlTask.schedule(60000);
+ }
+
+ public boolean getActiveTimed(L2PcInstance pl, boolean trade)
+ {
+ for (Info i : _timedItems.values())
+ {
+ if ((i != null) && (i._charId == pl.getObjectId()))
+ {
+ L2ItemInstance item = pl.getInventory().getItemByObjectId(i._itemId);
+ if (item != null)
+ {
+ if (System.currentTimeMillis() < i._activationTime)
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public synchronized void destroy(L2ItemInstance item)
+ {
+ Info inf = _timedItems.get(item.getObjectId());
+ if (inf != null)
+ {
+ _timedItems.remove(inf._itemId);
+ con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection(con);
+ PreparedStatement statement;
+ statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?");
+ statement.setInt(1, inf._charId);
+ statement.setInt(2, inf._itemId);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (Exception e)
+ {
+
+ }
+ }
+ }
+ }
+
+ public synchronized void setTimed(L2ItemInstance item)
+ {
+ Info inf = _timedItems.get(item.getObjectId());
+ if (inf != null)
+ {
+ inf._charId = item.getOwnerId();
+ }
+ else
+ {
+ inf = new Info();
+ inf._activationTime = (System.currentTimeMillis() / 1000) + (Config.TIMED_ITEM_TIME * 60);
+ inf._charId = item.getOwnerId();
+ inf._itemId = item.getObjectId();
+ _timedItems.put(inf._itemId, inf);
+ }
+ saveToDb(inf);
+ }
+
+ public boolean isActive(L2ItemInstance item)
+ {
+ for (Info i : _timedItems.values())
+ {
+ if (i._itemId == item.getObjectId())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void restore()
+ {
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection(con);
+ PreparedStatement statement = con.prepareStatement("SELECT charId, itemId, time FROM character_timed_items");
+ ResultSet rs = statement.executeQuery();
+
+ while (rs.next())
+ {
+ Info inf = new Info();
+ inf._activationTime = rs.getLong("time");
+ inf._charId = rs.getInt("charId");
+ inf._itemId = rs.getInt("itemId");
+ _timedItems.put(inf._itemId, inf);
+ }
+ rs.close();
+ statement.close();
+ _log.info("TimedItems: loaded " + _timedItems.size() + " items ");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (con != null)
+ {
+ con.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static void saveToDb(Info temp)
+ {
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection(con);
+ PreparedStatement statement;
+ statement = con.prepareStatement("update character_timed_items set charId = ? where itemId = ?");
+ statement.setInt(1, temp._charId);
+ statement.setInt(2, temp._itemId);
+ if (statement.executeUpdate() == 0)
+ {
+ statement.close();
+ statement = con.prepareStatement("INSERT INTO character_timed_items (charId, itemId, time) VALUES (?, ?, ?)");
+ statement.setInt(1, temp._charId);
+ statement.setInt(2, temp._itemId);
+ statement.setLong(3, temp._activationTime);
+ statement.execute();
+ }
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (con != null)
+ {
+ con.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void delete(Info temp)
+ {
+ _timedItems.remove(temp._itemId);
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection(con);
+ PreparedStatement statement;
+ statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?");
+ statement.setInt(1, temp._charId);
+ statement.setInt(2, temp._itemId);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (con != null)
+ {
+ con.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ L2PcInstance pl = L2World.getInstance().getPlayer(temp._charId);
+ if (pl != null)
+ {
+ L2ItemInstance item = pl.getInventory().getItemByObjectId(temp._itemId);
+ if (item != null)
+ {
+ if (item.isEquipped())
+ {
+ pl.getInventory().unEquipItemInSlot(item.getLocationSlot());
+ }
+ pl.getInventory().destroyItem("timeLost", item, pl, pl);
+ pl.sendPacket(new ItemList(pl, false));
+ }
+
+ SystemMessage msg = new SystemMessage(SystemMessageId.S1_DISAPPEARED);
+ msg.addItemName(item);
+ pl.sendPacket(msg);
+
+ }
+ else
+ {
+ con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection(con);
+ PreparedStatement statement;
+ if (temp._charId != 0)
+ {
+ statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? AND object_id = ?");
+ statement.setInt(1, temp._charId);
+ statement.setInt(2, temp._itemId);
+ statement.execute();
+ statement.close();
+ }
+ else
+ {
+ for (L2Object o : L2World.getInstance().getAllVisibleObjects())
+ {
+ if (o.getObjectId() == temp._itemId)
+ {
+ L2World.getInstance().removeVisibleObject(o, o.getWorldRegion());
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (con != null)
+ {
+ con.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private final ExclusiveTask _startControlTask = new ExclusiveTask()
+ {
+ @Override
+ protected void onElapsed()
+ {
+ for (Info temp : _timedItems.values())
+ {
+ if (temp._activationTime < (System.currentTimeMillis() / 1000))
+ {
+
+ delete(temp);
+ }
+ }
+ schedule(60000);
+ }
+ };
+
+}
\ No newline at end of file
### Eclipse Workspace Patch 1.0
#P Dream_GameServer
Index: src/com/dream/game/network/ExclusiveTask.java
===================================================================
+++ src/com/dream/game/network/ExclusiveTask.java	(working copy)
@@ -1,109 +0,0 @@
+package com.dream.game.network;
+
+import java.util.concurrent.Future;
+
+public abstract class ExclusiveTask
+{
+	private final boolean _returnIfAlreadyRunning;
+	
+	private Future<?> _future;
+	private boolean _isRunning;
+	private Thread _currentThread;
+	
+	protected ExclusiveTask(boolean returnIfAlreadyRunning)
+	{
+		_returnIfAlreadyRunning = returnIfAlreadyRunning;
+	}
+	
+	protected ExclusiveTask()
+	{
+		this(false);
+	}
+	
+	public synchronized boolean isScheduled()
+	{
+		return _future != null;
+	}
+	
+	public synchronized final void cancel()
+	{
+		if (_future != null)
+		{
+			_future.cancel(false);
+			_future = null;
+		}
+	}
+	
+	public synchronized final void schedule(long delay)
+	{
+		cancel();
+		
+		_future = ThreadPoolManager.getInstance().schedule(_runnable, delay);
+	}
+	
+	public synchronized final void scheduleAtFixedRate(long delay, long period)
+	{
+		cancel();
+		
+		_future = ThreadPoolManager.getInstance().scheduleAtFixedRate(_runnable, delay, period);
+	}
+	
+	private final Runnable _runnable = new Runnable()
+	{
+		@Override
+		public void run()
+		{
+			if (tryLock())
+			{
+				try
+				{
+					onElapsed();
+				}
+				finally
+				{
+					unlock();
+				}
+			}
+		}
+	};
+	
+	protected abstract void onElapsed();
+	
+	public synchronized boolean tryLock()
+	{
+		if (_returnIfAlreadyRunning)
+		{
+			return !_isRunning;
+		}
+		
+		_currentThread = Thread.currentThread();
+		
+		for (;;)
+		{
+			try
+			{
+				notifyAll();
+				
+				if (_currentThread != Thread.currentThread())
+				{
+					return false;
+				}
+				
+				if (!_isRunning)
+				{
+					return true;
+				}
+				
+				wait();
+			}
+			catch (InterruptedException e)
+			{
+			}
+		}
+	}
+	
+	public synchronized void unlock()
+	{
+		_isRunning = false;
+	}
+}





### Eclipse Workspace Patch 1.0
#P Dream_DataPack
Index: sql/server/character_timed_items.sql
===================================================================
--- sql/server/character_timed_items.sql    (revision 1754)
+++ sql/server/character_timed_items.sql    (working copy)
@@ -1,6 +0,0 @@
+DROP TABLE IF EXISTS `character_timed_items`;
+CREATE TABLE `character_timed_items` (
+ `charId` int(11) NOT NULL,
+ `itemId` int(11) NOT NULL,
+ `time` decimal(20,0) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
\ No newline at end of file



#=======================================#
#        Timed item
#=======================================#
# Timed Item ID use , for separate (57,3441,5588...)
ListOfTimedItems = 57,3441,5588

# Time for item disappear in Hour's
TimedItemTime = 2