mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
More reworking of Unarmed, renamed ArcheryBonusDamageEventHandler for
clarity's sake.
This commit is contained in:
parent
77b4aaa50d
commit
48dd537257
@ -2,13 +2,13 @@ package com.gmail.nossr50.skills.archery;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class BonusDamageEventHandler {
|
||||
public class ArcheryBonusDamageEventHandler {
|
||||
private ArcheryManager manager;
|
||||
private EntityDamageEvent event;
|
||||
|
||||
protected double damageBonusPercent;
|
||||
|
||||
protected BonusDamageEventHandler(ArcheryManager manager, EntityDamageEvent event) {
|
||||
protected ArcheryBonusDamageEventHandler(ArcheryManager manager, EntityDamageEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
}
|
@ -69,7 +69,7 @@ public class ArcheryManager {
|
||||
}
|
||||
|
||||
if (skillLevel >= Archery.BONUS_DAMAGE_INCREASE_LEVEL) {
|
||||
BonusDamageEventHandler eventHandler = new BonusDamageEventHandler(this, event);
|
||||
ArcheryBonusDamageEventHandler eventHandler = new ArcheryBonusDamageEventHandler(this, event);
|
||||
|
||||
eventHandler.calculateDamageBonus();
|
||||
eventHandler.modifyEventDamage();
|
||||
|
@ -1,106 +0,0 @@
|
||||
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.dropItem(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"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Iron Grip ability success
|
||||
*
|
||||
* @param defender The defending player
|
||||
* @param attacker The attacking player
|
||||
* @return true if the defender was not disarmed, false otherwise
|
||||
*/
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class DeflectEventHandler {
|
||||
private UnarmedManager manager;
|
||||
private EntityDamageEvent event;
|
||||
protected int skillModifier;
|
||||
|
||||
protected DeflectEventHandler(UnarmedManager manager, EntityDamageEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
|
||||
calculateSkillModifier();
|
||||
}
|
||||
|
||||
protected void calculateSkillModifier() {
|
||||
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Unarmed.DEFLECT_MAX_BONUS_LEVEL);
|
||||
}
|
||||
|
||||
protected void sendAbilityMessage() {
|
||||
manager.getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||
}
|
||||
|
||||
protected void cancelEvent() {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
|
@ -2,37 +2,15 @@ package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
|
||||
public class Unarmed {
|
||||
public static final int BONUS_DAMAGE_MAX_BONUS_MODIFIER = 8;
|
||||
public static final int BONUS_DAMAGE_INCREASE_LEVEL = 50;
|
||||
public static final int DEFLECT_MAX_BONUS_LEVEL = 1000;
|
||||
public static final int DISARM_MAX_BONUS_LEVEL = 1000;
|
||||
public static final int IRON_GRIP_MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected static Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class UnarmedBonusDamageEventHandler {
|
||||
private UnarmedManager manager;
|
||||
private EntityDamageEvent event;
|
||||
|
||||
protected int damageBonus;
|
||||
|
||||
protected UnarmedBonusDamageEventHandler(UnarmedManager manager, EntityDamageEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
protected void calculateDamageBonus() {
|
||||
int damageBonus = 3 + (manager.getSkillLevel() / Unarmed.BONUS_DAMAGE_INCREASE_LEVEL);
|
||||
|
||||
if (damageBonus > Unarmed.BONUS_DAMAGE_MAX_BONUS_MODIFIER) {
|
||||
damageBonus = Unarmed.BONUS_DAMAGE_MAX_BONUS_MODIFIER;
|
||||
}
|
||||
|
||||
this.damageBonus = damageBonus;
|
||||
}
|
||||
|
||||
protected void modifyEventDamage() {
|
||||
int damage = event.getDamage();
|
||||
int unarmedBonus = (int) (damage + damageBonus);
|
||||
|
||||
event.setDamage(damage + unarmedBonus);
|
||||
}
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
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;
|
||||
|
||||
@ -39,7 +36,7 @@ public class UnarmedManager {
|
||||
if (eventHandler.isHoldingItem()) {
|
||||
eventHandler.calculateSkillModifier();
|
||||
|
||||
if (Unarmed.getRandom().nextInt(3000) <= eventHandler.skillModifier) {
|
||||
if (Unarmed.getRandom().nextInt(3000) < eventHandler.skillModifier) {
|
||||
if (!hasIronGrip(defender)) {
|
||||
eventHandler.sendAbilityMessage();
|
||||
eventHandler.handleDisarm();
|
||||
@ -54,17 +51,35 @@ public class UnarmedManager {
|
||||
* @param defender The defending player
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public void deflectCheck(Player defender, EntityDamageEvent event) {
|
||||
if (!permissionsInstance.deflect(defender)) {
|
||||
public void deflectCheck(EntityDamageEvent event) {
|
||||
if (!permissionsInstance.deflect(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Unarmed.getRandom().nextInt(2000) <= skillLevel) {
|
||||
event.setCancelled(true);
|
||||
defender.sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||
DeflectEventHandler eventHandler = new DeflectEventHandler(this, event);
|
||||
|
||||
if (Unarmed.getRandom().nextInt(2000) < eventHandler.skillModifier) {
|
||||
eventHandler.cancelEvent();
|
||||
eventHandler.sendAbilityMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Unarmed bonus damage.
|
||||
*
|
||||
* @param event The event to modify.
|
||||
*/
|
||||
public void bonusDamage(EntityDamageEvent event) {
|
||||
if (!permissionsInstance.unarmedBonus(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UnarmedBonusDamageEventHandler eventHandler = new UnarmedBonusDamageEventHandler(this, event);
|
||||
|
||||
eventHandler.calculateDamageBonus();
|
||||
eventHandler.modifyEventDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Iron Grip ability success
|
||||
*
|
||||
@ -76,7 +91,7 @@ public class UnarmedManager {
|
||||
|
||||
IronGripEventHandler eventHandler = new IronGripEventHandler(this, defender);
|
||||
|
||||
if (Unarmed.getRandom().nextInt(1000) <= eventHandler.skillModifier) {
|
||||
if (Unarmed.getRandom().nextInt(1000) < eventHandler.skillModifier) {
|
||||
eventHandler.sendAbilityMessages();
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
||||
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
||||
import com.gmail.nossr50.skills.combat.Axes;
|
||||
import com.gmail.nossr50.skills.combat.Swords;
|
||||
import com.gmail.nossr50.skills.combat.Unarmed;
|
||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
|
||||
@ -135,9 +134,7 @@ public class Combat {
|
||||
|
||||
UnarmedManager unarmedManager = new UnarmedManager(attacker);
|
||||
|
||||
if (permInstance.unarmedBonus(attacker)) {
|
||||
Unarmed.unarmedBonus(PPa, event);
|
||||
}
|
||||
unarmedManager.bonusDamage(event);
|
||||
|
||||
if (PPa.getAbilityMode(AbilityType.BERSERK) && permInstance.berserk(attacker)) {
|
||||
event.setDamage((int) (event.getDamage() * 1.5));
|
||||
@ -254,7 +251,8 @@ public class Combat {
|
||||
|
||||
if (defender.getItemInHand().getType().equals(Material.AIR)) {
|
||||
if (configInstance.getUnarmedPVP()) {
|
||||
Unarmed.deflectCheck(defender, event);
|
||||
UnarmedManager unarmedManager = new UnarmedManager(defender);
|
||||
unarmedManager.deflectCheck(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user