SmeltingManager.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.gmail.nossr50.skills.smelting;
  2. import com.gmail.nossr50.datatypes.experience.XPGainReason;
  3. import com.gmail.nossr50.datatypes.experience.XPGainSource;
  4. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  5. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  6. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  7. import com.gmail.nossr50.mcMMO;
  8. import com.gmail.nossr50.skills.SkillManager;
  9. import com.gmail.nossr50.util.Permissions;
  10. import com.gmail.nossr50.util.random.RandomChanceUtil;
  11. import com.gmail.nossr50.util.skills.RankUtils;
  12. import com.gmail.nossr50.util.skills.SkillActivationType;
  13. import org.bukkit.block.BlockState;
  14. import org.bukkit.event.inventory.FurnaceBurnEvent;
  15. import org.bukkit.inventory.ItemStack;
  16. public class SmeltingManager extends SkillManager {
  17. public SmeltingManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
  18. super(pluginRef, mcMMOPlayer, PrimarySkillType.SMELTING);
  19. }
  20. /*public boolean canUseFluxMining(BlockState blockState) {
  21. return getSkillLevel() >= Smelting.fluxMiningUnlockLevel
  22. && BlockUtils.affectedByFluxMining(blockState)
  23. && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_FLUX_MINING)
  24. && !mcMMO.getPlaceStore().isTrue(blockState);
  25. }*/
  26. public boolean isSecondSmeltSuccessful() {
  27. return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_SECOND_SMELT)
  28. && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SMELTING_SECOND_SMELT, getPlayer());
  29. }
  30. /**
  31. * Process the Flux Mining ability.
  32. *
  33. * @param blockState The {@link BlockState} to check ability activation for
  34. * @return true if the ability was successful, false otherwise
  35. */
  36. /*public boolean processFluxMining(BlockState blockState) {
  37. Player player = getPlayer();
  38. if (RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), SubSkillType.SMELTING_FLUX_MINING, true)) {
  39. ItemStack item = null;
  40. switch (blockState.getType()) {
  41. case IRON_ORE:
  42. item = new ItemStack(Material.IRON_INGOT);
  43. break;
  44. case GOLD_ORE:
  45. item = new ItemStack(Material.GOLD_INGOT);
  46. break;
  47. default:
  48. break;
  49. }
  50. if (item == null) {
  51. return false;
  52. }
  53. if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, true)) {
  54. return false;
  55. }
  56. // We need to distribute Mining XP here, because the block break event gets cancelled
  57. applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE, XPGainSource.PASSIVE);
  58. SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), MainConfig.getInstance().getAbilityToolDamage());
  59. Misc.dropItems(Misc.getBlockCenter(blockState), item, isSecondSmeltSuccessful() ? 2 : 1);
  60. blockState.setType(Material.AIR);
  61. if (MainConfig.getInstance().getFluxPickaxeSoundEnabled()) {
  62. SoundManager.sendSound(player, blockState.getLocation(), SoundType.FIZZ);
  63. }
  64. ParticleEffectUtils.playFluxEffect(blockState.getLocation());
  65. return true;
  66. }
  67. return false;
  68. }*/
  69. /**
  70. * Increases burn time for furnace fuel.
  71. *
  72. * @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
  73. */
  74. public int fuelEfficiency(int burnTime) {
  75. return burnTime * getFuelEfficiencyMultiplier();
  76. }
  77. public int getFuelEfficiencyMultiplier() {
  78. switch (RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_FUEL_EFFICIENCY)) {
  79. case 1:
  80. return 2;
  81. case 2:
  82. return 3;
  83. case 3:
  84. return 4;
  85. default:
  86. return 1;
  87. }
  88. }
  89. public ItemStack smeltProcessing(ItemStack smelting, ItemStack result) {
  90. applyXpGain(Smelting.getResourceXp(smelting), XPGainReason.PVE, XPGainSource.PASSIVE);
  91. if (isSecondSmeltSuccessful()) {
  92. ItemStack newResult = result.clone();
  93. newResult.setAmount(result.getAmount() + 1);
  94. return newResult;
  95. }
  96. return result;
  97. }
  98. public int vanillaXPBoost(int experience) {
  99. return experience * getVanillaXpMultiplier();
  100. }
  101. /**
  102. * Gets the vanilla XP multiplier
  103. *
  104. * @return the vanilla XP multiplier
  105. */
  106. public int getVanillaXpMultiplier() {
  107. return Math.max(1, RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_UNDERSTANDING_THE_ART));
  108. }
  109. }