stayway

Untitled

Nov 12th, 2025
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.77 KB | None | 0 0
  1. diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/SpoilSystemHandler/SpoilSystemHandler.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/SpoilSystemHandler/SpoilSystemHandler.java
  2. new file mode 100644
  3. index 0000000..5893c2d
  4. --- /dev/null
  5. +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/SpoilSystemHandler/SpoilSystemHandler.java
  6. @@ -0,0 +1,210 @@
  7. +/*
  8. + * This file is part of the L2J Mobius project.
  9. + *
  10. + * This program is free software: you can redistribute it and/or modify
  11. + * it under the terms of the GNU General Public License as published by
  12. + * the Free Software Foundation, either version 3 of the License, or
  13. + * (at your option) any later version.
  14. + *
  15. + * This program is distributed in the hope that it will be useful,
  16. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. + * General Public License for more details.
  19. + *
  20. + * You should have received a copy of the GNU General Public License
  21. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. + */
  23. +
  24. +package handlers.SpoilSystemHandler;
  25. +
  26. +import java.util.logging.Logger;
  27. +
  28. +import org.l2jmobius.commons.util.Rnd;
  29. +import org.l2jmobius.gameserver.model.actor.Player;
  30. +import org.l2jmobius.gameserver.model.actor.instance.Monster;
  31. +import org.l2jmobius.gameserver.model.item.enums.ItemProcessType;
  32. +import org.l2jmobius.gameserver.model.item.instance.Item;
  33. +
  34. +import custom.SpoilConfig.SpoilConfig;
  35. +
  36. +/**
  37. + * SpoilSystemHandler
  38. + * @author Stayway
  39. + */
  40. +public class SpoilSystemHandler
  41. +{
  42. +   private static final Logger LOGGER = Logger.getLogger(SpoilSystemHandler.class.getName());
  43. +  
  44. +   private static final int SPOIL_SKILL_ID = 254;
  45. +  
  46. +   private static class SingletonHolder
  47. +   {
  48. +       protected static final SpoilSystemHandler INSTANCE = new SpoilSystemHandler();
  49. +   }
  50. +  
  51. +   public static SpoilSystemHandler getInstance()
  52. +   {
  53. +       return SingletonHolder.INSTANCE;
  54. +   }
  55. +  
  56. +   /**
  57. +    * @param player the player attempting to spoil
  58. +    * @param target the monster target
  59. +    * @return true if spoil was successful
  60. +    */
  61. +   public boolean trySpoil(Player player, Monster target)
  62. +   {
  63. +      
  64. +       if (!checkLevelDifference(player, target))
  65. +       {
  66. +           return false;
  67. +       }
  68. +      
  69. +       // Calculate spoil chance
  70. +       int spoilChance = calculateSpoilChance(player, target);
  71. +      
  72. +       // Roll for success
  73. +       boolean success = Rnd.get(10000) < spoilChance;
  74. +      
  75. +       // Handle result
  76. +       if (success)
  77. +       {
  78. +           handleSpoilSuccess(player, target, spoilChance);
  79. +       }
  80. +       else
  81. +       {
  82. +           handleSpoilFailure(player, target, spoilChance);
  83. +       }
  84. +      
  85. +       return success;
  86. +   }
  87. +  
  88. +   private boolean checkLevelDifference(Player player, Monster target)
  89. +   {
  90. +       int levelDiff = Math.abs(player.getLevel() - target.getLevel());
  91. +      
  92. +       if (levelDiff > SpoilConfig.SPOIL_MAX_LEVEL_DIFF)
  93. +       {
  94. +           if (SpoilConfig.SPOIL_FAIL_MESSAGE)
  95. +           {
  96. +               player.sendMessage("The level difference is too high to spoil this target.");
  97. +           }
  98. +           return false;
  99. +       }
  100. +      
  101. +       return true;
  102. +   }
  103. +  
  104. +   /**
  105. +    * @param player
  106. +    * @param target
  107. +    * @return
  108. +    */
  109. +   private int calculateSpoilChance(Player player, Monster target)
  110. +   {
  111. +       int spoilChance = SpoilConfig.SPOIL_BASE_CHANCE;
  112. +      
  113. +       // Level difference penalty
  114. +       int levelDiff = player.getLevel() - target.getLevel();
  115. +       if (levelDiff < -SpoilConfig.SPOIL_LEVEL_DIFF_PENALTY)
  116. +       {
  117. +           int penalty = Math.abs(levelDiff + SpoilConfig.SPOIL_LEVEL_DIFF_PENALTY);
  118. +           spoilChance -= penalty * SpoilConfig.SPOIL_LEVEL_DIFF_REDUCTION;
  119. +       }
  120. +      
  121. +       // WIT bonus
  122. +       spoilChance += player.getWIT() * 2;
  123. +      
  124. +       // Ensure within bounds (1% to 99%)
  125. +       return Math.max(100, Math.min(9900, spoilChance));
  126. +   }
  127. +  
  128. +   /**
  129. +    * Handle successful spoil
  130. +    * @param player
  131. +    * @param target
  132. +    * @param spoilChance
  133. +    */
  134. +   private void handleSpoilSuccess(Player player, Monster target, int spoilChance)
  135. +   {
  136. +       // Give rewards
  137. +       giveSpoilRewards(player, target);
  138. +      
  139. +       // Send success message
  140. +       if (SpoilConfig.SPOIL_SUCCESS_MESSAGE)
  141. +       {
  142. +           player.sendMessage("Spoil successful! You obtained items from the target.");
  143. +       }
  144. +   }
  145. +  
  146. +   /**
  147. +    * Handle failed spoil
  148. +    * @param player
  149. +    * @param target
  150. +    * @param spoilChance
  151. +    */
  152. +   private void handleSpoilFailure(Player player, Monster target, int spoilChance)
  153. +   {
  154. +       // Send fail message
  155. +       if (SpoilConfig.SPOIL_FAIL_MESSAGE)
  156. +       {
  157. +           player.sendMessage("Spoil failed.");
  158. +       }
  159. +   }
  160. +  
  161. +   /**
  162. +    * Give spoil rewards to player
  163. +    * @param player
  164. +    * @param target
  165. +    */
  166. +  
  167. +   private void giveSpoilRewards(Player player, Monster target)
  168. +   {
  169. +      
  170. +       // Give random materials (example items)
  171. +       giveRandomMaterials(player, target);
  172. +      
  173. +   }
  174. +  
  175. +   /**
  176. +    * Give random materials based on target level
  177. +    * @param player
  178. +    * @param target
  179. +    */
  180. +   @SuppressWarnings("unused")
  181. +   private void giveRandomMaterials(Player player, Monster target)
  182. +   {
  183. +       // Example material items - adjust IDs as needed
  184. +       int[] materialItems =
  185. +       {
  186. +           1865,
  187. +           1866,
  188. +           1867,
  189. +           1868,
  190. +           1869,
  191. +           1870
  192. +       }; // Animal bones, etc.
  193. +      
  194. +       int materialsToGive = Rnd.get(1, 3);
  195. +      
  196. +       for (int i = 0; i < materialsToGive; i++)
  197. +       {
  198. +           int itemId = materialItems[Rnd.get(materialItems.length)];
  199. +           int itemCount = Rnd.get(1, (int) (target.getLevel() * SpoilConfig.SPOIL_MATERIAL_MULTIPLIER));
  200. +          
  201. +           // Usando teus imports exatos: ItemProcessType e Item
  202. +           Item item = player.getInventory().addItem(ItemProcessType.SWEEP, itemId, itemCount, player, target);
  203. +          
  204. +       }
  205. +   }
  206. +  
  207. +   /**
  208. +    * Check if a skill ID is the spoil skill
  209. +    * @param skillId
  210. +    * @return
  211. +    */
  212. +   public boolean isSpoilSkill(int skillId)
  213. +   {
  214. +       return skillId == SPOIL_SKILL_ID;
  215. +   }
  216. +}
  217. \ No newline at end of file
  218.  
Advertisement
Add Comment
Please, Sign In to add comment