mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-29 04:04:43 +02:00
Skills refactoring
This commit is contained in:
84
src/main/java/com/gmail/nossr50/skills/combat/Archery.java
Normal file
84
src/main/java/com/gmail/nossr50/skills/combat/Archery.java
Normal file
@ -0,0 +1,84 @@
|
||||
package com.gmail.nossr50.skills.combat;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Combat;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Archery {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Track arrows fired for later retrieval.
|
||||
*
|
||||
* @param plugin mcMMO plugin instance
|
||||
* @param entity Entity damaged by the arrow
|
||||
* @param PPa PlayerProfile of the player firing the arrow
|
||||
*/
|
||||
public static void trackArrows(mcMMO plugin, Entity entity, PlayerProfile PPa) {
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
int skillLevel = PPa.getSkillLevel(SkillType.ARCHERY);
|
||||
|
||||
if (!plugin.arrowTracker.containsKey(entity)) {
|
||||
plugin.arrowTracker.put(entity, 0);
|
||||
}
|
||||
|
||||
if (skillLevel > MAX_BONUS_LEVEL || (random.nextInt(1000) <= skillLevel)) {
|
||||
plugin.arrowTracker.put(entity, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Daze.
|
||||
*
|
||||
* @param defender Defending player
|
||||
* @param attacker Attacking player
|
||||
*/
|
||||
public static void dazeCheck(Player defender, Player attacker) {
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.ARCHERY);
|
||||
Location loc = defender.getLocation();
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
if (random.nextInt(10) > 5) {
|
||||
loc.setPitch(90);
|
||||
}
|
||||
else {
|
||||
loc.setPitch(-90);
|
||||
}
|
||||
|
||||
if (random.nextInt(2000) <= skillCheck) {
|
||||
defender.teleport(loc);
|
||||
Combat.dealDamage(defender, 4);
|
||||
defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy"));
|
||||
attacker.sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for arrow retrieval.
|
||||
*
|
||||
* @param entity The entity hit by the arrows
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
public static void arrowRetrievalCheck(Entity entity, mcMMO plugin) {
|
||||
if (plugin.arrowTracker.containsKey(entity)) {
|
||||
Misc.mcDropItems(entity.getLocation(), new ItemStack(Material.ARROW), plugin.arrowTracker.get(entity));
|
||||
}
|
||||
|
||||
plugin.arrowTracker.remove(entity);
|
||||
}
|
||||
}
|
166
src/main/java/com/gmail/nossr50/skills/combat/Axes.java
Normal file
166
src/main/java/com/gmail/nossr50/skills/combat/Axes.java
Normal file
@ -0,0 +1,166 @@
|
||||
package com.gmail.nossr50.skills.combat;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Axes {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Apply bonus to damage done by axes.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) {
|
||||
final int MAX_BONUS = 4;
|
||||
|
||||
/* Add 1 DMG for every 50 skill levels */
|
||||
int bonus = Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / 50;
|
||||
|
||||
if (bonus > MAX_BONUS) {
|
||||
bonus = MAX_BONUS;
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() + bonus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for critical chances on axe damage.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) entity;
|
||||
|
||||
if (wolf.isTamed()) {
|
||||
AnimalTamer tamer = wolf.getOwner();
|
||||
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
|
||||
if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final int MAX_BONUS_LEVEL = 750;
|
||||
final double PVP_MODIFIER = 1.5;
|
||||
final int PVE_MODIFIER = 2;
|
||||
|
||||
PlayerProfile PPa = Users.getProfile(attacker);
|
||||
int skillLevel = PPa.getSkillLevel(SkillType.AXES);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
if (random.nextInt(2000) <= skillCheck && !entity.isDead()){
|
||||
int damage = event.getDamage();
|
||||
|
||||
if (entity instanceof Player){
|
||||
event.setDamage((int) (damage * PVP_MODIFIER));
|
||||
Player player = (Player) entity;
|
||||
player.sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
|
||||
}
|
||||
else {
|
||||
event.setDamage(damage * PVE_MODIFIER);
|
||||
}
|
||||
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Impact ability.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param target The defending entity
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
|
||||
|
||||
/*
|
||||
* TODO: Finish this skill. The idea is you will greatly damage an opponents armor.
|
||||
* When they are unarmored, you have a proc that will stun them and deal additional damage.
|
||||
*/
|
||||
if (target instanceof Player) {
|
||||
Player targetPlayer = (Player) target;
|
||||
short durabilityDamage = 5; //Start with 5 durability damage
|
||||
|
||||
/* Every 30 Skill Levels you gain 1 durability damage */
|
||||
durabilityDamage += Users.getProfile(attacker).getSkillLevel(SkillType.AXES)/30;
|
||||
|
||||
if (!hasArmor(targetPlayer)) {
|
||||
applyGreaterImpact(attacker, target, event);
|
||||
}
|
||||
else {
|
||||
for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) {
|
||||
armor.setDurability((short) (armor.getDurability() + durabilityDamage)); //Damage armor piece
|
||||
}
|
||||
targetPlayer.updateInventory();
|
||||
}
|
||||
}
|
||||
else {
|
||||
applyGreaterImpact(attacker, target, event); //Since mobs are technically unarmored, this will always trigger
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Greater Impact ability.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param target The defending entity
|
||||
* @param event The event to modify
|
||||
*/
|
||||
private static void applyGreaterImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
|
||||
final int GREATER_IMPACT_CHANCE = 25;
|
||||
final double GREATER_IMPACT_MULTIPLIER = 1.5;
|
||||
|
||||
if (!Permissions.getInstance().greaterImpact(attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (random.nextInt(100) <= GREATER_IMPACT_CHANCE) {
|
||||
event.setDamage(event.getDamage() + 2);
|
||||
target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
|
||||
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player has armor.
|
||||
*
|
||||
* @param player Player whose armor to check
|
||||
* @return true if the player has armor, false otherwise
|
||||
*/
|
||||
private static boolean hasArmor(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
if (inventory.getBoots() != null || inventory.getChestplate() != null || inventory.getHelmet() != null || inventory.getLeggings() != null) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
110
src/main/java/com/gmail/nossr50/skills/combat/Swords.java
Normal file
110
src/main/java/com/gmail/nossr50/skills/combat/Swords.java
Normal file
@ -0,0 +1,110 @@
|
||||
package com.gmail.nossr50.skills.combat;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
import com.gmail.nossr50.runnables.BleedTimer;
|
||||
import com.gmail.nossr50.util.Combat;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Swords {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Check for Bleed effect.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param entity The defending entity
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
public static void bleedCheck(Player attacker, LivingEntity entity, mcMMO plugin) {
|
||||
|
||||
if (entity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) entity;
|
||||
|
||||
if (wolf.isTamed()) {
|
||||
AnimalTamer tamer = wolf.getOwner();
|
||||
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
|
||||
if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final int MAX_BONUS_LEVEL = 750;
|
||||
|
||||
PlayerProfile PPa = Users.getProfile(attacker);
|
||||
int skillLevel = PPa.getSkillLevel(SkillType.SWORDS);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
if (random.nextInt(1000) <= skillCheck && !entity.isDead()) {
|
||||
int bleedTicks = 0;
|
||||
|
||||
if (skillLevel >= 750) {
|
||||
bleedTicks = 3;
|
||||
}
|
||||
else {
|
||||
bleedTicks = 2;
|
||||
}
|
||||
|
||||
BleedTimer.add(entity, bleedTicks);
|
||||
attacker.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counter-attack entities.
|
||||
*
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void counterAttackChecks(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
|
||||
if (!(attacker instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity target = event.getEntity();
|
||||
|
||||
if (target instanceof Player) {
|
||||
Player defender = (Player) target;
|
||||
PlayerProfile PPd = Users.getProfile(defender);
|
||||
|
||||
if (ItemChecks.isSword(defender.getItemInHand()) && Permissions.getInstance().counterAttack(defender)) {
|
||||
final int MAX_BONUS_LEVEL = 600;
|
||||
final int COUNTER_ATTACK_MODIFIER = 2;
|
||||
|
||||
int skillLevel = PPd.getSkillLevel(SkillType.SWORDS);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
if (random.nextInt(2000) <= skillCheck) {
|
||||
Combat.dealDamage((LivingEntity) attacker, event.getDamage() / COUNTER_ATTACK_MODIFIER);
|
||||
defender.sendMessage(LocaleLoader.getString("Swords.Combat.Countered"));
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
((Player) attacker).sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Hit"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
287
src/main/java/com/gmail/nossr50/skills/combat/Taming.java
Normal file
287
src/main/java/com/gmail/nossr50/skills/combat/Taming.java
Normal file
@ -0,0 +1,287 @@
|
||||
package com.gmail.nossr50.skills.combat;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
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;
|
||||
|
||||
public class Taming {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Apply the Fast Food Service ability.
|
||||
*
|
||||
* @param PPo The PlayerProfile of the wolf's owner
|
||||
* @param theWolf The wolf using the ability
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void fastFoodService (PlayerProfile PPo, Wolf theWolf, EntityDamageEvent event) {
|
||||
final int SKILL_ACTIVATION_LEVEL = 50;
|
||||
final int ACTIVATION_CHANCE = 50;
|
||||
|
||||
int health = theWolf.getHealth();
|
||||
int maxHealth = theWolf.getMaxHealth();
|
||||
int damage = event.getDamage();
|
||||
|
||||
if (PPo.getSkillLevel(SkillType.TAMING) >= SKILL_ACTIVATION_LEVEL) {
|
||||
if (health < maxHealth) {
|
||||
if (random.nextInt(100) < ACTIVATION_CHANCE) {
|
||||
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
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
public static void gore(PlayerProfile PPo, EntityDamageEvent event, Player master, mcMMO plugin) {
|
||||
final int GORE_MULTIPLIER = 2;
|
||||
|
||||
if (random.nextInt(1000) <= PPo.getSkillLevel(SkillType.TAMING)) {
|
||||
Entity entity = event.getEntity();
|
||||
event.setDamage(event.getDamage() * GORE_MULTIPLIER);
|
||||
|
||||
if (entity instanceof Player) {
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
|
||||
}
|
||||
|
||||
BleedTimer.add((LivingEntity) entity, 2);
|
||||
|
||||
master.sendMessage(LocaleLoader.getString("Combat.Gore"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of a tameable animal's owner.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
private static String getOwnerName(Tameable beast) {
|
||||
AnimalTamer tamer = beast.getOwner();
|
||||
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
return owner.getName();
|
||||
}
|
||||
else {
|
||||
return "Offline Master";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent damage to wolves based on various skills.
|
||||
*
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void preventDamage(EntityDamageEvent event) {
|
||||
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;
|
||||
|
||||
DamageCause cause = event.getCause();
|
||||
Wolf wolf = (Wolf) event.getEntity();
|
||||
Player master = (Player) wolf.getOwner();
|
||||
int skillLevel = Users.getProfile(master).getSkillLevel(SkillType.TAMING);
|
||||
|
||||
switch (cause) {
|
||||
|
||||
/* Environmentally Aware */
|
||||
case CONTACT:
|
||||
case LAVA:
|
||||
case FIRE:
|
||||
if (Permissions.getInstance().environmentallyAware(master)) {
|
||||
if (skillLevel >= ENVIRONMENTALLY_AWARE_LEVEL) {
|
||||
if (event.getDamage() >= wolf.getHealth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wolf.teleport(master.getLocation());
|
||||
master.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FALL:
|
||||
if (Permissions.getInstance().environmentallyAware(master)) {
|
||||
if (skillLevel >= ENVIRONMENTALLY_AWARE_LEVEL) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Thick Fur */
|
||||
case FIRE_TICK:
|
||||
if (Permissions.getInstance().thickFur(master)) {
|
||||
if(skillLevel >= THICK_FUR_LEVEL) {
|
||||
wolf.setFireTicks(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ENTITY_ATTACK:
|
||||
case PROJECTILE:
|
||||
if (Permissions.getInstance().thickFur(master)) {
|
||||
if (skillLevel >= THICK_FUR_LEVEL) {
|
||||
event.setDamage(event.getDamage() / THICK_FUR_MODIFIER);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Shock Proof */
|
||||
case ENTITY_EXPLOSION:
|
||||
case BLOCK_EXPLOSION:
|
||||
if (Permissions.getInstance().shockProof(master)) {
|
||||
if (skillLevel >= SHOCK_PROOF_LEVEL) {
|
||||
event.setDamage(event.getDamage() / SHOCK_PROOF_MODIFIER);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Summon an animal.
|
||||
*
|
||||
* @param type Type of animal to summon
|
||||
* @param player Player summoning the animal
|
||||
*/
|
||||
public static void animalSummon(EntityType type, Player player, mcMMO plugin) {
|
||||
ItemStack item = player.getItemInHand();
|
||||
Material summonItem = null;
|
||||
int summonAmount = 0;
|
||||
|
||||
switch (type) {
|
||||
case WOLF:
|
||||
summonItem = Material.BONE;
|
||||
summonAmount = Config.getInstance().getTamingCOTWWolfCost();
|
||||
break;
|
||||
|
||||
case OCELOT:
|
||||
summonItem = Material.RAW_FISH;
|
||||
summonAmount = Config.getInstance().getTamingCOTWOcelotCost();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.getType().equals(summonItem)) {
|
||||
if (item.getAmount() >= summonAmount) {
|
||||
for (Entity x : player.getNearbyEntities(40, 40, 40)) {
|
||||
if (x.getType().equals(type)) {
|
||||
switch (type) {
|
||||
case WOLF:
|
||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Wolf"));
|
||||
return;
|
||||
|
||||
case OCELOT:
|
||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Ocelot"));
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
|
||||
entity.setMetadata("mcmmoSummoned", new FixedMetadataValue(plugin, true));
|
||||
((Tameable) entity).setOwner(player);
|
||||
|
||||
if (entity.getType().equals(EntityType.OCELOT)) {
|
||||
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + random.nextInt(3)));
|
||||
}
|
||||
|
||||
if (entity.getType().equals(EntityType.WOLF)) {
|
||||
entity.setHealth(entity.getMaxHealth());
|
||||
}
|
||||
|
||||
player.setItemInHand(new ItemStack(summonItem, item.getAmount() - summonAmount));
|
||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + Misc.prettyItemString(summonItem.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspect a tameable animal for details.
|
||||
*
|
||||
* @param event Event to modify
|
||||
* @param target Animal to inspect
|
||||
* @param inspector Player inspecting the animal
|
||||
*/
|
||||
public static void beastLore(EntityDamageByEntityEvent event, LivingEntity target, Player inspector) {
|
||||
if (target instanceof Tameable) {
|
||||
Tameable beast = (Tameable) target;
|
||||
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
|
||||
int health = target.getHealth();
|
||||
event.setCancelled(true);
|
||||
|
||||
if (beast.isTamed()) {
|
||||
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", new Object[] {getOwnerName(beast)}) + " ");
|
||||
}
|
||||
|
||||
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", new Object[] {health, target.getMaxHealth()}));
|
||||
inspector.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
100
src/main/java/com/gmail/nossr50/skills/combat/Unarmed.java
Normal file
100
src/main/java/com/gmail/nossr50/skills/combat/Unarmed.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.gmail.nossr50.skills.combat;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Unarmed {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Apply bonus to Unarmed damage.
|
||||
*
|
||||
* @param PPa Profile of the attacking player
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void unarmedBonus(PlayerProfile PPa, EntityDamageByEntityEvent event) {
|
||||
final int MAX_BONUS = 8;
|
||||
int bonus = 3;
|
||||
|
||||
bonus += PPa.getSkillLevel(SkillType.UNARMED) / 50; //Add 1 DMG for every 50 skill levels
|
||||
|
||||
if (bonus > MAX_BONUS) {
|
||||
bonus = MAX_BONUS;
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() + bonus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for disarm.
|
||||
*
|
||||
* @param PPa Profile of the attacking player
|
||||
* @param defender The defending player
|
||||
*/
|
||||
public static void disarmProcCheck(Player attacker, Player defender) {
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
PlayerProfile PPa = Users.getProfile(attacker);
|
||||
int skillLevel = PPa.getSkillLevel(SkillType.UNARMED);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
ItemStack inHand = defender.getItemInHand();
|
||||
|
||||
if (!inHand.getType().equals(Material.AIR)) {
|
||||
if (random.nextInt(3000) <= skillCheck && ironGrip(defender, attacker)) {
|
||||
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||
|
||||
Misc.mcDropItem(defender.getLocation(), inHand);
|
||||
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for arrow deflection.
|
||||
*
|
||||
* @param defender The defending player
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void deflectCheck(Player defender, EntityDamageByEntityEvent event) {
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
int skillLevel = Users.getProfile(defender).getSkillLevel(SkillType.UNARMED);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
if (random.nextInt(2000) <= skillCheck && Permissions.getInstance().deflect(defender)) {
|
||||
event.setCancelled(true);
|
||||
defender.sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean ironGrip(Player defender, Player attacker) {
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
PlayerProfile PPd = Users.getProfile(defender);
|
||||
int skillLevel = PPd.getSkillLevel(SkillType.UNARMED);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
if (random.nextInt(1000) <= skillCheck) {
|
||||
defender.sendMessage(ChatColor.GREEN + "Your iron grip kept you from being disarmed!"); //TODO: Use locale
|
||||
attacker.sendMessage(ChatColor.RED + "Your opponent has an iron grip!"); //TODO: Use locale
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user