private void handleExamineNPC(Player player, Packet packet) { int npcId = packet.readUShort(); if (npcId < 0 || npcId > NpcData.getTotalNpcDefinitions() || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) return; player.getPackets().sendMessage(NpcData.forId(npcId).getExamine()); }
private void handleFifthClickNPC(Player player, Packet packet) { int npcIndex = packet.readLEShort(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } Console.WriteLine("Fifth click NPC " + npc.getId()); SkillHandler.resetAllSkills(player); if (Slayer.openPointsInterface(player, npc)) { return; } }
private void handleItemOnItem(Player player, Packet packet) { int itemSlot = packet.readUShort(); int unused = packet.readInt(); int withSlot = packet.readLEShort(); int unused2 = packet.readInt(); int itemUsed = packet.readLEShortA(); int usedWith = packet.readLEShortA(); if (itemSlot > 28 || itemSlot < 0 || withSlot > 28 || withSlot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); player.getPackets().closeInterfaces(); if (player.getInventory().getSlot(itemSlot).getItemId() == itemUsed && player.getInventory().getSlot(withSlot).getItemId() == usedWith) { if (Fletching.isFletching(player, itemUsed, usedWith)) { return; } else if (Herblore.doingHerblore(player, itemUsed, usedWith)) { return; } else if (Herblore.mixDoses(player, itemUsed, usedWith, itemSlot, withSlot)) { return; } else if (Crafting.wantsToCraft(player, itemUsed, usedWith)) { return; } else if (Firemaking.isFiremaking(player, itemUsed, usedWith, itemSlot, withSlot)) { return; } else if (Farming.plantSapling(player, itemUsed, usedWith)) { return; } else { player.getPackets().sendMessage("Nothing interesting happens."); } } }
private void handleItemOnGroundItem(Player player, Packet packet) { int objectX = packet.readLEShortA(); int itemSlot = packet.readLEShort(); int itemIdInInventory = packet.readLEShort(); int itemIdOnGround = packet.readLEShort(); int objectY = packet.readLEShortA(); int interfaceId = packet.readLEShort(); int child = packet.readUShort(); if (itemSlot > 28 || itemSlot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) return; if (Firemaking.isFiremaking(player, itemIdInInventory, itemIdOnGround, itemSlot, -1)) return; else player.getPackets().sendMessage("Nothing interesting happens."); }
private void handleInvenClickItem(Player player, Packet packet) { int slot = packet.readLEShortA(); int item = packet.readShortA(); int childId = packet.readLEShort(); int interfaceId = packet.readLEShort(); if (slot > 28 || slot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); if (player.getInventory().getItemInSlot(slot) == item) { player.getPackets().closeInterfaces(); if (Consumables.isEating(player, player.getInventory().getItemInSlot(slot), slot)) return; else if (Herblore.idHerb(player, player.getInventory().getItemInSlot(slot))) return; else if (RuneCraft.fillPouch(player, (RuneCraftData.POUCHES)player.getInventory().getItemInSlot(slot))) return; else if (Prayer.wantToBury(player, player.getInventory().getItemInSlot(slot), slot)) return; else if (Teleport.useTeletab(player, player.getInventory().getItemInSlot(slot), slot)) return; else if (FarmingAmulet.showOptions(player, player.getInventory().getItemInSlot(slot))) return; switch(item) { case 4155: // Slayer gem Slayer.doDialogue(player, 1051); break; case 6: // Dwarf multicannon if (player.getCannon() != null) { player.getPackets().sendMessage("You already have a cannon set up!"); break; } player.setCannon(new DwarfCannon(player)); break; case 5073: // Nest with seeds. case 5074: // Nest with jewellery. Woodcutting.randomNestItem(player, item); break; case 952: // Spade player.setLastAnimation(new Animation(830)); if (Barrows.enterCrypt(player)) { player.getPackets().sendMessage("You've broken into a crypt!"); break; } player.getPackets().sendMessage("You find nothing."); break; } } }
private static bool canCastSpell(Player p, Entity target, int i, bool fakeNPC) { // fakeNPC is used to keep location when autocasting. if (fakeNPC) { return !p.isDead(); } if (target.isDead() || p.isDead() || target.isDestroyed() || p.isDestroyed()) { return false; } if (target is Npc) { if (((Npc) target).getHp() <= 0) { return false; } if (i == 47) { p.getPackets().sendMessage("You cannot cast Teleblock upon an NPC."); return false; } } if ((target is Player) && (p is Player)) { if (Location.inFightPits(target.getLocation()) && Location.inFightPits(target.getLocation())) { if (!Server.getMinigames().getFightPits().hasGameStarted()) { return false; } return true; } if (p.getDuel() != null) { if (((Player)target).getDuel() != null) { if (p.getDuel().getPlayer2().Equals(((Player) target)) && ((Player) target).getDuel().getPlayer2().Equals(p)) { if (p.getDuel().ruleEnabled(DuelSession.RULE.NO_MAGIC)) { p.getPackets().sendMessage("Magical combat has been disabled in this duel!"); return false; } if (p.getDuel().getStatus() == 6 && ((Player) target).getDuel().getStatus() == 6) { return true; } } } p.getPackets().sendMessage("That isn't your opponent."); return false; } if (i == 47) { if (((Player)target).getTemporaryAttribute("teleblocked") != null) { p.getPackets().sendMessage("That player already has a teleportation block upon them."); return false; } } if (!Location.inWilderness(target.getLocation())) { p.getPackets().sendMessage("That player isn't in the wilderness."); return false; } if (!Location.inWilderness(p.getLocation())) { p.getPackets().sendMessage("You aren't in the wilderness."); return false; } int killerWildLevel = p.getLocation().wildernessLevel(); int targetWildLevel = ((Player)target).getLocation().wildernessLevel(); int killerCombatLevel = p.getSkills().getCombatLevel(); int targetCombatLevel = ((Player)target).getSkills().getCombatLevel(); int highest = killerCombatLevel > targetCombatLevel ? killerCombatLevel : targetCombatLevel; int lowest = highest == killerCombatLevel ? targetCombatLevel : killerCombatLevel; int difference = (highest - lowest); if (difference > killerWildLevel || difference > targetWildLevel) { ((Player) p).getPackets().sendMessage("You must move deeper into the wilderness to attack that player."); return false; } } if (!Location.inMultiCombat(target.getLocation())) { if (p.getAttacker() != null && !p.getAttacker().Equals(target)) { p.getPackets().sendMessage("You are already in combat!"); return false; } if (target.getAttacker() != null && !target.getAttacker().Equals(p)) { string type = target is Player ? "player" : "npc"; p.getPackets().sendMessage("That " + type + " is already in combat."); return false; } } if (p.getSkills().getCurLevel(Skills.SKILL.MAGIC) < SPELL_LEVEL[i]) { p.getPackets().sendMessage("You need a Magic level of " + SPELL_LEVEL[i] + " to cast that spell."); return false; } if (!hasRunes(p, RUNES[i], RUNE_AMOUNTS[i])) { p.getPackets().sendMessage("You do not have enough runes to cast that spell."); return false; } if (NEEDS_STAFF[i]) { if ((i != 38 && p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) != STAFF[i]) || (i == 38 && p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) != 8841 && p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) != STAFF[i])) { p.getPackets().sendMessage("You need to wield " + STAFF_NAME[i] + " to cast this spell."); return false; } } if (i == 37) { if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CAPE) != 2412) { p.getPackets().sendMessage("You need to wear the Cape of Saradomin to be able to cast Saradomin Strike."); return false; } } if (i == 38) { if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CAPE) != 2413) { p.getPackets().sendMessage("You need to wear the Cape of Guthix to be able to cast Claws of Guthix."); return false; } } if (i == 39) { if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CAPE) != 2414) { p.getPackets().sendMessage("You need to wear the Cape of Zamorak to be able to cast Flames of Zamorak."); return false; } } return true; }
private void handleSwapSlot2(Player player, Packet packet) { int interfaceId = packet.readLEShort(); int child = packet.readUShort(); int newSlot = packet.readLEShort(); int interface2 = packet.readUShort(); int child2 = packet.readUShort(); int oldSlot = packet.readLEShort(); int oldItem = player.getInventory().getItemInSlot(oldSlot); int oldAmount = player.getInventory().getAmountInSlot(oldSlot); int newItem = player.getInventory().getItemInSlot(newSlot); int newAmount = player.getInventory().getAmountInSlot(newSlot); if (oldSlot > 28 || oldSlot < 0 || newSlot > 28 || oldSlot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } switch (interfaceId) { case 621: // Shop. case 763: // Bank. case 336: // Duel player.getInventory().getSlot(oldSlot).setItemId(newItem); player.getInventory().getSlot(oldSlot).setItemAmount(newAmount); player.getInventory().getSlot(newSlot).setItemId(oldItem); player.getInventory().getSlot(newSlot).setItemAmount(oldAmount); break; default: misc.WriteError("UNHANDLED ITEM SWAP 2 : interface = " + interfaceId); break; } //No need to update the screen since the client does it for us! player.getPackets().refreshInventory(); }
private void handleRightClickTwo(Player player, Packet packet) { int childId = packet.readLEShort(); int interfaceId = packet.readLEShort(); int slot = packet.readLEShort(); int item = packet.readLEShort(); if (slot < 0 || slot > 28 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); if (player.getInventory().getItemInSlot(slot) == item) { player.getPackets().closeInterfaces(); switch(player.getInventory().getItemInSlot(slot)) { case 5509: // Small pouch. player.getPackets().sendMessage("There is " + player.getSmallPouchAmount() + " Pure essence in your small pouch. (holds 3)."); break; case 5510: // Medium pouch. player.getPackets().sendMessage("There is " + player.getMediumPouchAmount() + " Pure essence in your medium pouch. (holds 6)."); break; case 5512: // Large pouch. player.getPackets().sendMessage("There is " + player.getLargePouchAmount() + " Pure essence in your large pouch. (holds 9)."); break; case 5514: // Giant pouch. player.getPackets().sendMessage("There is " + player.getGiantPouchAmount() + " Pure essence in your giant pouch. (holds 12)."); break; } } }
private void handlePickupItem(Player player, Packet packet) { int x = packet.readLEShort(); int id = packet.readUShort(); int y = packet.readLEShortA(); Location l = new Location(x, y, player.getLocation().getZ()); SkillHandler.resetAllSkills(player); if (x < 1000 || y < 1000 | id < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } player.getPackets().closeInterfaces(); if(player.getLocation().Equals(l)) { Server.getGroundItems().pickupItem(player, id, player.getLocation()); return; } CoordinateEvent pickupItemCoordinateEvent = new CoordinateEvent(player, l); pickupItemCoordinateEvent.setAction(() => { Server.getGroundItems().pickupItem(player, id, player.getLocation()); }); Server.registerCoordinateEvent(pickupItemCoordinateEvent); }
private void handleThirdClickNPC(Player player, Packet packet) { int npcIndex = packet.readShortA(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } Console.WriteLine("Third click NPC " + npc.getId()); SkillHandler.resetAllSkills(player); if (Thieving.wantToThieveNpc(player, npc)) { return; } else if (Fishing.wantToFish(player, npc, true)) { return; } else if (AgilityArena.dialogue(player, npc, true)) { return; } else if (TzHaar.interactTzhaarNPC(player, npc, 2)) { return; } else if (WarriorGuild.talkToWarriorGuildNPC(player, npc, 2)) { return; } switch(npc.getId()) { case 553: // Aubury HomeArea.interactWithAubury(player, npc, 2); break; case 519: // Bob BrokenBarrows.talkToBob(player, npc, -1, 2); break; } }
private void handleSecondClickNPC(Player player, Packet packet) { int npcIndex = packet.readLEShort(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } Console.WriteLine("Second click NPC " + npc.getId()); SkillHandler.resetAllSkills(player); if (Fishing.wantToFish(player, npc, false)) { return; } else if (Slayer.talkToMaster(player, npc)) { return; } else if (AgilityArena.dialogue(player, npc, false)) { return; } else if (TzHaar.interactTzhaarNPC(player, npc, 1)) { return; } else if (WarriorGuild.talkToWarriorGuildNPC(player, npc, 1)) { return; } else if (BoatOptions.interactWithBoatNPC(player, npc)) { return; } switch(npc.getId()) { case 519: // Bob BrokenBarrows.talkToBob(player, npc, -1, 1); break; case 553: // Aubury HomeArea.interactWithAubury(player, npc, 1); break; case 1862: // Ali morisanne if (npc.getLocation().inArea(2319, 3177, 2321, 3182)) { // Home Ali HomeArea.interactWithAliMorissaae(player, npc); break; } else if (npc.getLocation().inArea(3311, 3198, 3316, 3199)) { // Al Kharid Ali AlKharid.interactWithAliMorissaae(player, npc); break; } break; } }
private void handleMagicOnNPC(Player player, Packet packet) { int childId = packet.readLEShort(); int interfaceId = packet.readLEShort(); int junk = packet.readShortA(); int npcIndex = packet.readLEShortA(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } SkillHandler.resetAllSkills(player); player.setTarget(npc); MagicCombat.newMagicAttack(player, npc, childId, interfaceId == 193); Console.WriteLine(childId); }
private void handleItemOnNPC(Player player, Packet packet) { int interfaceId = packet.readInt(); int slot = packet.readLEShort(); int npcIndex = packet.readLEShort(); int item = packet.readLEShortA(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } SkillHandler.resetAllSkills(player); player.getPackets().closeInterfaces(); Console.WriteLine("Item on NPC " + npc.getId()); if (player.getInventory().getItemInSlot(slot) == item) { switch(npc.getId()) { case 519: // Bob BrokenBarrows.talkToBob(player, npc, player.getInventory().getItemInSlot(slot), 0); break; } } }
private void handleFourthClickNPC(Player player, Packet packet) { int npcIndex = packet.readUShort(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } Console.WriteLine("Fourth click NPC " + npc.getId()); SkillHandler.resetAllSkills(player); if (Slayer.openSlayerShop(player, npc)) { return; } switch(npc.getId()) { case 553: // Aubury HomeArea.interactWithAubury(player, npc, 3); break; } }
private static bool canCastSpell2(Player p, Entity target, int i, bool fakeNPC) { // fakeNPC is used to keep location when autocasting. if (fakeNPC) { return !p.isDead(); } if (target.isDead() || p.isDead() || target.isDestroyed() || p.isDestroyed()) { return false; } if (target is Npc) { if (((Npc)target).getHp() <= 0) { return false; } } if ((target is Player) && (p is Player)) { if (Location.inFightPits(target.getLocation()) && Location.inFightPits(target.getLocation())) { if (!Server.getMinigames().getFightPits().hasGameStarted()) { return false; } return true; } if (p.getDuel() != null) { if (((Player)target).getDuel() != null) { if (p.getDuel().getPlayer2().Equals(((Player) target)) && ((Player) target).getDuel().getPlayer2().Equals(p)) { if (p.getDuel().ruleEnabled(DuelSession.RULE.NO_MAGIC)) { return false; } if (p.getDuel().getStatus() == 6 && ((Player) target).getDuel().getStatus() == 6) { return true; } } } return false; } if (!Location.inWilderness(target.getLocation()) && !Location.inWilderness(p.getLocation())) return false; int killerWildLevel = p.getLocation().wildernessLevel(); int targetWildLevel = ((Player)target).getLocation().wildernessLevel(); int killerCombatLevel = p.getSkills().getCombatLevel(); int targetCombatLevel = ((Player)target).getSkills().getCombatLevel(); int highest = killerCombatLevel > targetCombatLevel ? killerCombatLevel : targetCombatLevel; int lowest = highest == killerCombatLevel ? targetCombatLevel : killerCombatLevel; int difference = (highest - lowest); if (difference > killerWildLevel || difference > targetWildLevel) { return false; } } return true; }
private void handleItemOnObject(Player player, Packet packet) { int objectX = packet.readShortA(); int item = packet.readUShort(); int objectY = packet.readLEShort(); int slot = packet.readUShort(); int interfaceId = packet.readLEShort(); int child = packet.readUShort(); int objectId = packet.readShortA(); if (slot > 28 || slot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } Console.WriteLine("Item on object = " + objectId + " " + objectX + " " + objectY); SkillHandler.resetAllSkills(player); player.getPackets().closeInterfaces(); player.setFaceLocation(new Location(objectX, objectY, player.getLocation().getZ())); if (player.getInventory().getItemInSlot(slot) == item) { if (Crafting.wantsToCraftOnObject(player, player.getInventory().getItemInSlot(slot), objectId)) { return; } else if (Farming.interactWithPatch(player, objectId, objectX, objectY, player.getInventory().getItemInSlot(slot))) { return; } else if (WarriorGuild.useAnimator(player, player.getInventory().getItemInSlot(slot), objectId, objectX, objectY)) { return; } if (player.getInventory().getItemInSlot(slot) == 7936) { if (RuneCraft.wantToRunecraft(player, objectId, objectX, objectY)) { return; } if (RuneCraft.useTalisman(player, objectId, objectX, objectY)) { return; } } switch(objectId) { case 6: // Cannon: DwarfCannon cannon = player.getCannon(); Location l = new Location(objectX, objectY, player.getLocation().getZ()); if (cannon == null || (cannon != null & !l.withinDistance(cannon.getLocation(), 2))) { player.getPackets().sendMessage("This isn't your cannon!"); break; } cannon.loadCannon(); break; case 36781: // Lumbridge fountain. case 24214: // Fountain in east Varrock. case 24265: // Varrock main fountain. case 11661: // Falador waterpump. case 11759: // Falador south fountain. case 879: // Camelot fountains. case 29529: // Sink. case 874: // Sink. if (FillVial.fillingVial(player, new Location(objectX, objectY, player.getLocation().getZ())) && player.getInventory().getItemInSlot(slot) == 229) { break; } break; case 2728: // Range in Catherby if (Cooking.isCooking(player, player.getInventory().getItemInSlot(slot), false, -1, -1)) { break; } break; case 2732: // Fire if (Cooking.isCooking(player, player.getInventory().getItemInSlot(slot), true, objectX, objectY)) { break; } break; case 36956: // Lumbridge furnace case 11666: // Falador furnace if (Smelting.wantToSmelt(player, player.getInventory().getItemInSlot(slot))) { break; } else if (Crafting.wantsToCraftOnObject(player, player.getInventory().getItemInSlot(slot), objectId)) { break; } break; case 2783: // Anvil if (Smithing.wantToSmithOnAnvil(player, player.getInventory().getItemInSlot(slot), new Location(objectX, objectY, player.getLocation().getZ()))) { break; } break; default: player.getPackets().sendMessage("Nothing interesting happens."); break; } } }
private void handleOperateItem(Player player, Packet packet) { int item = packet.readShortA(); int slot = packet.readLEShort(); int interfaceId = packet.readLEShort(); int childId = packet.readLEShort(); if (slot < 0 || slot > 13 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } ItemData.EQUIP equipSlot = (ItemData.EQUIP)slot; if (player.getEquipment().getItemInSlot(equipSlot) == item) { SkillHandler.resetAllSkills(player); player.getPackets().closeInterfaces(); if (JewelleryTeleport.useJewellery(player, player.getEquipment().getItemInSlot(equipSlot), slot, true)) { return; } else if (equipSlot == ItemData.EQUIP.CAPE && Skillcape.emote(player)) { return; } player.getPackets().sendMessage("This item isn't operable."); } }
private void handleFirstClickNPC(Player player, Packet packet) { int npcIndex = packet.readLEShortA(); if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); Npc npc = Server.getNpcList()[npcIndex]; if (npc == null || npc.isDestroyed()) { return; } Combat.newAttack(player, npc); }
private void handleRightClickOne(Player player, Packet packet) { int childId = packet.readLEShort(); int interfaceId = packet.readLEShort(); int item = packet.readLEShortA(); int slot = packet.readLEShortA(); if (slot > 28 || slot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); if (player.getInventory().getItemInSlot(slot) == item) { player.getPackets().closeInterfaces(); if (interfaceId == 149 && childId == 0) { if (Herblore.emptyPotion(player, player.getInventory().getItemInSlot(slot), slot)) { return; } else if (JewelleryTeleport.useJewellery(player, player.getInventory().getItemInSlot(slot), slot, false)) { return; } } } }
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; } int damage = misc.random(npc.getMaxHit()); int prayer = p.getPrayers().getHeadIcon(); int hitDelay = npc.getHitDelay(); int animation = npc.getAttackAnimation(); switch(npc.getId()) { case 2734: // Tz-Kih (lvl 22) case 2735: if (prayer == PrayerData.MELEE) { damage = 0; } break; case 2739: // Tz-Xil (lvl 90) case 2740: if (prayer == PrayerData.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 (prayer == PrayerData.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.random(49); if (prayer == PrayerData.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.random(64); if (prayer == PrayerData.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 -= (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 void handleSwapSlot(Player player, Packet packet) { int oldSlot = packet.readUShort(); int childId = packet.readLEShort(); int interfaceId = packet.readLEShort(); int newSlot = packet.readShortA(); int swapType = packet.readByteS(); int oldItem = player.getInventory().getItemInSlot(oldSlot); int oldAmount = player.getInventory().getAmountInSlot(oldSlot); int newItem = player.getInventory().getItemInSlot(newSlot); int newAmount = player.getInventory().getAmountInSlot(newSlot); if (oldSlot > 28 || oldSlot < 0 || newSlot > 28 || oldSlot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } switch (interfaceId) { case 149: if (swapType == 0 && childId == 0) { player.getInventory().getSlot(oldSlot).setItemId(newItem); player.getInventory().getSlot(oldSlot).setItemAmount(newAmount); player.getInventory().getSlot(newSlot).setItemId(oldItem); player.getInventory().getSlot(newSlot).setItemAmount(oldAmount); } break; default: misc.WriteError("UNHANDLED ITEM SWAP 1 : interface = " + interfaceId); break; } //No need to update the screen since the client does it for us! }
private void handleEquipItem(Player player, Packet packet) { int item = packet.readLEShort(); int slot = packet.readShortA(); int interfaceId = packet.readInt(); if (slot > 28 || slot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); if (player.getInventory().getItemInSlot(slot) == item) { //player.getPackets().closeInterfaces(); if (RuneCraft.emptyPouch(player, (RuneCraftData.POUCHES)player.getInventory().getItemInSlot(slot))) { return; } player.getEquipment().equipItem(player.getInventory().getItemInSlot(slot), slot); } }
private void handleDropItem(Player player, Packet packet) { int item = packet.readShortA(); int slot = packet.readShortA(); int interfaceId = packet.readLEShort(); int childId = packet.readUShort(); if (slot > 28 || slot < 0 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) { return; } SkillHandler.resetAllSkills(player); if (player.getInventory().getItemInSlot(slot) == item) { player.getPackets().closeInterfaces(); if (ItemData.isPlayerBound(player.getInventory().getItemInSlot(slot))) { Item[] items = {new Item(player.getInventory().getItemInSlot(slot), 1)}; //player.getPackets().sendItems(94, 0, 93, items); player.getPackets().modifyText("Are you sure you want to destroy this item?", 94, 3); // Title //player.getPackets().modifyText("Yes", 94, 4); // Yes //player.getPackets().modifyText("No", 94, 5); // No player.getPackets().modifyText("", 94, 10); // Line 1 player.getPackets().modifyText("If you wish to get another Fire cape, you must", 94, 11); // Line 2 player.getPackets().modifyText("complete the Fight cave minigame again.", 94, 12); // Line 3 player.getPackets().modifyText("Fire Cape", 94, 13); // Item name player.getPackets().sendChatboxInterface(94); return; } int id = player.getInventory().getItemInSlot(slot); int amt = player.getInventory().getAmountInSlot(slot); GroundItem i = new GroundItem(id, amt, new Location(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()), player); if (player.getInventory().deleteItem(id, slot, amt)) { if (!Server.getGroundItems().addToStack(id, amt, player.getLocation(), player)) { Server.getGroundItems().newEntityDrop(i); } } } }
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); } }