-JRGames-

Time Itens JDrean

Oct 30th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.74 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Dream_DataPack
  3. Index: sql/server/character_timed_items.sql
  4. ===================================================================
  5. --- sql/server/character_timed_items.sql (revision 1754)
  6. +++ sql/server/character_timed_items.sql (working copy)
  7. @@ -1,6 +0,0 @@
  8. +DROP TABLE IF EXISTS `character_timed_items`;
  9. +CREATE TABLE `character_timed_items` (
  10. + `charId` int(11) NOT NULL,
  11. + `itemId` int(11) NOT NULL,
  12. + `time` decimal(20,0) NOT NULL DEFAULT '0'
  13. +) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  14. \ No newline at end of file
  15.  
  16.  
  17. #=======================================#
  18. # Timed item
  19. #=======================================#
  20. # Timed Item ID use , for separate (57,3441,5588...)
  21. ListOfTimedItems = 57,3441,5588
  22.  
  23. # Time for item disappear in Hour's
  24. TimedItemTime = 2
  25.  
  26.  
  27. ### Eclipse Workspace Patch 1.0
  28. #P Dream_GameServer
  29. Index: src/com/dream/game/model/itemcontainer/PcInventory.java
  30. ===================================================================
  31. --- src/com/dream/game/model/itemcontainer/PcInventory.java (revision 1760)
  32. +++ src/com/dream/game/model/itemcontainer/PcInventory.java (working copy)
  33. @@ -28,8 +28,8 @@
  34. import com.dream.game.datatables.SkillTable;
  35. import com.dream.game.datatables.sql.ItemTable;
  36. import com.dream.game.manager.FortSiegeManager;
  37. +import com.dream.game.manager.TimedItemManager;
  38. import com.dream.game.model.L2Object;
  39. -import com.dream.game.model.TimedItemControl;
  40. import com.dream.game.model.TradeList;
  41. import com.dream.game.model.TradeList.TradeItem;
  42. import com.dream.game.model.actor.instance.L2ItemInstance;
  43. @@ -309,7 +309,6 @@
  44. }
  45. }
  46. @Override
  47. public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)
  48. {
  49. @@ -324,9 +323,9 @@
  50. {
  51. _ancientAdena = item;
  52. }
  53. + if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
  54. + {
  55. + TimedItemManager.getInstance().setTimed(item);
  56. + }
  57. return item;
  58. }
  59. @@ -348,9 +347,9 @@
  60. {
  61. _ancientAdena = item;
  62. }
  63. + if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
  64. + {
  65. + TimedItemManager.getInstance().setTimed(item);
  66. + }
  67. return item;
  68. }
  69. @@ -393,9 +392,9 @@
  70. {
  71. _ancientAdena = null;
  72. }
  73. + if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
  74. + {
  75. + TimedItemManager.getInstance().destroy(item);
  76. + }
  77. return item;
  78. }
  79. Index: src/com/dream/game/L2GameServer.java
  80. ===================================================================
  81. --- src/com/dream/game/L2GameServer.java (revision 1760)
  82. +++ src/com/dream/game/L2GameServer.java (working copy)
  83. @@ -88,6 +88,7 @@
  84. import com.dream.game.manager.RaidBossSpawnManager;
  85. import com.dream.game.manager.RaidPointsManager;
  86. import com.dream.game.manager.SiegeManager;
  87. +import com.dream.game.manager.TimedItemManager;
  88. import com.dream.game.manager.TownManager;
  89. import com.dream.game.manager.ZoneManager;
  90. import com.dream.game.manager.clanhallsiege.BanditStrongholdSiege;
  91. @@ -369,7 +369,7 @@
  92. CastleManorManager.getInstance();
  93. L2Manor.getInstance();
  94. AuctionManager.getInstance();
  95. + TimedItemManager.getInstance();
  96. PartyRoomManager.getInstance();
  97.  
  98. Console.printSection("Olympiad");
  99.  
  100. Index: src/com/dream/Config.java
  101. ===================================================================
  102. --- src/com/dream/Config.java (revision 1783)
  103. +++ src/com/dream/Config.java (working copy)
  104. @@ -91,6 +91,9 @@
  105. public static boolean GRIDS_ALWAYS_ON;
  106. public static String PROTECTED_ITEMS;
  107. public static FastList LIST_PROTECTED_ITEMS = new FastList<>();
  108. + public static String TIMED_ITEMS;
  109. + public static FastList LIST_TIMED_ITEMS = new FastList<>();
  110. + public static int TIMED_ITEM_TIME;
  111. public static Pattern CNAME_PATTERN;
  112. public static Pattern PET_NAME_PATTERN;
  113. public static Pattern CLAN_ALLY_NAME_PATTERN;
  114. @@ -217,6 +220,14 @@
  115. LIST_PROTECTED_ITEMS.add(Integer.parseInt(id.trim()));
  116. }
  117.  
  118. + TIMED_ITEMS = altSettings.getProperty("ListOfTimedItems");
  119. + TIMED_ITEM_TIME = Integer.parseInt(altSettings.getProperty("TimedItemTime", "2"));
  120. + LIST_TIMED_ITEMS = new FastList<>();
  121. + for (String id : TIMED_ITEMS.trim().split(","))
  122. + {
  123. + LIST_TIMED_ITEMS.add(Integer.parseInt(id.trim()));
  124. + }
  125. +
  126. DESTROY_DROPPED_PLAYER_ITEM = Boolean.parseBoolean(altSettings.getProperty("DestroyPlayerDroppedItem", "false"));
  127. DESTROY_EQUIPABLE_PLAYER_ITEM = Boolean.parseBoolean(altSettings.getProperty("DestroyEquipableItem", "false"));
  128. SAVE_DROPPED_ITEM = Boolean.parseBoolean(altSettings.getProperty("SaveDroppedItem", "false"));
  129. Index: src/com/dream/game/manager/TimedItemManager.java
  130. ===================================================================
  131. --- src/com/dream/game/manager/TimedItemManager.java (revision 0)
  132. +++ src/com/dream/game/manager/TimedItemManager.java (working copy)
  133. @@ -0,0 +1,331 @@
  134. +package com.dream.game.manager;
  135. +
  136. +import java.sql.Connection;
  137. +import java.sql.PreparedStatement;
  138. +import java.sql.ResultSet;
  139. +import java.sql.SQLException;
  140. +
  141. +import javolution.util.FastMap;
  142. +
  143. +import org.apache.log4j.Logger;
  144. +
  145. +import com.dream.Config;
  146. +import com.dream.L2DatabaseFactory;
  147. +import com.dream.game.model.L2Object;
  148. +import com.dream.game.model.actor.instance.L2ItemInstance;
  149. +import com.dream.game.model.actor.instance.L2PcInstance;
  150. +import com.dream.game.model.world.L2World;
  151. +import com.dream.game.network.ExclusiveTask;
  152. +import com.dream.game.network.SystemMessageId;
  153. +import com.dream.game.network.serverpackets.ItemList;
  154. +import com.dream.game.network.serverpackets.SystemMessage;
  155. +
  156. +public class TimedItemManager
  157. +{
  158. + public final FastMap _timedItems = new FastMap<>();
  159. + private static Logger _log = Logger.getLogger(TimedItemManager.class);
  160. + private static Connection con;
  161. +
  162. + public class Info
  163. + {
  164. + int _charId;
  165. + int _itemId;
  166. + long _activationTime;
  167. + }
  168. +
  169. + public static final TimedItemManager getInstance()
  170. + {
  171. + return SingletonHolder._instance;
  172. + }
  173. +
  174. + private static class SingletonHolder
  175. + {
  176. + protected static final TimedItemManager _instance = new TimedItemManager();
  177. + }
  178. +
  179. + public TimedItemManager()
  180. + {
  181. + restore();
  182. + _startControlTask.schedule(60000);
  183. + }
  184. +
  185. + public boolean getActiveTimed(L2PcInstance pl, boolean trade)
  186. + {
  187. + for (Info i : _timedItems.values())
  188. + {
  189. + if ((i != null) && (i._charId == pl.getObjectId()))
  190. + {
  191. + L2ItemInstance item = pl.getInventory().getItemByObjectId(i._itemId);
  192. + if (item != null)
  193. + {
  194. + if (System.currentTimeMillis() < i._activationTime)
  195. + {
  196. + return true;
  197. + }
  198. + }
  199. + }
  200. + }
  201. + return false;
  202. + }
  203. +
  204. + public synchronized void destroy(L2ItemInstance item)
  205. + {
  206. + Info inf = _timedItems.get(item.getObjectId());
  207. + if (inf != null)
  208. + {
  209. + _timedItems.remove(inf._itemId);
  210. + con = null;
  211. + try
  212. + {
  213. + con = L2DatabaseFactory.getInstance().getConnection(con);
  214. + PreparedStatement statement;
  215. + statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?");
  216. + statement.setInt(1, inf._charId);
  217. + statement.setInt(2, inf._itemId);
  218. + statement.execute();
  219. + statement.close();
  220. + }
  221. + catch (Exception e)
  222. + {
  223. + e.printStackTrace();
  224. + }
  225. + finally
  226. + {
  227. + try
  228. + {
  229. + con.close();
  230. + }
  231. + catch (Exception e)
  232. + {
  233. +
  234. + }
  235. + }
  236. + }
  237. + }
  238. +
  239. + public synchronized void setTimed(L2ItemInstance item)
  240. + {
  241. + Info inf = _timedItems.get(item.getObjectId());
  242. + if (inf != null)
  243. + {
  244. + inf._charId = item.getOwnerId();
  245. + }
  246. + else
  247. + {
  248. + inf = new Info();
  249. + inf._activationTime = (System.currentTimeMillis() / 1000) + (Config.TIMED_ITEM_TIME * 60);
  250. + inf._charId = item.getOwnerId();
  251. + inf._itemId = item.getObjectId();
  252. + _timedItems.put(inf._itemId, inf);
  253. + }
  254. + saveToDb(inf);
  255. + }
  256. +
  257. + public boolean isActive(L2ItemInstance item)
  258. + {
  259. + for (Info i : _timedItems.values())
  260. + {
  261. + if (i._itemId == item.getObjectId())
  262. + {
  263. + return true;
  264. + }
  265. + }
  266. + return false;
  267. + }
  268. +
  269. + private void restore()
  270. + {
  271. + try
  272. + {
  273. + con = L2DatabaseFactory.getInstance().getConnection(con);
  274. + PreparedStatement statement = con.prepareStatement("SELECT charId, itemId, time FROM character_timed_items");
  275. + ResultSet rs = statement.executeQuery();
  276. +
  277. + while (rs.next())
  278. + {
  279. + Info inf = new Info();
  280. + inf._activationTime = rs.getLong("time");
  281. + inf._charId = rs.getInt("charId");
  282. + inf._itemId = rs.getInt("itemId");
  283. + _timedItems.put(inf._itemId, inf);
  284. + }
  285. + rs.close();
  286. + statement.close();
  287. + _log.info("TimedItems: loaded " + _timedItems.size() + " items ");
  288. + }
  289. + catch (Exception e)
  290. + {
  291. + e.printStackTrace();
  292. + }
  293. + finally
  294. + {
  295. + try
  296. + {
  297. + if (con != null)
  298. + {
  299. + con.close();
  300. + }
  301. + }
  302. + catch (SQLException e)
  303. + {
  304. + e.printStackTrace();
  305. + }
  306. + }
  307. + }
  308. +
  309. + private static void saveToDb(Info temp)
  310. + {
  311. + try
  312. + {
  313. + con = L2DatabaseFactory.getInstance().getConnection(con);
  314. + PreparedStatement statement;
  315. + statement = con.prepareStatement("update character_timed_items set charId = ? where itemId = ?");
  316. + statement.setInt(1, temp._charId);
  317. + statement.setInt(2, temp._itemId);
  318. + if (statement.executeUpdate() == 0)
  319. + {
  320. + statement.close();
  321. + statement = con.prepareStatement("INSERT INTO character_timed_items (charId, itemId, time) VALUES (?, ?, ?)");
  322. + statement.setInt(1, temp._charId);
  323. + statement.setInt(2, temp._itemId);
  324. + statement.setLong(3, temp._activationTime);
  325. + statement.execute();
  326. + }
  327. + statement.close();
  328. + }
  329. + catch (Exception e)
  330. + {
  331. + e.printStackTrace();
  332. + }
  333. + finally
  334. + {
  335. + try
  336. + {
  337. + if (con != null)
  338. + {
  339. + con.close();
  340. + }
  341. + }
  342. + catch (SQLException e)
  343. + {
  344. + e.printStackTrace();
  345. + }
  346. + }
  347. + }
  348. +
  349. + public void delete(Info temp)
  350. + {
  351. + _timedItems.remove(temp._itemId);
  352. + try
  353. + {
  354. + con = L2DatabaseFactory.getInstance().getConnection(con);
  355. + PreparedStatement statement;
  356. + statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?");
  357. + statement.setInt(1, temp._charId);
  358. + statement.setInt(2, temp._itemId);
  359. + statement.execute();
  360. + statement.close();
  361. + }
  362. + catch (Exception e)
  363. + {
  364. + e.printStackTrace();
  365. + }
  366. + finally
  367. + {
  368. + try
  369. + {
  370. + if (con != null)
  371. + {
  372. + con.close();
  373. + }
  374. + }
  375. + catch (SQLException e)
  376. + {
  377. + e.printStackTrace();
  378. + }
  379. + }
  380. + L2PcInstance pl = L2World.getInstance().getPlayer(temp._charId);
  381. + if (pl != null)
  382. + {
  383. + L2ItemInstance item = pl.getInventory().getItemByObjectId(temp._itemId);
  384. + if (item != null)
  385. + {
  386. + if (item.isEquipped())
  387. + {
  388. + pl.getInventory().unEquipItemInSlot(item.getLocationSlot());
  389. + }
  390. + pl.getInventory().destroyItem("timeLost", item, pl, pl);
  391. + pl.sendPacket(new ItemList(pl, false));
  392. + }
  393. +
  394. + SystemMessage msg = new SystemMessage(SystemMessageId.S1_DISAPPEARED);
  395. + msg.addItemName(item);
  396. + pl.sendPacket(msg);
  397. +
  398. + }
  399. + else
  400. + {
  401. + con = null;
  402. + try
  403. + {
  404. + con = L2DatabaseFactory.getInstance().getConnection(con);
  405. + PreparedStatement statement;
  406. + if (temp._charId != 0)
  407. + {
  408. + statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? AND object_id = ?");
  409. + statement.setInt(1, temp._charId);
  410. + statement.setInt(2, temp._itemId);
  411. + statement.execute();
  412. + statement.close();
  413. + }
  414. + else
  415. + {
  416. + for (L2Object o : L2World.getInstance().getAllVisibleObjects())
  417. + {
  418. + if (o.getObjectId() == temp._itemId)
  419. + {
  420. + L2World.getInstance().removeVisibleObject(o, o.getWorldRegion());
  421. + break;
  422. + }
  423. + }
  424. + }
  425. + }
  426. + catch (Exception e)
  427. + {
  428. + e.printStackTrace();
  429. + }
  430. + finally
  431. + {
  432. + try
  433. + {
  434. + if (con != null)
  435. + {
  436. + con.close();
  437. + }
  438. + }
  439. + catch (SQLException e)
  440. + {
  441. + e.printStackTrace();
  442. + }
  443. + }
  444. + }
  445. + }
  446. +
  447. + private final ExclusiveTask _startControlTask = new ExclusiveTask()
  448. + {
  449. + @Override
  450. + protected void onElapsed()
  451. + {
  452. + for (Info temp : _timedItems.values())
  453. + {
  454. + if (temp._activationTime < (System.currentTimeMillis() / 1000))
  455. + {
  456. +
  457. + delete(temp);
  458. + }
  459. + }
  460. + schedule(60000);
  461. + }
  462. + };
  463. +
  464. +}
  465. \ No newline at end of file
  466. ### Eclipse Workspace Patch 1.0
  467. #P Dream_GameServer
  468. Index: src/com/dream/game/network/ExclusiveTask.java
  469. ===================================================================
  470. +++ src/com/dream/game/network/ExclusiveTask.java (working copy)
  471. @@ -1,109 +0,0 @@
  472. +package com.dream.game.network;
  473. +
  474. +import java.util.concurrent.Future;
  475. +
  476. +public abstract class ExclusiveTask
  477. +{
  478. + private final boolean _returnIfAlreadyRunning;
  479. +
  480. + private Future<?> _future;
  481. + private boolean _isRunning;
  482. + private Thread _currentThread;
  483. +
  484. + protected ExclusiveTask(boolean returnIfAlreadyRunning)
  485. + {
  486. + _returnIfAlreadyRunning = returnIfAlreadyRunning;
  487. + }
  488. +
  489. + protected ExclusiveTask()
  490. + {
  491. + this(false);
  492. + }
  493. +
  494. + public synchronized boolean isScheduled()
  495. + {
  496. + return _future != null;
  497. + }
  498. +
  499. + public synchronized final void cancel()
  500. + {
  501. + if (_future != null)
  502. + {
  503. + _future.cancel(false);
  504. + _future = null;
  505. + }
  506. + }
  507. +
  508. + public synchronized final void schedule(long delay)
  509. + {
  510. + cancel();
  511. +
  512. + _future = ThreadPoolManager.getInstance().schedule(_runnable, delay);
  513. + }
  514. +
  515. + public synchronized final void scheduleAtFixedRate(long delay, long period)
  516. + {
  517. + cancel();
  518. +
  519. + _future = ThreadPoolManager.getInstance().scheduleAtFixedRate(_runnable, delay, period);
  520. + }
  521. +
  522. + private final Runnable _runnable = new Runnable()
  523. + {
  524. + @Override
  525. + public void run()
  526. + {
  527. + if (tryLock())
  528. + {
  529. + try
  530. + {
  531. + onElapsed();
  532. + }
  533. + finally
  534. + {
  535. + unlock();
  536. + }
  537. + }
  538. + }
  539. + };
  540. +
  541. + protected abstract void onElapsed();
  542. +
  543. + public synchronized boolean tryLock()
  544. + {
  545. + if (_returnIfAlreadyRunning)
  546. + {
  547. + return !_isRunning;
  548. + }
  549. +
  550. + _currentThread = Thread.currentThread();
  551. +
  552. + for (;;)
  553. + {
  554. + try
  555. + {
  556. + notifyAll();
  557. +
  558. + if (_currentThread != Thread.currentThread())
  559. + {
  560. + return false;
  561. + }
  562. +
  563. + if (!_isRunning)
  564. + {
  565. + return true;
  566. + }
  567. +
  568. + wait();
  569. + }
  570. + catch (InterruptedException e)
  571. + {
  572. + }
  573. + }
  574. + }
  575. +
  576. + public synchronized void unlock()
  577. + {
  578. + _isRunning = false;
  579. + }
  580. +}
Add Comment
Please, Sign In to add comment