2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.taming;
|
|
|
|
|
2013-03-01 21:49:24 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2013-03-01 21:49:24 +01:00
|
|
|
import org.bukkit.entity.Ocelot;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Tameable;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.entity.Wolf;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2013-03-01 21:49:24 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
2013-03-01 21:49:24 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-03-01 21:49:24 +01:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2013-08-23 16:58:50 +02:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
|
|
public class TamingManager extends SkillManager {
|
|
|
|
public TamingManager(McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.TAMING);
|
|
|
|
}
|
|
|
|
|
2013-03-01 21:49:24 +01:00
|
|
|
public boolean canUseThickFur() {
|
2013-03-04 15:40:03 +01:00
|
|
|
return getSkillLevel() >= Taming.thickFurUnlockLevel && Permissions.thickFur(getPlayer());
|
2013-03-01 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseEnvironmentallyAware() {
|
2013-03-04 15:40:03 +01:00
|
|
|
return getSkillLevel() >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(getPlayer());
|
2013-03-01 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseShockProof() {
|
2013-03-04 15:40:03 +01:00
|
|
|
return getSkillLevel() >= Taming.shockProofUnlockLevel && Permissions.shockProof(getPlayer());
|
2013-03-01 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseHolyHound() {
|
2013-03-04 15:40:03 +01:00
|
|
|
return getSkillLevel() >= Taming.holyHoundUnlockLevel && Permissions.holyHound(getPlayer());
|
2013-03-01 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
public boolean canUseFastFoodService() {
|
|
|
|
return getSkillLevel() >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseSharpenedClaws() {
|
|
|
|
return getSkillLevel() >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseGore() {
|
|
|
|
return Permissions.gore(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseBeastLore() {
|
|
|
|
return Permissions.beastLore(getPlayer());
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Award XP for taming.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param entity The LivingEntity to award XP for
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public void awardTamingXP(LivingEntity entity) {
|
|
|
|
switch (entity.getType()) {
|
|
|
|
case WOLF:
|
|
|
|
applyXpGain(Taming.wolfXp);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case OCELOT:
|
|
|
|
applyXpGain(Taming.ocelotXp);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Fast Food Service ability.
|
|
|
|
*
|
|
|
|
* @param wolf The wolf using the ability
|
|
|
|
* @param damage The damage being absorbed by the wolf
|
|
|
|
*/
|
2013-07-11 18:43:36 +02:00
|
|
|
public void fastFoodService(Wolf wolf, double damage) {
|
2013-03-05 04:45:37 +01:00
|
|
|
if (Taming.fastFoodServiceActivationChance > Misc.getRandom().nextInt(getActivationChance())) {
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-07-11 18:43:36 +02:00
|
|
|
double health = wolf.getHealth();
|
|
|
|
double maxHealth = wolf.getMaxHealth();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (health < maxHealth) {
|
2013-07-11 18:43:36 +02:00
|
|
|
double newHealth = health + damage;
|
2013-03-01 06:52:01 +01:00
|
|
|
wolf.setHealth(Math.min(newHealth, maxHealth));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Gore ability.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param target The LivingEntity to apply Gore on
|
|
|
|
* @param damage The initial damage
|
2013-08-23 17:21:56 +02:00
|
|
|
* @param wolf The wolf using the ability
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-08-23 16:58:50 +02:00
|
|
|
public void gore(LivingEntity target, double damage, Wolf wolf) {
|
|
|
|
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-01 21:49:24 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
BleedTimerTask.add(target, Taming.goreBleedTicks);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
if (target instanceof Player) {
|
|
|
|
((Player) target).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-01 21:49:24 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
|
|
|
|
|
|
|
|
damage = (damage * Taming.goreModifier) - damage;
|
|
|
|
CombatUtils.dealDamage(target, damage, wolf);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sharpenedClaws(LivingEntity target, Wolf wolf) {
|
|
|
|
CombatUtils.dealDamage(target, Taming.sharpenedClawsBonusDamage, wolf);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Summon an ocelot to your side.
|
|
|
|
*/
|
|
|
|
public void summonOcelot() {
|
2013-08-30 19:50:34 +02:00
|
|
|
if (!Permissions.callOfTheWild(getPlayer(), EntityType.OCELOT)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
callOfTheWild(EntityType.OCELOT, Config.getInstance().getTamingCOTWOcelotCost());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Summon a wolf to your side.
|
|
|
|
*/
|
|
|
|
public void summonWolf() {
|
2013-08-30 19:50:34 +02:00
|
|
|
if (!Permissions.callOfTheWild(getPlayer(), EntityType.WOLF)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
callOfTheWild(EntityType.WOLF, Config.getInstance().getTamingCOTWWolfCost());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Beast Lore ability.
|
|
|
|
*
|
2013-03-01 21:49:24 +01:00
|
|
|
* @param target The entity to examine
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-03-01 21:49:24 +01:00
|
|
|
public void beastLore(LivingEntity target) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
Tameable beast = (Tameable) target;
|
|
|
|
|
|
|
|
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
|
|
|
|
|
2013-07-22 11:35:48 +02:00
|
|
|
if (beast.isTamed() && beast.getOwner() != null) {
|
2013-03-03 21:22:40 +01:00
|
|
|
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", beast.getOwner().getName()) + " ");
|
2013-03-01 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", target.getHealth(), target.getMaxHealth()));
|
|
|
|
player.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
2013-07-11 18:43:36 +02:00
|
|
|
public void processEnvironmentallyAware(Wolf wolf, double damage) {
|
2013-03-01 21:49:24 +01:00
|
|
|
if (damage > wolf.getHealth()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player owner = getPlayer();
|
|
|
|
|
|
|
|
wolf.teleport(owner);
|
|
|
|
owner.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
|
2013-03-01 06:52:01 +01: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
|
|
|
|
*/
|
|
|
|
private void callOfTheWild(EntityType type, int summonAmount) {
|
2013-03-01 21:49:24 +01:00
|
|
|
Player player = getPlayer();
|
|
|
|
|
|
|
|
ItemStack heldItem = player.getItemInHand();
|
|
|
|
int heldItemAmount = heldItem.getAmount();
|
|
|
|
|
|
|
|
if (heldItemAmount < summonAmount) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(heldItem.getTypeId())));
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-24 20:13:58 +02:00
|
|
|
if (!rangeCheck(type)) {
|
|
|
|
return;
|
2013-03-01 21:49:24 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-07-24 20:01:16 +02:00
|
|
|
int amount = Config.getInstance().getTamingCOTWAmount(type);
|
2013-07-24 20:13:58 +02:00
|
|
|
|
2013-07-24 20:01:16 +02:00
|
|
|
for (int i = 0; i < amount; i++) {
|
|
|
|
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-07-24 20:01:16 +02:00
|
|
|
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
|
|
|
|
((Tameable) entity).setOwner(player);
|
2013-03-01 21:49:24 +01:00
|
|
|
|
2013-07-24 20:13:58 +02:00
|
|
|
switch (type) {
|
|
|
|
case OCELOT:
|
|
|
|
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Misc.getRandom().nextInt(3)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WOLF:
|
|
|
|
entity.setMaxHealth(20.0);
|
|
|
|
entity.setHealth(entity.getMaxHealth());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2013-07-24 20:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Permissions.renamePets(player)) {
|
2013-07-24 20:13:58 +02:00
|
|
|
entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type)));
|
2013-07-24 20:01:16 +02:00
|
|
|
entity.setCustomNameVisible(true);
|
|
|
|
}
|
2013-04-18 23:04:27 +02:00
|
|
|
}
|
|
|
|
|
2013-03-01 21:49:24 +01:00
|
|
|
player.setItemInHand(new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-07-24 20:13:58 +02:00
|
|
|
|
|
|
|
private boolean rangeCheck(EntityType type) {
|
|
|
|
double range = Config.getInstance().getTamingCOTWRange();
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
|
|
|
if (range == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Entity entity : player.getNearbyEntities(range, range, range)) {
|
|
|
|
if (entity.getType() == type) {
|
|
|
|
player.sendMessage(Taming.getCallOfTheWildFailureMessage(type));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|