2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.runnables.skills;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2019-01-24 01:01:30 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.util.MobHealthbarUtils;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
2019-01-22 00:14:01 +01:00
|
|
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
|
|
import com.gmail.nossr50.util.sounds.SoundType;
|
2012-03-18 21:59:35 +01:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-03-20 08:11:16 +01:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2013-03-20 08:11:16 +01:00
|
|
|
public class BleedTimerTask extends BukkitRunnable {
|
2019-01-24 00:22:16 +01:00
|
|
|
private final static int MAX_BLEED_TICKS = 100; //The cap has been raised :)
|
2012-04-28 06:14:19 +02:00
|
|
|
private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>();
|
2019-01-22 00:14:01 +01:00
|
|
|
private static Map<LivingEntity, Integer> bleedDamage = new HashMap<LivingEntity, Integer>();
|
2019-01-24 00:22:16 +01:00
|
|
|
private static Map<LivingEntity, LivingEntity> attackerMap = new HashMap<>();
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-01-24 01:01:30 +01:00
|
|
|
for(LivingEntity target : bleedList.keySet())
|
|
|
|
{
|
2019-01-24 01:08:41 +01:00
|
|
|
//mcMMO.p.getServer().broadcastMessage("Entity "+target.getName()+" has "+bleedList.get(target)+" ticks of bleed left");
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
if (bleedList.get(target) <= 0 || !target.isValid()) {
|
|
|
|
remove(target);
|
2013-02-26 16:32:06 +01:00
|
|
|
continue;
|
2012-03-21 03:51:02 +01:00
|
|
|
}
|
|
|
|
|
2014-10-11 12:18:31 +02:00
|
|
|
double damage;
|
2013-02-27 13:49:56 +01:00
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
if (target instanceof Player) {
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = AdvancedConfig.getInstance().getRuptureDamagePlayer();
|
|
|
|
|
|
|
|
//Above Bleed Rank 3 deals 50% more damage
|
2019-01-24 01:01:30 +01:00
|
|
|
if(bleedDamage.get(target) >= 3)
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = damage * 1.5;
|
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
Player player = (Player) target;
|
2012-04-28 06:14:19 +02:00
|
|
|
|
|
|
|
if (!player.isOnline()) {
|
2019-01-24 01:01:30 +01:00
|
|
|
remove(target);
|
2012-04-28 06:14:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
/*if (bleedList.get(target) <= 0) {
|
2019-01-14 07:21:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Swords.Combat.Bleeding.Stopped");
|
2019-01-24 00:08:04 +01:00
|
|
|
}*/
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = AdvancedConfig.getInstance().getRuptureDamageMobs();
|
2019-01-24 01:01:30 +01:00
|
|
|
MobHealthbarUtils.handleMobHealthbars(target, damage, mcMMO.p); //Update health bars
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
2019-01-24 01:01:30 +01:00
|
|
|
|
2019-01-24 01:08:41 +01:00
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(target, damage, attackerMap.get(target));
|
2019-01-24 01:08:41 +01:00
|
|
|
//Play Bleed Sound
|
|
|
|
SoundManager.worldSendSound(target.getWorld(), target.getLocation(), SoundType.BLEED);
|
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
ParticleEffectUtils.playBleedEffect(target);
|
|
|
|
lowerBleedDurationTicks(target);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
private void lowerBleedDurationTicks(LivingEntity target) {
|
2019-01-24 01:12:52 +01:00
|
|
|
if(bleedList.get(target) != null)
|
|
|
|
bleedList.put(target, bleedList.get(target) - 1);
|
2019-01-24 01:01:30 +01:00
|
|
|
}
|
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
/**
|
|
|
|
* Instantly Bleed out a LivingEntity
|
2012-06-05 15:57:10 +02:00
|
|
|
*
|
2012-04-28 06:14:19 +02:00
|
|
|
* @param entity LivingEntity to bleed out
|
|
|
|
*/
|
|
|
|
public static void bleedOut(LivingEntity entity) {
|
|
|
|
if (bleedList.containsKey(entity)) {
|
2019-01-24 00:22:16 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(entity, bleedList.get(entity) * 2, attackerMap.get(entity));
|
2012-04-28 06:14:19 +02:00
|
|
|
bleedList.remove(entity);
|
2019-01-22 00:14:01 +01:00
|
|
|
bleedDamage.remove(entity);
|
2019-01-24 00:22:16 +01:00
|
|
|
attackerMap.remove(entity);
|
2012-12-24 22:56:25 +01:00
|
|
|
}
|
2012-04-28 06:14:19 +02:00
|
|
|
}
|
|
|
|
|
2012-03-18 21:59:35 +01:00
|
|
|
/**
|
|
|
|
* Remove a LivingEntity from the bleedList if it is in it
|
2012-06-05 15:57:10 +02:00
|
|
|
*
|
2012-03-18 21:59:35 +01:00
|
|
|
* @param entity LivingEntity to remove
|
|
|
|
*/
|
|
|
|
public static void remove(LivingEntity entity) {
|
2013-02-26 16:32:06 +01:00
|
|
|
if (bleedList.containsKey(entity)) {
|
|
|
|
bleedList.remove(entity);
|
2019-01-22 00:14:01 +01:00
|
|
|
bleedDamage.remove(entity);
|
2019-01-24 00:22:16 +01:00
|
|
|
attackerMap.remove(entity);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-21 03:51:02 +01:00
|
|
|
* Add a LivingEntity to the bleedList if it is not in it.
|
|
|
|
*
|
2012-03-18 21:59:35 +01:00
|
|
|
* @param entity LivingEntity to add
|
2012-05-01 01:32:50 +02:00
|
|
|
* @param ticks Number of bleeding ticks
|
2012-03-18 21:59:35 +01:00
|
|
|
*/
|
2019-01-24 00:22:16 +01:00
|
|
|
public static void add(LivingEntity entity, LivingEntity attacker, int ticks, int bleedRank) {
|
2012-04-28 06:14:19 +02:00
|
|
|
int newTicks = ticks;
|
|
|
|
|
2013-02-26 16:32:06 +01:00
|
|
|
if (bleedList.containsKey(entity)) {
|
|
|
|
newTicks += bleedList.get(entity);
|
2019-01-24 00:22:16 +01:00
|
|
|
bleedList.put(entity, Math.min(MAX_BLEED_TICKS, newTicks));
|
2019-01-22 00:14:01 +01:00
|
|
|
|
|
|
|
//Override the current bleed rank only if this one is higher
|
|
|
|
if(bleedDamage.get(entity) < bleedRank)
|
|
|
|
bleedDamage.put(entity, bleedRank);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2019-01-24 00:22:16 +01:00
|
|
|
bleedList.put(entity, Math.min(MAX_BLEED_TICKS, newTicks));
|
2019-01-22 00:14:01 +01:00
|
|
|
bleedDamage.put(entity, bleedRank);
|
2019-01-24 00:22:16 +01:00
|
|
|
attackerMap.put(entity, attacker);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-02 19:41:44 +02:00
|
|
|
|
|
|
|
public static boolean isBleeding(LivingEntity entity) {
|
|
|
|
return bleedList.containsKey(entity);
|
|
|
|
}
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|