public static void newMagicAttack(Player p, Entity target, int id, bool ancients) { int index = getSpellIndex(p, id, ancients); bool autoCasting = p.getTemporaryAttribute("autoCasting") != null; bool fakeNPC = target != null && target is Npc && ((Npc)target).getId() == 0; Entity lastAutocastEntity = null; bool frozen = false; if (index == -1) { return; } if (p.getTarget() == null) { if (autoCasting) { if (Location.inMultiCombat(p.getLocation())) { lastAutocastEntity = (Entity)p.getTemporaryAttribute("autocastEntity") == null ? null : (Entity)p.getTemporaryAttribute("autocastEntity"); if (lastAutocastEntity == null || lastAutocastEntity is Player) { p.removeTemporaryAttribute("autoCasting"); Combat.resetCombat(p, 1); return; } if (hitsMulti(p, index)) { Location location = (Location)p.getTemporaryAttribute("autocastLocation"); Entity newTarget = new Npc(0); newTarget.setLocation(location); p.setTarget(newTarget); newMagicAttack(p, newTarget, id, ancients); return; } } else { p.removeTemporaryAttribute("autoCasting"); Combat.resetCombat(p, 1); return; } } else { p.removeTemporaryAttribute("autoCasting"); Combat.resetCombat(p, 1); return; } } else { if (!canCastSpell(p, target, index, fakeNPC)) { p.removeTemporaryAttribute("autoCasting"); Combat.resetCombat(p, 1); return; } } int distance = 8; if (target is Player) { if (((Player)target).getSprites().getPrimarySprite() != -1) { distance = 8; } } if (!fakeNPC) { // we're actually attacking a real npc/player if (!p.getLocation().withinDistance(target.getLocation(), distance)) { p.getFollow().setFollowing(target); Event attemptMagicAttackEvent = new Event(500); int attemptMagicAttackCounter = 0; attemptMagicAttackEvent.setAction(() => { if (p.getLocation().withinDistance(target.getLocation(), distance) && p.getTarget() != null) { attemptMagicAttackEvent.stop(); newMagicAttack(p, target, id, ancients); return; } attemptMagicAttackCounter++; if (attemptMagicAttackCounter >= 12) { attemptMagicAttackEvent.stop(); } }); Server.registerEvent(attemptMagicAttackEvent); return; } } int timeSinceLastCast = autoCasting ? 3500 : 2000; if (Environment.TickCount - p.getLastMagicAttack() < timeSinceLastCast) { p.getWalkingQueue().resetWalkingQueue(); //return; } int time = p.getLastCombatType().Equals(Combat.CombatType.MAGE) ? 1550 : 600; if (Environment.TickCount - p.getLastAttack() < time) { int delay = p.getLastCombatType().Equals(Combat.CombatType.MAGE) ? 1350 : 800; Event attemptMagicAttackEvent = new Event(500); attemptMagicAttackEvent.setAction(() => { if (Environment.TickCount - p.getLastAttack() > delay) { attemptMagicAttackEvent.stop(); newMagicAttack(p, target, id, ancients); } }); Server.registerEvent(attemptMagicAttackEvent); p.getWalkingQueue().resetWalkingQueue(); p.getPackets().clearMapFlag(); p.setLastCombatType(Combat.CombatType.MAGE); return; } if (fakeNPC && !monsterInArea(p, target)) { p.removeTemporaryAttribute("autoCasting"); Combat.resetCombat(p, 1); return; } int endGfx = END_GFX[index]; double damage = Misc.random(CombatFormula.getMagicHit(p, target, getSpellMaxHit(p, index))); bool mp = false; bool magicProtect = mp; if (target is Player) { mp = ((Player)target).getPrayers().getHeadIcon() == PrayerData.MAGIC; } if (magicProtect) { damage *= 0.60; } if (p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) == 8841) { damage *= 1.10; // void mace 10% hit increase. } if (damage == 0 && index != 41 && index != 42 && index != 43 && index != 44 && index != 45 && index != 46 && index != 47) { endGfx = 85; } if (!deleteRunes(p, RUNES[index], RUNE_AMOUNTS[index])) { p.setTarget(null); return; } p.getFollow().setFollowing(null); p.getWalkingQueue().resetWalkingQueue(); p.getPackets().clearMapFlag(); p.setFaceLocation(target.getLocation()); if (HANDS_GFX[index] != -1) { p.setLastGraphics(new Graphics(HANDS_GFX[index], 0, getStartingGraphicHeight(index))); } p.setLastAnimation(new Animation(SPELL_ANIM[index])); p.getPackets().closeInterfaces(); if (target is Player) { ((Player)target).getPackets().closeInterfaces(); } target.setAttacker(p); p.setTarget(target); target.setLastAttacked(Environment.TickCount); p.setLastAttack(Environment.TickCount); p.setLastMagicAttack(Environment.TickCount); p.setCombatTurns(p.getAttackSpeed()); Combat.setSkull(p, target); if (damage > 0) { frozen = freezeTarget(index, target); if (!frozen && index == 31) { endGfx = 1677; } } if (AIR_GFX[index] != -1 || ((index == 31 || index == 27) && target is Player && ((Player)target).getWalkingQueue().isRunning())) { sendProjectile(index, target, p); } if (damage > target.getHp()) { damage = target.getHp(); } if (index == 47 && Misc.random(2) == 0) { endGfx = 85; } Combat.checkIfWillDie(target, damage); Event doMagicAttackEvent = new Event(getSpellHitDelay(index)); doMagicAttackEvent.setAction(() => { doMagicAttackEvent.stop(); if (p == null || p.isDead() || !fakeNPC && (target.isDead() || target.isHidden() || target.isDestroyed())) { return; } if (target.isAutoRetaliating() && target.getTarget() == null && damage > 0) { if (target is Npc) { } else { if (((Player)target).getTemporaryAttribute("autoCastSpell") != null) { int autoCastSpell = (int)((Player)target).getTemporaryAttribute("autoCastSpell"); ((Player)target).setTemporaryAttribute("autoCasting", true); target.setTarget(p); MagicCombat.newMagicAttack((Player)target, p, autoCastSpell, ((Player)target).getTemporaryAttribute("autoCastAncients") != null); } } target.getFollow().setFollowing(p); target.setEntityFocus(p.getClientIndex()); if ((target.getCombatTurns() <= (target.getAttackSpeed() / 2) || target.getCombatTurns() >= (target.getAttackSpeed()))) { target.setCombatTurns(target.getAttackSpeed() / 2); } target.setTarget(p); if (target is Player) { ((Player)target).getWalkingQueue().resetWalkingQueue(); ((Player)target).getPackets().clearMapFlag(); } } addMagicXp(p, target, damage, index, true); target.setLastGraphics(new Graphics(endGfx, 0, getGroundHeight(index, endGfx))); if (index == 47 && endGfx != 85) { // teleblock if (target is Player) { teleblockPlayer(p, (Player)target); } } if (damage != 0) { Combat.checkRecoil(p, target, damage); Combat.checkSmite(p, target, damage); Combat.checkVengeance(p, target, damage); hitInMulti(p, target, index); applyMiasmicEffects(p, target, index); if ((target.getCombatTurns() > 2 || target.getCombatTurns() < 0) && !target.isDead()) { target.setLastAnimation(new Animation(target.getDefenceAnimation())); } if (index != 27) { target.hit((int)damage); if (index == 18 || index == 22 || index == 26 || index == 30) { p.heal(Convert.ToInt32(damage / 4)); } } else if (index == 27) { Event doHitEvent = new Event(1000); doHitEvent.setAction(() => { doHitEvent.stop(); target.hit((int)damage); }); Server.registerEvent(doHitEvent); } } }); Server.registerEvent(doMagicAttackEvent); if (p.getTemporaryAttribute("autoCasting") != null) { if (p.getTemporaryAttribute("autoCastSpell") != null) { if (id != (int)p.getTemporaryAttribute("autoCastSpell")) { p.setTarget(null); return; } } if (!fakeNPC) { p.setTemporaryAttribute("autocastLocation", target.getLocation()); p.setTemporaryAttribute("autocastEntity", target); } Event autoCastSpellEvent = new Event(3500); autoCastSpellEvent.setAction(() => { autoCastSpellEvent.stop(); if (p.getTemporaryAttribute("autoCasting") != null && p.getTemporaryAttribute("autoCastSpell") != null) { int autoCastSpell = (int)p.getTemporaryAttribute("autoCastSpell"); MagicCombat.newMagicAttack(p, p.getTarget(), autoCastSpell, p.getTemporaryAttribute("autoCastAncients") != null); } }); Server.registerEvent(autoCastSpellEvent); } else { p.setTarget(null); } }
public static void resetCombat(Entity killer, int type) { if (killer != null) { killer.setEntityFocus(65535); killer.setTarget(null); killer.getFollow().setFollowing(null); if (type == 1) { killer.setLastAttack(0); killer.setLastAttacked(0); if (killer.getAttacker() != null) { if (killer.getAttacker().getEntityFocus() != -1) { if (killer.getAttacker().getEntityFocus() == killer.getClientIndex()) { killer.getAttacker().setEntityFocus(65535); } } killer.setAttacker(null); } } } }
public static void attack(Npc npc, Entity target) { if (npc.isDead() || npc.getOwner() == null || npc.isDestroyed() || target.isDead() || target.isDestroyed()) { return; } int damage = Misc.random(npc.getMaxHit()); int prayer = ((Player)target).getPrayers().getHeadIcon(); int hitDelay = npc.getHitDelay(); bool special = false; switch (npc.getId()) { case 2026: // Dharok int healthHit = (npc.getMaxHp() - npc.getHp()) / 2; damage = Misc.random(damage + healthHit); if (Misc.random(1) == 0) { if (damage < (npc.getMaxHp() / 3)) { damage = (npc.getMaxHp() / 4) + Misc.random(damage + healthHit) - (npc.getMaxHp() / 4); } } if (prayer == PrayerData.MELEE) { damage = 0; } break; case 2025: // Ahrim hitDelay = 1000; ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 156, 50, 40, 34, 60, target); if (Misc.random(3) == 0) { special = true; Skills.SKILL[] weakenableSkills = (Skills.SKILL[])Enum.GetValues(typeof(Skills.SKILL)); Skills.SKILL weakenedSkill = weakenableSkills[Misc.random(0, 2)]; int currentLevel = ((Player)target).getSkills().getCurLevel(weakenedSkill); int newLevel = currentLevel - Misc.random(((Player)target).getSkills().getMaxLevel(weakenedSkill) / 12); newLevel = Math.Max(0, newLevel); ((Player)target).getSkills().setCurLevel(weakenedSkill, newLevel); ((Player)target).getPackets().sendSkillLevel(weakenedSkill); } if (prayer == PrayerData.MAGIC) { damage = 0; } break; case 2027: // Guthan if (prayer == PrayerData.MELEE) { damage = 0; } if (Misc.random(3) == 0) { special = true; target.setLastGraphics(new Graphics(398)); npc.heal(Misc.random(damage)); } break; case 2030: // Verac if (Misc.random(1) == 0 && prayer != 0) { if (damage <= npc.getMaxHit() / 2) { damage += npc.getMaxHit() / 2; if (damage > npc.getMaxHit()) { damage = npc.getMaxHit(); } } } break; case 2029: // Torag if (Misc.random(3) == 0) { special = true; } if (prayer == PrayerData.MELEE) { damage = 0; } break; case 2028: // Karil hitDelay = 700; ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 27, 50, 40, 34, 40, target); if (Misc.random(10) == 0) { special = true; int agility = ((Player)target).getSkills().getCurLevel(Skills.SKILL.AGILITY); int newAgility = agility / 4; if (newAgility <= 1) newAgility = 1; ((Player)target).getSkills().setCurLevel(Skills.SKILL.AGILITY, newAgility); ((Player)target).getPackets().sendSkillLevel(Skills.SKILL.AGILITY); } if (Misc.random(1) == 0) { damage = damage > 0 ? damage : Misc.random(npc.getMaxHit()); } if (prayer == PrayerData.RANGE) { damage = 0; } break; } npc.setLastAnimation(new Animation(npc.getAttackAnimation())); target.setLastAttacked(Environment.TickCount); npc.setLastAttack(Environment.TickCount); npc.resetCombatTurns(); target.setAttacker(npc); if ((target.getCombatTurns() > 2 || target.getCombatTurns() < 0)) { target.setLastAnimation(new Animation(target.getDefenceAnimation())); } if (damage > target.getHp()) { damage = target.getHp(); } Event doHitEvent = new Event(hitDelay); doHitEvent.setAction(() => { if (npc.getId() == 2025) { if (special) { target.setLastGraphics(new Graphics(400, 0, 100)); ((Player)target).getPackets().sendMessage("You feel weakened."); } target.setLastGraphics(new Graphics(damage == 0 ? 85 : 157, 0, 100)); } else if (npc.getId() == 2027) { if (special) { if (!npc.isDead()) { int newHp = npc.getHp() + damage; if (newHp > npc.getMaxHp()) { newHp = npc.getMaxHp(); } npc.setHp(newHp); } } } else if (npc.getId() == 2029) { if (special) { target.setLastGraphics(new Graphics(399, 0, 100)); int energy = ((Player)target).getRunEnergy(); int newEnergy = energy - (int)(energy * 0.50); if (newEnergy < 0) { newEnergy = 0; } ((Player)target).getPackets().sendMessage("You feel drained of energy."); ((Player)target).setRunEnergy(newEnergy); ((Player)target).getPackets().sendEnergy(); } } else if (npc.getId() == 2028) { if (special) { target.setLastGraphics(new Graphics(399)); ((Player)target).getPackets().sendMessage("You feel less agile."); } } target.hit(damage); doHitEvent.stop(); }); }
public static void attack(Npc npc, Entity target) { if (npc.isDead() || npc.isDestroyed() || target.isDead() || target.isDestroyed() || target.isDead()) { return; } int damage = Misc.random(npc.getMaxHit()); int prayer = ((Player)target).getPrayers().getHeadIcon(); int hitDelay = npc.getHitDelay(); int animation = npc.getAttackAnimation(); bool special = false; switch (npc.getId()) { case 6263: // Steelwill (bandos mage) hitDelay = 1000; animation = 65535; if (prayer == PrayerData.MAGIC) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1203, 50, 40, 34, 50, target); //npc.graphics(1201); break; case 6260: // Graardor (bandos) randomMessage(npc, BANDOS_SHOUTS); if (Misc.random(3) == 0) { special = true; hitDelay = 1000; animation = 7063; ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1200, 50, 40, 34, 50, target); if (prayer == PrayerData.RANGE) { damage = 0; } else { damage = Misc.random(35); } } else { if (prayer == PrayerData.MELEE) { damage = 0; } } break; case 6265: // Grimspike (bandos range) hitDelay = 1000; animation = 65535; if (prayer == PrayerData.RANGE) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1206, 50, 40, 34, 50, target); //npc.graphics(1201); break; case 6247: // Zilyana (sara boss) randomMessage(npc, SARADOMIN_SHOUTS); if (Misc.random(3) == 0) { animation = 6967; special = true; if (prayer == PrayerData.MAGIC) { damage = 0; } } else { if (prayer == PrayerData.MELEE) { damage = 0; } } break; case 6250: // Growler (sara mage) hitDelay = 1000; if (prayer == PrayerData.MAGIC) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1227, 50, 20, 27, 50, target); break; case 6252: // Bree (sara range) hitDelay = 1000; if (prayer == PrayerData.RANGE) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1227, 50, 20, 27, 50, target); //TODO all anims break; case 6203: // K'ril Tsutsaroth (zammy boss) randomMessage(npc, ZAMORAK_SHOUTS); if (prayer == PrayerData.MELEE) { damage = 0; } if (Misc.random(3) == 0) { animation = 6947; damage = Misc.random(49); if (prayer != 0 && damage < (49 / 2)) { damage = (49 / 2) + Misc.random(49 / 2); } } if (Misc.random(4) == 0) { if (!target.isPoisoned()) { if (damage > 0) { Server.registerEvent(new PoisonEvent(target, 16)); } } } break; case 6208: // Balfrug Kreeyath (zammy mage) hitDelay = 1200; if (prayer == PrayerData.MAGIC) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1213, 50, 20, 27, 70, target); // TODO attack anim break; case 6206: // Zakl'n Gritch (zammy range) hitDelay = 1200; if (prayer == PrayerData.RANGE) { damage = 0; } npc.setLastGraphics(new Graphics(1208)); ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1209, 50, 20, 27, 70, target); break; case 6222: // Kree'arra (armadyl boss) if (Misc.random(4) == 0) { npc.setForceText("Kraaaaw!"); } hitDelay = 1200; if (Misc.random(2) == 0 && npc.getAttacker() != null && npc.getAttacker().Equals(npc.getTarget())) { special = true; // Magic attack damage = Misc.random(21); if (prayer == PrayerData.MAGIC) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1198, 50, 20, 27, 70, target); } else if (npc.getAttacker() != null && npc.getAttacker().Equals(npc.getTarget())) { //range attack if (prayer == PrayerData.RANGE) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1197, 50, 20, 27, 70, target); } else { // do melee attack because they arent attacking kree arra damage = Misc.random(25); if (prayer == PrayerData.MELEE) { damage = 0; } animation = 6977; } break; case 6223: // Armadyl mage hitDelay = 1200; if (prayer == PrayerData.MAGIC) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1199, 50, 20, 27, 70, target); break; case 6225: // Armadyl range hitDelay = 1200; if (prayer == PrayerData.RANGE) { damage = 0; } ((Player)target).getPackets().sendProjectile(npc.getLocation(), target.getLocation(), 32, 1190, 50, 20, 27, 70, target); break; } if (animation != 65535) { npc.setLastAnimation(new Animation(animation)); } target.setLastAttacked(Environment.TickCount); npc.setLastAttack(Environment.TickCount); target.setAttacker(npc); npc.resetCombatTurns(); if (damage > target.getHp()) { damage = target.getHp(); } int hit = damage; Event attackEvent = new Event(hitDelay); attackEvent.setAction(() => { attackEvent.stop(); if (npc.getId() == 6263) { target.setLastGraphics(new Graphics(hit > 0 ? 166 : 85, 0, 100)); } else if (npc.getId() == 6260) { if (special) { target.setLastGraphics(new Graphics(hit > 0 ? 160 : 65535, 0, 100)); } } else if (npc.getId() == 6247) { if (special) { if (hit < 1) { return; } else { target.setLastGraphics(new Graphics(1207, 0, 100)); npc.setCombatTurns(npc.getAttackSpeed() * 2); } } } else if (npc.getId() == 6208) { if (hit == 0) { target.setLastGraphics(new Graphics(85, 0, 100)); } } else if (npc.getId() == 6222) { if (special) { target.setLastGraphics(new Graphics(hit == 0 ? 85 : 65535, 0, 100)); } } if ((target.getCombatTurns() > 2 || target.getCombatTurns() < 0)) { target.setLastAnimation(new Animation(target.getDefenceAnimation())); } target.hit(hit); }); Server.registerEvent(attackEvent); }