God spells now properly drain stats

Charge spell no longer null-dereferences when attempting to refresh it
Manually casting spells no longer changes attack style
This commit is contained in:
Avi Weinstock
2023-03-01 07:48:31 +00:00
committed by Ryan
parent 6d182a5984
commit e1faa64af7
3 changed files with 44 additions and 28 deletions
@@ -47,6 +47,8 @@ public final class ChargeSpell extends MagicSpell {
} }
p.getLocks().lock("charge_cast", 100); p.getLocks().lock("charge_cast", 100);
visualize(entity, target); visualize(entity, target);
// Remove the previous copy of the state in order to refresh the duration if recast before 7 minutes
p.clearState("godcharge");
p.registerState("godcharge").init(); p.registerState("godcharge").init();
p.getPacketDispatch().sendMessage("You feel charged with magic power."); p.getPacketDispatch().sendMessage("You feel charged with magic power.");
return true; return true;
@@ -2,21 +2,22 @@ package content.global.skill.magic.modern;
import core.cache.def.impl.ItemDefinition; import core.cache.def.impl.ItemDefinition;
import core.game.container.impl.EquipmentContainer; import core.game.container.impl.EquipmentContainer;
import core.plugin.Initializable;
import core.game.node.entity.combat.spell.Runes;
import core.game.node.Node; import core.game.node.Node;
import core.game.node.entity.Entity; import core.game.node.entity.Entity;
import core.game.node.entity.combat.BattleState; import core.game.node.entity.combat.BattleState;
import core.game.node.entity.combat.spell.CombatSpell; import core.game.node.entity.combat.spell.CombatSpell;
import core.game.node.entity.combat.spell.Runes;
import core.game.node.entity.combat.spell.SpellType; import core.game.node.entity.combat.spell.SpellType;
import core.game.node.entity.impl.Projectile;
import core.game.node.entity.impl.Animator.Priority; import core.game.node.entity.impl.Animator.Priority;
import core.game.node.entity.impl.Projectile;
import core.game.node.entity.npc.NPC; import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player; import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.SpellBookManager.SpellBook; import core.game.node.entity.player.link.SpellBookManager.SpellBook;
import core.game.node.entity.skill.Skills;
import core.game.node.item.Item; import core.game.node.item.Item;
import core.game.world.update.flag.context.Animation; import core.game.world.update.flag.context.Animation;
import core.game.world.update.flag.context.Graphics; import core.game.world.update.flag.context.Graphics;
import core.plugin.Initializable;
import core.plugin.Plugin; import core.plugin.Plugin;
import org.rs09.consts.Items; import org.rs09.consts.Items;
@@ -32,6 +33,7 @@ public final class GodSpells extends CombatSpell {
* The spell names. * The spell names.
*/ */
private static final String[] NAMES = new String[] { "Saradomin strike", "Guthix claws", "Flames of Zamorak" }; private static final String[] NAMES = new String[] { "Saradomin strike", "Guthix claws", "Flames of Zamorak" };
private static final int[] GOD_STAVES = new int[] { Items.SARADOMIN_STAFF_2415, Items.GUTHIX_STAFF_2416, Items.ZAMORAK_STAFF_2417 };
/** /**
* The start graphic for Air strike. * The start graphic for Air strike.
@@ -105,6 +107,22 @@ public final class GodSpells extends CombatSpell {
super(type, SpellBook.MODERN, 60, 35.0, -1, -1, ANIMATION, start, projectile, end, runes); super(type, SpellBook.MODERN, 60, 35.0, -1, -1, ANIMATION, start, projectile, end, runes);
} }
private int getSpellIndex() {
int index = -1;
switch (runes[1].getAmount()) {
case 2: // Saradomin strike
index = 0;
break;
case 1: // Guthix claws
index = 1;
break;
case 4: // Flames of Zamorak
index = 2;
break;
}
return index;
}
@Override @Override
public boolean meetsRequirements(Entity caster, boolean message, boolean remove) { public boolean meetsRequirements(Entity caster, boolean message, boolean remove) {
if (caster instanceof NPC) { if (caster instanceof NPC) {
@@ -112,21 +130,11 @@ public final class GodSpells extends CombatSpell {
} }
if (caster instanceof Player) { if (caster instanceof Player) {
int staffId = ((Player) caster).getEquipment().getNew(EquipmentContainer.SLOT_WEAPON).getId(); int staffId = ((Player) caster).getEquipment().getNew(EquipmentContainer.SLOT_WEAPON).getId();
int required = -1; int index = getSpellIndex();
int index = 0; if(index < 0) {
switch (runes[1].getAmount()) { return false;
case 2: // Saradomin strike }
required = 2415; int required = GOD_STAVES[index];
break;
case 1: // Guthix claws
required = 2416;
index = 1;
break;
case 4: // Flames of Zamorak
required = 2417;
index = 2;
break;
}
Player p = (Player) caster; Player p = (Player) caster;
if (p.getSavedData().getActivityData().getGodCasts()[index] < 100 && !p.getZoneMonitor().isInZone("mage arena")) { if (p.getSavedData().getActivityData().getGodCasts()[index] < 100 && !p.getZoneMonitor().isInZone("mage arena")) {
p.sendMessage("You need to cast " + NAMES[index] + " " + (100 - p.getSavedData().getActivityData().getGodCasts()[index]) + " more times inside the Mage Arena."); p.sendMessage("You need to cast " + NAMES[index] + " " + (100 - p.getSavedData().getActivityData().getGodCasts()[index]) + " more times inside the Mage Arena.");
@@ -143,6 +151,21 @@ public final class GodSpells extends CombatSpell {
return super.meetsRequirements(caster, message, remove); return super.meetsRequirements(caster, message, remove);
} }
@Override
public void fireEffect(Entity entity, Entity victim, BattleState state) {
switch(getSpellIndex()) {
case 0:
victim.getSkills().decrementPrayerPoints(1);
break;
case 1:
victim.getSkills().drainLevel(Skills.DEFENCE, 0.05, 0.05);
break;
case 2:
victim.getSkills().drainLevel(Skills.MAGIC, 0.05, 0.05);
break;
}
}
@Override @Override
public void visualize(Entity entity, Node target) { public void visualize(Entity entity, Node target) {
super.visualize(entity, target); super.visualize(entity, target);
@@ -157,15 +180,7 @@ public final class GodSpells extends CombatSpell {
@Override @Override
public void visualizeImpact(Entity entity, Entity target, BattleState state) { public void visualizeImpact(Entity entity, Entity target, BattleState state) {
if (entity instanceof Player) { if (entity instanceof Player) {
int index = 0; // Saradomin strike int index = getSpellIndex();
switch (runes[1].getAmount()) {
case 1: // Guthix claws
index = 1;
break;
case 4: // Flames of Zamorak
index = 2;
break;
}
Player p = (Player) entity; Player p = (Player) entity;
if (p.getSavedData().getActivityData().getGodCasts()[index] < 100) { if (p.getSavedData().getActivityData().getGodCasts()[index] < 100) {
p.getSavedData().getActivityData().getGodCasts()[index]++; p.getSavedData().getActivityData().getGodCasts()[index]++;
@@ -226,7 +226,6 @@ abstract class CombatSwingHandler(var type: CombatStyle?) {
entity.attack(victim) entity.attack(victim)
entity.removeAttribute("autocast_component") entity.removeAttribute("autocast_component")
} }
weapEx?.setAttackStyle(1)
weapEx?.updateInterface() weapEx?.updateInterface()
entity.debug("Adjusting attack style") entity.debug("Adjusting attack style")
} }