Simplified combat ability checks

This commit is contained in:
bm01 2012-06-22 20:20:28 +02:00
parent d51fa92b46
commit e61342177d
2 changed files with 49 additions and 64 deletions

View File

@ -23,7 +23,6 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.ToolType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@ -64,8 +63,6 @@ public class Combat {
ItemStack itemInHand = attacker.getItemInHand(); ItemStack itemInHand = attacker.getItemInHand();
PlayerProfile PPa = Users.getProfile(attacker); PlayerProfile PPa = Users.getProfile(attacker);
combatAbilityChecks(attacker);
if (ItemChecks.isSword(itemInHand)) { if (ItemChecks.isSword(itemInHand)) {
if (targetIsPlayer || targetIsTamedPet) { if (targetIsPlayer || targetIsTamedPet) {
if (!configInstance.getSwordsPVP()) { if (!configInstance.getSwordsPVP()) {
@ -76,6 +73,8 @@ public class Combat {
return; return;
} }
Skills.abilityCheck(attacker, SkillType.SWORDS);
SwordsManager swordsManager = new SwordsManager(attacker); SwordsManager swordsManager = new SwordsManager(attacker);
swordsManager.bleedCheck(target); swordsManager.bleedCheck(target);
@ -96,6 +95,8 @@ public class Combat {
return; return;
} }
Skills.abilityCheck(attacker, SkillType.AXES);
if (permInstance.axeBonus(attacker)) { if (permInstance.axeBonus(attacker)) {
Axes.axesBonus(attacker, event); Axes.axesBonus(attacker, event);
} }
@ -124,6 +125,8 @@ public class Combat {
return; return;
} }
Skills.abilityCheck(attacker, SkillType.UNARMED);
UnarmedManager unarmedManager = new UnarmedManager(attacker); UnarmedManager unarmedManager = new UnarmedManager(attacker);
unarmedManager.bonusDamage(event); unarmedManager.bonusDamage(event);
@ -218,25 +221,6 @@ public class Combat {
} }
} }
/**
* Process combat abilities based on weapon preparation modes.
*
* @param attacker The player attacking
*/
public static void combatAbilityChecks(Player attacker) {
PlayerProfile PPa = Users.getProfile(attacker);
if (PPa.getToolPreparationMode(ToolType.AXE)) {
Skills.abilityCheck(attacker, SkillType.AXES);
}
else if (PPa.getToolPreparationMode(ToolType.SWORD)) {
Skills.abilityCheck(attacker, SkillType.SWORDS);
}
else if (PPa.getToolPreparationMode(ToolType.FISTS)) {
Skills.abilityCheck(attacker, SkillType.UNARMED);
}
}
/** /**
* Process archery abilities. * Process archery abilities.
* *

View File

@ -384,54 +384,55 @@ public class Skills {
*/ */
public static void abilityCheck(Player player, SkillType type) { public static void abilityCheck(Player player, SkillType type) {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
AbilityType ability = type.getAbility();
ToolType tool = type.getTool(); ToolType tool = type.getTool();
if (type.getTool().inHand(player.getItemInHand())) { if (!PP.getToolPreparationMode(tool)) {
if (PP.getToolPreparationMode(tool)) { return;
PP.setToolPreparationMode(tool, false); }
}
/* Axes and Woodcutting are odd because they share the same tool. PP.setToolPreparationMode(tool, false);
* We show them the too tired message when they take action.
*/ AbilityType ability = type.getAbility();
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
if (!PP.getAbilityMode(ability) && !cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { /* Axes and Woodcutting are odd because they share the same tool.
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); * We show them the too tired message when they take action.
return; */
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
if (!PP.getAbilityMode(ability) && !cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
return;
}
}
int ticks = 2 + (PP.getSkillLevel(type) / 50);
if (player.hasPermission("mcmmo.perks.activationtime.twelveseconds")) {
ticks = ticks + 12;
}
else if (player.hasPermission("mcmmo.perks.activationtime.eightseconds")) {
ticks = ticks + 8;
}
else if (player.hasPermission("mcmmo.perks.activationtime.fourseconds")) {
ticks = ticks + 4;
}
int maxTicks = ability.getMaxTicks();
if (maxTicks != 0 && ticks > maxTicks) {
ticks = maxTicks;
}
if (!PP.getAbilityMode(ability) && cooldownOver(PP.getSkillDATS(ability), ability.getCooldown(), player)) {
player.sendMessage(ability.getAbilityOn());
for (Player y : player.getWorld().getPlayers()) {
if (y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
y.sendMessage(ability.getAbilityPlayer(player));
} }
} }
int ticks = 2 + (PP.getSkillLevel(type) / 50); PP.setSkillDATS(ability, System.currentTimeMillis() + (ticks * TIME_CONVERSION_FACTOR));
PP.setAbilityMode(ability, true);
if (player.hasPermission("mcmmo.perks.activationtime.twelveseconds")) {
ticks = ticks + 12;
}
else if (player.hasPermission("mcmmo.perks.activationtime.eightseconds")) {
ticks = ticks + 8;
}
else if (player.hasPermission("mcmmo.perks.activationtime.fourseconds")) {
ticks = ticks + 4;
}
int maxTicks = ability.getMaxTicks();
if (maxTicks != 0 && ticks > maxTicks) {
ticks = maxTicks;
}
if (!PP.getAbilityMode(ability) && cooldownOver(PP.getSkillDATS(ability), ability.getCooldown(), player)) {
player.sendMessage(ability.getAbilityOn());
for (Player y : player.getWorld().getPlayers()) {
if (y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
y.sendMessage(ability.getAbilityPlayer(player));
}
}
PP.setSkillDATS(ability, System.currentTimeMillis() + (ticks * TIME_CONVERSION_FACTOR));
PP.setAbilityMode(ability, true);
}
} }
} }