mcMMO/src/main/java/com/gmail/nossr50/skills/Swords.java

149 lines
4.8 KiB
Java
Raw Normal View History

2012-01-09 20:00:13 +01:00
package com.gmail.nossr50.skills;
2012-03-13 20:55:42 +01:00
import org.bukkit.entity.AnimalTamer;
2012-01-09 20:00:13 +01:00
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;
2012-03-13 20:55:42 +01:00
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.Combat;
import com.gmail.nossr50.ItemChecks;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.Users;
2012-03-13 20:55:42 +01:00
import com.gmail.nossr50.m;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
2012-03-03 20:48:40 +01:00
import com.gmail.nossr50.locale.mcLocale;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.party.Party;
2012-03-13 20:55:42 +01:00
public class Swords {
/**
* 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 = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 1000 <= skillCheck && !entity.isDead()) {
if (entity instanceof Player) {
Player target = (Player) entity;
int bleedTicks;
if (skillLevel >= 750) {
bleedTicks = 3;
}
else {
bleedTicks = 2;
}
Users.getProfile(target).addBleedTicks(bleedTicks);
}
else {
plugin.misc.addToBleedQue(entity);
}
attacker.sendMessage(mcLocale.getString("Swords.EnemyBleeding"));
}
2012-01-09 20:00:13 +01:00
}
2012-03-13 20:55:42 +01:00
/**
* 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()) && mcPermissions.getInstance().swords(defender)) {
final int MAX_BONUS_LEVEL = 600;
final int COUNTER_ATTACK_MODIFIER = 2;
int skillLevel = PPd.getSkillLevel(SkillType.SWORDS);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 2000 <= skillCheck) {
Combat.dealDamage((LivingEntity) attacker, event.getDamage() / COUNTER_ATTACK_MODIFIER);
defender.sendMessage(mcLocale.getString("Swords.CounterAttacked"));
if (attacker instanceof Player) {
((Player) attacker).sendMessage(mcLocale.getString("Swords.HitByCounterAttack"));
}
}
}
}
2012-01-09 20:00:13 +01:00
}
2012-03-13 20:55:42 +01:00
/**
* Simulate a bleed.
*
* @param plugin mcMMO plugin instance
*/
public static void bleedSimulate(mcMMO plugin) {
/* Add items from Que list to BleedTrack list */
for (LivingEntity entity : plugin.misc.bleedQue) {
plugin.misc.bleedTracker.add(entity);
}
/* Clear the BleedQue list */
plugin.misc.bleedQue = new LivingEntity[plugin.misc.bleedQue.length];
plugin.misc.bleedQuePos = 0;
/* Cleanup any dead entities from the list */
for(LivingEntity entity : plugin.misc.bleedRemovalQue) {
plugin.misc.bleedTracker.remove(entity);
}
/* Clear bleed removal list */
plugin.misc.bleedRemovalQue = new LivingEntity[plugin.misc.bleedRemovalQue.length];
plugin.misc.bleedRemovalQuePos = 0;
/* Bleed monsters/animals */
for (LivingEntity entity : plugin.misc.bleedTracker) {
if (entity == null || entity.isDead()) {
plugin.misc.addToBleedRemovalQue(entity);
continue;
}
else {
Combat.dealDamage(entity, 2);
}
2012-01-09 20:00:13 +01:00
}
}
}