mcMMO/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java

231 lines
7.0 KiB
Java
Raw Normal View History

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;
2012-06-12 20:42:38 +02:00
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
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
import com.gmail.nossr50.mcMMO;
2012-06-12 20:42:38 +02:00
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
2013-01-10 15:26:01 +01:00
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillType;
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 {
public TamingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.TAMING);
2012-06-12 17:07:51 +02:00
}
/**
* Award XP for taming.
2012-06-12 17:07:51 +02:00
*
* @param event The event to award XP for
2012-06-12 17:07:51 +02:00
*/
public void awardTamingXP(EntityTameEvent event) {
if (mcMMO.placeStore.isSpawnedMob(event.getEntity())) {
return;
}
switch (event.getEntityType()) {
case WOLF:
mcMMOPlayer.addXp(SkillType.TAMING, Taming.wolfXp);
break;
case OCELOT:
mcMMOPlayer.addXp(SkillType.TAMING, Taming.ocelotXp);
break;
default:
break;
2012-06-12 17:07:51 +02:00
}
}
2012-06-12 17:07:51 +02: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 (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
2012-06-12 17:07:51 +02: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) {
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-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:
case FIRE_TICK:
2012-06-12 20:42:38 +02:00
case PROJECTILE:
thickFur(event, cause);
break;
case BLOCK_EXPLOSION:
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, Config.getInstance().getTamingCOTWOcelotCost());
2012-06-12 20:42:38 +02:00
}
/**
* Summon a wolf to your side.
*/
public void summonWolf() {
callOfTheWild(EntityType.WOLF, Config.getInstance().getTamingCOTWWolfCost());
2012-06-12 20:42:38 +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) {
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(mcMMOPlayer.getPlayer(), livingEntity);
2012-06-12 20:42:38 +02:00
eventHandler.sendInspectMessage();
}
/**
* 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) {
if (!Permissions.callOfTheWild(mcMMOPlayer.getPlayer())) {
2012-06-12 20:42:38 +02:00
return;
}
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
}
}
/**
* 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) {
if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(mcMMOPlayer.getPlayer())) {
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;
}
}
}
/**
* 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) {
if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(mcMMOPlayer.getPlayer())) {
2012-12-24 22:56:25 +01:00
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
eventHandler.modifyEventDamage();
2012-06-12 20:42:38 +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) {
if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(mcMMOPlayer.getPlayer())) {
2012-06-12 20:42:38 +02:00
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
eventHandler.modifyEventDamage();
}
}
2012-06-12 17:07:51 +02:00
}