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

257 lines
7.3 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.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;
import org.bukkit.inventory.ItemStack;
2012-06-13 14:54:02 +02:00
2012-06-12 20:42:38 +02:00
import com.gmail.nossr50.config.Config;
2012-06-12 17:07:51 +02:00
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class TamingManager {
private Player player;
private PlayerProfile profile;
private int skillLevel;
private Permissions permissionsInstance;
2012-06-12 20:42:38 +02:00
private Config configInstance;
2012-06-12 17:07:51 +02:00
public TamingManager (Player player) {
this.player = player;
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.TAMING);
2012-06-12 20:42:38 +02:00
this.permissionsInstance = Permissions.getInstance();
this.configInstance = Config.getInstance();
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 (!permissionsInstance.fastFoodService(player)) {
return;
}
if (skillLevel >= Taming.FAST_FOOD_SERVICE_ACTIVATION_LEVEL) {
if (Taming.getRandom().nextInt(100) < Taming.FAST_FOOD_SERVICE_ACTIVATION_CHANCE) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
eventHandler.modifyHealth(damage);
}
}
}
/**
* Apply the Sharpened Claws ability.
*
* @param event The event to modify
*/
public void sharpenedClaws(EntityDamageEvent event) {
if (!permissionsInstance.sharpenedClaws(player)) {
return;
}
if (skillLevel >= Taming.SHARPENED_CLAWS_ACTIVATION_LEVEL) {
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
eventHandler.modifyEventDamage();
}
}
/**
* Apply the Gore ability.
*
* @param event The event to modify
*/
public void gore(EntityDamageEvent event) {
if (!permissionsInstance.gore(player)) {
return;
}
GoreEventHandler eventHandler = new GoreEventHandler(this, event);
2012-06-15 02:34:24 +02:00
if (Taming.getRandom().nextInt(1000) < eventHandler.skillModifier) {
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, configInstance.getTamingCOTWOcelotCost());
}
/**
* Summon a wolf to your side.
*/
public void summonWolf() {
callOfTheWild(EntityType.WOLF, configInstance.getTamingCOTWWolfCost());
}
/**
* Handle the Beast Lore ability.
*
* @param livingEntity The entity to examine
*/
2012-06-12 20:42:38 +02:00
public void beastLore(LivingEntity livingEntity) {
if (!permissionsInstance.beastLore(player)) {
return;
}
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity);
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 (!permissionsInstance.callOfTheWild(player)) {
return;
}
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(player, type, summonAmount);
ItemStack inHand = eventHandler.inHand;
int inHandAmount = inHand.getAmount();
if (inHandAmount < summonAmount) {
eventHandler.sendInsufficientAmountMessage();
return;
}
else {
if (eventHandler.nearbyEntityExists()) {
eventHandler.sendFailureMessage();
}
else {
eventHandler.spawnCreature();
eventHandler.processResourceCost();
eventHandler.sendSuccessMessage();
}
}
}
/**
* 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 (!permissionsInstance.environmentallyAware(player)) {
return;
}
if (skillLevel >= Taming.ENVIRONMENTALLY_AWARE_ACTIVATION_LEVEL) {
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 (!permissionsInstance.thickFur(player)) {
return;
}
if (skillLevel >= Taming.THICK_FUR_ACTIVATION_LEVEL) {
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
eventHandler.modifyEventDamage();
}
}
/**
* 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 (!permissionsInstance.shockProof(player)) {
return;
}
if (skillLevel >= Taming.SHOCK_PROOF_ACTIVATION_LEVEL) {
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
eventHandler.modifyEventDamage();
}
}
2012-06-12 17:07:51 +02:00
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
}