TamingManager.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package com.gmail.nossr50.skills.taming;
  2. import org.bukkit.entity.EntityType;
  3. import org.bukkit.entity.LivingEntity;
  4. import org.bukkit.entity.Wolf;
  5. import org.bukkit.event.entity.EntityDamageEvent;
  6. import org.bukkit.event.entity.EntityTameEvent;
  7. import org.bukkit.inventory.ItemStack;
  8. import com.gmail.nossr50.mcMMO;
  9. import com.gmail.nossr50.config.Config;
  10. import com.gmail.nossr50.datatypes.McMMOPlayer;
  11. import com.gmail.nossr50.skills.SkillManager;
  12. import com.gmail.nossr50.skills.utilities.SkillType;
  13. import com.gmail.nossr50.util.Misc;
  14. import com.gmail.nossr50.util.Permissions;
  15. public class TamingManager extends SkillManager {
  16. public TamingManager(McMMOPlayer mcMMOPlayer) {
  17. super(mcMMOPlayer, SkillType.TAMING);
  18. }
  19. /**
  20. * Award XP for taming.
  21. *
  22. * @param event The event to award XP for
  23. */
  24. public void awardTamingXP(EntityTameEvent event) {
  25. if (event.getEntity() == null) {
  26. return;
  27. }
  28. else if (event.getEntity().hasMetadata(mcMMO.entityMetadataKey)) {
  29. return;
  30. }
  31. switch (event.getEntityType()) {
  32. case WOLF:
  33. mcMMOPlayer.beginXpGain(SkillType.TAMING, Taming.wolfXp);
  34. break;
  35. case OCELOT:
  36. mcMMOPlayer.beginXpGain(SkillType.TAMING, Taming.ocelotXp);
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. /**
  43. * Apply the Fast Food Service ability.
  44. *
  45. * @param wolf The wolf using the ability
  46. * @param damage The damage being absorbed by the wolf
  47. */
  48. public void fastFoodService(Wolf wolf, int damage) {
  49. if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
  50. FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
  51. eventHandler.modifyHealth(damage);
  52. }
  53. }
  54. /**
  55. * Apply the Sharpened Claws ability.
  56. *
  57. * @param event The event to modify
  58. */
  59. public void sharpenedClaws(EntityDamageEvent event) {
  60. SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
  61. eventHandler.modifyEventDamage();
  62. }
  63. /**
  64. * Apply the Gore ability.
  65. *
  66. * @param event The event to modify
  67. */
  68. public void gore(EntityDamageEvent event) {
  69. GoreEventHandler eventHandler = new GoreEventHandler(this, event);
  70. float chance = (float) ((Taming.goreMaxChance / Taming.goreMaxBonusLevel) * skillLevel);
  71. if (chance > Taming.goreMaxChance) chance = (float) Taming.goreMaxChance;
  72. if (chance > Misc.getRandom().nextInt(activationChance)) {
  73. eventHandler.modifyEventDamage();
  74. eventHandler.applyBleed();
  75. eventHandler.sendAbilityMessage();
  76. }
  77. }
  78. /**
  79. * Summon an ocelot to your side.
  80. */
  81. public void summonOcelot() {
  82. callOfTheWild(EntityType.OCELOT, Config.getInstance().getTamingCOTWOcelotCost());
  83. }
  84. /**
  85. * Summon a wolf to your side.
  86. */
  87. public void summonWolf() {
  88. callOfTheWild(EntityType.WOLF, Config.getInstance().getTamingCOTWWolfCost());
  89. }
  90. /**
  91. * Handle the Beast Lore ability.
  92. *
  93. * @param livingEntity The entity to examine
  94. */
  95. public void beastLore(LivingEntity livingEntity) {
  96. BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(mcMMOPlayer.getPlayer(), livingEntity);
  97. eventHandler.sendInspectMessage();
  98. }
  99. /**
  100. * Handle the Call of the Wild ability.
  101. *
  102. * @param type The type of entity to summon.
  103. * @param summonAmount The amount of material needed to summon the entity
  104. */
  105. private void callOfTheWild(EntityType type, int summonAmount) {
  106. if (!Permissions.callOfTheWild(mcMMOPlayer.getPlayer())) {
  107. return;
  108. }
  109. CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(mcMMOPlayer.getPlayer(), type, summonAmount);
  110. ItemStack inHand = eventHandler.inHand;
  111. int inHandAmount = inHand.getAmount();
  112. if (inHandAmount < summonAmount) {
  113. eventHandler.sendInsufficientAmountMessage();
  114. return;
  115. }
  116. if (eventHandler.nearbyEntityExists()) {
  117. eventHandler.sendFailureMessage();
  118. }
  119. else {
  120. eventHandler.spawnCreature();
  121. eventHandler.processResourceCost();
  122. eventHandler.sendSuccessMessage();
  123. }
  124. }
  125. }