Advertisement
tensador125

Improved Buff Mobius Interlude

Jul 26th, 2023 (edited)
1,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.81 KB | Gaming | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Mobius_C6_Interlude
  3. diff --git dist/game/data/xml/ImprovedBuffs.xml dist/game/data/xml/ImprovedBuffs.xml
  4. new file mode 100644
  5. index 0000000..cafdcac
  6. --- /dev/null
  7. +++ dist/game/data/xml/ImprovedBuffs.xml
  8. @@ -0,0 +1,14 @@
  9. +<?xml version="1.0" encoding="utf-8"?>
  10. +<ImprovedBuffs>
  11. +   <improved BuffId="4358">
  12. +       <replace buffId="4342"/>
  13. +       <replace buffId="4355"/>
  14. +       <replace buffId="4356"/>
  15. +   </improved>
  16. +   <improved BuffId="1311">
  17. +       <replace buffId="4345"/>
  18. +       <replace buffId="4357"/>
  19. +       <replace buffId="4342"/>
  20. +
  21. +   </improved>
  22. +</ImprovedBuffs>
  23. \ No newline at end of file
  24. diff --git java/Base/Improved/ImprovedBuff.java java/Base/Improved/ImprovedBuff.java
  25. new file mode 100644
  26. index 0000000..b716c8b
  27. --- /dev/null
  28. +++ java/Base/Improved/ImprovedBuff.java
  29. @@ -0,0 +1,36 @@
  30. +package Base.Improved;
  31. +
  32. +import java.util.ArrayList;
  33. +import java.util.List;
  34. +
  35. +public class ImprovedBuff {
  36. +    private int buffId;
  37. +    private List<Integer> replaceBuffIds;
  38. +    private boolean active;
  39. +
  40. +    public ImprovedBuff(int buffId) {
  41. +        this.buffId = buffId;
  42. +        this.replaceBuffIds = new ArrayList<>();
  43. +        this.active = false;
  44. +    }
  45. +
  46. +    public int getBuffId() {
  47. +        return buffId;
  48. +    }
  49. +
  50. +    public List<Integer> getReplaceBuffIds() {
  51. +        return replaceBuffIds;
  52. +    }
  53. +
  54. +    public void addReplaceBuff(int replaceBuffId) {
  55. +        replaceBuffIds.add(replaceBuffId);
  56. +    }
  57. +
  58. +    public boolean isActive() {
  59. +        return active;
  60. +    }
  61. +
  62. +    public void setActive(boolean active) {
  63. +        this.active = active;
  64. +    }
  65. +}
  66. diff --git java/Base/Improved/ImprovedData.java java/Base/Improved/ImprovedData.java
  67. new file mode 100644
  68. index 0000000..6bb675a
  69. --- /dev/null
  70. +++ java/Base/Improved/ImprovedData.java
  71. @@ -0,0 +1,104 @@
  72. +package Base.Improved;
  73. +
  74. +import java.io.File;
  75. +import java.util.ArrayList;
  76. +import java.util.HashMap;
  77. +import java.util.List;
  78. +import java.util.Map;
  79. +
  80. +import org.w3c.dom.Document;
  81. +import org.w3c.dom.NamedNodeMap;
  82. +import org.w3c.dom.Node;
  83. +
  84. +import Base.XML.XMLDocument;
  85. +
  86. +public class ImprovedData extends XMLDocument
  87. +{
  88. +   private final Map<Integer, ImprovedBuff> improvedBuffs;
  89. +  
  90. +   public ImprovedData()
  91. +   {
  92. +       improvedBuffs = new HashMap<>();
  93. +       load();
  94. +   }
  95. +  
  96. +   public static ImprovedData getInstance()
  97. +   {
  98. +       return SingletonHolder.INSTANCE;
  99. +   }
  100. +  
  101. +   private static class SingletonHolder
  102. +   {
  103. +       protected static final ImprovedData INSTANCE = new ImprovedData();
  104. +   }
  105. +  
  106. +   @Override
  107. +   protected void load()
  108. +   {
  109. +       loadDocument("./data/xml/ImprovedBuffs.xml");
  110. +       LOG.info("ImprovedData: Loaded " + improvedBuffs.size() + " improved buffs.");
  111. +   }
  112. +  
  113. +   @Override
  114. +   protected void parseDocument(Document doc, File file)
  115. +   {
  116. +       try
  117. +       {
  118. +           final Node root = doc.getFirstChild();
  119. +          
  120. +           for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling())
  121. +           {
  122. +               if (!"improved".equalsIgnoreCase(node.getNodeName()))
  123. +               {
  124. +                   continue;
  125. +               }
  126. +              
  127. +               NamedNodeMap attrs = node.getAttributes();
  128. +               int buffId = Integer.parseInt(attrs.getNamedItem("BuffId").getNodeValue());
  129. +              
  130. +               ImprovedBuff improvedBuff = new ImprovedBuff(buffId);
  131. +              
  132. +               for (Node replaceNode = node.getFirstChild(); replaceNode != null; replaceNode = replaceNode.getNextSibling())
  133. +               {
  134. +                   if (!"replace".equalsIgnoreCase(replaceNode.getNodeName()))
  135. +                   {
  136. +                       continue;
  137. +                   }
  138. +                  
  139. +                   NamedNodeMap replaceAttrs = replaceNode.getAttributes();
  140. +                   int replaceBuffId = Integer.parseInt(replaceAttrs.getNamedItem("buffId").getNodeValue());
  141. +                  
  142. +                   improvedBuff.addReplaceBuff(replaceBuffId);
  143. +               }
  144. +              
  145. +               improvedBuffs.put(buffId, improvedBuff);
  146. +           }
  147. +       }
  148. +       catch (Exception e)
  149. +       {
  150. +           // LOG.warning("ImprovedData: Error while loading improved buffs: " + e);
  151. +           e.printStackTrace();
  152. +       }
  153. +   }
  154. +  
  155. +   public Map<Integer, ImprovedBuff> getImprovedBuffs()
  156. +   {
  157. +       return improvedBuffs;
  158. +   }
  159. +  
  160. +   public ImprovedBuff getImprovedBuffById(int buffId)
  161. +   {
  162. +       return improvedBuffs.get(buffId);
  163. +   }
  164. +  
  165. +   public List<Integer> getReplaceBuffIds(int buffId)
  166. +   {
  167. +       ImprovedBuff improvedBuff = improvedBuffs.get(buffId);
  168. +       if (improvedBuff != null)
  169. +       {
  170. +           return improvedBuff.getReplaceBuffIds();
  171. +       }
  172. +       return new ArrayList<>(); // Devuelve una lista vacía si no se encuentran replaceBuffIds
  173. +   }
  174. +  
  175. +}
  176. diff --git java/org/l2jmobius/gameserver/GameServer.java java/org/l2jmobius/gameserver/GameServer.java
  177. index dcb71b0..cc2b44c 100644
  178. --- java/org/l2jmobius/gameserver/GameServer.java
  179. +++ java/org/l2jmobius/gameserver/GameServer.java
  180. @@ -129,6 +129,7 @@
  181.  import org.l2jmobius.gameserver.ui.Gui;
  182.  
  183.  import Base.Data.IconTable;
  184. +import Base.Improved.ImprovedData;
  185.  import Base.RandomCraft.RandomCraftXML;
  186.  import Base.XML.XMLDocumentFactory;
  187.  
  188. @@ -347,6 +348,9 @@
  189.         printSection("RandomCraft - Terius");
  190.         RandomCraftXML.getInstance();
  191.        
  192. +       printSection("Buff Improved - Terius");
  193. +       ImprovedData.getInstance();
  194. +      
  195.         XMLDocumentFactory.getInstance();
  196.        
  197.         printSection("Handlers");
  198. diff --git java/org/l2jmobius/gameserver/model/actor/Player.java java/org/l2jmobius/gameserver/model/actor/Player.java
  199. index acdedfa..2e6f883 100644
  200. --- java/org/l2jmobius/gameserver/model/actor/Player.java
  201. +++ java/org/l2jmobius/gameserver/model/actor/Player.java
  202. @@ -15649,4 +15649,16 @@
  203.     {
  204.         return true;
  205.     }
  206. +  
  207. +   boolean active = false;
  208. +  
  209. +   public boolean isActiveImproved()
  210. +   {
  211. +       return active;
  212. +   }
  213. +  
  214. +   public void setActiveImproved(boolean active)
  215. +   {
  216. +       this.active = active;
  217. +   }
  218.  }
  219. \ No newline at end of file
  220. diff --git java/org/l2jmobius/gameserver/model/effects/Effect.java java/org/l2jmobius/gameserver/model/effects/Effect.java
  221. index 957cff3..635232e 100644
  222. --- java/org/l2jmobius/gameserver/model/effects/Effect.java
  223. +++ java/org/l2jmobius/gameserver/model/effects/Effect.java
  224. @@ -124,6 +124,7 @@
  225.     private final EffectTemplate _template;
  226.    
  227.     private boolean _inUse = false;
  228. +   private boolean _startConditionsCorrect = true;
  229.    
  230.     protected Effect(Env env, EffectTemplate template)
  231.     {
  232. @@ -209,9 +210,21 @@
  233.         return _inUse;
  234.     }
  235.    
  236. -   public void setInUse(boolean inUse)
  237. +   public boolean setInUse(boolean inUse)
  238.     {
  239.         _inUse = inUse;
  240. +      
  241. +       if (_inUse)
  242. +       {
  243. +           _startConditionsCorrect = onStart2();
  244. +       }
  245. +       else
  246. +       {
  247. +           onExit();
  248. +       }
  249. +      
  250. +       return _startConditionsCorrect;
  251. +      
  252.     }
  253.    
  254.     public String getStackType()
  255. @@ -350,7 +363,8 @@
  256.      */
  257.     public abstract EffectType getEffectType();
  258.    
  259. -   /** Notify started */
  260. +   /* /** Notify started */
  261. +  
  262.     public void onStart()
  263.     {
  264.         if (_abnormalEffect != 0)
  265. @@ -360,6 +374,20 @@
  266.     }
  267.    
  268.     /**
  269. +    * Fire an event, happening on start2.
  270. +    * @return Always true, but overidden in each effect.
  271. +    */
  272. +   public boolean onStart2()
  273. +   {
  274. +       if (_abnormalEffect != 0)
  275. +       {
  276. +           _effected.startAbnormalEffect(_abnormalEffect);
  277. +       }
  278. +      
  279. +       return true;
  280. +   }
  281. +  
  282. +   /**
  283.      * Cancel the effect in the the abnormal effect map of the effected Creature.
  284.      */
  285.     public void onExit()
  286. @@ -403,6 +431,8 @@
  287.             _state = EffectState.ACTING;
  288.            
  289.             onStart();
  290. +           // Effects not having count or period should start.
  291. +           _startConditionsCorrect = onStart2();
  292.            
  293.             if (_skill.isPvpSkill() && (_effected != null) && (_effected instanceof Player) && _template.showIcon)
  294.             {
  295. diff --git java/org/l2jmobius/gameserver/model/skill/effects/EffectBuff.java java/org/l2jmobius/gameserver/model/skill/effects/EffectBuff.java
  296. index 3a62890..d9a8be1 100644
  297. --- java/org/l2jmobius/gameserver/model/skill/effects/EffectBuff.java
  298. +++ java/org/l2jmobius/gameserver/model/skill/effects/EffectBuff.java
  299. @@ -16,10 +16,17 @@
  300.   */
  301.  package org.l2jmobius.gameserver.model.skill.effects;
  302.  
  303. +import java.util.List;
  304. +import java.util.Map;
  305. +
  306. +import org.l2jmobius.gameserver.model.actor.Player;
  307.  import org.l2jmobius.gameserver.model.effects.Effect;
  308.  import org.l2jmobius.gameserver.model.effects.EffectType;
  309.  import org.l2jmobius.gameserver.model.skill.Env;
  310.  
  311. +import Base.Improved.ImprovedBuff;
  312. +import Base.Improved.ImprovedData;
  313. +
  314.  /**
  315.   * @author mkizub TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
  316.   */
  317. @@ -37,6 +44,95 @@
  318.     }
  319.    
  320.     @Override
  321. +   public boolean onStart2()
  322. +   {
  323. +      
  324. +       super.onStart();
  325. +      
  326. +       if (getEffected() instanceof Player)
  327. +       {
  328. +           Player player = (Player) getEffected();
  329. +           ImprovedData improvedData = ImprovedData.getInstance();
  330. +          
  331. +           // Obtener los Improved Buff IDs del archivo XML
  332. +           Map<Integer, ImprovedBuff> improvedBuffs = improvedData.getImprovedBuffs();
  333. +          
  334. +           // Iterar sobre los Improved Buffs
  335. +           for (ImprovedBuff improvedBuff : improvedBuffs.values())
  336. +           {
  337. +               int buffId = improvedBuff.getBuffId();
  338. +              
  339. +               List<Integer> buffIdr = improvedBuff.getReplaceBuffIds();
  340. +              
  341. +               if (player.isActiveImproved() && buffIdr.contains(getSkill().getId()))
  342. +               {
  343. +                  
  344. +                   // Verificar si el Improved Buff correspondiente está activo
  345. +                   int improvedBuffId = improvedBuff.getBuffId();
  346. +                   if (player.getFirstEffect(improvedBuffId) != null)
  347. +                   {
  348. +                       // Obtener los replace buff IDs asociados al Improved Buff activo
  349. +                       List<Integer> replaceBuffIds2 = improvedBuff.getReplaceBuffIds();
  350. +                       for (int replaceBuffId : replaceBuffIds2)
  351. +                       {
  352. +                           if (player.getFirstEffect(replaceBuffId) != null)
  353. +                           {
  354. +                               player.stopSkillEffects(replaceBuffId);
  355. +                           }
  356. +                       }
  357. +                   }
  358. +               }
  359. +              
  360. +               // Verificar si el ID del skill actual coincide con el Improved Buff ID
  361. +               if (getSkill().getId() == buffId)
  362. +               {
  363. +                   // Eliminar los ReplaceBuffs activos
  364. +                   List<Integer> replaceBuffIds = improvedBuff.getReplaceBuffIds();
  365. +                   for (int replaceBuffId : replaceBuffIds)
  366. +                   {
  367. +                       if (player.getFirstEffect(replaceBuffId) != null)
  368. +                       {
  369. +                           player.stopSkillEffects(replaceBuffId);
  370. +                       }
  371. +                      
  372. +                   }
  373. +                   player.setActiveImproved(true);
  374. +                  
  375. +                   break;
  376. +               }
  377. +           }
  378. +       }
  379. +       return super.onStart2();
  380. +      
  381. +   }
  382. +  
  383. +   @Override
  384. +   public void onExit()
  385. +   {
  386. +       super.onExit();
  387. +       if (getEffected() instanceof Player)
  388. +       {
  389. +           Player player = (Player) getEffected();
  390. +           ImprovedData improvedData = ImprovedData.getInstance();
  391. +          
  392. +           // Obtener los Improved Buff IDs del archivo XML
  393. +           Map<Integer, ImprovedBuff> improvedBuffs = improvedData.getImprovedBuffs();
  394. +          
  395. +           // Iterar sobre los Improved Buffs
  396. +           for (ImprovedBuff improvedBuff : improvedBuffs.values())
  397. +           {
  398. +               int buffId = improvedBuff.getBuffId();
  399. +              
  400. +               if (getSkill().getId() == buffId)
  401. +               {
  402. +                   player.setActiveImproved(false);
  403. +               }
  404. +           }
  405. +          
  406. +       }
  407. +   }
  408. +  
  409. +   @Override
  410.     public boolean onActionTime()
  411.     {
  412.         // just stop this effect
  413.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement