Hey boys and grills,
These kids in the Discord chat are like, "You don't contribute anything to the website." Well I'll show them losers.
So, I used this on the simplicity source, but it should work on all ruse related servers.
Make a new file in
com.ruseps.net.packet.impl
I called it "MagicOnObjectPacketListener" so I kept the naming scheme throughout.
Add the contents in that file.
package com.ruseps.net.packet.impl;
import com.ruseps.GameSettings;
import com.ruseps.engine.task.impl.WalkToTask;
import com.ruseps.engine.task.impl.WalkToTask.FinalizedMovementTask;
import com.ruseps.model.Animation;
import com.ruseps.model.GameObject;
import com.ruseps.model.Graphic;
import com.ruseps.model.GraphicHeight;
import com.ruseps.model.PlayerRights;
import com.ruseps.model.Position;
import com.ruseps.model.Skill;
import com.ruseps.model.definitions.GameObjectDefinition;
import com.ruseps.net.packet.Packet;
import com.ruseps.net.packet.PacketListener;
import com.ruseps.world.clip.region.RegionClipping;
import com.ruseps.world.content.combat.magic.MagicSpells;
import com.ruseps.world.content.combat.magic.Spell;
import com.ruseps.world.entity.impl.player.Player;
/**
* Magic on object packet listener.
* @author Bananastreet
*
*/
public class MagicOnObjectPacketListener implements PacketListener {
/**
* Handles the click option for an object.
* @param player The player that clicked on the object.
* @param packet The packet containing the object's and spell's information.
*/
@Override
public void handleMessage(Player player, Packet packet) {
final int objectX = packet.readLEShort();
final int spellId = packet.readShortA();
final int objectY = packet.readShortA();
final int objectId = packet.readLEShort();
//Objects position.
final Position position = new Position(objectX, objectY, player.getPosition().getZ());
//Intialize a new game object from the packets.
final GameObject gameObject = new GameObject(objectId, position);
//Check if the object exists in the region.
if (!RegionClipping.objectExists(gameObject)) {
if (player.getRights().isStaff()) {
player.getPacketSender().sendMessage("Object with id " + objectId + " does not exist").sendMessage("Please report to Bananastreet");
} else {
player.getPacketSender().sendMessage("An error occured. Error code: " + objectId).sendMessage("Please report the error to a staff member.");
}
return;
}
//Check if the spell id is less than 0.
if (spellId < 0) {
if (player.getRights() == PlayerRights.DEVELOPER) {
player.getPacketSender().sendMessage("Error in MagicOnObjectPacketListener!");
}
return;
}
//Getting the magic spell from the spell id.
final MagicSpells magicSpell = MagicSpells.forSpellId(spellId);
//Checking if the spell is null.
if (magicSpell == null) {
player.getPacketSender().sendMessage("magicSpell is null");
return;
}
//Initializing a new spell from the magic spell.
Spell spell = magicSpell.getSpell();
//Get the object definition from the object id.
final GameObjectDefinition def = GameObjectDefinition.forId(objectId);
//Calculate the size of the object.
final int size = def.getSizeX() - def.getSizeY() - 1;
//Set the game objects size.
gameObject.setSize(size);
//Walk towards the object and set which object we are interacting with.
player.setInteractingObject(gameObject).setWalkToTask(new WalkToTask(player, position, gameObject.getSize(), new FinalizedMovementTask () {
@Override
public void execute() {
//Face the object.
player.setPositionToFace(gameObject.getPosition());
switch (objectId) {
case 2151:
if (magicSpell.equals(MagicSpells.CHARGE_WATER_ORB)) {
if (spell == null || !spell.canCast(player, true)) {
return;
}
if (player.getInventory().contains(567)) {
player.getInventory().delete(567, 1);
}
player.performAnimation(ORB_ANIMATION);
player.performGraphic(WATER_ORB_GRAPHIC);
player.getSkillManager().addExperience(Skill.MAGIC, spell.baseExperience());
player.getInventory().add(571, 1);
return;
} else {
player.getPacketSender().sendMessage("You can only use Charge Water Orb spell on this obelisk.");
}
player.getPacketSender().sendInterfaceRemoval();
player.getSkillManager().stopSkilling();
break;
case 2153:
if (magicSpell.equals(MagicSpells.CHARGE_FIRE_ORB)) {
if (spell == null || !spell.canCast(player, true)) {
return;
}
player.getPacketSender().sendTab(GameSettings.INVENTORY_TAB);
if (player.getInventory().contains(567)) {
player.getInventory().delete(567, 1);
}
player.performAnimation(ORB_ANIMATION);
player.performGraphic(FIRE_ORB_GRAPHIC);
player.getSkillManager().addExperience(Skill.MAGIC, spell.baseExperience());
player.getInventory().add(569, 1);
player.getPacketSender().sendTab(GameSettings.MAGIC_TAB);
} else {
player.getPacketSender().sendMessage("You can only use Charge Fire Orb spell on this obelisk.");
}
break;
}
}
}));
player.getClickDelay().reset();
player.getInventory().refreshItems();
}
private static final Animation ORB_ANIMATION = new Animation(726);
private static final Animation DEFAULT_ANIMATION = new Animation(65535);
private static final Graphic WATER_ORB_GRAPHIC = new Graphic(149, GraphicHeight.HIGH);
private static final Graphic FIRE_ORB_GRAPHIC = new Graphic(152, GraphicHeight.HIGH);
private static final Graphic EARTH_ORB_GRAPHIC = new Graphic(151, GraphicHeight.HIGH);
private static final Graphic AIR_ORB_GRAPHIC = new Graphic(150, GraphicHeight.HIGH);
public static final int MAGIC_ON_OBJECTS = 35;
}
You'll probably get a few errors telling you that "CHARGE_WATER_ORB" and the others don't exist. On to step 2:
Add these spells in your MagicSpells enum:
CHARGE_WATER_ORB(new Spell() {
@Override
public int spellId() {
return 1179;
}
@Override
public int levelRequired() {
return 56;
}
@Override
public int baseExperience() {
return 66;
}
@Override
public Optional<Item[]> itemsRequired(Player player) {
return Optional.of(new Item[] {new Item(555, 30), new Item(564, 3), new Item(567)});
}
@Override
public Optional<Item[]> equipmentRequired(Player player) {
return Optional.empty();
}
@Override
public void startCast(Character cast, Character castOn) {
//Empty
}
}),
CHARGE_FIRE_ORB(new Spell() {
@Override
public int spellId() {
return 1184;
}
@Override
public int levelRequired() {
return 63;
}
@Override
public int baseExperience() {
return 73;
}
@Override
public Optional<Item[]> itemsRequired(Player player) {
return Optional.of(new Item[] {new Item(554, 30), new Item(564, 3), new Item(567)});
}
@Override
public Optional<Item[]> equipmentRequired(Player player) {
return Optional.empty();
}
@Override
public void startCast(Character cast, Character castOn) {
}
}),
Then at last we need to call the MagicOnPacketListener into the packets.
Open up PacketConstants and add this with the other magic on stuff to keep it close together.
PACKETS[MagicOnObjectPacketListener.MAGIC_ON_OBJECTS] = new MagicOnObjectPacketListener();
Remember to make all of your imports. Which is Ctrl + Shift + O in eclipse.
If I missed anything let me know, and on a side note, I know this isn't complete, or done "properly", I just used it to test if the packet was working, and whether I could actually perform the spell on the object.