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.Player;
|
|
|
|
import org.bukkit.entity.Wolf;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2012-06-12 20:42:38 +02:00
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
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-01-10 15:26:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillType;
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.skills.Skills;
|
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 {
|
2012-06-12 20:42:38 +02:00
|
|
|
private Config configInstance;
|
2012-06-12 17:07:51 +02:00
|
|
|
|
|
|
|
public TamingManager (Player player) {
|
2013-01-10 15:26:01 +01:00
|
|
|
super(player, SkillType.TAMING);
|
2012-06-12 20:42:38 +02:00
|
|
|
this.configInstance = Config.getInstance();
|
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) {
|
|
|
|
if (mcMMO.placeStore.isSpawnedMob(event.getEntity())) {
|
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:
|
|
|
|
Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.wolfXP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OCELOT:
|
|
|
|
Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.ocelotXP);
|
|
|
|
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) {
|
|
|
|
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(player)) {
|
2013-01-22 16:48:10 +01:00
|
|
|
if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
|
2012-06-12 17:07:51 +02:00
|
|
|
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
|
|
|
|
|
|
|
|
eventHandler.modifyHealth(damage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Sharpened Claws ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public void sharpenedClaws(EntityDamageEvent event) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(player)) {
|
2012-06-12 17:07:51 +02:00
|
|
|
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
|
|
|
|
|
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Gore ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public void gore(EntityDamageEvent event) {
|
2013-01-07 02:52:31 +01:00
|
|
|
if (!Permissions.gore(player)) {
|
2012-06-12 17:07:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Prevent damage to wolves based on various skills.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public void preventDamage(EntityDamageEvent event) {
|
|
|
|
DamageCause cause = event.getCause();
|
|
|
|
|
|
|
|
switch (cause) {
|
|
|
|
case CONTACT:
|
|
|
|
case LAVA:
|
|
|
|
case FIRE:
|
|
|
|
case FALL:
|
|
|
|
environmentallyAware(event, cause);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENTITY_ATTACK:
|
2012-06-12 20:48:28 +02:00
|
|
|
case FIRE_TICK:
|
2012-06-12 20:42:38 +02:00
|
|
|
case PROJECTILE:
|
|
|
|
thickFur(event, cause);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_EXPLOSION:
|
2012-06-12 20:48:28 +02:00
|
|
|
case ENTITY_EXPLOSION:
|
|
|
|
case LIGHTNING:
|
2012-06-12 20:42:38 +02:00
|
|
|
shockProof(event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Summon an ocelot to your side.
|
|
|
|
*/
|
|
|
|
public void summonOcelot() {
|
|
|
|
callOfTheWild(EntityType.OCELOT, configInstance.getTamingCOTWOcelotCost());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Summon a wolf to your side.
|
|
|
|
*/
|
|
|
|
public void summonWolf() {
|
|
|
|
callOfTheWild(EntityType.WOLF, configInstance.getTamingCOTWWolfCost());
|
|
|
|
}
|
|
|
|
|
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-01-07 02:52:31 +01:00
|
|
|
if (!Permissions.beastLore(player)) {
|
2012-06-12 20:42:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity);
|
|
|
|
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-01-07 02:52:31 +01:00
|
|
|
if (!Permissions.callOfTheWild(player)) {
|
2012-06-12 20:42:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(player, type, summonAmount);
|
|
|
|
|
|
|
|
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 20:48:28 +02:00
|
|
|
/**
|
|
|
|
* Handle the Environmentally Aware ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
* @param cause The damage cause of the event
|
|
|
|
*/
|
2012-06-12 20:42:38 +02:00
|
|
|
private void environmentallyAware(EntityDamageEvent event, DamageCause cause) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(player)) {
|
2012-06-12 20:42:38 +02:00
|
|
|
EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event);
|
|
|
|
|
|
|
|
switch (cause) {
|
|
|
|
case CONTACT:
|
|
|
|
case FIRE:
|
|
|
|
case LAVA:
|
|
|
|
eventHandler.teleportWolf();
|
|
|
|
eventHandler.sendAbilityMessage();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FALL:
|
|
|
|
eventHandler.cancelEvent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 20:48:28 +02:00
|
|
|
/**
|
|
|
|
* Handle the Thick Fur ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
* @param cause The damage cause of the event
|
|
|
|
*/
|
2012-06-12 20:42:38 +02:00
|
|
|
private void thickFur(EntityDamageEvent event, DamageCause cause) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(player)) {
|
2012-12-24 22:56:25 +01:00
|
|
|
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
|
|
|
|
eventHandler.modifyEventDamage();
|
2012-06-12 20:42:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 20:48:28 +02:00
|
|
|
/**
|
|
|
|
* Handle the Shock Proof ability.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
2012-06-12 20:42:38 +02:00
|
|
|
private void shockProof(EntityDamageEvent event) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(player)) {
|
2012-06-12 20:42:38 +02:00
|
|
|
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
|
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
}
|
|
|
|
}
|
2012-06-12 17:07:51 +02:00
|
|
|
}
|