2012-05-01 19:58:47 +02:00
|
|
|
package com.gmail.nossr50.skills.combat;
|
2012-03-07 00:48:24 +01:00
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2012-03-18 06:42:56 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2012-03-07 00:48:24 +01:00
|
|
|
import org.bukkit.Material;
|
2012-03-14 18:33:00 +01:00
|
|
|
import org.bukkit.entity.AnimalTamer;
|
2012-03-07 00:48:24 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2012-03-26 16:03:05 +02:00
|
|
|
import org.bukkit.entity.Ocelot;
|
2012-03-07 00:48:24 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2012-03-14 18:33:00 +01:00
|
|
|
import org.bukkit.entity.Tameable;
|
2012-03-07 00:48:24 +01:00
|
|
|
import org.bukkit.entity.Wolf;
|
2012-03-20 03:05:17 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
2012-03-07 00:48:24 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-03-14 18:33:00 +01:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
2012-03-07 00:48:24 +01:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-03-07 00:48:24 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.runnables.BleedTimer;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-03-07 00:48:24 +01:00
|
|
|
|
2012-03-14 18:33:00 +01:00
|
|
|
public class Taming {
|
2012-03-26 17:04:17 +02:00
|
|
|
private static Random random = new Random();
|
|
|
|
|
2012-03-14 18:33:00 +01:00
|
|
|
/**
|
|
|
|
* Apply the Fast Food Service ability.
|
|
|
|
*
|
|
|
|
* @param PPo The PlayerProfile of the wolf's owner
|
|
|
|
* @param theWolf The wolf using the ability
|
2012-06-05 15:57:10 +02:00
|
|
|
* @param damage The damage being absorbed by the wolf
|
2012-03-14 18:33:00 +01:00
|
|
|
*/
|
2012-05-21 16:31:10 +02:00
|
|
|
public static void fastFoodService (PlayerProfile PPo, Wolf theWolf, int damage) {
|
2012-03-14 18:33:00 +01:00
|
|
|
final int SKILL_ACTIVATION_LEVEL = 50;
|
|
|
|
final int ACTIVATION_CHANCE = 50;
|
|
|
|
|
|
|
|
int health = theWolf.getHealth();
|
|
|
|
int maxHealth = theWolf.getMaxHealth();
|
|
|
|
|
|
|
|
if (PPo.getSkillLevel(SkillType.TAMING) >= SKILL_ACTIVATION_LEVEL) {
|
|
|
|
if (health < maxHealth) {
|
2012-03-26 17:04:17 +02:00
|
|
|
if (random.nextInt(100) < ACTIVATION_CHANCE) {
|
2012-03-14 18:33:00 +01:00
|
|
|
if (health + damage <= maxHealth) {
|
|
|
|
theWolf.setHealth(health + damage);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
theWolf.setHealth(maxHealth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Sharpened Claws ability.
|
|
|
|
*
|
|
|
|
* @param PPo The PlayerProfile of the wolf's owner
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public static void sharpenedClaws(PlayerProfile PPo, EntityDamageEvent event) {
|
|
|
|
final int SKILL_ACTIVATION_LEVEL = 750;
|
|
|
|
final int SHARPENED_CLAWS_BONUS = 2;
|
|
|
|
|
|
|
|
if (PPo.getSkillLevel(SkillType.TAMING) >= SKILL_ACTIVATION_LEVEL) {
|
|
|
|
event.setDamage(event.getDamage() + SHARPENED_CLAWS_BONUS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Gore ability.
|
|
|
|
*
|
|
|
|
* @param PPo The PlayerProfile of the wolf's owner
|
|
|
|
* @param event The event to modify
|
|
|
|
* @param master The wolf's master
|
|
|
|
*/
|
2012-05-21 16:31:10 +02:00
|
|
|
public static void gore(PlayerProfile PPo, EntityDamageEvent event, Player master) {
|
2012-03-14 18:33:00 +01:00
|
|
|
final int GORE_MULTIPLIER = 2;
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
if (random.nextInt(1000) <= PPo.getSkillLevel(SkillType.TAMING)) {
|
2012-03-14 18:33:00 +01:00
|
|
|
Entity entity = event.getEntity();
|
|
|
|
event.setDamage(event.getDamage() * GORE_MULTIPLIER);
|
|
|
|
|
|
|
|
if (entity instanceof Player) {
|
2012-04-28 06:14:19 +02:00
|
|
|
((Player) entity).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
BleedTimer.add((LivingEntity) entity, 2);
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
master.sendMessage(LocaleLoader.getString("Combat.Gore"));
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-22 16:07:20 +01:00
|
|
|
* Get the name of a tameable animal's owner.
|
2012-03-14 18:33:00 +01:00
|
|
|
*
|
2012-03-22 16:07:20 +01:00
|
|
|
* @param beast The animal whose owner's name to get
|
|
|
|
* @return the name of the animal's owner, or "Offline Master" if the owner is offline
|
2012-03-14 18:33:00 +01:00
|
|
|
*/
|
2012-03-22 16:07:20 +01:00
|
|
|
private static String getOwnerName(Tameable beast) {
|
|
|
|
AnimalTamer tamer = beast.getOwner();
|
2012-03-14 18:33:00 +01:00
|
|
|
|
|
|
|
if (tamer instanceof Player) {
|
2012-05-21 16:31:10 +02:00
|
|
|
return ((Player) tamer).getName();
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "Offline Master";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent damage to wolves based on various skills.
|
|
|
|
*
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
2012-03-15 22:29:27 +01:00
|
|
|
public static void preventDamage(EntityDamageEvent event) {
|
2012-03-14 18:33:00 +01:00
|
|
|
final int ENVIRONMENTALLY_AWARE_LEVEL = 100;
|
|
|
|
final int THICK_FUR_LEVEL = 250;
|
|
|
|
final int SHOCK_PROOF_LEVEL = 500;
|
|
|
|
|
|
|
|
final int THICK_FUR_MODIFIER = 2;
|
|
|
|
final int SHOCK_PROOF_MODIFIER = 6;
|
|
|
|
|
2012-05-21 10:44:48 +02:00
|
|
|
if (!(event.getEntity() instanceof Wolf)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-14 18:33:00 +01:00
|
|
|
DamageCause cause = event.getCause();
|
|
|
|
Wolf wolf = (Wolf) event.getEntity();
|
2012-03-07 00:48:24 +01:00
|
|
|
Player master = (Player) wolf.getOwner();
|
2012-03-14 18:33:00 +01:00
|
|
|
int skillLevel = Users.getProfile(master).getSkillLevel(SkillType.TAMING);
|
|
|
|
|
|
|
|
switch (cause) {
|
|
|
|
|
|
|
|
/* Environmentally Aware */
|
|
|
|
case CONTACT:
|
|
|
|
case LAVA:
|
|
|
|
case FIRE:
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Permissions.getInstance().environmentallyAware(master)) {
|
2012-03-20 03:05:17 +01:00
|
|
|
if (skillLevel >= ENVIRONMENTALLY_AWARE_LEVEL) {
|
|
|
|
if (event.getDamage() >= wolf.getHealth()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
wolf.teleport(master.getLocation());
|
2012-04-27 11:47:11 +02:00
|
|
|
master.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
|
2012-03-20 03:05:17 +01:00
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FALL:
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Permissions.getInstance().environmentallyAware(master)) {
|
2012-03-20 03:05:17 +01:00
|
|
|
if (skillLevel >= ENVIRONMENTALLY_AWARE_LEVEL) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Thick Fur */
|
|
|
|
case FIRE_TICK:
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Permissions.getInstance().thickFur(master)) {
|
2012-03-20 03:05:17 +01:00
|
|
|
if(skillLevel >= THICK_FUR_LEVEL) {
|
|
|
|
wolf.setFireTicks(0);
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENTITY_ATTACK:
|
|
|
|
case PROJECTILE:
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Permissions.getInstance().thickFur(master)) {
|
2012-03-20 03:05:17 +01:00
|
|
|
if (skillLevel >= THICK_FUR_LEVEL) {
|
|
|
|
event.setDamage(event.getDamage() / THICK_FUR_MODIFIER);
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Shock Proof */
|
|
|
|
case ENTITY_EXPLOSION:
|
|
|
|
case BLOCK_EXPLOSION:
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Permissions.getInstance().shockProof(master)) {
|
2012-03-20 03:05:17 +01:00
|
|
|
if (skillLevel >= SHOCK_PROOF_LEVEL) {
|
|
|
|
event.setDamage(event.getDamage() / SHOCK_PROOF_MODIFIER);
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Summon an animal.
|
|
|
|
*
|
|
|
|
* @param type Type of animal to summon
|
|
|
|
* @param player Player summoning the animal
|
|
|
|
*/
|
2012-06-07 00:02:22 +02:00
|
|
|
public static void animalSummon(EntityType type, Player player, mcMMO plugin) {
|
2012-03-14 18:33:00 +01:00
|
|
|
ItemStack item = player.getItemInHand();
|
|
|
|
Material summonItem = null;
|
|
|
|
int summonAmount = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case WOLF:
|
|
|
|
summonItem = Material.BONE;
|
2012-04-27 05:58:21 +02:00
|
|
|
summonAmount = Config.getInstance().getTamingCOTWWolfCost();
|
2012-03-14 18:33:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OCELOT:
|
|
|
|
summonItem = Material.RAW_FISH;
|
2012-04-27 05:58:21 +02:00
|
|
|
summonAmount = Config.getInstance().getTamingCOTWOcelotCost();
|
2012-03-14 18:33:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-19 04:17:43 +01:00
|
|
|
if (item.getType().equals(summonItem)) {
|
2012-03-18 06:42:56 +01:00
|
|
|
if (item.getAmount() >= summonAmount) {
|
|
|
|
for (Entity x : player.getNearbyEntities(40, 40, 40)) {
|
|
|
|
if (x.getType().equals(type)) {
|
2012-03-22 16:07:20 +01:00
|
|
|
switch (type) {
|
|
|
|
case WOLF:
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Wolf"));
|
2012-03-22 16:07:20 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
case OCELOT:
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Ocelot"));
|
2012-03-22 16:07:20 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2012-03-18 06:42:56 +01:00
|
|
|
}
|
2012-03-29 04:24:32 +02:00
|
|
|
}
|
|
|
|
|
2012-03-18 06:42:56 +01:00
|
|
|
LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
|
|
|
|
entity.setMetadata("mcmmoSummoned", new FixedMetadataValue(plugin, true));
|
|
|
|
((Tameable) entity).setOwner(player);
|
2012-03-14 18:33:00 +01:00
|
|
|
|
2012-03-26 16:03:05 +02:00
|
|
|
if (entity.getType().equals(EntityType.OCELOT)) {
|
2012-03-26 17:04:17 +02:00
|
|
|
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + random.nextInt(3)));
|
2012-03-26 16:03:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-29 04:24:32 +02:00
|
|
|
if (entity.getType().equals(EntityType.WOLF)) {
|
|
|
|
entity.setHealth(entity.getMaxHealth());
|
|
|
|
}
|
|
|
|
|
2012-03-18 06:42:56 +01:00
|
|
|
player.setItemInHand(new ItemStack(summonItem, item.getAmount() - summonAmount));
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
|
2012-03-18 06:42:56 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-05-21 16:31:10 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GRAY + Misc.prettyItemString(summonItem.getId()));
|
2012-03-18 06:42:56 +01:00
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 03:05:17 +01:00
|
|
|
|
|
|
|
/**
|
2012-03-22 16:07:20 +01:00
|
|
|
* Inspect a tameable animal for details.
|
2012-03-20 03:05:17 +01:00
|
|
|
*
|
2012-03-22 16:07:20 +01:00
|
|
|
* @param event Event to modify
|
|
|
|
* @param target Animal to inspect
|
|
|
|
* @param inspector Player inspecting the animal
|
2012-03-20 03:05:17 +01:00
|
|
|
*/
|
2012-03-22 16:07:20 +01:00
|
|
|
public static void beastLore(EntityDamageByEntityEvent event, LivingEntity target, Player inspector) {
|
|
|
|
if (target instanceof Tameable) {
|
|
|
|
Tameable beast = (Tameable) target;
|
2012-04-27 11:47:11 +02:00
|
|
|
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
|
2012-03-22 16:07:20 +01:00
|
|
|
int health = target.getHealth();
|
2012-03-20 03:05:17 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
|
2012-03-22 16:07:20 +01:00
|
|
|
if (beast.isTamed()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", new Object[] {getOwnerName(beast)}) + " ");
|
2012-03-20 03:05:17 +01:00
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", new Object[] {health, target.getMaxHealth()}));
|
2012-03-22 16:07:20 +01:00
|
|
|
inspector.sendMessage(message);
|
2012-03-20 03:05:17 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-07 00:48:24 +01:00
|
|
|
}
|