From 2d8ae82086be2477b698f3dfb5d168495ce405d9 Mon Sep 17 00:00:00 2001 From: Danial Date: Tue, 5 Oct 2021 16:01:16 +1300 Subject: [PATCH] Telekinetic grab and stuff (#508) * tidy up * Tidy up check for space * Telekinetic base * Don't allow player to pickup statue * Tidy up item pickup * fixup, statue spawn * Update telekinetic grab * 2nd option for guardian statue * handle telegrab on statue * Allow picking up global drops with telekinetic grab * Check if player can see/reach item * Update PickupItem.java * Allow pasting into chatbox * camera stuff * fixup clipboard stuff * Update PlayerAssistant.java * Update Commands.java * Add mazes initial * Tidy up the clipboard pasting * Update mazes * Calculate new position of statue * fixup telegrab * More tidy up, remove constant running of container * more tidy up.. * Handle moving statues * remove the statue from global drops * Update MagicOnFloorItems.java * Show telekinetic interface * Make public accessable * Only show items to player that are on the same height level * Moving statues around, Spawning * Reward exp, points, law runes * Show points, mazes completed * Add comment * Add observable statue (still needs work) * Fixup where camera focuses * Load items when player changes level * Graveyard base * Add a couple more checks * Update Player.java * Update Commands.java * Make sure statue is visible when player appears at maze * [Mage training arena] Graveyard * Update MageTrainingArena.java * Update MageTrainingArena.java * Update ItemHandler.java --- 2006Scape Client/src/main/java/Game.java | 46 ++- .../game/content/combat/magic/MagicData.java | 4 +- .../combat/magic/MagicRequirements.java | 23 +- .../minigames/magetrainingarena/Alchemy.java | 2 +- .../magetrainingarena/Enchanting.java | 2 +- .../magetrainingarena/Graveyard.java | 129 +++++++++ .../magetrainingarena/MageTrainingArena.java | 14 +- .../magetrainingarena/Telekinetic.java | 271 ++++++++++++++++++ .../java/com/rs2/game/items/GroundItem.java | 7 +- .../com/rs2/game/objects/ObjectsActions.java | 15 +- .../java/com/rs2/game/players/Player.java | 17 +- .../com/rs2/game/players/PlayerAssistant.java | 27 +- .../com/rs2/game/players/PlayerHandler.java | 1 + .../java/com/rs2/game/players/PlayerSave.java | 5 + .../rs2/net/packets/impl/ClickingButtons.java | 31 +- .../com/rs2/net/packets/impl/Commands.java | 19 +- .../packets/impl/ItemClick2OnGroundItem.java | 5 + .../net/packets/impl/MagicOnFloorItems.java | 138 ++++----- .../com/rs2/net/packets/impl/PickupItem.java | 76 ++--- .../src/main/java/com/rs2/world/Boundary.java | 17 +- .../com/rs2/world/GlobalDropsHandler.java | 14 +- .../main/java/com/rs2/world/ItemHandler.java | 49 ++-- 22 files changed, 719 insertions(+), 193 deletions(-) create mode 100644 2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Graveyard.java create mode 100644 2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Telekinetic.java diff --git a/2006Scape Client/src/main/java/Game.java b/2006Scape Client/src/main/java/Game.java index af9bb878..5d177779 100644 --- a/2006Scape Client/src/main/java/Game.java +++ b/2006Scape Client/src/main/java/Game.java @@ -6,6 +6,7 @@ import javax.swing.*; import java.applet.AppletContext; import java.awt.*; +import java.awt.datatransfer.*; import java.awt.event.KeyEvent; import java.awt.event.MouseWheelEvent; import java.io.ByteArrayInputStream; @@ -9177,12 +9178,14 @@ public class Game extends RSApplet { } public int method121() { - int j = method42(plane, yCameraPos, xCameraPos); - if (j - zCameraPos < 800 && (byteGroundArray[plane][xCameraPos >> 7][yCameraPos >> 7] & 4) != 0) { - return plane; - } else { - return 3; - } + // Hide other planes when using fixed camera + return plane; + // int j = method42(plane, yCameraPos, xCameraPos); + // if (j - zCameraPos < 800 && (byteGroundArray[plane][xCameraPos >> 7][yCameraPos >> 7] & 4) != 0) { + // return plane; + // } else { + // return 3; + // } } public void delIgnore(long l) { @@ -12599,6 +12602,14 @@ public class Game extends RSApplet { if (zoom < (WorldController.drawDistance / 3)) zoom++; break; + case KeyEvent.VK_V: + if (keyevent.isControlDown()) { + inputString += getClipBoard(); + if (inputString.length() > 80) { + inputString = inputString.substring(0, 80); + } + inputTaken = true; + } } } @@ -12782,4 +12793,27 @@ public class Game extends RSApplet { } } } + + public String getClipBoard(){ + String myString = ""; + try { + myString = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); + } catch (HeadlessException e) { + e.printStackTrace(); + } catch (UnsupportedFlavorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + String output = ""; + for(int i = 0; i < myString.length(); i++) { + int j = (int) myString.charAt(i); + if (j >= 32 && j <= 122) { + output += (char) j; + } + } + + return output; + } } diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicData.java b/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicData.java index ee76932d..2581de3a 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicData.java +++ b/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicData.java @@ -149,7 +149,9 @@ public class MagicData { // alch { -1, 55, 713, 113, 0, 0, 0, 20, 554, 5, 561, 1, 0, 0, 0, 0, 0 }, // high // alch - { -1, 33, 728, 142, 143, 144, 0, 35, 556, 1, 563, 1, 0, 0, 0, 0, 0 } // telegrab + { -1, 33, 728, 142, 143, 144, 0, 35, 556, 1, 563, 1, 0, 0, 0, 0, 0 }, // telegrab + { -1, 15, 722, 141, 0, 0, 0, 25, 561, 1, 557, 2, 555, 2, 0, 0, 0, 0 }, // bones to bananas + { -1, 60, 722, 311, 0, 0, 0, 35, 561, 2, 557, 4, 555, 4, 0, 0, 0, 0 } // bones to peaches }; diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicRequirements.java b/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicRequirements.java index 854be403..1e2d5c73 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicRequirements.java +++ b/2006Scape Server/src/main/java/com/rs2/game/content/combat/magic/MagicRequirements.java @@ -40,7 +40,7 @@ public class MagicRequirements { public static boolean checkMagicReqs(Player c, int spell, boolean runesRequired) { int[] spellData = MagicData.MAGIC_SPELLS[spell]; - if (c.usingMagic && runesRequired) { // check for runes + if (runesRequired) { // check for runes if ( !c.getItemAssistant().playerHasItem(spellData[8], spellData[9]) && !wearingStaff(c, spellData[8]) || !c.getItemAssistant().playerHasItem(spellData[10], spellData[11]) && !wearingStaff(c, spellData[10]) @@ -52,7 +52,7 @@ public class MagicRequirements { } } - if (c.usingMagic && c.playerIndex > 0) { + if (c.playerIndex > 0) { if (PlayerHandler.players[c.playerIndex] != null) { for (int r = 0; r < c.REDUCE_SPELLS.length; r++) { // reducing // spells, @@ -81,7 +81,7 @@ public class MagicRequirements { } int staffRequired = getStaffNeeded(c); - if (c.usingMagic && staffRequired > 0 && runesRequired) { // staff + if (staffRequired > 0 && runesRequired) { // staff // required if (c.playerEquipment[c.playerWeapon] != staffRequired) { c.getPacketSender() @@ -94,16 +94,15 @@ public class MagicRequirements { } } - if (c.usingMagic) { // check magic level - if (c.playerLevel[GameConstants.MAGIC] < MagicData.MAGIC_SPELLS[spell][1]) { - c.getPacketSender().sendMessage( - "You need to have a magic level of " - + MagicData.MAGIC_SPELLS[spell][1] - + " to cast this spell."); - return false; - } + // check magic level + if (c.playerLevel[GameConstants.MAGIC] < MagicData.MAGIC_SPELLS[spell][1]) { + c.getPacketSender().sendMessage( + "You need to have a magic level of " + + MagicData.MAGIC_SPELLS[spell][1] + + " to cast this spell."); + return false; } - if (c.usingMagic && runesRequired) { + if (runesRequired) { if (MagicData.MAGIC_SPELLS[spell][8] > 0) { // deleting runes if (!wearingStaff(c, MagicData.MAGIC_SPELLS[spell][8])) { c.getItemAssistant().deleteItem( diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Alchemy.java b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Alchemy.java index 2054ac73..626bc1ad 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Alchemy.java +++ b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Alchemy.java @@ -13,7 +13,7 @@ import com.rs2.world.Boundary; public class Alchemy { - private final Player player; + private Player player; public Alchemy(Player c) { this.player = c; diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Enchanting.java b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Enchanting.java index 69d2f321..4950fc79 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Enchanting.java +++ b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Enchanting.java @@ -14,7 +14,7 @@ import com.rs2.world.Boundary; public class Enchanting { // TODO: Add dragonstone drops occasionally, double points when enchanted - private final Player player; + private Player player; private int itemsEnchanted = 0; private int orbsDeposited = 0; diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Graveyard.java b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Graveyard.java new file mode 100644 index 00000000..05a005e3 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Graveyard.java @@ -0,0 +1,129 @@ +package com.rs2.game.content.minigames.magetrainingarena; + +import java.util.Random; + +import com.rs2.GameConstants; +import com.rs2.game.content.combat.magic.MagicData; +import com.rs2.game.content.combat.magic.MagicRequirements; +import com.rs2.game.content.music.sound.SoundList; +import com.rs2.game.npcs.NpcHandler; +import com.rs2.game.players.Player; +import com.rs2.game.players.PlayerHandler; +import com.rs2.world.Boundary; + +public class Graveyard { + + private Player player; + private int bonesCollected = 0; + private int fruitDeposited = 0; + + public Graveyard(Player c) { + this.player = c; + } + + public void searchBonePile(int objectID) { + int index = (int) Math.floor(bonesCollected / 4); + if (player.getItemAssistant().freeSlots(items[index], 1) <= 0) { + player.getPacketSender().sendMessage("You don't have enough space in your inventory."); + return; + } + player.getItemAssistant().addItem(items[index], 1); + bonesCollected = (bonesCollected + 1) % (items.length * 4); + } + + public void bonesToFood(int spellID) { + if (!player.getCombatAssistant().checkMagicReqs(spellID)) { + return; + } + player.boneDelay = System.currentTimeMillis(); + player.startAnimation(MagicData.MAGIC_SPELLS[spellID][2]); + player.gfx100(MagicData.MAGIC_SPELLS[spellID][3]); + player.getPlayerAssistant().addSkillXP(MagicData.MAGIC_SPELLS[spellID][7], GameConstants.MAGIC); + player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); + player.getPacketSender().sendShowTab(6); + player.getPacketSender().sendSound(SoundList.BONES_TO_BANNAS, 100, 0); + int amount = 0; + for (int i = 0; i < items.length; i++) { + amount = player.getItemAssistant().getItemAmount(items[i]); + if (amount > 0) { + player.getItemAssistant().deleteItem(items[i], amount); + player.getItemAssistant().addItem(spellID == 52 ? 1963 : 6883, amount * values[i]); + } + } + } + + public void depositFood() { + int amount = player.getItemAssistant().getItemAmount(1963); + amount += player.getItemAssistant().getItemAmount(6883); + // remove all peaches and bananas + player.getItemAssistant().deleteItem(1963, Integer.MAX_VALUE); + player.getItemAssistant().deleteItem(6883, Integer.MAX_VALUE); + fruitDeposited += amount; + while (fruitDeposited >= 16) { + int reward = random.nextInt(rewards.length); + player.getItemAssistant().addOrDropItem(rewards[reward], 1); + player.graveyardPoints++; + fruitDeposited -= 16; + } + } + + public void clearItems() { + for (int item: items) { + player.getItemAssistant().deleteItem(item, Integer.MAX_VALUE); + } + player.getItemAssistant().deleteItem(1963, Integer.MAX_VALUE); + player.getItemAssistant().deleteItem(6883, Integer.MAX_VALUE); + } + + /* ITEMS */ + // 6904 - Animal Bones + // 6905 - Animal Bones + // 6906 - Animal Bones + // 6907 - Animal Bones + public static int[] items = {6904, 6905, 6906, 6907}; + public static int[] values = {1, 2, 3, 4}; + public static int[] rewards = {555, 557, 561, 560, 565}; + + public static int ticks = 0; + private static Random random = new Random(); + + /* OBJECTS */ + // 10735 - Food Chute + + /* INTERFACES */ + // 15931 - Main interface + + public static void process() { + for (Player p : PlayerHandler.players) { + if (p == null) { + continue; + } + updateInterface(p); + } + // Every 12 ticks deal 2 damage to player (50% chance) + if (++ticks % 12 == 0) { + for (Player p : PlayerHandler.players) { + if (p == null) { + continue; + } + if (!Boundary.isIn(p, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD)) { + return; + } + // TODO: Find falling bones animation/gfx ID + if (random.nextInt(1) == 0) { + p.dealDamage(2); + p.handleHitMask(2); + } + updateInterface(p); + } + } + } + + public static void updateInterface(Player player) { + if (!Boundary.isIn(player, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD)) { + return; + } + player.getPacketSender().sendString("" + player.graveyardPoints, 15935); + player.getPacketSender().walkableInterface(15931); + } +} diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/MageTrainingArena.java b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/MageTrainingArena.java index fd10e020..cbb12202 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/MageTrainingArena.java +++ b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/MageTrainingArena.java @@ -15,16 +15,22 @@ public class MageTrainingArena { public static void process() { Alchemy.process(); Enchanting.process(); + Telekinetic.process(); + Graveyard.process(); } - private final Player player; - public final Enchanting enchanting; - public final Alchemy alchemy; + private Player player; + public Enchanting enchanting; + public Alchemy alchemy; + public Telekinetic telekinetic; + public Graveyard graveyard; public MageTrainingArena(Player c) { this.player = c; this.enchanting = new Enchanting(c); this.alchemy = new Alchemy(c); + this.telekinetic = new Telekinetic(c); + this.graveyard = new Graveyard(c); } private final int[] shopItems = { @@ -277,6 +283,8 @@ public class MageTrainingArena { } else { player.getItemAssistant().addItem(itemId, 1); } + // Update point amounts + openShop(); } public void enchantItem(int itemID, int spellID) { diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Telekinetic.java b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Telekinetic.java new file mode 100644 index 00000000..9f6a589a --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/game/content/minigames/magetrainingarena/Telekinetic.java @@ -0,0 +1,271 @@ +package com.rs2.game.content.minigames.magetrainingarena; + +import java.awt.Point; +import java.util.Random; + +import com.rs2.GameConstants; +import com.rs2.GameEngine; +import com.rs2.event.CycleEvent; +import com.rs2.event.CycleEventContainer; +import com.rs2.event.CycleEventHandler; +import com.rs2.game.content.combat.magic.MagicData; +import com.rs2.game.items.GroundItem; +import com.rs2.game.players.Player; +import com.rs2.game.players.PlayerHandler; +import com.rs2.world.Boundary; +import com.rs2.world.clip.Region; + +public class Telekinetic { + + public static enum Maze { + MAZE_0(3338, 9705, 0, + 3343, 9705, + 3347, 9714), + MAZE_1(3366, 9711, 0, + 3375, 9715, + 3367, 9720), + MAZE_2(3338, 9675, 0, + 3343, 9680, + 3342, 9684), + MAZE_3(3369, 9673, 0, + 3373, 9678, + 3375, 9682), + MAZE_4(3374, 9713, 1, + 3374, 9713, + 3383, 9713), + MAZE_5(3341, 9708, 1, + 3350, 9717, + 3341, 9708), + MAZE_6(3346, 9680, 1, + 3351, 9684, + 3353, 9680), + MAZE_7(3376, 9677, 1, + 3376, 9686, + 3385, 9686), + MAZE_8(3339, 9674, 2, + 3348, 9674, + 3339, 9683), + MAZE_9(3343, 9709, 2, + 3346, 9718, + 3345, 9718); + + public int minX, maxX, minY, maxY, height, startX, startY, endX, endY; + public Boundary mazeArea, mazeUp, mazeRight, mazeDown, mazeLeft; + public GroundItem statue; + public boolean initialized = false; + + private Maze(int minX, int minY, int height, int startX, int startY, int endX, int endY) { + this.minX = minX; + this.maxX = minX + 9; + this.minY = minY; + this.maxY = minY + 9; + this.height = height; + this.startX = startX; + this.startY = startY; + this.endX = endX; + this.endY = endY; + this.mazeArea = new Boundary(minX, maxX, minY, maxY, height); + this.mazeUp = new Boundary(minX, maxX, maxY + 1, maxY + 2, height); + this.mazeRight = new Boundary(maxX + 1, maxX + 2, minY, maxY, height); + this.mazeDown = new Boundary(minX, maxX, minY - 2, minY - 1, height); + this.mazeLeft = new Boundary(minX - 2, minX - 1, minY, maxY, height); + this.statue = new GroundItem(6888, startX, startY, height, 1, -1, 0, ""); + } + + public static Maze getMaze(int x, int y, int h) { + for (Maze maze : values()){ + if (Boundary.isIn(x, y, h, maze.mazeArea)) { + return maze; + } + } + return null; + } + + public Point calcDirection(Player player) { + if (Boundary.isIn(player, mazeUp)) { + return new Point(0, 1); + } + if (Boundary.isIn(player, mazeRight)) { + return new Point(1, 0); + } + if (Boundary.isIn(player, mazeDown)) { + return new Point(0, -1); + } + if (Boundary.isIn(player, mazeLeft)) { + return new Point(-1, 0); + } + return new Point(0, 0); + } + + public Point getNewPos(int curX, int curY, int dirX, int dirY) { + if (dirX != 0) { + while(curX >= minX && curX <= maxX && Region.getClipping(curX + dirX, curY, this.height, dirX, dirY)) { + curX += dirX; + } + } + if (dirY != 0) { + while(curY >= minY && curY <= maxY && Region.getClipping(curX, curY + dirY, this.height, dirX, dirY)) { + curY += dirY; + } + } + return new Point(curX, curY); + } + } + + private Player player; + private Random random = new Random(); + private boolean observingStatue = false; + + public Telekinetic(Player c) { + this.player = c; + } + + public void moveStatue(int itemX, int itemY) { + // Play animation, Award XP + player.walkingToItem = true; + int offY = (player.getX() - itemX) * -1; + int offX = (player.getY() - itemY) * -1; + player.teleGrabX = itemX; + player.teleGrabY = itemY; + player.turnPlayerTo(itemX, itemY); + player.teleGrabDelay = System.currentTimeMillis(); + player.startAnimation(MagicData.MAGIC_SPELLS[51][2]); + player.gfx100(MagicData.MAGIC_SPELLS[51][3]); + player.getPlayerAssistant().createPlayersStillGfx(144, itemX, itemY, 0, 72); + player.getPlayerAssistant().createPlayersProjectile(player.getX(), player.getY(), offX, offY, 50, 70, MagicData.MAGIC_SPELLS[51][4], 50, 10, 0, 50); + player.getPlayerAssistant().addSkillXP(MagicData.MAGIC_SPELLS[51][7], GameConstants.MAGIC); + player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); + player.stopMovement(); + + Maze maze = Maze.getMaze(itemX, itemY, player.heightLevel); + if (maze == null) { + return; + } + + Point direction = maze.calcDirection(player); + Point newPosition = maze.getNewPos(itemX, itemY, direction.x, direction.y); + + CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { + @Override + public void execute(CycleEventContainer container) { + if (!player.walkingToItem) { + container.stop(); + } else if (System.currentTimeMillis() - player.teleGrabDelay > 1550) { + if (GameEngine.itemHandler.itemExists(6888, itemX, itemY)) { + GameEngine.itemHandler.moveItem(maze.statue, newPosition.x, newPosition.y); + + if (newPosition.x == maze.endX && newPosition.y == maze.endY) { + player.telekineticPoints += 2; + player.telekineticMazesSolved++; + + // Every 5 solves, give the player 8 extra points, 10 law runes, 1000 magic experience + if (player.telekineticMazesSolved % 5 == 0) { + player.telekineticPoints += 8; + player.getItemAssistant().addOrDropItem(563, 10); + player.getPlayerAssistant().addSkillXP(1000, GameConstants.MAGIC); + player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); + } + + resetStatue(newPosition.x, newPosition.y); + + if (observingStatue) { + observingStatue = false; + player.getPlayerAssistant().sendCameraReset(); + } + goToMaze(); + } + } + stop(); + } + } + + @Override + public void stop() { + player.usingMagic = false; + player.walkingToItem = false; + } + }, 1); + } + + public void goToMaze() { + int r = random.nextInt(Maze.values().length); + Maze maze = Maze.values()[r]; + player.getPlayerAssistant().startTeleport2(maze.minX - 1, maze.minY - 1, maze.height); + + CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { + @Override + public void execute(CycleEventContainer container) { + GameEngine.itemHandler.reloadItems(player); + container.stop(); + } + + @Override + public void stop() {} + }, 8); + } + + public void observeStatue(int itemX, int itemY) { + Maze maze = Maze.getMaze(itemX, itemY, player.heightLevel); + if (maze == null) { + return; + } + if (!observingStatue) { + observingStatue = true; + player.getPlayerAssistant().sendCameraCutscene((maze.minX + 5) - 8 * player.getMapRegionX(), (maze.minY - 1) - 8 * player.getMapRegionY(), 10, 25, 0); + player.getPlayerAssistant().sendCameraCutscene2((maze.minX + 5) - 8 * player.getMapRegionX(), (maze.minY + 5) - 8 * player.getMapRegionY() - 8, 2400, 25, 0); + player.getPacketSender().sendMessage("You overlook the maze.."); + player.getPacketSender().sendMessage("Click the statue again to leave this view."); + } else { + observingStatue = false; + player.getPlayerAssistant().sendCameraReset(); + } + // TODO: Figure out how to get this working correctly + // not sure exactly where the camera is supposed to be facing etc + } + + public void resetStatue(int itemX, int itemY) { + Maze maze = Maze.getMaze(itemX, itemY, player.heightLevel); + if (maze == null) { + return; + } + + // reset statue to start position + GameEngine.itemHandler.moveItem(maze.statue, maze.startX, maze.startY); + } + + /* ITEMS */ + // 6888 - Guardian Statue + + /* OBJECTS */ + + /* INTERFACES */ + // 15962 - Main interface + // 15966 - Pizazz points + // 15968 - Mazes solved + + public static int ticks = 0; + + public static void process() { + for (Maze maze: Maze.values()) { + if (!maze.initialized) { + maze.initialized = true; + GameEngine.itemHandler.createGlobalItem(maze.statue); + } + } + for (Player p : PlayerHandler.players) { + if (p == null) { + continue; + } + updateInterface(p); + } + } + + + public static void updateInterface(Player player) { + if (!Boundary.isIn(player, Boundary.MAGE_TRAINING_ARENA_TELEKINETIC)) { + return; + } + player.getPacketSender().sendString("" + player.telekineticPoints, 15966); + player.getPacketSender().sendString("" + player.telekineticMazesSolved, 15968); + } +} diff --git a/2006Scape Server/src/main/java/com/rs2/game/items/GroundItem.java b/2006Scape Server/src/main/java/com/rs2/game/items/GroundItem.java index de64375f..95f9d67e 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/items/GroundItem.java +++ b/2006Scape Server/src/main/java/com/rs2/game/items/GroundItem.java @@ -2,7 +2,7 @@ package com.rs2.game.items; public class GroundItem { - public int itemId, itemX, itemY, itemAmount, itemController, hideTicks, removeTicks; + public int itemId, itemX, itemY, itemH, itemAmount, itemController, hideTicks, removeTicks; public String ownerName; @@ -11,6 +11,7 @@ public class GroundItem { itemId = id; itemX = x; itemY = y; + itemH = h; itemAmount = amount; itemController = controller; this.hideTicks = hideTicks; @@ -29,6 +30,10 @@ public class GroundItem { return itemY; } + public int getItemH() { + return itemH; + } + public int getItemAmount() { return itemAmount; } diff --git a/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java b/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java index e3fb2609..b3f0b182 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java +++ b/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java @@ -2636,9 +2636,18 @@ public class ObjectsActions { else if (player.absY == 3300) player.getPlayerAssistant().movePlayer(player.absX, player.absY - 2, 0); break; + case 10725: // Bone Pile + case 10726: // Bone Pile + case 10727: // Bone Pile + case 10728: // Bone Pile + player.getMageTrainingArena().graveyard.searchBonePile(objectType); + break; case 10734: // Coin Collector player.getMageTrainingArena().alchemy.collectCoins(); break; + case 10735: // Food Chute + player.getMageTrainingArena().graveyard.depositFood(); + break; case 10771: player.getPlayerAssistant().movePlayer(3369, 3307, 1); break; @@ -2653,8 +2662,7 @@ public class ObjectsActions { break; case 10778: // TODO: Require Pizazz progress hat equiped - player.getDialogueHandler().sendStatement("This area is currently closed."); - // player.getPlayerAssistant().startTeleport2(3336, 9718, 0); // Telekinetic floor 0 + player.getMageTrainingArena().telekinetic.goToMaze(); break; case 10779: // TODO: Require Pizazz progress hat equiped @@ -2670,8 +2678,7 @@ public class ObjectsActions { break; case 10781: // TODO: Require Pizazz progress hat equiped - player.getDialogueHandler().sendStatement("This area is currently closed."); - // player.getPlayerAssistant().startTeleport2(3364, 9639, 1); // Graveyard training + player.getPlayerAssistant().startTeleport2(3364, 9639, 1); // Graveyard training break; case 10782: // Leave mage training rooms player.getPlayerAssistant().startTeleport2(3363, 3318, 0); diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/Player.java b/2006Scape Server/src/main/java/com/rs2/game/players/Player.java index f23d419f..f584f640 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/Player.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/Player.java @@ -824,6 +824,10 @@ public abstract class Player { getPacketSender().walkableInterface(15892); } else if (Boundary.isIn(this, Boundary.MAGE_TRAINING_ARENA_ENCHANTING)) { getPacketSender().walkableInterface(15917); + } else if (Boundary.isIn(this, Boundary.MAGE_TRAINING_ARENA_TELEKINETIC)) { + getPacketSender().walkableInterface(15962); + } else if (Boundary.isIn(this, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD)) { + getPacketSender().walkableInterface(15931); } else { getPacketSender().sendMapState(0); if (!isSnowy) { @@ -1642,7 +1646,7 @@ public abstract class Player { crystalBowArrowCount, playerMagicBook, teleGfx, teleEndAnimation, teleHeight, teleX, teleY, rangeItemUsed, killingNpcIndex, totalDamageDealt, globalDamageDealt, oldNpcIndex, fightMode, attackTimer, - bowSpecShot, ectofuntusWorshipped, graveyardPoints, alchemyPoints, enchantmentPoints, telekineticPoints; + bowSpecShot, ectofuntusWorshipped, graveyardPoints, alchemyPoints, enchantmentPoints, telekineticPoints, telekineticMazesSolved; public boolean magicFailed, oldMagicFailed; /** * End @@ -2160,14 +2164,21 @@ public abstract class Player { getMageTrainingArena().alchemy.clearItems(); } if (Boundary.isIn(this, Boundary.MAGE_TRAINING_ARENA_ENCHANTING) && !Boundary.isIn(teleportToX, teleportToY, teleHeight, Boundary.MAGE_TRAINING_ARENA_ENCHANTING)) { - // remove any alchemy training items + // remove any enchanting training items getMageTrainingArena().enchanting.clearItems(); } + if (Boundary.isIn(this, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD) && !Boundary.isIn(teleportToX, teleportToY, teleHeight, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD)) { + // remove any enchanting training items + getMageTrainingArena().graveyard.clearItems(); + } currentX = teleportToX - 8 * mapRegionX; currentY = teleportToY - 8 * mapRegionY; absX = teleportToX; absY = teleportToY; - heightLevel = teleHeight >= 0 ? teleHeight : heightLevel >= 0 ? heightLevel : 0; + int newHeight = teleHeight >= 0 ? teleHeight : heightLevel >= 0 ? heightLevel : 0; + if (heightLevel != newHeight) + GameEngine.itemHandler.reloadItems(this); + heightLevel = newHeight; resetWalkingQueue(); teleportToX = teleportToY = teleHeight = -1; diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java index 61344e7d..1875467c 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java @@ -769,6 +769,9 @@ public class PlayerAssistant { player.npcIndex = 0; player.playerIndex = 0; player.faceUpdate(0); + if (player.heightLevel != height) { + player.refresh = true; + } player.teleHeight = height; player.startAnimation(714); player.teleTimer = 11; @@ -833,6 +836,9 @@ public class PlayerAssistant { player.npcIndex = 0; player.playerIndex = 0; player.faceUpdate(0); + if (player.heightLevel != height) { + player.refresh = true; + } player.teleHeight = height; player.startAnimation(714); player.teleTimer = 11; @@ -2302,8 +2308,25 @@ public class PlayerAssistant { */ public void sendCameraCutscene(int x, int y, int height, int speed, int angle) { player.getOutStream().createFrame(177); - player.getOutStream().writeByte(x / 64); // - player.getOutStream().writeByte(y / 64); // + player.getOutStream().writeByte(x); // divided by 64 apparently allows real world coords + player.getOutStream().writeByte(y); // divided by 64 apparently allows real world coords + player.getOutStream().writeWord(height); // + player.getOutStream().writeByte(speed); // + player.getOutStream().writeByte(angle); + } + + /** + * anchors the camera to a specific view (for cutscenes) + * @param x The X Coordinate (Within the player's loaded area) + * @param y The Y Coordinate (Within the player's loaded area) + * @param height The Height of Camera (not relative to the game world height) + * @param speed The Camera Speed (Speed at which the camera turns to where it should point?) + * @param angle The Camera Angle + */ + public void sendCameraCutscene2(int x, int y, int height, int speed, int angle) { + player.getOutStream().createFrame(166); + player.getOutStream().writeByte(x); // + player.getOutStream().writeByte(y); // player.getOutStream().writeWord(height); // player.getOutStream().writeByte(speed); // player.getOutStream().writeByte(angle); diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerHandler.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerHandler.java index 04563c6d..d9bc69d3 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerHandler.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerHandler.java @@ -399,6 +399,7 @@ public class PlayerHandler { if (plr.refresh) { GlobalDropsHandler.reset((Client)plr); + GameEngine.itemHandler.reloadItems(plr); plr.refresh = false; } } diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java index 6fdbccd9..96a38cc0 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerSave.java @@ -425,6 +425,9 @@ public class PlayerSave { case "telekinetic-points": player.telekineticPoints = Integer.parseInt(token2); break; + case "telekinetic-mazes-solved": + player.telekineticMazesSolved = Integer.parseInt(token2); + break; case "unlocked-bones-to-peaches": player.unlockedBonesToPeaches = Boolean.parseBoolean(token2); break; @@ -806,6 +809,8 @@ public class PlayerSave { characterfile.newLine(); characterfile.write("telekinetic-points = " + player.telekineticPoints); characterfile.newLine(); + characterfile.write("telekinetic-mazes-solved = " + player.telekineticMazesSolved); + characterfile.newLine(); characterfile.write("unlocked-bones-to-peaches = " + player.unlockedBonesToPeaches); characterfile.newLine(); String voidStatus = ""; diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java index c31c2ca7..2251778c 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java @@ -35,6 +35,7 @@ import com.rs2.game.players.Player; import com.rs2.game.players.PlayerHandler; import com.rs2.net.packets.PacketType; import com.rs2.util.Misc; +import com.rs2.world.Boundary; /** * Clicking most buttons @@ -121,6 +122,9 @@ public class ClickingButtons implements PacketType { case 4135: + if (System.currentTimeMillis() - player.boneDelay < 2000) { + return; + } if (player.inTrade) { player.getPacketSender().sendMessage( "You can't do this in trade!"); @@ -133,9 +137,12 @@ public class ClickingButtons implements PacketType { player.getPacketSender().sendChatInterface(356); return; } + if (Boundary.isIn(player, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD)) { + player.getMageTrainingArena().graveyard.bonesToFood(52); + return; + } if (!player.getItemAssistant().playerHasItem(526, 1)) { - player.getPacketSender().sendMessage( - "You don't have any bones!"); + player.getPacketSender().sendMessage("You don't have any bones!"); return; } if (!player.getItemAssistant().playerHasItem(561, 1) @@ -149,22 +156,23 @@ public class ClickingButtons implements PacketType { player.getItemAssistant().deleteItem(561, 1); player.getItemAssistant().deleteItem(557, 2); player.getItemAssistant().deleteItem(555, 2); - player.getPlayerAssistant().addSkillXP(40, 6); + player.getPlayerAssistant().addSkillXP(25, 6); player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); player.startAnimation(722); player.gfx100(141); player.getPacketSender().sendShowTab(6); - player.getPacketSender().sendSound( - SoundList.BONES_TO_BANNAS, 100, 0); + player.getPacketSender().sendSound(SoundList.BONES_TO_BANNAS, 100, 0); player.boneDelay = System.currentTimeMillis(); do { - player.getItemAssistant().deleteItem(526, 1); - player.getItemAssistant().addItem(1963, 1); + player.getItemAssistant().replaceItem(526, 1963); } while (player.getItemAssistant().playerHasItem(526, 1)); } break; case 62005: + if (System.currentTimeMillis() - player.boneDelay < 2000) { + return; + } if (player.inTrade) { player.getPacketSender().sendMessage( "You can't do this in trade!"); @@ -180,6 +188,10 @@ public class ClickingButtons implements PacketType { player.getPacketSender().sendChatInterface(356); return; } + if (Boundary.isIn(player, Boundary.MAGE_TRAINING_ARENA_GRAVEYARD)) { + player.getMageTrainingArena().graveyard.bonesToFood(53); + return; + } if (!player.getItemAssistant().playerHasItem(526, 1)) { player.getPacketSender().sendMessage("You don't have any bones!"); return; @@ -197,15 +209,14 @@ public class ClickingButtons implements PacketType { player.getItemAssistant().deleteItem(561, 2); player.getItemAssistant().deleteItem(557, 4); player.getItemAssistant().deleteItem(555, 4); - player.getPlayerAssistant().addSkillXP(40, 6); + player.getPlayerAssistant().addSkillXP(35.5, 6); player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); player.startAnimation(722); player.gfx100(311); player.getPacketSender().sendShowTab(6); player.boneDelay = System.currentTimeMillis(); do { - player.getItemAssistant().deleteItem(526, 1); - player.getItemAssistant().addItem(6883, 1); + player.getItemAssistant().replaceItem(526, 6883); } while (player.getItemAssistant().playerHasItem(526, 1)); } break; diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index df88b7e8..e8253136 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -118,6 +118,7 @@ public class Commands implements PacketType { case "pos": case "loc": player.getPacketSender().sendMessage("Your coords are [" + player.absX + ", " + player.absY + ", " + player.heightLevel + "]"); + player.getPacketSender().sendMessage("local coord are [" + player.getLocalX() + ", " + player.getLocalY() + "]"); break; case "energy": player.getPacketSender().sendMessage(String.format("Run energy: %d", (int) player.playerEnergy)); @@ -685,16 +686,16 @@ public class Commands implements PacketType { player.getPlayerAssistant().movePlayer(Integer.parseInt(arguments[0]), Integer.parseInt(arguments[1]), Integer.parseInt(arguments[2])); break; case "up": + player.getPacketSender().sendMessage("You are now on height level " + (player.heightLevel + 1) + "."); player.getPlayerAssistant().movePlayer(player.absX, player.absY, player.heightLevel + 1); - player.getPacketSender().sendMessage("You are now on height level " + player.heightLevel + "."); break; case "up2": player.getPlayerAssistant().movePlayer(player.absX, player.absY - 6400, player.heightLevel); player.getPacketSender().sendMessage("You are now on height level " + player.heightLevel + "."); break; case "down": + player.getPacketSender().sendMessage("You are now on height level " + (player.heightLevel - 1) + "."); player.getPlayerAssistant().movePlayer(player.absX, player.absY, player.heightLevel - 1); - player.getPacketSender().sendMessage("You are now on height level " + player.heightLevel + "."); break; case "down2": player.getPlayerAssistant().movePlayer(player.absX, player.absY + 6400, player.heightLevel); @@ -795,12 +796,24 @@ public class Commands implements PacketType { player.getPacketSender().sendMessage("Sound could not be sent."); } break; + case "ccs": case "cameracutscene": - player.getPlayerAssistant().sendCameraCutscene(player.getX(), player.getY(), 10, 10, 10); //Test numbers + if (arguments.length < 5) { + return; + } + player.getPlayerAssistant().sendCameraCutscene(Integer.parseInt(arguments[0]), Integer.parseInt(arguments[1]), Integer.parseInt(arguments[2]), Integer.parseInt(arguments[3]), Integer.parseInt(arguments[4])); //Test numbers + break; + case "ccs2": + case "cameracutscene2": + if (arguments.length < 5) { + return; + } + player.getPlayerAssistant().sendCameraCutscene2(Integer.parseInt(arguments[0]), Integer.parseInt(arguments[1]), Integer.parseInt(arguments[2]), Integer.parseInt(arguments[3]), Integer.parseInt(arguments[4])); //Test numbers break; case "camerashake": player.getPlayerAssistant().sendCameraShake(1, 9, 1, 9); //these are just test numbers break; + case "cr": case "camerareset": player.getPlayerAssistant().sendCameraReset(); //Resets the camera to the normal player view break; diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2OnGroundItem.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2OnGroundItem.java index a2e64618..d0d35d9c 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2OnGroundItem.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2OnGroundItem.java @@ -13,6 +13,11 @@ public class ItemClick2OnGroundItem implements PacketType { final int itemY = player.getInStream().readSignedWordBigEndianA(); final int itemId = player.getInStream().readUnsignedWordA(); System.out.println("ItemClick2OnGroundItem - " + player.playerName + " - " + itemId + " - " + itemX + " - " + itemY); + // Reset position for the telekinetic guardian statue + if (itemId == 6888) { + player.getMageTrainingArena().telekinetic.resetStatue(itemX, itemY); + return; + } if (player.absX != itemX || player.absY != itemY) { player.getPacketSender().sendMessage("You can't do that there!"); return; diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnFloorItems.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnFloorItems.java index 5bad5888..ba391f6c 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnFloorItems.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnFloorItems.java @@ -6,9 +6,10 @@ import com.rs2.event.CycleEvent; import com.rs2.event.CycleEventContainer; import com.rs2.event.CycleEventHandler; import com.rs2.game.content.combat.magic.MagicData; -import com.rs2.game.items.ItemData; import com.rs2.game.players.Player; import com.rs2.net.packets.PacketType; +import com.rs2.world.GlobalDropsHandler; +import com.rs2.world.clip.PathFinder; /** * Magic on floor items @@ -22,95 +23,74 @@ public class MagicOnFloorItems implements PacketType { int itemId = player.getInStream().readUnsignedWord(); final int itemX = player.getInStream().readSignedWordBigEndian(); player.getInStream().readUnsignedWordA(); + player.stopMovement(); if (!GameEngine.itemHandler.itemExists(itemId, itemX, itemY)) { - player.stopMovement(); + player.getPacketSender().sendMessage("This item no longer exist."); return; } - player.usingMagic = true; + if (System.currentTimeMillis() - player.teleGrabDelay <= 1550) { + return; + } + if (player.getItemAssistant().freeSlots(itemId, 1) <= 0) { + player.getPacketSender().sendMessage("You don't have enough space in your inventory."); + return; + } + if (!player.goodDistance(player.getX(), player.getY(), itemX, itemY, 12)) { + return; + } + if (!PathFinder.isProjectilePathClear(player.getX(), player.getY(), player.heightLevel, itemX, itemY)) { + player.getPacketSender().sendMessage("You can't see this item."); + return; + } + player.endCurrentTask(); + player.usingMagic = true; if (!player.getCombatAssistant().checkMagicReqs(51)) { - player.stopMovement(); return; } - if ((player.getItemAssistant().freeSlots() >= 1 || player.getItemAssistant() - .playerHasItem(itemId, 1)) - && ItemData.itemStackable[itemId] - || player.getItemAssistant().freeSlots() > 0 - && !ItemData.itemStackable[itemId]) { - if (player.goodDistance(player.getX(), player.getY(), itemX, itemY, 12)) { - player.walkingToItem = true; - int offY = (player.getX() - itemX) * -1; - int offX = (player.getY() - itemY) * -1; - player.teleGrabX = itemX; - player.teleGrabY = itemY; - player.teleGrabItem = itemId; - player.turnPlayerTo(itemX, itemY); - player.teleGrabDelay = System.currentTimeMillis(); - player.startAnimation(MagicData.MAGIC_SPELLS[51][2]); - player.gfx100(MagicData.MAGIC_SPELLS[51][3]); - player.getPlayerAssistant().createPlayersStillGfx(144, itemX, itemY, - 0, 72); - player.getPlayerAssistant().createPlayersProjectile(player.getX(), - player.getY(), offX, offY, 50, 70, - MagicData.MAGIC_SPELLS[51][4], 50, 10, 0, 50); - player.getPlayerAssistant().addSkillXP( - MagicData.MAGIC_SPELLS[51][7], 6); - player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); - player.stopMovement(); - CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { - @Override - public void execute(CycleEventContainer container) { - if (!player.walkingToItem) { - stop(); - } - if (System.currentTimeMillis() - player.teleGrabDelay > 1550 - && player.usingMagic) { - if (GameEngine.itemHandler.itemExists(player.teleGrabItem, - player.teleGrabX, player.teleGrabY) - && player.goodDistance(player.getX(), player.getY(), - itemX, itemY, 12)) { - GameEngine.itemHandler.removeGroundItem(player, - player.teleGrabItem, player.teleGrabX, - player.teleGrabY, true); - player.usingMagic = false; - container.stop(); - } - } + if (itemId == 6888 && player.goodDistance(player.getX(), player.getY(), itemX, itemY, 20)) { + player.getMageTrainingArena().telekinetic.moveStatue(itemX, itemY); + return; + } + + player.walkingToItem = true; + int offY = (player.getX() - itemX) * -1; + int offX = (player.getY() - itemY) * -1; + player.teleGrabX = itemX; + player.teleGrabY = itemY; + player.teleGrabItem = itemId; + player.turnPlayerTo(itemX, itemY); + player.teleGrabDelay = System.currentTimeMillis(); + player.startAnimation(MagicData.MAGIC_SPELLS[51][2]); + player.gfx100(MagicData.MAGIC_SPELLS[51][3]); + player.getPlayerAssistant().createPlayersStillGfx(144, itemX, itemY, 0, 72); + player.getPlayerAssistant().createPlayersProjectile(player.getX(), + player.getY(), offX, offY, 50, 70, + MagicData.MAGIC_SPELLS[51][4], 50, 10, 0, 50); + player.getPlayerAssistant().addSkillXP(MagicData.MAGIC_SPELLS[51][7], 6); + player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); + player.stopMovement(); + CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { + @Override + public void execute(CycleEventContainer container) { + if (!player.walkingToItem) { + container.stop(); + } else if (System.currentTimeMillis() - player.teleGrabDelay > 1550) { + if (GameEngine.itemHandler.itemExists(player.teleGrabItem, player.teleGrabX, player.teleGrabY)) { + GameEngine.itemHandler.removeGroundItem(player, player.teleGrabItem, player.teleGrabX, player.teleGrabY, true); + GlobalDropsHandler.pickup(player, player.teleGrabItem, player.teleGrabX, player.teleGrabY); } - - @Override - public void stop() { - player.walkingToItem = false; - } - }, 1); + stop(); + } } - } else { - player.getPacketSender().sendMessage( - "You don't have enough space in your inventory."); - player.stopMovement(); - } - if (player.goodDistance(player.getX(), player.getY(), itemX, itemY, 12)) { - int offY = (player.getX() - itemX) * -1; - int offX = (player.getY() - itemY) * -1; - player.teleGrabX = itemX; - player.teleGrabY = itemY; - player.teleGrabItem = itemId; - player.turnPlayerTo(itemX, itemY); - player.teleGrabDelay = System.currentTimeMillis(); - player.startAnimation(MagicData.MAGIC_SPELLS[51][2]); - player.gfx100(MagicData.MAGIC_SPELLS[51][3]); - player.getPlayerAssistant().createPlayersStillGfx(144, itemX, itemY, 0, - 72); - player.getPlayerAssistant().createPlayersProjectile(player.getX(), player.getY(), - offX, offY, 50, 70, MagicData.MAGIC_SPELLS[51][4], 50, 10, - 0, 50); - player.getPlayerAssistant().addSkillXP(MagicData.MAGIC_SPELLS[51][7], 6); - player.getPlayerAssistant().refreshSkill(GameConstants.MAGIC); - player.stopMovement(); - } + @Override + public void stop() { + player.usingMagic = false; + player.walkingToItem = false; + } + }, 1); } - } diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/PickupItem.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/PickupItem.java index 639bc360..1655d006 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/PickupItem.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/PickupItem.java @@ -13,7 +13,9 @@ import com.rs2.game.items.impl.RareProtection; import com.rs2.game.players.Player; import com.rs2.net.packets.PacketType; import com.rs2.util.GameLogger; +import com.rs2.world.Boundary; import com.rs2.world.GlobalDropsHandler; +import com.rs2.world.clip.PathFinder; /** * Pickup Item @@ -26,13 +28,19 @@ public class PickupItem implements PacketType { player.pItemY = player.getInStream().readSignedWordBigEndian(); player.pItemId = player.getInStream().readUnsignedWord(); player.pItemX = player.getInStream().readSignedWordBigEndian(); - if (player.getItemAssistant().freeSlots() < 1) - { - if (!(player.getItemAssistant().playerHasItem(player.pItemId) && player.getItemAssistant().isStackable(player.pItemId))) - { - player.getPacketSender().sendMessage("Not enough space in your inventory."); - return; - } + // Cannot pickup the telekinetic guardian statue, should show overview of current maze + if (player.pItemId == 6888) { + player.getMageTrainingArena().telekinetic.observeStatue(player.pItemX, player.pItemY); + return; + } + // Disabled for now, doesn't detect open doors etc + // if (!PathFinder.getPathFinder().accessible(player.getX(), player.getY(), player.heightLevel, player.pItemX, player.pItemY)) { + // player.getPacketSender().sendMessage("You can't reach this item."); + // return; + // } + if (player.getItemAssistant().freeSlots(player.pItemId, 1) <= 0) { + player.getPacketSender().sendMessage("Not enough space in your inventory."); + return; } if (Math.abs(player.getX() - player.pItemX) > 25 || Math.abs(player.getY() - player.pItemY) > 25) { player.resetWalkingQueue(); @@ -53,7 +61,8 @@ public class PickupItem implements PacketType { if (!RareProtection.removeItemOtherActions(player, player.pItemId)) { return; } - if (player.pItemY > 9817 && player.pItemY < 9825 && player.pItemX > 3186 && player.pItemX < 3197 || player.pItemX > 3107 && player.pItemX < 3113 && player.pItemY > 3155 && player.pItemY < 3159 && player.heightLevel == 2) { + if (Boundary.isIn(player.pItemX, player.pItemY, player.heightLevel, Boundary.VARROCK_BANK_BASEMENT) + || Boundary.isIn(player.pItemX, player.pItemY, player.heightLevel, Boundary.MAGE_TOWER_CAGE)) { player.getPacketSender().sendMessage("You can't pick up these items!"); return; } @@ -71,35 +80,30 @@ public class PickupItem implements PacketType { } SkillHandler.resetSkills(player); player.getCombatAssistant().resetPlayerAttack(); - player.walkingToItem = true; - player.soundDone = false; - CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { - @Override - public void execute(CycleEventContainer container) { - if (!player.walkingToItem) { - container.stop(); - } - if ((player.getX() == player.pItemX && player.getY() == player.pItemY - || player.getX() - 1 == player.pItemX && player.getY() == player.pItemY - || player.getY() - 1 == player.pItemY && player.getX() == player.pItemX - || player.getX() + 1 == player.pItemX && player.getY() == player.pItemY - || player.getY() + 1 == player.pItemY && player.getX() == player.pItemX - ||player.getX() == player.pItemX && player.getY() == player.pItemY) && player.walkingToItem) { - container.stop(); - } + player.walkingToItem = true; + player.soundDone = false; + CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { + @Override + public void execute(CycleEventContainer container) { + if (!player.walkingToItem) { + container.stop(); } + if (player.goodDistance(player.getX(), player.getY(), player.pItemX, player.pItemY, 1) && player.walkingToItem) { + container.stop(); + } + } - @Override - public void stop() { - player.walkingToItem = false; - GameEngine.itemHandler.removeGroundItem(player, player.pItemId, player.pItemX, player.pItemY, true); - GlobalDropsHandler.pickup(player, player.pItemId, player.pItemX, player.pItemY); - if (!player.soundDone) - { - player.soundDone = true; - player.getPacketSender().sendSound(SoundList.ITEM_PICKUP, 100, 0); - } - } - }, 1); + @Override + public void stop() { + player.walkingToItem = false; + GameEngine.itemHandler.removeGroundItem(player, player.pItemId, player.pItemX, player.pItemY, true); + GlobalDropsHandler.pickup(player, player.pItemId, player.pItemX, player.pItemY); + if (!player.soundDone) + { + player.soundDone = true; + player.getPacketSender().sendSound(SoundList.ITEM_PICKUP, 100, 0); + } + } + }, 1); } } diff --git a/2006Scape Server/src/main/java/com/rs2/world/Boundary.java b/2006Scape Server/src/main/java/com/rs2/world/Boundary.java index a8a4215f..65302c20 100644 --- a/2006Scape Server/src/main/java/com/rs2/world/Boundary.java +++ b/2006Scape Server/src/main/java/com/rs2/world/Boundary.java @@ -14,17 +14,16 @@ import com.rs2.game.players.PlayerHandler; public class Boundary { - int minX, highX, minY, highY; - int height; + public int minX, highX, minY, highY, height; /** * * @param minX * The south-west x coordinate - * @param minY - * The south-west y coordinate * @param highX * The north-east x coordinate + * @param minY + * The south-west y coordinate * @param highY * The north-east y coordinate */ @@ -40,10 +39,10 @@ public class Boundary { * * @param minX * The south-west x coordinate - * @param minY - * The south-west y coordinate * @param highX * The north-east x coordinate + * @param minY + * The south-west y coordinate * @param highY * The north-east y coordinate * @param height @@ -301,6 +300,8 @@ public class Boundary { new Boundary(3087, 3094, 3251, 3255), new Boundary(3121, 3130, 3240, 3246), new Boundary(3102, 3112, 3162, 3165), new Boundary(3107, 3111, 3166, 3166), new Boundary(3103, 3115, 3157, 3161), new Boundary(3105, 3114, 3156, 3156), new Boundary(3105, 3113, 3155, 3155), new Boundary(3106, 3112, 3154, 3154), new Boundary(3092, 3097, 3240, 3246) }; + public static final Boundary VARROCK_BANK_BASEMENT = new Boundary(3186, 3197, 9817, 9824, 0); + public static final Boundary MAGE_TOWER_CAGE = new Boundary(3108, 3112, 3156, 3158, 2); public static final Boundary ARDOUGNE_ZOO = new Boundary(2593, 2639, 3265, 3288); public static final Boundary APE_ATOLL = new Boundary(2694, 2811, 2691, 2805); public static final Boundary BARROWS = new Boundary(3543, 3584, 3265, 3311); @@ -313,7 +314,9 @@ public class Boundary { public static final Boundary PARTY_ROOM = new Boundary(2727, 2746, 3460, 3479); public static final Boundary PARTY_ROOM_TABLE = new Boundary(2735, 2740, 3467, 3468); public static final Boundary MAGE_TRAINING_ARENA = new Boundary(3330, 3388, 9614, 9727); - public static final Boundary MAGE_TRAINING_ARENA_ALCHEMY = new Boundary(3350, 3379, 9616, 9655, 2); public static final Boundary MAGE_TRAINING_ARENA_ENCHANTING = new Boundary(3341, 3386, 9618, 9662, 0); + public static final Boundary MAGE_TRAINING_ARENA_GRAVEYARD = new Boundary(3340, 3386, 9616, 9662, 1); + public static final Boundary MAGE_TRAINING_ARENA_ALCHEMY = new Boundary(3350, 3379, 9616, 9655, 2); + public static final Boundary MAGE_TRAINING_ARENA_TELEKINETIC = new Boundary(3329, 3390, 9665, 9726); } \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/world/GlobalDropsHandler.java b/2006Scape Server/src/main/java/com/rs2/world/GlobalDropsHandler.java index ebf5f84a..b0259b94 100644 --- a/2006Scape Server/src/main/java/com/rs2/world/GlobalDropsHandler.java +++ b/2006Scape Server/src/main/java/com/rs2/world/GlobalDropsHandler.java @@ -146,9 +146,9 @@ public class GlobalDropsHandler { return null; } - public static boolean itemExists(int a, int b, int c, boolean yes) { + public static boolean itemExists(int itemID, int itemX, int itemY, boolean yes) { for (GlobalDrop drop : spawnedDrops) { - if (drop.getId() == a && drop.getX() == b && drop.getY() == c) { + if (drop.getId() == itemID && drop.getX() == itemX && drop.getY() == itemY) { return true; } } @@ -159,12 +159,12 @@ public class GlobalDropsHandler { * Pick up an item at the given location * * @param player the Player - * @param a item id - * @param b cord x - * @param c cord y + * @param itemID item id + * @param itemX cord x + * @param itemY cord y */ - public static void pickup(Player player, int a, int b, int c) { - GlobalDrop drop = itemExists(a, b, c); + public static void pickup(Player player, int itemID, int itemX, int itemY) { + GlobalDrop drop = itemExists(itemID, itemX, itemY); if (drop == null) { return; } diff --git a/2006Scape Server/src/main/java/com/rs2/world/ItemHandler.java b/2006Scape Server/src/main/java/com/rs2/world/ItemHandler.java index e63fec88..0270898f 100644 --- a/2006Scape Server/src/main/java/com/rs2/world/ItemHandler.java +++ b/2006Scape Server/src/main/java/com/rs2/world/ItemHandler.java @@ -58,11 +58,7 @@ public class ItemHandler { public int itemAmount(String name, int itemId, int itemX, int itemY) { for (GroundItem i : items) { - if (i.hideTicks >= 1 && i.getName().equalsIgnoreCase(name)) { - if (i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) { - return i.getItemAmount(); - } - } else if (i.hideTicks < 1) { + if (i.getName().equalsIgnoreCase(name)) { if (i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) { return i.getItemAmount(); } @@ -76,25 +72,42 @@ public class ItemHandler { **/ public boolean itemExists(int itemId, int itemX, int itemY) { for (GroundItem i : items) { - if (i.getItemId() == itemId && i.getItemX() == itemX - && i.getItemY() == itemY) { + if (i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) { return true; } } + if (GlobalDropsHandler.itemExists(itemId, itemX, itemY, true)) { + return true; + } return false; } + public void moveItem(GroundItem item, int itemX, int itemY) { + if (items.remove(item)) { + int oldX = item.itemX; + int oldY = item.itemY; + item.itemX = itemX; + item.itemY = itemY; + items.add(item); + for (Player p: PlayerHandler.players) { + if (p == null) continue; + p.getPacketSender().removeGroundItem(item.itemId, oldX, oldY, item.itemAmount); + reloadItems(p); + } + } + } + /** * Reloads any items if you enter a new region **/ public void reloadItems(Player c) { for (GroundItem i : items) { if (c != null) { - if (c.getItemAssistant().tradeable(i.getItemId()) - || i.getName().equalsIgnoreCase(c.playerName)) { - if (c.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) { - if (i.hideTicks > 0 - && i.getName().equalsIgnoreCase(c.playerName)) { + // If it's a players item or tradeable + if (c.getItemAssistant().tradeable(i.getItemId()) || i.getName().equalsIgnoreCase(c.playerName)) { + // Make sure item on the same height and within 60 blocks + if (c.getH() == i.getItemH() && c.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) { + if (i.hideTicks > 0 && i.getName().equalsIgnoreCase(c.playerName)) { c.getPacketSender().removeGroundItem( i.getItemId(), i.getItemX(), i.getItemY(), i.getItemAmount()); @@ -175,7 +188,6 @@ public class ItemHandler { } if (!com.rs2.game.items.ItemData.itemStackable[itemId] && itemAmount > 0) { for (int j = 0; j < itemAmount; j++) { - c.getPacketSender().createGroundItem(itemId, itemX, itemY, 1); GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), 1, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName); addItem(item); String itemName = ItemAssistant.getItemName(itemId).toLowerCase(); @@ -186,7 +198,6 @@ public class ItemHandler { } } } else { - c.getPacketSender().createGroundItem(itemId, itemX, itemY, itemAmount); GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), itemAmount, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName); addItem(item); String itemName = ItemAssistant.getItemName(itemId).toLowerCase(); @@ -196,6 +207,7 @@ public class ItemHandler { } } } + reloadItems(c); } } @@ -203,6 +215,9 @@ public class ItemHandler { * Shows items for everyone who is within 60 squares **/ public void createGlobalItem(GroundItem i) { + if (!itemExists(i.getItemId(), i.getItemX(), i.getItemY())) { + addItem(i); + } for (Player p : PlayerHandler.players) { if (p != null) { Client person = (Client) p; @@ -212,7 +227,7 @@ public class ItemHandler { && person.playerId != i.getItemController()) { continue; } - if (person.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) { + if (person.getH() == i.getItemH() && person.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) { person.getPacketSender().createGroundItem( i.getItemId(), i.getItemX(), i.getItemY(), i.getItemAmount()); @@ -293,8 +308,7 @@ public class ItemHandler { Client person = (Client) p; if (person != null) { if (person.distanceToPoint(itemX, itemY) <= 60) { - person.getPacketSender().removeGroundItem(itemId, - itemX, itemY, itemAmount); + person.getPacketSender().removeGroundItem(itemId, itemX, itemY, itemAmount); } } } @@ -460,6 +474,7 @@ public class ItemHandler { try { FileWriter fileWriter = new FileWriter("item-dump.json"); fileWriter.write(array.toString()); + fileWriter.close(); characterfile.close(); } catch (IOException e) { }