New spell listeners + other bugfixes

This commit is contained in:
Ceikry 2021-03-24 00:20:48 -05:00
parent a126de93f1
commit 380c502a0c
16 changed files with 139115 additions and 138966 deletions

View file

@ -2128,15 +2128,21 @@
"main": [
{
"minAmount": "1",
"weight": "50.0",
"weight": "33.0",
"id": "0",
"maxAmount": "1"
},
{
"minAmount": "11",
"weight": "50.0",
"minAmount": "1",
"weight": "33.0",
"id": "314",
"maxAmount": "30"
"maxAmount": "6"
},
{
"minAmount": "15",
"weight": "33.0",
"id": "314",
"maxAmount": "15"
}
]
},
@ -32376,7 +32382,7 @@
{
"minAmount": "1",
"weight": "5.0",
"id": "2821",
"id": "5733",
"maxAmount": "1"
},
{
@ -32499,31 +32505,7 @@
"main": [
{
"minAmount": "1",
"weight": "25.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"weight": "45.0",
"id": "5521",
"maxAmount": "1"
},
@ -32560,7 +32542,7 @@
{
"minAmount": "1",
"weight": "5.0",
"id": "2821",
"id": "5733",
"maxAmount": "1"
},
{
@ -32683,31 +32665,7 @@
"main": [
{
"minAmount": "1",
"weight": "25.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"id": "5521",
"maxAmount": "1"
},
{
"minAmount": "1",
"weight": "5.0",
"weight": "45.0",
"id": "5521",
"maxAmount": "1"
},
@ -32744,7 +32702,7 @@
{
"minAmount": "1",
"weight": "5.0",
"id": "2821",
"id": "5733",
"maxAmount": "1"
},
{

File diff suppressed because it is too large Load diff

View file

@ -1,22 +1,20 @@
package core.game.content.activity.mta;
import core.game.node.entity.player.link.diary.DiaryType;
import core.game.world.map.zone.ZoneBorders;
import org.rs09.consts.Items;
import core.game.node.entity.skill.magic.MagicSpell;
import core.game.node.entity.skill.magic.Runes;
import core.game.content.activity.mta.impl.AlchemistZone;
import core.game.content.activity.mta.impl.AlchemistZone.AlchemistItem;
import core.game.node.Node;
import core.game.node.entity.Entity;
import core.game.node.entity.combat.equipment.SpellType;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.SpellBookManager.SpellBook;
import core.game.node.entity.player.link.diary.DiaryType;
import core.game.node.entity.skill.magic.MagicSpell;
import core.game.node.item.Item;
import core.game.world.map.zone.ZoneBorders;
import core.game.world.update.flag.context.Animation;
import core.game.world.update.flag.context.Graphics;
import core.plugin.Plugin;
import core.game.content.activity.mta.impl.AlchemistZone;
import core.game.content.activity.mta.impl.AlchemistZone.AlchemistItem;
import org.rs09.consts.Items;
/**
* Represents the plugin for the magic spell alchemy.
@ -55,8 +53,8 @@ public final class AlchemySpell extends MagicSpell {
@Override
public Plugin<SpellType> newInstance(SpellType arg) throws Throwable {
SpellBook.MODERN.register(13, new AlchemySpell(21, 31, Animation.create(712), new Graphics(112, 96), false, Runes.FIRE_RUNE.getItem(3), Runes.NATURE_RUNE.getItem(1)));
SpellBook.MODERN.register(34, new AlchemySpell(55, 65, Animation.create(713), new Graphics(113, 96), true, Runes.FIRE_RUNE.getItem(5), Runes.NATURE_RUNE.getItem(1)));
//SpellBook.MODERN.register(13, new AlchemySpell(21, 31, Animation.create(712), new Graphics(112, 96), false, Runes.FIRE_RUNE.getItem(3), Runes.NATURE_RUNE.getItem(1)));
//SpellBook.MODERN.register(34, new AlchemySpell(55, 65, Animation.create(713), new Graphics(113, 96), true, Runes.FIRE_RUNE.getItem(5), Runes.NATURE_RUNE.getItem(1)));
return this;
}

View file

@ -271,7 +271,7 @@ public final class HansDialoguePlugin extends DialoguePlugin {
case 110:
switch (buttonId) {
case 1: //I would like to be an Iron Man
if (player.getSkills().getTotalLevel() > 500 || player.getQuestRepository().getPoints() > 10){
if (player.getSkills().getTotalLevel() > 50 || player.getQuestRepository().getPoints() > 10){
interpreter.sendDialogues(npc, FacialExpression.GUILTY, "Sorry, but you are too far along your journey.", "It would be unfair for those with other", " restrictions if your status were to be changed!");
stage = 50;
break;
@ -335,9 +335,7 @@ public final class HansDialoguePlugin extends DialoguePlugin {
case 3: //ultimate ironman
if (!player.getBank().isEmpty())
{
if (!inStartDungeon) {
interpreter.sendDialogues(npc, FacialExpression.GUILTY, "Sorry, but your bank is has items in it.", "Please empty your bank and speak to me again.");
}
interpreter.sendDialogues(npc, FacialExpression.GUILTY, "Sorry, but your bank is has items in it.", "Please empty your bank and speak to me again.");
stage = 50;
break;
} else {

View file

@ -7,6 +7,9 @@ import core.plugin.Initializable;
import core.game.node.entity.skill.magic.MagicSpell;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.SpellBookManager.SpellBook;
import rs09.game.node.entity.skill.magic.SpellListener;
import rs09.game.node.entity.skill.magic.SpellListeners;
import rs09.game.node.entity.skill.magic.SpellUtils;
import rs09.game.world.GameWorld;
import core.plugin.Plugin;
@ -31,6 +34,7 @@ public final class MagicBookInterface extends ComponentPlugin {
if (GameWorld.getTicks() < player.getAttribute("magic:delay", -1)) {
return true;
}
SpellListeners.run(button, SpellListener.NONE, SpellUtils.getBookFromInterface(component.getId()),player,null);
return MagicSpell.castSpell(player, component.getId() == 192 ? SpellBook.MODERN : component.getId() == 193 ? SpellBook.ANCIENT : SpellBook.LUNAR, button, player);
}
}

View file

@ -1,105 +0,0 @@
package core.game.node.entity.skill.magic;
import rs09.ServerConstants;
import core.game.node.Node;
import core.game.node.entity.Entity;
import core.game.node.entity.combat.equipment.SpellType;
import core.game.node.entity.player.link.SpellBookManager.SpellBook;
import core.game.node.entity.player.link.TeleportManager.TeleportType;
import core.game.node.entity.player.link.diary.DiaryType;
import core.game.node.item.Item;
import rs09.game.world.GameWorld;
import core.game.world.map.Location;
import core.plugin.Initializable;
import core.plugin.Plugin;
import core.tools.RandomFunction;
/**
* Represents the plugin to handle all teleport spells in the modern book.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class ModernTeleportPlugin extends MagicSpell {
/**
* Represents the location to teleport to.
*/
private Location location;
/**
* Constructs a new {@code ModernTeleportPlugin} {@code Object}.
*/
public ModernTeleportPlugin() {
/**
* empty.
*/
}
/**
* Constructs a new {@code ModernTeleportPlugin.java} {@code Object}.
* @param level the level.
* @param experience the experience.
* @param location the location.
* @param items the items.
*/
public ModernTeleportPlugin(final int level, final double experience, final Location location, final Item... items) {
super(SpellBook.MODERN, level, experience, null, null, null, items);
this.location = location;
}
@Override
public boolean cast(Entity entity, Node target) {
if (entity.getLocks().isTeleportLocked() || !super.meetsRequirements(entity, true, false)) {
return false;
}
if (entity.getTeleporter().send(location.transform(0, RandomFunction.random(3), 0), getSpellId() == 0 ? TeleportType.HOME : TeleportType.NORMAL)) {
if (!super.meetsRequirements(entity, true, true)) {
entity.getTeleporter().getCurrentTeleport().stop();
return false;
}
// Use the teleport to Varrock spell
if (entity.isPlayer() && location.equals(Location.create(3213, 3424, 0))) {
entity.asPlayer().getAchievementDiaryManager().finishTask(entity.asPlayer(),DiaryType.VARROCK,1, 13);
}
//
if (entity.isPlayer() && location.getX() == 2758 && location.getY() == 3478) {
entity.asPlayer().getAchievementDiaryManager().finishTask(entity.asPlayer(), DiaryType.SEERS_VILLAGE, 1, 5);
}
// Use the teleport Lumbridge spell
if (entity.isPlayer() && location.equals(Location.create(3221, 3219, 0))) {
entity.asPlayer().getAchievementDiaryManager().finishTask(entity.asPlayer(), DiaryType.LUMBRIDGE, 2, 2);
}
entity.setAttribute("teleport:items", super.runes);
entity.setAttribute("magic-delay", GameWorld.getTicks() + 5);
return true;
}
return false;
}
@Override
public Plugin<SpellType> newInstance(SpellType arg) throws Throwable {
// home
SpellBook.MODERN.register(0, new ModernTeleportPlugin(0, 0, ServerConstants.HOME_LOCATION));
// varrock
SpellBook.MODERN.register(15, new ModernTeleportPlugin(25, 35, Location.create(3213, 3424, 0), new Item(Runes.FIRE_RUNE.getId()), new Item(Runes.AIR_RUNE.getId(), 3), new Item(Runes.LAW_RUNE.getId(), 1)));
// lumby
SpellBook.MODERN.register(18, new ModernTeleportPlugin(31, 41, Location.create(3221, 3219, 0), new Item(Runes.EARTH_RUNE.getId()), new Item(Runes.AIR_RUNE.getId(), 3), new Item(Runes.LAW_RUNE.getId(), 1)));
// fally
SpellBook.MODERN.register(21, new ModernTeleportPlugin(37, 47, Location.create(2965, 3378, 0), new Item(Runes.WATER_RUNE.getId()), new Item(Runes.AIR_RUNE.getId(), 3), new Item(Runes.LAW_RUNE.getId(), 1)));
// camelot
SpellBook.MODERN.register(26, new ModernTeleportPlugin(45, 55.5, Location.create(2758, 3478, 0), new Item(Runes.AIR_RUNE.getId(), 5), new Item(Runes.LAW_RUNE.getId(), 1)));
// house
SpellBook.MODERN.register(23, new HouseTeleportPlugin(40, 50, new Item(Runes.LAW_RUNE.getId()), new Item(Runes.AIR_RUNE.getId(), 1), new Item(Runes.EARTH_RUNE.getId(), 1)));
// ardougne
SpellBook.MODERN.register(32, new ModernTeleportPlugin(51, 61, Location.create(2662, 3307, 0), new Item(Runes.WATER_RUNE.getId(), 2), new Item(Runes.LAW_RUNE.getId(), 2)));
// watchtower
SpellBook.MODERN.register(37, new ModernTeleportPlugin(58, 68, Location.create(2549, 3112, 0), new Item(Runes.EARTH_RUNE.getId(), 2), new Item(Runes.LAW_RUNE.getId(), 2)));
// trollheim
SpellBook.MODERN.register(44, new ModernTeleportPlugin(61, 68, Location.create(2891, 3678, 0), new Item(Runes.FIRE_RUNE.getId(), 2), new Item(Runes.LAW_RUNE.getId(), 2)));
// ape atol
SpellBook.MODERN.register(47, new ModernTeleportPlugin(64, 74, Location.create(2754, 2784, 0), new Item(Runes.FIRE_RUNE.getId(), 2), new Item(Runes.WATER_RUNE.getId(), 2), new Item(Runes.LAW_RUNE.getId(), 2), new Item(1963, 1)));
return this;
}
}

View file

@ -1,82 +0,0 @@
package core.game.node.entity.skill.magic;
import core.plugin.Initializable;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.skill.smithing.smelting.Bar;
import core.game.node.entity.skill.smithing.smelting.SmeltingPulse;
import core.game.node.Node;
import core.game.node.entity.Entity;
import core.game.node.entity.combat.equipment.SpellType;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.SpellBookManager.SpellBook;
import core.game.node.item.Item;
import core.plugin.Plugin;
/**
* Represents the super heat spell.
* @author Vexia
* @version 1.0
*/
@Initializable
public final class SuperheatSpell extends MagicSpell {
/**
* Constructs a new {@code SuperheatSpell} {@code Object}.
*/
public SuperheatSpell() {
/**
* empty.
*/
}
/**
* Constructs a new {@code SuperheatSpell} {@code Object}.
* @param level the level.
* @param runes the runes.
*/
public SuperheatSpell(int level, Item... runes) {
super(SpellBook.MODERN, level, 53.0, null, null, null, runes);
}
@Override
public Plugin<SpellType> newInstance(SpellType arg) throws Throwable {
SpellBook.MODERN.register(25, new SuperheatSpell(43, new Item(Runes.FIRE_RUNE.getId(), 4), new Item(Runes.NATURE_RUNE.getId(), 1)));
return this;
}
@Override
public boolean cast(Entity entity, Node target) {
final Player player = ((Player) entity);
final Item item = ((Item) target);
player.getInterfaceManager().setViewedTab(6);
if (player.inCombat()) {
player.getPacketDispatch().sendMessage("You can't do that during combat.");
return false;
}
if (!item.getName().contains("ore") && !item.getName().toLowerCase().equals("coal")) {
player.getPacketDispatch().sendMessage("You need to cast superheat item on ore.");
return false;
}
final Bar bar = Bar.forOre(item.getId());
if (bar == null) {
return false;
}
if (player.getSkills().getLevel(Skills.SMITHING) < bar.getLevel()) {
player.sendMessage("You need a Smithing level of at least " + bar.getLevel() + " to do this.");
return false;
}
for (Item items : bar.getOres()) {
if (!player.getInventory().contains(items.getId(), items.getAmount())) {
player.getPacketDispatch().sendMessage("You do not have the required ores to make this bar.");
return false;
}
}
if (!super.meetsRequirements(entity, true, true)) {
return false;
}
player.getAudioManager().send(117);
player.getPulseManager().run(new SmeltingPulse(player, item, bar, 1, true));
return true;
}
}

View file

@ -11,6 +11,9 @@ import core.game.node.entity.player.link.SpellBookManager;
import core.game.node.item.GroundItemManager;
import core.game.node.item.Item;
import core.game.node.object.GameObject;
import rs09.game.node.entity.skill.magic.SpellListener;
import rs09.game.node.entity.skill.magic.SpellListeners;
import rs09.game.node.entity.skill.magic.SpellUtils;
import rs09.game.world.GameWorld;
import core.game.world.map.Location;
import core.game.world.map.RegionManager;
@ -55,6 +58,7 @@ public class InterfaceUseOnPacket implements IncomingPacket {
break;
}
if (CombatSwingHandler.isProjectileClipped(player, groundItem, false)) {
SpellListeners.run(spell, SpellListener.GROUND_ITEM, SpellUtils.getBookFromInterface(interfaceId),player,groundItem);
MagicSpell.castSpell(player, SpellBookManager.SpellBook.MODERN, spell, groundItem);
} else {
player.getPulseManager().run(new MovementPulse(player, groundItem) {
@ -73,6 +77,7 @@ public class InterfaceUseOnPacket implements IncomingPacket {
@Override
public boolean pulse() {
SpellListeners.run(spell, SpellListener.GROUND_ITEM,SpellUtils.getBookFromInterface(interfaceId),player,groundItem);
MagicSpell.castSpell(player, SpellBookManager.SpellBook.MODERN, spell, groundItem);
return true;
}
@ -92,6 +97,9 @@ public class InterfaceUseOnPacket implements IncomingPacket {
PacketRepository.send(ClearMinimapFlag.class, new PlayerContext(player));
break;
}
if(!SpellUtils.getBookFromInterface(interfaceId).equals("none")){
SpellListeners.run(componentId,SpellListener.PLAYER,SpellUtils.getBookFromInterface(interfaceId),player,target);
}
switch (interfaceId) {
case 192:
MagicSpell.castSpell(player, SpellBookManager.SpellBook.MODERN, componentId, target);
@ -144,6 +152,9 @@ public class InterfaceUseOnPacket implements IncomingPacket {
PacketRepository.send(ClearMinimapFlag.class, new PlayerContext(player));
break;
}
if(!SpellUtils.getBookFromInterface(interfaceId).equals("none")){
SpellListeners.run(componentId,SpellListener.OBJECT,SpellUtils.getBookFromInterface(interfaceId),player,object);
}
switch (interfaceId) {
case 430:
MagicSpell.castSpell(player, SpellBookManager.SpellBook.LUNAR, componentId, object);
@ -179,6 +190,9 @@ public class InterfaceUseOnPacket implements IncomingPacket {
if (player.getAttribute("magic:delay", -1) > GameWorld.getTicks()) {
break;
}
if(!SpellUtils.getBookFromInterface(interfaceId).equals("none")){
SpellListeners.run(componentId,SpellListener.NPC, SpellUtils.getBookFromInterface(interfaceId),player,npc);
}
switch (interfaceId) {
case 430:
MagicSpell.castSpell(player, SpellBookManager.SpellBook.LUNAR, componentId, npc);
@ -222,6 +236,9 @@ public class InterfaceUseOnPacket implements IncomingPacket {
if (item == null) {
break;
}
if(!SpellUtils.getBookFromInterface(interfaceId).equals("none")){
SpellListeners.run(componentId,SpellListener.ITEM,SpellUtils.getBookFromInterface(interfaceId),player,item);
}
switch (interfaceId) {
case 430:
if (player.getAttribute("magic:delay", -1) > GameWorld.getTicks()) {

View file

@ -18,9 +18,7 @@ class NPCDropTable : WeightBasedTable() {
}
override fun roll(player: Player?): ArrayList<Item> {
if(size == 0) return ArrayList()
val items= ArrayList<Item>(3)
var tempWeight = RandomFunction.randomDouble(totalWeight)
items.addAll(guaranteedItems.map { it.getItem() }.toList())
if(RandomFunction.random(1,15) == 5){
@ -31,6 +29,7 @@ class NPCDropTable : WeightBasedTable() {
return items
}
if(isNotEmpty()) {
var tempWeight = RandomFunction.randomDouble(totalWeight)
for (item in shuffled()) {
tempWeight -= item.weight
if (tempWeight <= 0) {

View file

@ -24,9 +24,7 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
}
open fun roll(player: Player?): ArrayList<Item>{
if(size == 0) return ArrayList()
val items= ArrayList<Item>(3)
var tempWeight = RandomFunction.randomDouble(totalWeight)
items.addAll(guaranteedItems.map { it.getItem() }.toList())
if(player?.inventory?.isFull == true){
@ -34,6 +32,7 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
}
if(isNotEmpty()) {
var tempWeight = RandomFunction.randomDouble(totalWeight)
for (item in shuffled()) {
tempWeight -= item.weight
if (tempWeight <= 0) {

View file

@ -0,0 +1,160 @@
package rs09.game.node.entity.skill.magic
import core.game.node.entity.player.Player
import core.game.node.entity.player.link.TeleportManager
import core.game.node.entity.player.link.diary.DiaryType
import core.game.node.entity.skill.Skills
import core.game.node.entity.skill.smithing.smelting.Bar
import core.game.node.entity.skill.smithing.smelting.SmeltingPulse
import core.game.node.item.Item
import core.game.world.map.Location
import core.game.world.map.zone.ZoneBorders
import core.game.world.update.flag.context.Animation
import core.game.world.update.flag.context.Graphics
import org.rs09.consts.Items
import rs09.ServerConstants
import rs09.game.node.entity.skill.magic.spellconsts.Modern
class ModernListeners : SpellListener("modern"){
override fun defineListeners() {
onCast(Modern.HOME_TELEPORT,NONE){player, _ ->
requires(player)
player.teleporter.send(ServerConstants.HOME_LOCATION,TeleportManager.TeleportType.HOME)
setDelay(player,true)
}
onCast(Modern.VARROCK_TELEPORT,NONE){player, _->
requires(player,25, arrayOf(Item(Items.FIRE_RUNE_554),Item(Items.AIR_RUNE_556,3),Item(Items.LAW_RUNE_563)))
player.achievementDiaryManager.finishTask(player, DiaryType.VARROCK,1, 13)
sendTeleport(player,35.0,Location.create(3213, 3424, 0))
}
onCast(Modern.LUMBRIDGE_TELEPORT,NONE){player,_ ->
requires(player,31, arrayOf(Item(Items.EARTH_RUNE_557),Item(Items.AIR_RUNE_556,3),Item(Items.LAW_RUNE_563)))
player.achievementDiaryManager.finishTask(player, DiaryType.LUMBRIDGE, 2, 2)
sendTeleport(player,41.0,Location.create(3221, 3219, 0))
}
onCast(Modern.FALADOR_TELEPORT,NONE){player, _ ->
requires(player,37, arrayOf(Item(Items.WATER_RUNE_555),Item(Items.AIR_RUNE_556,3),Item(Items.LAW_RUNE_563)))
sendTeleport(player,47.0,Location.create(2965, 3378, 0))
}
onCast(Modern.CAMELOT_TELEPORT,NONE){player, _->
requires(player,45, arrayOf(Item(Items.AIR_RUNE_556,5),Item(Items.LAW_RUNE_563)))
player.achievementDiaryManager.finishTask(player, DiaryType.SEERS_VILLAGE, 1, 5);
sendTeleport(player,55.5, Location.create(2758, 3478, 0))
}
onCast(Modern.ARDOUGNE_TELEPORT,NONE){player,_ ->
requires(player,51, arrayOf(Item(Items.WATER_RUNE_555,2),Item(Items.LAW_RUNE_563,2)))
sendTeleport(player,61.0, Location.create(2662, 3307, 0))
}
onCast(Modern.WATCHTOWER_TELEPORT,NONE){player,_ ->
requires(player,58, arrayOf(Item(Items.EARTH_RUNE_557,2),Item(Items.LAW_RUNE_563,2)))
sendTeleport(player,68.0, Location.create(2549, 3112, 0))
}
onCast(Modern.TROLLHEIM_TELEPORT,NONE){player, _ ->
requires(player,61, arrayOf(Item(Items.FIRE_RUNE_554,2),Item(Items.LAW_RUNE_563,2)))
sendTeleport(player,68.0, Location.create(2891, 3678, 0))
}
onCast(Modern.APE_ATOLL_TELEPORT,NONE){player,_ ->
requires(player,64, arrayOf(Item(Items.FIRE_RUNE_554,2),Item(Items.WATER_RUNE_555,2),Item(Items.LAW_RUNE_563,2),Item(Items.BANANA_1963)))
sendTeleport(player,74.0, Location.create(2754, 2784, 0))
}
onCast(Modern.LOW_ALCHEMY,ITEM){player, node ->
val item = node?.asItem() ?: return@onCast
requires(player,21, arrayOf(Item(Items.FIRE_RUNE_554,3),Item(Items.NATURE_RUNE_561)))
alchemize(player,item,high = false)
}
onCast(Modern.HIGH_ALCHEMY,ITEM){player, node ->
val item = node?.asItem() ?: return@onCast
requires(player,55, arrayOf(Item(Items.FIRE_RUNE_554,5),Item(Items.NATURE_RUNE_561,1)))
alchemize(player,item,high = true)
}
onCast(Modern.SUPERHEAT,ITEM){player, node ->
val item = node?.asItem() ?: return@onCast
requires(player,43, arrayOf(Item(Items.FIRE_RUNE_554,4),Item(Items.NATURE_RUNE_561,1)))
superheat(player,item)
}
}
private fun superheat(player: Player,item: Item){
if(!item.name.contains("ore") && !item.name.toLowerCase().equals("coal")){
player.sendMessage("You can only cast this spell on ore.")
return
}
var bar = Bar.forOre(item.id) ?: return
if(bar == Bar.IRON && player.inventory.getAmount(Items.COAL_453) >= 2 && player.skills.getLevel(Skills.SMITHING) >= Bar.STEEL.level && player.inventory.contains(Items.IRON_ORE_441,1)) bar = Bar.STEEL
if(player.skills.getLevel(Skills.SMITHING) < bar.level){
player.sendMessage("You need a smithing level of ${bar.level} to superheat that ore.")
return
}
for (items in bar.ores) {
if (!player.inventory.contains(items.id, items.amount)) {
player.packetDispatch.sendMessage("You do not have the required ores to make this bar.")
return
}
}
player.lock(3)
removeRunes(player)
addXP(player,53.0)
player.audioManager.send(117)
player.interfaceManager.setViewedTab(6)
player.pulseManager.run(SmeltingPulse(player, item, bar, 1, true))
setDelay(player,false)
}
private fun alchemize(player: Player,item: Item,high:Boolean){
if(item.name == "Coins") player.sendMessage("You can't alchemize something that's already gold!").also { return }
if(!item.definition.isTradeable) player.sendMessage("You can't cast this spell on something like that.").also { return }
val coins = Item(995, item.definition.getAlchemyValue(high))
if (coins.amount > 0 && !player.inventory.hasSpaceFor(coins)) {
player.sendMessage("Not enough space in your inventory!")
return
}
player.lock(3)
if(player.inventory.remove(Item(item.id,1))) {
removeRunes(player)
player.audioManager.send(if (high) 97 else 98)
if (high) {
player.visualize(Animation(713), Graphics(113, 5))
} else {
player.visualize(Animation(712), Graphics(112, 5))
}
if(coins.amount > 0)
player.inventory.add(coins)
if((item.id == Items.MAGIC_SHORTBOW_861 || item.id == Items.MAGIC_LONGBOW_859) && high && ZoneBorders(2721,3493,2730,3487).insideBorder(player)){
player.achievementDiaryManager.finishTask(player, DiaryType.SEERS_VILLAGE, 2, 6);
}
addXP(player,if(high) 65.0 else 31.0)
player.interfaceManager.setViewedTab(6)
setDelay(player,false)
}
}
private fun sendTeleport(player: Player, xp: Double, location: Location){
player.teleporter.send(location,TeleportManager.TeleportType.NORMAL)
removeRunes(player)
addXP(player,xp)
setDelay(player,true)
}
}

View file

@ -0,0 +1,72 @@
package rs09.game.node.entity.skill.magic
import core.cache.def.impl.ItemDefinition
import core.game.node.Node
import core.game.node.entity.player.Player
import core.game.node.entity.skill.Skills
import core.game.node.item.Item
import rs09.game.interaction.Listener
import rs09.game.world.GameWorld
abstract class SpellListener(val bookName: String) : Listener {
companion object {
@JvmField
val NPC = -1
@JvmField
val OBJECT = -2
@JvmField
val ITEM = -3
@JvmField
val PLAYER = -4
@JvmField
val NONE = -5
@JvmField
val GROUND_ITEM = -6
}
fun onCast(spellID: Int,type: Int,method: (player: Player, node: Node?) -> Unit){
SpellListeners.add(spellID,type,bookName,method)
}
fun onCast(spellID: Int,type: Int, id: Int,method: (player: Player,node: Node?) -> Unit){
SpellListeners.add(spellID,type,id,bookName,method)
}
fun requires(player: Player, magicLevel: Int = 0, runes: Array<Item> = arrayOf<Item>(), specialEquipment: IntArray = intArrayOf()){
if(player.getAttribute("magic-delay",0) > GameWorld.ticks){
throw IllegalStateException()
}
if(player.skills.getLevel(Skills.MAGIC) < magicLevel){
player.sendMessage("You need a magic level of $magicLevel to cast this spell.")
throw IllegalStateException()
}
for(rune in runes){
if(!SpellUtils.hasRune(player,rune)){
player.sendMessage("You don't have enough ${rune.definition.name.toLowerCase()}s to cast this spell.")
throw IllegalStateException()
}
}
for(item in specialEquipment){
if(!player.equipment.contains(item,1)){
player.sendMessage("You need a ${ItemDefinition.forId(item).name} to cast this.")
throw IllegalStateException()
}
}
}
fun removeRunes(player: Player){
player.inventory.remove(*player.getAttribute("spell:runes",ArrayList<Item>()).toTypedArray())
player.removeAttribute("spell:runes")
}
fun addXP(player: Player,amount:Double){
player.skills.addExperience(Skills.MAGIC,amount)
}
fun setDelay(player: Player,isTeleport: Boolean = false){
if(!isTeleport) player.setAttribute("magic-delay",GameWorld.ticks + 3) else player.setAttribute("magic-delay",GameWorld.ticks + 5)
}
fun interrupt(player: Player){
player.pulseManager.clear()
}
}

View file

@ -0,0 +1,42 @@
package rs09.game.node.entity.skill.magic
import core.game.node.Node
import core.game.node.entity.player.Player
import rs09.game.system.SystemLogger
object SpellListeners {
val castMap = HashMap<String,(Player, Node?) -> Unit>()
fun add(spellID: Int, type: Int, book: String, method: (Player,Node?) -> Unit){
SystemLogger.logInfo("add $book:$spellID:$type")
castMap["$book:$spellID:$type"] = method
}
fun add(spellID: Int, type: Int, id: Int, book: String, method: (Player, Node?) -> Unit){
SystemLogger.logInfo("add $book:$spellID:$type")
castMap["$book:$spellID:$type:$id"] = method
}
fun get(spellID: Int, type: Int, book: String): ((Player,Node?) -> Unit)?{
SystemLogger.logInfo("Getting $book:$spellID:$type")
return castMap["$book:$spellID:$type"]
}
fun get(spellID: Int, type: Int, id: Int, book: String): ((Player,Node?) -> Unit)?{
SystemLogger.logInfo("Getting $book:$spellID:$type:$id")
return castMap["$book:$spellID:$type:$id"]
}
@JvmStatic
fun run(button: Int, type: Int, book: String, player: Player, node: Node? = null){
val method = get(button,type,node?.id ?: 0,book) ?: get(button,type,book) ?: return
try {
method.invoke(player, node)
} catch (e: IllegalStateException){
player.removeAttribute("spell:runes")
return
}
}
}

View file

@ -0,0 +1,93 @@
package rs09.game.node.entity.skill.magic
import core.game.node.entity.player.Player
import core.game.node.entity.skill.magic.CombinationRune
import core.game.node.entity.skill.magic.MagicStaff
import core.game.node.entity.skill.magic.Runes
import core.game.node.item.Item
object SpellUtils {
fun usingStaff(p: Player, rune: Int): Boolean {
val weapon = p.equipment[3] ?: return false
val staff = MagicStaff.forId(rune) ?: return false
val staves = staff.staves
for (id in staves) {
if (weapon.id == id) {
return true
}
}
return false
}
fun hasRune(p:Player,rune:Item):Boolean{
val removeItems = p.getAttribute("spell:runes",ArrayList<Item>())
if(usingStaff(p,rune.id)) return true
if(p.inventory.containsItem(rune)){
removeItems.add(rune)
p.setAttribute("spell:runes",removeItems)
}
val baseAmt = p.inventory.getAmount(rune.id)
var amtRemaining = rune.amount - baseAmt
val possibleComboRunes = CombinationRune.eligibleFor(Runes.forId(rune.id))
for (r in possibleComboRunes) {
if (p.inventory.containsItem(Item(r.id)) && amtRemaining > 0) {
val amt = p.inventory.getAmount(r.id)
if (amtRemaining <= amt) {
removeItems.add(Item(r.id,amtRemaining))
amtRemaining = 0
break
}
removeItems.add(Item(r.id,p.inventory.getAmount(r.id)))
amtRemaining -= p.inventory.getAmount(r.id)
}
}
p.setAttribute("spell:runes",removeItems)
return amtRemaining <= 0
}
fun hasRune(p: Player, item: Item, toRemove: MutableList<Item?>, message: Boolean): Boolean {
if (!usingStaff(p, item.id)) {
val hasBaseRune = p.inventory.contains(item.id, item.amount)
if (!hasBaseRune) {
val baseAmt = p.inventory.getAmount(item.id)
if (baseAmt > 0) {
toRemove.add(Item(item.id, p.inventory.getAmount(item.id)))
}
var amtRemaining = item.amount - baseAmt
val possibleComboRunes = CombinationRune.eligibleFor(Runes.forId(item.id))
for (r in possibleComboRunes) {
if (p.inventory.containsItem(Item(r.id)) && amtRemaining > 0) {
val amt = p.inventory.getAmount(r.id)
if (amtRemaining < amt) {
toRemove.add(Item(r.id, amtRemaining))
amtRemaining = 0
continue
}
amtRemaining -= p.inventory.getAmount(r.id)
toRemove.add(Item(r.id, p.inventory.getAmount(r.id)))
}
}
return if (amtRemaining <= 0) {
true
} else {
p.packetDispatch.sendMessage("You don't have enough " + item.name + "s to cast this spell.")
false
}
}
toRemove.add(item)
return true
}
return true
}
@JvmStatic
fun getBookFromInterface(id: Int): String{
return when(id){
192 -> "modern"
193 -> "ancient"
430 -> "lunar"
else -> "none"
}
}
}

View file

@ -0,0 +1,17 @@
package rs09.game.node.entity.skill.magic.spellconsts
object Modern {
const val HOME_TELEPORT = 0
const val VARROCK_TELEPORT = 15
const val LUMBRIDGE_TELEPORT = 18
const val FALADOR_TELEPORT = 21
const val CAMELOT_TELEPORT = 26
const val TELEPORT_TO_HOUSE = 23
const val ARDOUGNE_TELEPORT = 32
const val WATCHTOWER_TELEPORT = 37
const val TROLLHEIM_TELEPORT = 44
const val APE_ATOLL_TELEPORT = 47
const val LOW_ALCHEMY = 13
const val HIGH_ALCHEMY = 34
const val SUPERHEAT = 25
}

View file

@ -13,6 +13,7 @@ import io.github.classgraph.ClassGraph
import io.github.classgraph.ClassInfo
import rs09.game.interaction.InteractionListener
import rs09.game.interaction.InterfaceListener
import rs09.game.node.entity.skill.magic.SpellListener
import rs09.game.system.SystemLogger
import rs09.game.system.command.Command
import java.util.*
@ -82,6 +83,10 @@ object PluginManager {
val clazz = it.loadClass().newInstance() as InterfaceListener
clazz.defineListeners()
}
result.getSubclasses("rs09.game.node.entity.skill.magic.SpellListener").forEach {
val clazz = it.loadClass().newInstance() as SpellListener
clazz.defineListeners()
}
}
/**