示例#1
0
 public static void interactWithAliMorissaae(Player p, Npc n)
 {
     p.setEntityFocus(n.getClientIndex());
     AreaEvent interactWithAliMorissaaeAreaEvent = new AreaEvent(p, n.getLocation().getX() - 1, n.getLocation().getY() - 1, n.getLocation().getX() + 1, n.getLocation().getY() + 1);
     interactWithAliMorissaaeAreaEvent.setAction(() => {
         n.setFaceLocation(p.getLocation());
         p.setFaceLocation(n.getLocation());
         p.setEntityFocus(65535);
         showAliDialogue(p, 205);
     });
     Server.registerCoordinateEvent(interactWithAliMorissaaeAreaEvent);
 }
示例#2
0
        public static bool interactWithBoatNPC(Player p, Npc n)
        {
            int id = n.getId();
            if (id != 4540 && id != 1304 && id != 2436 && id != 3781 && id != 1361 && id != 4962) {
                return false;
            }
            p.setEntityFocus(n.getClientIndex());
            AreaEvent interactWithBoatNPCAreaEvent = new AreaEvent(p, n.getLocation().getX() - 1, n.getLocation().getY() - 1, n.getLocation().getX() + 1, n.getLocation().getY() + 1);
            interactWithBoatNPCAreaEvent.setAction(() => {
                n.setFaceLocation(p.getLocation());
                p.setFaceLocation(n.getLocation());
                p.setEntityFocus(65535);
                switch(n.getId()) {
                    case 4540: // Home boat
                        showBentleyDialogue(p, 240);
                        break;

                    case 1304: // Canifis sailor
                        showCanifisSailorDialogue(p, 280);
                        break;

                    case 2436: // Waterbirth isle
                        showJarvaldDialogue(p, 300);
                        break;

                    case 3781: // Pest control squire
                        showSquireDialogue(p, 340);
                        break;

                    case 1361: // Warrior guild
                        showArnorDialogue(p, 370);
                        break;

                    case 4962: // fremmenik shore
                        showCaptainBarnabyDialogue(p, 410);
                        break;
                }
            });
            Server.registerCoordinateEvent(interactWithBoatNPCAreaEvent);
            return true;
        }
示例#3
0
        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;
                }
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        public static bool openTunnelDoor(Player player, int doorId, int x, int y)
        {
            if (doorId < 6716 || (doorId > 6731 && doorId < 6735) || doorId > 6750) {
                return false;
            }
            int index = getDoorIndex(doorId, x, y);
            int index2 = getOtherDoor(x, y); // index of the door next to the one you clicked.
            if (index == -1 || index2 == -1) {
                return false;
            }
            bool betweenDoors = player.getTemporaryAttribute("betweenDoors") != null;
            Location clickedDoor = new Location(DOOR_LOCATION[index][0], DOOR_LOCATION[index][1], 0);
            Location otherDoor = new Location(DOOR_LOCATION[index2][0], DOOR_LOCATION[index2][1], 0);
            int openDoorId = DOOR_OPEN_DIRECTION[index][0];
            int openDoorId2 = DOOR_OPEN_DIRECTION[index2][0];
            int openDirection = DOOR_OPEN_DIRECTION[index][2];
            int newX = openDirection == 1 ? x+1 : openDirection == 2 ? x : openDirection == 3 ? x-1 : openDirection == 4 ? x : x;
            int newY = openDirection == 1 ? y : openDirection == 2 ? y+1 : openDirection == 3 ? y : openDirection == 4 ? y-1 : y;
            int newX2 = openDirection == 1 ? DOOR_LOCATION[index2][0] + 1 : openDirection == 2 ? DOOR_LOCATION[index2][0] : openDirection == 3 ? DOOR_LOCATION[index2][0] - 1 : openDirection == 4 ? DOOR_LOCATION[index2][0] : DOOR_LOCATION[index2][0];
            int newY2 = openDirection == 1 ? DOOR_LOCATION[index2][1] : openDirection == 2 ? DOOR_LOCATION[index2][1] + 1 : openDirection == 3 ? DOOR_LOCATION[index2][1] : openDirection == 4 ? DOOR_LOCATION[index2][1] - 1 : DOOR_LOCATION[index2][1];
            int[] doorStandCoordinates = getDoorCoordinates(player, index, index2, betweenDoors);
            int[] walkDirections = getWalkDirections(player, index, index2, betweenDoors);
            player.setFaceLocation(clickedDoor);
            AreaEvent doorsWalkAreaEvent = new AreaEvent(player, doorStandCoordinates[0], doorStandCoordinates[1], doorStandCoordinates[2] + 1, doorStandCoordinates[3] + 1);
            doorsWalkAreaEvent.setAction(() => {
                player.setTemporaryAttribute("unmovable", true);

                Event forceWalkDoorEvent = new Event(800);
                forceWalkDoorEvent.setAction(() => {
                    player.getWalkingQueue().resetWalkingQueue();
                    foreach(Player p in Server.getPlayerList()) { //change door for all logged in players? uhh what?
                        p.getPackets().removeObject(clickedDoor, openDoorId == 6713 ? 4 : 3, 0);
                        p.getPackets().removeObject(otherDoor, openDoorId2 == 6732 ? 3 : 4, 0);
                        p.getPackets().createObject(openDoorId, new Location(newX, newY, 0), DOOR_OPEN_DIRECTION[index][1], 0);
                        p.getPackets().createObject(openDoorId2, new Location(newX2, newY2, 0), DOOR_OPEN_DIRECTION[index2][1], 0);
                    }
                    player.getWalkingQueue().forceWalk(walkDirections[0], walkDirections[1]);
                    forceWalkDoorEvent.stop();
                });
                Server.registerEvent(forceWalkDoorEvent);
                Event betweenDoorsEvent = new Event(betweenDoors ? 2200 : 1900);
                betweenDoorsEvent.setAction(() => {
                    int face = openDirection == 3 ? 0 : openDirection == 4 ? 3 : openDirection == 2 ? 1 : 2;
                    foreach(Player p in Server.getPlayerList()) {
                        p.getPackets().removeObject(new Location(newX, newY, 0), openDoorId == 6713 ? 4 : 3, 0);
                        p.getPackets().removeObject(new Location(newX2, newY2, 0), openDoorId2 == 6732 ? 3 : 4, 0);
                        p.getPackets().createObject(DOORS[index], clickedDoor, face, 0);
                        p.getPackets().createObject(DOORS[index2], otherDoor, face, 0);
                    }
                    player.removeTemporaryAttribute("unmovable");
                    if (!betweenDoors) {
                        player.getPackets().sendConfig(1270, 1);
                        player.setTemporaryAttribute("betweenDoors", true);
                    } else {
                        player.getPackets().sendConfig(1270, 0);
                        player.removeTemporaryAttribute("betweenDoors");
                    }
                    betweenDoorsEvent.stop();
                });
                Server.registerEvent(betweenDoorsEvent);
            });
            Server.registerCoordinateEvent(doorsWalkAreaEvent);
            return true;
        }
示例#6
0
        public void clickDesk(Player p, int x, int y, int option)
        {
            AreaEvent clickDeskAreaEvent = new AreaEvent(p, x - 1, y - 1, x + 1, y + 1);
            clickDeskAreaEvent.setAction(() =>
            {
                p.setFaceLocation(new Location(x, y, 0));
                switch (option)
                {
                    case 1:
                        break;

                    case 2:
                        p.getPackets().closeInterfaces();
                        p.setGESession(new GESession(p));
                        break;
                }
            });
            Server.registerCoordinateEvent(clickDeskAreaEvent);
        }
示例#7
0
 public static void talkToBob(Player p, Npc npc, int item, int option)
 {
     p.setEntityFocus(npc.getClientIndex());
     AreaEvent talkToBobAreaEvent = new AreaEvent(p, npc.getLocation().getX() - 1, npc.getLocation().getY() - 1, npc.getLocation().getX() + 1, npc.getLocation().getY() + 1);
     talkToBobAreaEvent.setAction(() => {
         npc.setFaceLocation(p.getLocation());
         p.setFaceLocation(npc.getLocation());
         p.setEntityFocus(65535);
         if (option == 0) { // use item on bob
             if (item > 0) {
                 p.setTemporaryAttribute("bobsAxesBarrowItem", item);
                 showBobDialogue(p, 101);
             }
         } else if (option == 1) { // talk
             showBobDialogue(p, 107);
         } else if (option == 2) { // trade
             p.setShopSession(new ShopSession(p, 4));
         }
     });
     Server.registerCoordinateEvent(talkToBobAreaEvent);
 }
示例#8
0
 public static void useLever(Player p, int id, Location leverLocation)
 {
     if (p.getTemporaryAttribute("teleporting") != null)
     {
         return;
     }
     foreach (LoadedLaddersAndStairs.Lever lever in LoadedLaddersAndStairs.levers)
     {
         if (lever.getId() == id)
         {
             if (lever.getLeverLocation().Equals(leverLocation))
             {
                 LoadedLaddersAndStairs.Lever l = lever;
                 //TODO when in use it cant be used (in use = lever is facing down)
                 CoordinateEvent useLeverCoordinateEvent = new CoordinateEvent(p, l.getLeverLocation());
                 useLeverCoordinateEvent.setAction(() =>
                 {
                     p.setFaceLocation(l.getFaceLocation());
                     if (p.getTemporaryAttribute("teleblocked") != null)
                     {
                         p.getPackets().sendMessage("A magical force prevents you from teleporting!");
                         return;
                     }
                     else if ((p.getTemporaryAttribute("teleporting") != null))
                     {
                         return;
                     }
                     p.setLastAnimation(new Animation(2140));
                     p.getPackets().closeInterfaces();
                     p.setTemporaryAttribute("teleporting", true);
                     p.getWalkingQueue().resetWalkingQueue();
                     p.getPackets().clearMapFlag();
                     SkillHandler.resetAllSkills(p);
                     l.setInUse(true);
                     Event useLeverEvent = new Event(700);
                     useLeverEvent.setAction(() =>
                     {
                         useLeverEvent.stop();
                         p.setLastAnimation(new Animation(8939, 0));
                         p.setLastGraphics(new Graphics(1576, 0));
                         l.setInUse(false);
                         Event setLeverTeleportEvent = new Event(1800);
                         setLeverTeleportEvent.setAction(() =>
                         {
                             setLeverTeleportEvent.stop();
                             p.teleport(l.getTeleLocation());
                             p.setLastAnimation(new Animation(8941, 0));
                             p.setLastGraphics(new Graphics(1577, 0));
                             Teleport.resetTeleport(p);
                         });
                         Server.registerEvent(setLeverTeleportEvent);
                     });
                     Server.registerEvent(useLeverEvent);
                 });
                 Server.registerCoordinateEvent(useLeverCoordinateEvent);
                 break;
             }
         }
     }
 }
示例#9
0
 public static void teleport(Player p, LoadedLaddersAndStairs.HeightObject obj)
 {
     p.getWalkingQueue().resetWalkingQueue();
     p.setTemporaryAttribute("unmovable", true);
     p.setFaceLocation(obj.getLocation());
     if (obj.getAnimation() != -1)
     {
         p.setLastAnimation(new Animation(obj.getAnimation()));
     }
     Event teleportEvent = new Event(obj.getAnimation() != -1 ? obj.getTeleDelay() : 500);
     teleportEvent.setAction(() =>
     {
         teleportEvent.stop();
         p.teleport(obj.getTeleLocation());
         p.removeTemporaryAttribute("unmovable");
     });
     Server.registerEvent(teleportEvent);
 }