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 new file mode 100644 index 0000000..5893c2d --- /dev/null +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/SpoilSystemHandler/SpoilSystemHandler.java @@ -0,0 +1,210 @@ +/* + * This file is part of the L2J Mobius project. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package handlers.SpoilSystemHandler; + +import java.util.logging.Logger; + +import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.actor.instance.Monster; +import org.l2jmobius.gameserver.model.item.enums.ItemProcessType; +import org.l2jmobius.gameserver.model.item.instance.Item; + +import custom.SpoilConfig.SpoilConfig; + +/** + * SpoilSystemHandler + * @author Stayway + */ +public class SpoilSystemHandler +{ + private static final Logger LOGGER = Logger.getLogger(SpoilSystemHandler.class.getName()); + + private static final int SPOIL_SKILL_ID = 254; + + private static class SingletonHolder + { + protected static final SpoilSystemHandler INSTANCE = new SpoilSystemHandler(); + } + + public static SpoilSystemHandler getInstance() + { + return SingletonHolder.INSTANCE; + } + + /** + * @param player the player attempting to spoil + * @param target the monster target + * @return true if spoil was successful + */ + public boolean trySpoil(Player player, Monster target) + { + + if (!checkLevelDifference(player, target)) + { + return false; + } + + // Calculate spoil chance + int spoilChance = calculateSpoilChance(player, target); + + // Roll for success + boolean success = Rnd.get(10000) < spoilChance; + + // Handle result + if (success) + { + handleSpoilSuccess(player, target, spoilChance); + } + else + { + handleSpoilFailure(player, target, spoilChance); + } + + return success; + } + + private boolean checkLevelDifference(Player player, Monster target) + { + int levelDiff = Math.abs(player.getLevel() - target.getLevel()); + + if (levelDiff > SpoilConfig.SPOIL_MAX_LEVEL_DIFF) + { + if (SpoilConfig.SPOIL_FAIL_MESSAGE) + { + player.sendMessage("The level difference is too high to spoil this target."); + } + return false; + } + + return true; + } + + /** + * @param player + * @param target + * @return + */ + private int calculateSpoilChance(Player player, Monster target) + { + int spoilChance = SpoilConfig.SPOIL_BASE_CHANCE; + + // Level difference penalty + int levelDiff = player.getLevel() - target.getLevel(); + if (levelDiff < -SpoilConfig.SPOIL_LEVEL_DIFF_PENALTY) + { + int penalty = Math.abs(levelDiff + SpoilConfig.SPOIL_LEVEL_DIFF_PENALTY); + spoilChance -= penalty * SpoilConfig.SPOIL_LEVEL_DIFF_REDUCTION; + } + + // WIT bonus + spoilChance += player.getWIT() * 2; + + // Ensure within bounds (1% to 99%) + return Math.max(100, Math.min(9900, spoilChance)); + } + + /** + * Handle successful spoil + * @param player + * @param target + * @param spoilChance + */ + private void handleSpoilSuccess(Player player, Monster target, int spoilChance) + { + // Give rewards + giveSpoilRewards(player, target); + + // Send success message + if (SpoilConfig.SPOIL_SUCCESS_MESSAGE) + { + player.sendMessage("Spoil successful! You obtained items from the target."); + } + } + + /** + * Handle failed spoil + * @param player + * @param target + * @param spoilChance + */ + private void handleSpoilFailure(Player player, Monster target, int spoilChance) + { + // Send fail message + if (SpoilConfig.SPOIL_FAIL_MESSAGE) + { + player.sendMessage("Spoil failed."); + } + } + + /** + * Give spoil rewards to player + * @param player + * @param target + */ + + private void giveSpoilRewards(Player player, Monster target) + { + + // Give random materials (example items) + giveRandomMaterials(player, target); + + } + + /** + * Give random materials based on target level + * @param player + * @param target + */ + @SuppressWarnings("unused") + private void giveRandomMaterials(Player player, Monster target) + { + // Example material items - adjust IDs as needed + int[] materialItems = + { + 1865, + 1866, + 1867, + 1868, + 1869, + 1870 + }; // Animal bones, etc. + + int materialsToGive = Rnd.get(1, 3); + + for (int i = 0; i < materialsToGive; i++) + { + int itemId = materialItems[Rnd.get(materialItems.length)]; + int itemCount = Rnd.get(1, (int) (target.getLevel() * SpoilConfig.SPOIL_MATERIAL_MULTIPLIER)); + + // Usando teus imports exatos: ItemProcessType e Item + Item item = player.getInventory().addItem(ItemProcessType.SWEEP, itemId, itemCount, player, target); + + } + } + + /** + * Check if a skill ID is the spoil skill + * @param skillId + * @return + */ + public boolean isSpoilSkill(int skillId) + { + return skillId == SPOIL_SKILL_ID; + } +} \ No newline at end of file