public static void fightCaveAttacks(Npc npc, Player p) {
		    if (npc.isDead() || npc.isDestroyed() || p.isDead() || p.isDestroyed() || p.isDead() || !Location.inFightCave(p.getLocation()) || p.getTeleportTo() != null) {
			    return;
		    }
		    double damage = misc.randomDouble(npc.getMaxHit());
            PrayerData.PrayerHeadIcon prayerHeadIcon = p.getPrayers().getHeadIcon();
		    int hitDelay = npc.getHitDelay();
		    int animation = npc.getAttackAnimation();
		    switch(npc.getId()) {
			    case 2734: // Tz-Kih (lvl 22)
			    case 2735:
                    if (prayerHeadIcon == PrayerData.PrayerHeadIcon.MELEE)
                    {
					    damage = 0;
				    }
				    break;
				
			    case 2739: // Tz-Xil (lvl 90)
			    case 2740:
                    if (prayerHeadIcon == PrayerData.PrayerHeadIcon.RANGE)
                    {
					    damage = 0;
				    }
				    p.getPackets().sendProjectile(npc.getLocation(), p.getLocation(), 32, 1616, 50, 40, 34, 50, p);
				    break;
				
			    case 2741: // Yt-MejKot (lvl 180)
			    case 2742:
                    if (prayerHeadIcon == PrayerData.PrayerHeadIcon.MELEE)
                    {
					    damage = 0;
				    }
				    // TODO healing
				    break;
				
			    case 2743: // Ket-Zek (lvl 360)
			    case 2744:
				    if (!p.getLocation().withinDistance(npc.getLocation(), 2)) {
					    hitDelay = 1600;
					    animation = 9266;
					    npc.setLastGraphics(new Graphics(1622));
					    damage = misc.randomDouble(49);
                        if (prayerHeadIcon == PrayerData.PrayerHeadIcon.MAGIC)
                        {
						    damage = 0;
					    }
                        Event sendProjectileToNpc = new Event(300);
                        sendProjectileToNpc.setAction(() => {
							sendProjectileToNpc.stop();
							p.getPackets().sendProjectile(npc.getLocation(), p.getLocation(), 32, 1623, 50, 40, 34, 80, p);
					    });
                        Server.registerEvent(sendProjectileToNpc);
				    } else {
					    damage = misc.randomDouble(64);
                        if (prayerHeadIcon == PrayerData.PrayerHeadIcon.MELEE)
                        {
						    damage = 0;
					    }
				    }
				    break;
				
			    case 2745: // TzTok Jad (lvl 702)
				    doJadAttacks(p, npc);
				    break;
		    }
		    if (npc.getId() == 2745){
			    return;
		    }
		    if (animation != 65535) {
			    npc.setLastAnimation(new Animation(animation));
		    }
            p.setLastAttacked(Environment.TickCount);
            npc.setLastAttack(Environment.TickCount);
		    p.setAttacker(npc);
		    npc.resetCombatTurns();
		    if (damage > p.getHp()) {
			    damage = p.getHp();
		    }
		    int npcId = npc.getId();

            Event losePrayerFightingEvent = new Event(hitDelay);
            losePrayerFightingEvent.setAction(() => {
				losePrayerFightingEvent.stop();
				if (!Location.inFightCave(p.getLocation()) || p.getTeleportTo() != null) {
					return;
				}
				if (npcId == 2734 || npcId == 2735) {
                    int prayerLevel = p.getSkills().getCurLevel(Skills.SKILL.PRAYER);
                    int newPrayerLevel = prayerLevel -= (int)(damage + 1);
					if (newPrayerLevel <= 0) {
						newPrayerLevel = 0;
					}
					p.getSkills().setCurLevel(Skills.SKILL.PRAYER, newPrayerLevel);
                    p.getPackets().sendSkillLevel(Skills.SKILL.PRAYER);
				} else if (npcId == 2743 || npcId == 2744) {
					if (misc.random(1) == 0) {
						p.setLastGraphics(new Graphics(1624, 0));
					}
				}
				if ((p.getCombatTurns() > 2 || p.getCombatTurns() < 0)) {
					p.setLastAnimation(new Animation(p.getDefenceAnimation()));
				}
                p.hit(damage);
		    });
            Server.registerEvent(losePrayerFightingEvent);
	    }
	    private static double applyBoltGraphic(Player killer, Entity target, double damage, int bolt) {
            //10% chance that damage is returned if attacker's bow isn't a crossbow.
            if (misc.random(10) != 0 || getBowType(killer) != BOW_TYPE.CROSSBOW)
            {
			    return damage;
		    }
            double maxDamage = getDamage((Player)killer, target, ((Player)killer).getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON), bolt);
		    switch(bolt) {
			    case 9236: // Opal.
				    target.setLastGraphics(new Graphics(749));
				    maxDamage *= 1.25;
				    break;
				
			    case 9237: // Jade.
				    target.setLastGraphics(new Graphics(756));
				    //TODO Falling emote
				    break;
				
			    case 9238: // Pearl.
				    target.setLastGraphics(new Graphics(750));
				    break;
				
			    case 9239: // Topaz.
				    target.setLastGraphics(new Graphics(757, 0, 0));
				    if (target is Player) {
					    int magicLevel = ((Player) target).getSkills().getCurLevel(Skills.SKILL.MAGIC);
					    if (magicLevel == 1)
						    return maxDamage;
					    int magicLevelDeduction = misc.random(1,10);
                        magicLevelDeduction = Math.Min(magicLevelDeduction, (magicLevel - 1));
                        string s = magicLevelDeduction == 1 ? "" : "s";
                        ((Player)target).getSkills().setCurLevel(Skills.SKILL.MAGIC, magicLevel - magicLevelDeduction);
                        ((Player)target).getPackets().sendSkillLevel(Skills.SKILL.MAGIC);
                        ((Player)target).getPackets().sendMessage("Your Magic level has been reduced by " + magicLevelDeduction + " level" + s + " !");
				    }
				    break;
				
			    case 9240: // Sapphire.
				    target.setLastGraphics(new Graphics(751));
				    if (target is Player) {
                        int prayerLevel = ((Player)target).getSkills().getCurLevel(Skills.SKILL.PRAYER);
                        if (prayerLevel == 1)
                            return maxDamage;
                        int prayerLevelDeduction = misc.random(1, 10);
                        prayerLevelDeduction = Math.Min(prayerLevelDeduction, (prayerLevel - 1));
                        string s = prayerLevelDeduction == 1 ? "" : "s";
                        ((Player)target).getSkills().setCurLevel(Skills.SKILL.PRAYER, prayerLevel - prayerLevelDeduction);
                        ((Player)target).getPackets().sendSkillLevel(Skills.SKILL.PRAYER);
                        ((Player)target).getPackets().sendMessage("Your Prayer level has been lowered by " + prayerLevelDeduction + " level" + s + " !");
                        killer.getPackets().sendMessage("You steal " + prayerLevelDeduction + " Prayer point" + s + " from your opponent!");

                        int prayerLevelObtained = Math.Min(killer.getSkills().getCurLevel(Skills.SKILL.PRAYER)+prayerLevelDeduction, killer.getSkills().getMaxLevel(Skills.SKILL.PRAYER));
                        killer.getSkills().setCurLevel(Skills.SKILL.PRAYER, prayerLevelObtained);
                        killer.getPackets().sendSkillLevel(Skills.SKILL.PRAYER);
				    }
				    break;
				
			    case 9241: // Emerald.
				    if (!target.isPoisoned()) {
					    Server.registerEvent(new PoisonEvent(target, 6));
					    target.setLastGraphics(new Graphics(752));
				    }
				    break;
				
			    case 9242: // Ruby
				    target.setLastGraphics(new Graphics(754));
				    int currentHP = killer.getHp();
				    bool has11Percent = (currentHP * 0.11) < currentHP;
				    double removeFromOpponent = (target.getHp() * 0.20); //20% off opponents HP.
				    if (has11Percent) {
					    killer.hit(currentHP * 0.10);
					    target.hit(removeFromOpponent);
					    killer.getPackets().sendMessage("You sacrifice some of your own health to deal more damage to your opponent!");
				    }
				    break;
				
			    case 9243: // Diamond.
				    target.setLastGraphics(new Graphics(758));
				    maxDamage *= 1.15; //15% increase.
				    //TODO this affects opponents range defence for X minutes.
				    break;
				
			    case 9244: // Dragon.
				    bool hitsFire = true;
				    if (target is Player) {
					    int shield = ((Player)target).getEquipment().getItemInSlot(ItemData.EQUIP.SHIELD);
					    /*
					     * Opponent has anti-fire shield.
					     */
					    if (shield == 11283 || shield == 1540) {
						    hitsFire = false;
					    }
				    } else {
					    int id = ((Npc)target).getId();
					    /*
					     * NPC is a dragon
					     */
					    if ((id >= 50 && id <= 55) || id == 941 || (id >= 1589 && id <= 1592) || id == 2642 || id == 3376 
						    || id == 3588 || id == 3590 || (id >= 4665 && id <= 4684) || id == 5178 || id == 5362 || id == 5363) {
						    hitsFire = false;
					    }
				    }
				    if (hitsFire) {
					    target.setLastGraphics(new Graphics(756));
					    maxDamage *= 1.45; //increase damage by 45%.
				    }
				    break;
				
			    case 9245: // Onyx.
				    target.setLastGraphics(new Graphics(753));
				    maxDamage *= 1.15; //15% increase.
				    killer.heal(misc.random((int)(maxDamage * 0.60)));
				    break;
		    }
		    damage = misc.randomDouble(maxDamage);
		    if (misc.random(2) == 0 && bolt != 9242) {
			    damage = ((maxDamage * 0.50) + misc.randomDouble(maxDamage * 0.50));
		    }
		    if (damage > target.getHp()) {
			    damage = target.getHp();
		    }
		    return damage;
	    }
	    private static void doJadAttacks(Player p, Npc npc) {
		    if (npc.getHp() <= (npc.getMaxHp() * 0.50)) {
			    if (p.getFightCave() != null) {
                    if (!p.getFightCave().isHealersSpawned())
                    {
					    summonJadHealers(p, npc);
					    p.getFightCave().setHealersSpawned(true);
				    }
			    }
		    }
		    npc.resetCombatTurns();
		    npc.setEntityFocus(p.getClientIndex());
		    switch(misc.random(1)) {
			    case 0: // Range
				    npc.setLastAnimation(new Animation(9276));
				    npc.setLastGraphics(new Graphics(1625));
                    Event jadRangeAttackEvent = new Event(1600);
                    int jadRangeAttackStatus = 0;
                    jadRangeAttackEvent.setAction(() => {
					    double hit = 0;
                        PrayerData.PrayerHeadIcon prayerHeadIcon = p.getPrayers().getHeadIcon();
                        if (jadRangeAttackStatus == 0)
                        {
                            jadRangeAttackStatus++;
							jadRangeAttackEvent.setTick(1500);
							p.setLastGraphics(new Graphics(451));
                            if (prayerHeadIcon == PrayerData.PrayerHeadIcon.RANGE)
								hit = 0;
							else
								hit = misc.randomDouble(96);
						} else {
                            if (prayerHeadIcon != PrayerData.PrayerHeadIcon.RANGE)
								hit = misc.randomDouble(96);
							jadRangeAttackEvent.stop();
                            p.setLastAttacked(Environment.TickCount);
                            npc.setLastAttack(Environment.TickCount);
							p.setAttacker(npc);
							if (hit > p.getHp()) {
								hit = p.getHp();
							}
							if (!Location.inFightCave(p.getLocation()) || p.getTeleportTo() != null) {
								return;
							}
							if ((p.getCombatTurns() > 2 || p.getCombatTurns() < 0)) {
								p.setLastAnimation(new Animation(p.getDefenceAnimation()));
							}
							p.hit(hit);
                            Event animationEvent = new Event(100);
                            animationEvent.setAction(() => {
								animationEvent.stop();
								p.setLastGraphics(new Graphics(157, 0, 100));
							});
                            Server.registerEvent(animationEvent);
						}
				    });
                    Server.registerEvent(jadRangeAttackEvent);
				    break;
	
			    case 1: // Magic
				    npc.setLastGraphics(new Graphics(1626));
                    Event jadMagicAttackEvent = new Event(300);
                    int jadMagicAttackStatus = 0;
                    jadMagicAttackEvent.setAction(() => {
					    double hit = 0;
						PrayerData.PrayerHeadIcon prayerHeadIcon = p.getPrayers().getHeadIcon();
						npc.setLastAnimation(new Animation(9278));
                        if (jadMagicAttackStatus == 0)
                        {
                            jadMagicAttackStatus++;
							jadMagicAttackEvent.setTick(1600);
							p.getPackets().sendProjectile(npc.getLocation(), p.getLocation(), 32, 1627, 50, 40, 34, 90, p);
						} else {
							jadMagicAttackEvent.stop();
                            if (prayerHeadIcon == PrayerData.PrayerHeadIcon.MAGIC)
                            {
								hit = 0;
							} else {
								hit = misc.randomDouble(96);
							}
                            p.setLastAttacked(Environment.TickCount);
                            npc.setLastAttack(Environment.TickCount);
							p.setAttacker(npc);
							if (hit > p.getHp()) {
								hit = p.getHp();
							}
							if (!Location.inFightCave(p.getLocation()) || p.getTeleportTo() != null) {
								return;
							}
							if ((p.getCombatTurns() > 2 || p.getCombatTurns() < 0)) {
								p.setLastAnimation(new Animation(p.getDefenceAnimation()));
							}
							p.hit(hit);
                            Event animationEvent = new Event(100);
                            animationEvent.setAction(() => {
								animationEvent.stop();
								p.setLastGraphics(new Graphics(157, 0, 100));
							});
                            Server.registerEvent(animationEvent);
						}
				    });
                    Server.registerEvent(jadMagicAttackEvent);
				    break;
		    }
	    }