2012-06-12 17:07:51 +02:00
|
|
|
package com.gmail.nossr50.skills.taming;
|
|
|
|
|
2012-06-12 20:42:38 +02:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2012-06-12 17:07:51 +02:00
|
|
|
import org.bukkit.entity.Wolf;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2013-01-25 02:10:50 +01:00
|
|
|
import org.bukkit.event.entity.EntityTameEvent;
|
2012-06-12 20:42:38 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-06-13 14:54:02 +02:00
|
|
|
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-06-12 20:42:38 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2013-01-10 15:26:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2013-01-10 05:46:35 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-06-12 17:07:51 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
|
2013-01-10 15:26:01 +01:00
|
|
|
public class TamingManager extends SkillManager {
|
2013-02-01 06:38:25 +01:00
|
|
|
public TamingManager(McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.TAMING);
|
2012-06-12 17:07:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-25 02:10:50 +01:00
|
|
|
* Award XP for taming.
|
2012-06-12 17:07:51 +02:00
|
|
|
*
|
2013-01-25 02:10:50 +01:00
|
|
|
* @param event The event to award XP for
|
2012-06-12 17:07:51 +02:00
|
|
|
*/
|
2013-01-25 02:10:50 +01:00
|
|
|
public void awardTamingXP(EntityTameEvent event) {
|
2013-02-19 01:13:33 +01:00
|
|
|
if (event.getEntity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (event.getEntity().hasMetadata(mcMMO.entityMetadataKey)) {
|
2012-10-30 19:46:52 +01:00
|
|
|
return;
|
2013-01-25 02:10:50 +01:00
|
|
|
}
|
2012-10-30 19:46:52 +01:00
|
|
|
|
2013-01-25 02:10:50 +01:00
|
|
|
switch (event.getEntityType()) {
|
|
|
|
case WOLF:
|
2013-02-03 12:45:19 +01:00
|
|
|
mcMMOPlayer.beginXpGain(SkillType.TAMING, Taming.wolfXp);
|
2013-01-25 02:10:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OCELOT:
|
2013-02-03 12:45:19 +01:00
|
|
|
mcMMOPlayer.beginXpGain(SkillType.TAMING, Taming.ocelotXp);
|
2013-01-25 02:10:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-06-12 17:07:51 +02:00
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
}
|
2012-06-12 17:07:51 +02:00
|
|
|
|
2013-01-25 02:10:50 +01:00
|
|
|
/**
|
|
|
|
* Apply the Fast Food Service ability.
|
|
|
|
*
|
|
|
|
* @param wolf The wolf using the ability
|
|
|
|
* @param damage The damage being absorbed by the wolf
|
|
|
|
*/
|
|
|
|
public void fastFoodService(Wolf wolf, int damage) {
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
|
|
|
|
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
|
2012-06-12 17:07:51 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
eventHandler.modifyHealth(damage);
|
2012-06-12 17:07:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Sharpened Claws ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public void sharpenedClaws(EntityDamageEvent event) {
|
2013-01-25 23:21:18 +01:00
|
|
|
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
|
|
|
|
eventHandler.modifyEventDamage();
|
2012-06-12 17:07:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Gore ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public void gore(EntityDamageEvent event) {
|
|
|
|
GoreEventHandler eventHandler = new GoreEventHandler(this, event);
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2013-01-22 16:48:10 +01:00
|
|
|
float chance = (float) ((Taming.goreMaxChance / Taming.goreMaxBonusLevel) * skillLevel);
|
|
|
|
if (chance > Taming.goreMaxChance) chance = (float) Taming.goreMaxChance;
|
2013-01-02 01:27:50 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
2012-06-12 17:07:51 +02:00
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
eventHandler.applyBleed();
|
|
|
|
eventHandler.sendAbilityMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 20:42:38 +02:00
|
|
|
/**
|
|
|
|
* Summon an ocelot to your side.
|
|
|
|
*/
|
|
|
|
public void summonOcelot() {
|
2013-02-01 06:38:25 +01:00
|
|
|
callOfTheWild(EntityType.OCELOT, Config.getInstance().getTamingCOTWOcelotCost());
|
2012-06-12 20:42:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Summon a wolf to your side.
|
|
|
|
*/
|
|
|
|
public void summonWolf() {
|
2013-02-01 06:38:25 +01:00
|
|
|
callOfTheWild(EntityType.WOLF, Config.getInstance().getTamingCOTWWolfCost());
|
2012-06-12 20:42:38 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 20:48:28 +02:00
|
|
|
/**
|
|
|
|
* Handle the Beast Lore ability.
|
|
|
|
*
|
|
|
|
* @param livingEntity The entity to examine
|
|
|
|
*/
|
2012-06-12 20:42:38 +02:00
|
|
|
public void beastLore(LivingEntity livingEntity) {
|
2013-02-01 06:38:25 +01:00
|
|
|
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(mcMMOPlayer.getPlayer(), livingEntity);
|
2012-06-12 20:42:38 +02:00
|
|
|
eventHandler.sendInspectMessage();
|
|
|
|
}
|
|
|
|
|
2012-06-12 20:48:28 +02:00
|
|
|
/**
|
|
|
|
* Handle the Call of the Wild ability.
|
|
|
|
*
|
|
|
|
* @param type The type of entity to summon.
|
|
|
|
* @param summonAmount The amount of material needed to summon the entity
|
|
|
|
*/
|
2012-06-12 20:42:38 +02:00
|
|
|
private void callOfTheWild(EntityType type, int summonAmount) {
|
2013-02-01 06:38:25 +01:00
|
|
|
if (!Permissions.callOfTheWild(mcMMOPlayer.getPlayer())) {
|
2012-06-12 20:42:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(mcMMOPlayer.getPlayer(), type, summonAmount);
|
2012-06-12 20:42:38 +02:00
|
|
|
|
|
|
|
ItemStack inHand = eventHandler.inHand;
|
|
|
|
int inHandAmount = inHand.getAmount();
|
|
|
|
|
|
|
|
if (inHandAmount < summonAmount) {
|
|
|
|
eventHandler.sendInsufficientAmountMessage();
|
|
|
|
return;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
if (eventHandler.nearbyEntityExists()) {
|
|
|
|
eventHandler.sendFailureMessage();
|
|
|
|
}
|
2012-06-12 20:42:38 +02:00
|
|
|
else {
|
2013-01-10 04:43:21 +01:00
|
|
|
eventHandler.spawnCreature();
|
|
|
|
eventHandler.processResourceCost();
|
|
|
|
eventHandler.sendSuccessMessage();
|
2012-06-12 20:42:38 +02:00
|
|
|
}
|
|
|
|
}
|
2012-06-12 17:07:51 +02:00
|
|
|
}
|