Advertisement
tensador125

Terius Buffer L2JMobius

Jul 26th, 2023 (edited)
1,485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.76 KB | Gaming | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Mobius_C6_Interlude
  3. diff --git dist/game/config/General.ini dist/game/config/General.ini
  4. index 95ed0c2..22bd252 100644
  5. --- dist/game/config/General.ini
  6. +++ dist/game/config/General.ini
  7. @@ -717,3 +717,6 @@
  8.  #======================================================================================
  9.  
  10.  BlackCouponId = 6392
  11. +
  12. +BufferTeriusRadius = 200
  13. +BufferTeriusAdenaCount = 1000000
  14. diff --git dist/game/data/xml/TeriusBuffs.xml dist/game/data/xml/TeriusBuffs.xml
  15. new file mode 100644
  16. index 0000000..509d73e
  17. --- /dev/null
  18. +++ dist/game/data/xml/TeriusBuffs.xml
  19. @@ -0,0 +1,64 @@
  20. +<TeriusBuffs>
  21. +   <Terius category="Mage" playerMinLevel="1" playerMaxLevel="30">
  22. +       <Buffs id="4322" level="1"/>
  23. +   </Terius>
  24. +   <Terius category="Mage" playerMinLevel="31" playerMaxLevel="60">
  25. +       <Buffs id="1204" level="2"/>
  26. +   </Terius>
  27. +   <Terius category="Mage" playerMinLevel="61" playerMaxLevel="80">
  28. +       <Buffs id="1040" level="3"/>
  29. +       <Buffs id="1204" level="2"/>
  30. +       <Buffs id="1035" level="3"/>
  31. +       <Buffs id="1036" level="2"/>
  32. +       <Buffs id="1040" level="3"/>
  33. +       <Buffs id="1045" level="6"/>
  34. +       <Buffs id="1048" level="6"/>
  35. +       <Buffs id="1078" level="6"/>
  36. +       <Buffs id="1085" level="3"/>
  37. +       <Buffs id="1062" level="2"/>
  38. +       <Buffs id="1059" level="3"/>
  39. +       <Buffs id="273" level="1"/>
  40. +       <Buffs id="276" level="1"/>
  41. +       <Buffs id="365" level="1"/>
  42. +       <Buffs id="264" level="1"/>
  43. +       <Buffs id="268" level="1"/>
  44. +       <Buffs id="304" level="1"/>
  45. +       <Buffs id="267" level="1"/>
  46. +       <Buffs id="349" level="1"/>
  47. +       <Buffs id="1389" level="3"/>
  48. +       <Buffs id="1413" level="1"/>
  49. +       <Buffs id="1303" level="1"/>
  50. +   </Terius>
  51. +   <Terius category="Fighter" playerMinLevel="1" playerMaxLevel="30">
  52. +       <Buffs id="4323" level="1"/>
  53. +   </Terius>
  54. +   <Terius category="Fighter" playerMinLevel="31" playerMaxLevel="60">
  55. +      <Buffs id="4323" level="1"/>
  56. +   </Terius>
  57. +   <Terius category="Fighter" playerMinLevel="61" playerMaxLevel="80">
  58. +       <Buffs id="266" level="1"/>
  59. +       <Buffs id="1204" level="2"/>
  60. +       <Buffs id="1036" level="2"/>
  61. +       <Buffs id="1040" level="3"/>
  62. +       <Buffs id="1045" level="6"/>
  63. +       <Buffs id="1048" level="6"/>
  64. +       <Buffs id="1068" level="3"/>
  65. +       <Buffs id="1077" level="3"/>
  66. +       <Buffs id="1086" level="2"/>
  67. +       <Buffs id="1268" level="3"/>
  68. +       <Buffs id="271" level="1"/>
  69. +       <Buffs id="274" level="1"/>
  70. +       <Buffs id="275" level="1"/>
  71. +       <Buffs id="310" level="1"/>
  72. +       <Buffs id="264" level="1"/>
  73. +       <Buffs id="267" level="1"/>
  74. +       <Buffs id="269" level="1"/>
  75. +       <Buffs id="304" level="1"/>
  76. +       <Buffs id="364" level="1"/>
  77. +       <Buffs id="268" level="1"/>
  78. +       <Buffs id="349" level="1"/>
  79. +       <Buffs id="1242" level="3"/>
  80. +       <Buffs id="1363" level="1"/>
  81. +       <Buffs id="1388" level="1"/>
  82. +   </Terius>
  83. +</TeriusBuffs>
  84. diff --git java/Base/BufferTerius/TeriusBuff.java java/Base/BufferTerius/TeriusBuff.java
  85. new file mode 100644
  86. index 0000000..6bbe8b9
  87. --- /dev/null
  88. +++ java/Base/BufferTerius/TeriusBuff.java
  89. @@ -0,0 +1,67 @@
  90. +package Base.BufferTerius;
  91. +
  92. +import java.util.ArrayList;
  93. +import java.util.List;
  94. +
  95. +public class TeriusBuff
  96. +{
  97. +   private final String category;
  98. +   private final int playerMinLevel;
  99. +   private final int playerMaxLevel;
  100. +   private final List<Buff> buffs;
  101. +  
  102. +   public TeriusBuff(String category, int playerMinLevel, int playerMaxLevel)
  103. +   {
  104. +       this.category = category;
  105. +       this.playerMinLevel = playerMinLevel;
  106. +       this.playerMaxLevel = playerMaxLevel;
  107. +       buffs = new ArrayList<>();
  108. +   }
  109. +  
  110. +   public String getCategory()
  111. +   {
  112. +       return category;
  113. +   }
  114. +  
  115. +   public int getPlayerMinLevel()
  116. +   {
  117. +       return playerMinLevel;
  118. +   }
  119. +  
  120. +   public int getPlayerMaxLevel()
  121. +   {
  122. +       return playerMaxLevel;
  123. +   }
  124. +  
  125. +   public List<Buff> getBuffs()
  126. +   {
  127. +       return buffs;
  128. +   }
  129. +  
  130. +   public void addBuff(Buff buff)
  131. +   {
  132. +       buffs.add(buff);
  133. +   }
  134. +  
  135. +   public static class Buff
  136. +   {
  137. +       private final int id;
  138. +       private final int level;
  139. +      
  140. +       public Buff(int id, int level)
  141. +       {
  142. +           this.id = id;
  143. +           this.level = level;
  144. +       }
  145. +      
  146. +       public int getId()
  147. +       {
  148. +           return id;
  149. +       }
  150. +      
  151. +       public int getLevel()
  152. +       {
  153. +           return level;
  154. +       }
  155. +   }
  156. +}
  157. diff --git java/Base/BufferTerius/TeriusBuffData.java java/Base/BufferTerius/TeriusBuffData.java
  158. new file mode 100644
  159. index 0000000..4185917
  160. --- /dev/null
  161. +++ java/Base/BufferTerius/TeriusBuffData.java
  162. @@ -0,0 +1,109 @@
  163. +package Base.BufferTerius;
  164. +
  165. +import java.io.File;
  166. +import java.util.ArrayList;
  167. +import java.util.HashMap;
  168. +import java.util.List;
  169. +import java.util.Map;
  170. +
  171. +import org.w3c.dom.Document;
  172. +import org.w3c.dom.NamedNodeMap;
  173. +import org.w3c.dom.Node;
  174. +
  175. +import Base.XML.XMLDocument;
  176. +
  177. +public class TeriusBuffData extends XMLDocument
  178. +{
  179. +   private final Map<String, List<TeriusBuff>> teriusBuffsByCategory;
  180. +  
  181. +   public TeriusBuffData()
  182. +   {
  183. +       teriusBuffsByCategory = new HashMap<>();
  184. +       load();
  185. +   }
  186. +  
  187. +   public void reload()
  188. +   {
  189. +       teriusBuffsByCategory.clear();
  190. +       load();
  191. +   }
  192. +  
  193. +   public static TeriusBuffData getInstance()
  194. +   {
  195. +       return SingletonHolder.INSTANCE;
  196. +   }
  197. +  
  198. +   private static class SingletonHolder
  199. +   {
  200. +       protected static final TeriusBuffData INSTANCE = new TeriusBuffData();
  201. +   }
  202. +  
  203. +   @Override
  204. +   protected void load()
  205. +   {
  206. +       loadDocument("./data/xml/TeriusBuffs.xml");
  207. +       LOG.info("TeriusBuffData2: Loaded " + teriusBuffsByCategory.size() + " categories.");
  208. +   }
  209. +  
  210. +   @Override
  211. +   protected void parseDocument(Document doc, File file)
  212. +   {
  213. +       try
  214. +       {
  215. +           final Node root = doc.getFirstChild();
  216. +          
  217. +           for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling())
  218. +           {
  219. +               if (!"Terius".equalsIgnoreCase(node.getNodeName()))
  220. +               {
  221. +                   continue;
  222. +               }
  223. +              
  224. +               NamedNodeMap attrs = node.getAttributes();
  225. +               String category = attrs.getNamedItem("category").getNodeValue();
  226. +               int playerMinLevel = Integer.parseInt(attrs.getNamedItem("playerMinLevel").getNodeValue());
  227. +               int playerMaxLevel = Integer.parseInt(attrs.getNamedItem("playerMaxLevel").getNodeValue());
  228. +              
  229. +               TeriusBuff teriusBuff = new TeriusBuff(category, playerMinLevel, playerMaxLevel);
  230. +              
  231. +               for (Node buffNode = node.getFirstChild(); buffNode != null; buffNode = buffNode.getNextSibling())
  232. +               {
  233. +                   if (!"Buffs".equalsIgnoreCase(buffNode.getNodeName()))
  234. +                   {
  235. +                       continue;
  236. +                   }
  237. +                  
  238. +                   NamedNodeMap buffAttrs = buffNode.getAttributes();
  239. +                   int id = Integer.parseInt(buffAttrs.getNamedItem("id").getNodeValue());
  240. +                   int level = Integer.parseInt(buffAttrs.getNamedItem("level").getNodeValue());
  241. +                  
  242. +                   TeriusBuff.Buff buff = new TeriusBuff.Buff(id, level);
  243. +                   teriusBuff.addBuff(buff);
  244. +               }
  245. +              
  246. +               List<TeriusBuff> buffList = teriusBuffsByCategory.get(category);
  247. +               if (buffList == null)
  248. +               {
  249. +                   buffList = new ArrayList<>();
  250. +                   teriusBuffsByCategory.put(category, buffList);
  251. +               }
  252. +               buffList.add(teriusBuff);
  253. +           }
  254. +       }
  255. +       catch (Exception e)
  256. +       {
  257. +           // LOG.warning("TeriusBuffData2: Error while loading data: " + e);
  258. +           e.printStackTrace();
  259. +       }
  260. +   }
  261. +  
  262. +   public Map<String, List<TeriusBuff>> getTeriusBuffsByCategory()
  263. +   {
  264. +       return teriusBuffsByCategory;
  265. +   }
  266. +  
  267. +   public List<TeriusBuff> getTeriusBuffsByCategory(String category)
  268. +   {
  269. +       return teriusBuffsByCategory.get(category);
  270. +   }
  271. +}
  272. diff --git java/org/l2jmobius/Config.java java/org/l2jmobius/Config.java
  273. index 290d922..bae1a22 100644
  274. --- java/org/l2jmobius/Config.java
  275. +++ java/org/l2jmobius/Config.java
  276. @@ -116,6 +116,9 @@
  277.     // login
  278.     private static final String LOGIN_CONFIG_FILE = "./config/LoginServer.ini";
  279.    
  280. +   public static int RADIUS_BUFFER_TERIUS;
  281. +   public static int TERIUS_BUFF_ADENA_COUNT;
  282. +  
  283.     // --------------------------------------------------
  284.     // Variable Definitions
  285.     // --------------------------------------------------
  286. @@ -1304,6 +1307,8 @@
  287.        
  288.         RANDOM_CRAFT_ITEM_CONSUME_CREATE = generalConfig.getInt("RandromCraftConsumeCreate", 300000);
  289.         BLACK_COUPON_ID = generalConfig.getInt("BlackCouponId", 6392);
  290. +       RADIUS_BUFFER_TERIUS = generalConfig.getInt("BufferTeriusRadius", 200);
  291. +       TERIUS_BUFF_ADENA_COUNT = generalConfig.getInt("BufferTeriusAdenaCount", 1000000);
  292.         ALT_DEV_NO_QUESTS = generalConfig.getBoolean("AltDevNoQuests", false);
  293.         ALT_DEV_NO_SPAWNS = generalConfig.getBoolean("AltDevNoSpawns", false);
  294.         ALT_DEV_NO_SCRIPT = generalConfig.getBoolean("AltDevNoScript", false);
  295. diff --git java/org/l2jmobius/gameserver/GameServer.java java/org/l2jmobius/gameserver/GameServer.java
  296. index cc2b44c..05ff16a 100644
  297. --- java/org/l2jmobius/gameserver/GameServer.java
  298. +++ java/org/l2jmobius/gameserver/GameServer.java
  299. @@ -128,6 +128,7 @@
  300.  import org.l2jmobius.gameserver.taskmanager.TaskManager;
  301.  import org.l2jmobius.gameserver.ui.Gui;
  302.  
  303. +import Base.BufferTerius.TeriusBuffData;
  304.  import Base.Data.IconTable;
  305.  import Base.Improved.ImprovedData;
  306.  import Base.RandomCraft.RandomCraftXML;
  307. @@ -351,6 +352,9 @@
  308.         printSection("Buff Improved - Terius");
  309.         ImprovedData.getInstance();
  310.        
  311. +       printSection("Buffer - Terius");
  312. +       TeriusBuffData.getInstance();
  313. +      
  314.         XMLDocumentFactory.getInstance();
  315.        
  316.         printSection("Handlers");
  317. diff --git java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java
  318. index 36a2a98..4975f05 100644
  319. --- java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java
  320. +++ java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java
  321. @@ -33,6 +33,7 @@
  322.  import org.l2jmobius.gameserver.model.actor.Player;
  323.  import org.l2jmobius.gameserver.util.BuilderUtil;
  324.  
  325. +import Base.BufferTerius.TeriusBuffData;
  326.  import Base.RandomCraft.RandomCraftXML;
  327.  
  328.  /**
  329. @@ -93,6 +94,12 @@
  330.                     sendReloadPage(activeChar);
  331.                     BuilderUtil.sendSysMessage(activeChar, "Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  332.                 }
  333. +               else if (type.startsWith("teriusbuff"))
  334. +               {
  335. +                   TeriusBuffData.getInstance().reload();
  336. +                   sendReloadPage(activeChar);
  337. +                   BuilderUtil.sendSysMessage(activeChar, "TeriusBuffer reloaded.");
  338. +               }
  339.                 else if (type.startsWith("item"))
  340.                 {
  341.                     ItemTable.getInstance().reload();
  342. diff --git java/org/l2jmobius/gameserver/model/WorldObject.java java/org/l2jmobius/gameserver/model/WorldObject.java
  343. index 2b6443a..0acd5b1 100644
  344. --- java/org/l2jmobius/gameserver/model/WorldObject.java
  345. +++ java/org/l2jmobius/gameserver/model/WorldObject.java
  346. @@ -16,6 +16,9 @@
  347.   */
  348.  package org.l2jmobius.gameserver.model;
  349.  
  350. +import java.util.ArrayList;
  351. +import java.util.Collections;
  352. +import java.util.List;
  353.  import java.util.logging.Logger;
  354.  
  355.  import org.l2jmobius.Config;
  356. @@ -24,6 +27,7 @@
  357.  import org.l2jmobius.gameserver.instancemanager.MercTicketManager;
  358.  import org.l2jmobius.gameserver.model.actor.Creature;
  359.  import org.l2jmobius.gameserver.model.actor.Player;
  360. +import org.l2jmobius.gameserver.model.actor.instance.Fence;
  361.  import org.l2jmobius.gameserver.model.actor.knownlist.WorldObjectKnownList;
  362.  import org.l2jmobius.gameserver.model.item.instance.Item;
  363.  import org.l2jmobius.gameserver.network.GameClient;
  364. @@ -409,6 +413,44 @@
  365.         }
  366.     }
  367.    
  368. +   /**
  369. +    * Return the known list of given object type.
  370. +    * @param <A> : Object type must be instance of {@link WorldObject}.
  371. +    * @param type : Class specifying object type.
  372. +    * @return List<A> : Known list of given object type.
  373. +    */
  374. +   @SuppressWarnings("unchecked")
  375. +   public final <A> List<A> getKnownType(Class<A> type)
  376. +   {
  377. +       final WorldRegion region = _worldRegion;
  378. +       if (region == null)
  379. +       {
  380. +           return Collections.emptyList();
  381. +       }
  382. +      
  383. +       final List<A> result = new ArrayList<>();
  384. +      
  385. +       for (WorldRegion reg : region.getSurroundingRegions())
  386. +       {
  387. +           for (WorldObject obj : reg.getVisibleObjects())
  388. +           {
  389. +               if ((obj == this) || !type.isAssignableFrom(obj.getClass()))
  390. +               {
  391. +                   continue;
  392. +               }
  393. +              
  394. +               if ((obj.getInstanceId() != getInstanceId()) && !(obj instanceof Fence))
  395. +               {
  396. +                   continue;
  397. +               }
  398. +              
  399. +               result.add((A) obj);
  400. +           }
  401. +       }
  402. +      
  403. +       return result;
  404. +   }
  405. +  
  406.     public WorldObjectKnownList getKnownList()
  407.     {
  408.         if (_knownList == null)
  409. diff --git java/org/l2jmobius/gameserver/model/actor/instance/BufferTerius.java java/org/l2jmobius/gameserver/model/actor/instance/BufferTerius.java
  410. new file mode 100644
  411. index 0000000..24868a1
  412. --- /dev/null
  413. +++ java/org/l2jmobius/gameserver/model/actor/instance/BufferTerius.java
  414. @@ -0,0 +1,229 @@
  415. +package org.l2jmobius.gameserver.model.actor.instance;
  416. +
  417. +import java.util.List;
  418. +import java.util.Map;
  419. +import java.util.concurrent.ConcurrentHashMap;
  420. +import java.util.concurrent.ScheduledFuture;
  421. +import java.util.stream.Collectors;
  422. +
  423. +import org.l2jmobius.Config;
  424. +import org.l2jmobius.commons.threads.ThreadPool;
  425. +import org.l2jmobius.gameserver.ai.CtrlIntention;
  426. +import org.l2jmobius.gameserver.data.SkillTable;
  427. +import org.l2jmobius.gameserver.model.Skill;
  428. +import org.l2jmobius.gameserver.model.actor.Npc;
  429. +import org.l2jmobius.gameserver.model.actor.Player;
  430. +import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
  431. +import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
  432. +import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
  433. +import org.l2jmobius.gameserver.network.serverpackets.MyTargetSelected;
  434. +import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  435. +import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
  436. +
  437. +import Base.BufferTerius.TeriusBuff;
  438. +import Base.BufferTerius.TeriusBuff.Buff;
  439. +import Base.BufferTerius.TeriusBuffData;
  440. +
  441. +public class BufferTerius extends Npc
  442. +{
  443. +   private ScheduledFuture<?> _aiTask;
  444. +   private final Map<String, List<TeriusBuff>> buffsCache = new ConcurrentHashMap<>();
  445. +  
  446. +   @Override
  447. +   public void onAction(Player player)
  448. +   {
  449. +       if (!canTarget(player))
  450. +       {
  451. +           return;
  452. +       }
  453. +      
  454. +       if (this != player.getTarget())
  455. +       {
  456. +           // Set the target of the Player player
  457. +           player.setTarget(this);
  458. +          
  459. +           // Send a Server->Client packet MyTargetSelected to the Player player
  460. +           // The color to display in the select window is White
  461. +           player.sendPacket(new MyTargetSelected(getObjectId(), 0));
  462. +          
  463. +           // Send a Server->Client packet ValidateLocation to correct the Artefact position and heading on the client
  464. +           player.sendPacket(new ValidateLocation(this));
  465. +       }
  466. +       else if (!canInteract(player)) // Calculate the distance between the Player and the Npc
  467. +       {
  468. +           // Notify the Player AI with AI_INTENTION_INTERACT
  469. +           player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  470. +       }
  471. +       else
  472. +       {
  473. +           showMainWindow(player);
  474. +       }
  475. +      
  476. +       // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  477. +       player.sendPacket(ActionFailed.STATIC_PACKET);
  478. +   }
  479. +  
  480. +   public void showMainWindow(Player player)
  481. +   {
  482. +       NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  483. +       html.setFile("data/html/mods/TeriusBuff.htm");
  484. +       html.replace("%objectId%", String.valueOf(getObjectId()));
  485. +       html.replace("%npcname%", getName());
  486. +       player.sendPacket(html);
  487. +   }
  488. +  
  489. +   private class TeriusAI implements Runnable
  490. +   {
  491. +       private final BufferTerius _caster;
  492. +      
  493. +       protected TeriusAI(final BufferTerius caster)
  494. +       {
  495. +           _caster = caster;
  496. +       }
  497. +      
  498. +       @Override
  499. +       public void run()
  500. +       {
  501. +           List<Player> playersInRange = getKnownType(Player.class).stream().filter(player -> player.isInsideRadius3D(_caster, Config.RADIUS_BUFFER_TERIUS)).collect(Collectors.toList());
  502. +          
  503. +           if (playersInRange.isEmpty())
  504. +           {
  505. +               return;
  506. +           }
  507. +          
  508. +           List<Player> magesInRange = playersInRange.stream().filter(Player::isMageClass).collect(Collectors.toList());
  509. +           List<Player> fightersInRange = playersInRange.stream().filter(player -> !player.isMageClass()).collect(Collectors.toList());
  510. +          
  511. +           // Solo realizar consultas y operaciones si hay jugadores presentes en el rango.
  512. +           if (!magesInRange.isEmpty())
  513. +           {
  514. +               List<TeriusBuff> mageBuffs = getBuffsFromCache("Mage");
  515. +               if (mageBuffs != null)
  516. +               {
  517. +                   for (Player mage : magesInRange)
  518. +                   {
  519. +                       int playerLevel = mage.getLevel();
  520. +                       boolean hasBuffed = false;
  521. +
  522. +                        // Verificar si el jugador tiene suficiente adena para pagar por los buffs.
  523. +                        if (mage.getAdena() < Config.TERIUS_BUFF_ADENA_COUNT && mage.getLevel() >= 31) {
  524. +                            continue;
  525. +                        }
  526. +                  
  527. +                       for (TeriusBuff buff : mageBuffs)
  528. +                       {
  529. +                           if ((buff.getPlayerMinLevel() <= playerLevel) && (buff.getPlayerMaxLevel() >= playerLevel))
  530. +                           {
  531. +                               hasBuffed |= TeriusCast(mage, buff.getBuffs());
  532. +                           }
  533. +                       }
  534. +                      
  535. +                       // Si el jugador cumple la condición, reducir adena una vez si ha habido al menos un buff exitoso.
  536. +                       if ((mage.getLevel() >= 31) && (mage.getAdena() >= Config.TERIUS_BUFF_ADENA_COUNT) && hasBuffed)
  537. +                       {
  538. +                           mage.reduceAdena("Cobro", Config.TERIUS_BUFF_ADENA_COUNT, mage, true);
  539. +                       }
  540. +                   }
  541. +               }
  542. +           }
  543. +          
  544. +           if (!fightersInRange.isEmpty())
  545. +           {
  546. +               List<TeriusBuff> fighterBuffs = getBuffsFromCache("Fighter");
  547. +               if (fighterBuffs != null)
  548. +               {
  549. +                   for (Player fighter : fightersInRange)
  550. +                   {
  551. +                       int playerLevel = fighter.getLevel();
  552. +                       boolean hasBuffed = false;
  553. +
  554. +                        // Verificar si el jugador tiene suficiente adena para pagar por los buffs.
  555. +                        if (fighter.getAdena() < Config.TERIUS_BUFF_ADENA_COUNT && fighter.getLevel() >= 31) {
  556. +                            continue;
  557. +                        }
  558. +                        
  559. +                       for (TeriusBuff buff : fighterBuffs)
  560. +                       {
  561. +                           if ((buff.getPlayerMinLevel() <= playerLevel) && (buff.getPlayerMaxLevel() >= playerLevel))
  562. +                           {
  563. +                               hasBuffed |= TeriusCast(fighter, buff.getBuffs());
  564. +                           }
  565. +                       }
  566. +                      
  567. +                       // Si el jugador cumple la condición, reducir adena una vez si ha habido al menos un buff exitoso.
  568. +                       if ((fighter.getLevel() >= 31) && (fighter.getAdena() >= Config.TERIUS_BUFF_ADENA_COUNT) && hasBuffed)
  569. +                       {
  570. +                           fighter.reduceAdena("Cobro", Config.TERIUS_BUFF_ADENA_COUNT, fighter, true);
  571. +                       }
  572. +                   }
  573. +               }
  574. +           }
  575. +       }
  576. +      
  577. +       private boolean TeriusCast(final Player player, List<Buff> buffs)
  578. +       {
  579. +           if (player.isDead())
  580. +           {
  581. +               return false;
  582. +           }
  583. +          
  584. +           boolean hasBuffed = false;
  585. +          
  586. +           for (Buff buff : buffs)
  587. +           {
  588. +               int skillId = buff.getId();
  589. +               int skillLevel = buff.getLevel();
  590. +              
  591. +               Skill skill = SkillTable.getInstance().getSkill(skillId, skillLevel);
  592. +              
  593. +               if ((skill == null) || (player.getFirstEffect(skill) != null))
  594. +               {
  595. +                   continue;
  596. +               }
  597. +              
  598. +               skill.applyEffects(_caster, player);
  599. +               broadcastPacket(new MagicSkillUse(_caster, player, skillId, skillLevel, 1000, 0));
  600. +               hasBuffed = true;
  601. +           }
  602. +          
  603. +           return hasBuffed;
  604. +       }
  605. +   }
  606. +  
  607. +   // Método para obtener los buffs desde la caché o realizar la consulta si no están en la caché.
  608. +   private List<TeriusBuff> getBuffsFromCache(String category)
  609. +   {
  610. +       List<TeriusBuff> buffs = buffsCache.get(category);
  611. +       if (buffs == null)
  612. +       {
  613. +           // Si los buffs no están en la caché, realiza la consulta para obtenerlos.
  614. +           try
  615. +           {
  616. +               buffs = TeriusBuffData.getInstance().getTeriusBuffsByCategory(category);
  617. +               if (buffs != null)
  618. +               {
  619. +                   // Almacenar los buffs en la caché con una duración de vida de 5 minutos.
  620. +                   buffsCache.put(category, buffs);
  621. +                   // Programar una tarea para eliminar los datos de la caché después de 5 minutos.
  622. +                   ThreadPool.schedule(() -> buffsCache.remove(category), 5);
  623. +               }
  624. +           }
  625. +           catch (Exception e)
  626. +           {
  627. +               // Manejo adecuado de excepciones o registro de errores.
  628. +               e.printStackTrace();
  629. +           }
  630. +       }
  631. +       return buffs;
  632. +   }
  633. +  
  634. +   public BufferTerius(final int objectId, final NpcTemplate template)
  635. +   {
  636. +       super(objectId, template);
  637. +      
  638. +       // Cancelar la tarea anterior y liberar recursos.
  639. +       if (_aiTask != null)
  640. +       {
  641. +           _aiTask.cancel(true);
  642. +           _aiTask = null;
  643. +       }
  644. +      
  645. +       // Obtener la cantidad de jugadores cercanos.
  646. +       List<Player> playersInRange = getKnownType(Player.class).stream().filter(player -> player.isInsideRadius3D(this, Config.RADIUS_BUFFER_TERIUS)).collect(Collectors.toList());
  647. +      
  648. +       int playerCount = Math.max(playersInRange.size(), 1); // Asegurarse de que playerCount sea al menos 1.
  649. +      
  650. +       // Programar la nueva tarea con una cantidad de subprocesos igual a la cantidad de jugadores cercanos o 1.
  651. +       _aiTask = ThreadPool.scheduleAtFixedRate(new TeriusAI(this), 3000, 3000 / playerCount);
  652. +   }
  653. +}
  654.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement