[Ranger/Sharpshooter] Missing two shots causes the damage bonus to reset. [PC-352]

This commit is contained in:
Ben 2016-05-24 01:16:11 +01:00
parent 5791cc5dec
commit bc3ec4088a

View File

@ -18,18 +18,24 @@ import mineplex.minecraft.game.classcombat.Skill.Skill;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.util.BlockIterator;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public class Sharpshooter extends Skill
{
private WeakHashMap<Player, Integer> _missedCount = new WeakHashMap<Player, Integer>();
private WeakHashMap<Player, Integer> _hitCount = new WeakHashMap<Player, Integer>();
private HashMap<Entity, Player> _arrows = new HashMap<Entity, Player>();
private HashMap<Arrow, Player> _arrows = new HashMap<Arrow, Player>();
public Sharpshooter(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int levels)
{
@ -54,8 +60,14 @@ public class Sharpshooter extends Skill
int level = getLevel((Player)event.getEntity());
if (level == 0) return;
if (!(event.getProjectile() instanceof Arrow))
{
System.out.println(GetName() + " : " + event.getEntity().getName() + " shot bow but resulting projectile was now Arrow?!?!?!?");
return;
}
//Store
_arrows.put(event.getProjectile(), (Player)event.getEntity());
_arrows.put((Arrow) event.getProjectile(), (Player)event.getEntity());
}
@EventHandler(priority = EventPriority.HIGH)
@ -98,9 +110,46 @@ public class Sharpshooter extends Skill
projectile.remove();
_missedCount.remove(player);
Recharge.Instance.useForce(player, GetName() + " Timer", 5000);
}
@EventHandler
public void missReset(ProjectileHitEvent event)
{
final Projectile projectile = event.getEntity();
Factory.runSyncLater(() -> {
if (!projectile.isDead() && _arrows.containsKey(projectile))
{
Player shooter = (Player) projectile.getShooter();
if (!_hitCount.containsKey(shooter))
{
return;
}
if (!_missedCount.containsKey(shooter))
{
_missedCount.put(shooter, Integer.valueOf(1));
}
else
{
_missedCount.put(shooter, Integer.valueOf(_missedCount.get(shooter).intValue() + 1));
// Reset
if (_missedCount.get(shooter).intValue() >= 2)
{
_hitCount.remove(shooter);
_missedCount.remove(shooter);
UtilPlayer.message(shooter, F.main(GetClassType().name(), GetName() + " : " + F.elem("Damage Bonus Reset")));
shooter.playSound(shooter.getLocation(), Sound.NOTE_PLING, 1f, 0.75f);
}
}
}
}, 3l);
}
@EventHandler
public void resetViaTime(UpdateEvent event)
{
@ -148,5 +197,6 @@ public class Sharpshooter extends Skill
public void Reset(Player player)
{
_hitCount.remove(player);
_missedCount.remove(player);
}
}