mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 13:46:46 +01:00
Updating Unarmed (WIP)
This commit is contained in:
parent
1014316581
commit
77b4aaa50d
@ -0,0 +1,40 @@
|
|||||||
|
package com.gmail.nossr50.skills.unarmed;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
|
||||||
|
public class DisarmEventHandler {
|
||||||
|
private UnarmedManager manager;
|
||||||
|
private Player defender;
|
||||||
|
private ItemStack inHand;
|
||||||
|
protected int skillModifier;
|
||||||
|
|
||||||
|
protected DisarmEventHandler(UnarmedManager manager, Player defender) {
|
||||||
|
this.manager = manager;
|
||||||
|
this.defender = defender;
|
||||||
|
this.inHand = defender.getItemInHand();
|
||||||
|
|
||||||
|
calculateSkillModifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isHoldingItem() {
|
||||||
|
return (inHand.getType() != Material.AIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void calculateSkillModifier() {
|
||||||
|
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Unarmed.DISARM_MAX_BONUS_LEVEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendAbilityMessage() {
|
||||||
|
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleDisarm() {
|
||||||
|
Misc.dropItem(defender.getLocation(), inHand);
|
||||||
|
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public class IronGripEventHandler {
|
||||||
|
private UnarmedManager manager;
|
||||||
|
private Player defender;
|
||||||
|
protected int skillModifier;
|
||||||
|
|
||||||
|
protected IronGripEventHandler(UnarmedManager manager, Player defender) {
|
||||||
|
this.manager = manager;
|
||||||
|
this.defender = defender;
|
||||||
|
|
||||||
|
calculateSkillModifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void calculateSkillModifier() {
|
||||||
|
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Unarmed.DISARM_MAX_BONUS_LEVEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendAbilityMessages() {
|
||||||
|
defender.sendMessage(ChatColor.GREEN + "Your iron grip kept you from being disarmed!"); //TODO: Use locale
|
||||||
|
manager.getPlayer().sendMessage(ChatColor.RED + "Your opponent has an iron grip!"); //TODO: Use locale
|
||||||
|
}
|
||||||
|
}
|
39
src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java
Normal file
39
src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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 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,95 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public class UnarmedManager {
|
||||||
|
private Player player;
|
||||||
|
private PlayerProfile profile;
|
||||||
|
private int skillLevel;
|
||||||
|
private Permissions permissionsInstance;
|
||||||
|
|
||||||
|
public UnarmedManager (Player player) {
|
||||||
|
this.player = player;
|
||||||
|
this.profile = Users.getProfile(player);
|
||||||
|
this.skillLevel = profile.getSkillLevel(SkillType.TAMING);
|
||||||
|
this.permissionsInstance = Permissions.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for disarm.
|
||||||
|
*
|
||||||
|
* @param defender The defending player
|
||||||
|
*/
|
||||||
|
public void disarmCheck(Player defender) {
|
||||||
|
if (!permissionsInstance.disarm(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DisarmEventHandler eventHandler = new DisarmEventHandler(this, defender);
|
||||||
|
|
||||||
|
if (eventHandler.isHoldingItem()) {
|
||||||
|
eventHandler.calculateSkillModifier();
|
||||||
|
|
||||||
|
if (Unarmed.getRandom().nextInt(3000) <= eventHandler.skillModifier) {
|
||||||
|
if (!hasIronGrip(defender)) {
|
||||||
|
eventHandler.sendAbilityMessage();
|
||||||
|
eventHandler.handleDisarm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for arrow deflection.
|
||||||
|
*
|
||||||
|
* @param defender The defending player
|
||||||
|
* @param event The event to modify
|
||||||
|
*/
|
||||||
|
public void deflectCheck(Player defender, EntityDamageEvent event) {
|
||||||
|
if (!permissionsInstance.deflect(defender)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Unarmed.getRandom().nextInt(2000) <= skillLevel) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
defender.sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check Iron Grip ability success
|
||||||
|
*
|
||||||
|
* @param defender The defending player
|
||||||
|
* @return true if the defender was not disarmed, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean hasIronGrip(Player defender) {
|
||||||
|
//TODO: Add permission for Iron Grip
|
||||||
|
|
||||||
|
IronGripEventHandler eventHandler = new IronGripEventHandler(this, defender);
|
||||||
|
|
||||||
|
if (Unarmed.getRandom().nextInt(1000) <= eventHandler.skillModifier) {
|
||||||
|
eventHandler.sendAbilityMessages();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getSkillLevel() {
|
||||||
|
return skillLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,7 @@ import com.gmail.nossr50.skills.combat.Axes;
|
|||||||
import com.gmail.nossr50.skills.combat.Swords;
|
import com.gmail.nossr50.skills.combat.Swords;
|
||||||
import com.gmail.nossr50.skills.combat.Unarmed;
|
import com.gmail.nossr50.skills.combat.Unarmed;
|
||||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
|
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||||
|
|
||||||
public class Combat {
|
public class Combat {
|
||||||
private static Config configInstance = Config.getInstance();
|
private static Config configInstance = Config.getInstance();
|
||||||
@ -132,6 +133,8 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnarmedManager unarmedManager = new UnarmedManager(attacker);
|
||||||
|
|
||||||
if (permInstance.unarmedBonus(attacker)) {
|
if (permInstance.unarmedBonus(attacker)) {
|
||||||
Unarmed.unarmedBonus(PPa, event);
|
Unarmed.unarmedBonus(PPa, event);
|
||||||
}
|
}
|
||||||
@ -140,8 +143,8 @@ public class Combat {
|
|||||||
event.setDamage((int) (event.getDamage() * 1.5));
|
event.setDamage((int) (event.getDamage() * 1.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetIsPlayer && permInstance.disarm(attacker)) {
|
if (targetIsPlayer) {
|
||||||
Unarmed.disarmProcCheck(attacker, (Player) target);
|
unarmedManager.disarmCheck((Player) target);
|
||||||
}
|
}
|
||||||
|
|
||||||
startGainXp(attacker, PPa, target, SkillType.UNARMED);
|
startGainXp(attacker, PPa, target, SkillType.UNARMED);
|
||||||
|
@ -264,6 +264,7 @@ public class Misc {
|
|||||||
* @return whichever value is lower
|
* @return whichever value is lower
|
||||||
*/
|
*/
|
||||||
public static int skillCheck(int skillLevel, int maxLevel) {
|
public static int skillCheck(int skillLevel, int maxLevel) {
|
||||||
|
//TODO: Could we just use Math.min(skillLevel, maxLevel) here?
|
||||||
if (skillLevel > maxLevel) {
|
if (skillLevel > maxLevel) {
|
||||||
return maxLevel;
|
return maxLevel;
|
||||||
}
|
}
|
||||||
@ -288,3 +289,4 @@ public class Misc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user