1package com.osroyale.game.world.entity.combat.strategy.player;
3import com.osroyale.content.itemaction.impl.ThammaronsSceptre;
4import com.osroyale.game.Animation;
5import com.osroyale.game.Graphic;
6import com.osroyale.game.UpdatePriority;
7import com.osroyale.game.world.entity.combat.CombatImpact;
8import com.osroyale.game.world.entity.combat.CombatType;
9import com.osroyale.game.world.entity.combat.attack.FightType;
10import com.osroyale.game.world.entity.combat.hit.CombatHit;
11import com.osroyale.game.world.entity.combat.hit.Hit;
12import com.osroyale.game.world.entity.combat.magic.CombatSpell;
13import com.osroyale.game.world.entity.combat.magic.MagicRune;
14import com.osroyale.game.world.entity.combat.strategy.basic.MagicStrategy;
15import com.osroyale.game.world.entity.mob.Mob;
16import com.osroyale.game.world.entity.mob.player.Player;
17import com.osroyale.game.world.entity.mob.player.PlayerRight;
18import com.osroyale.game.world.entity.skill.Skill;
19import com.osroyale.game.world.items.Item;
20import com.osroyale.game.world.items.containers.equipment.Equipment;
21import com.osroyale.net.packet.out.SendMessage;
22import com.osroyale.util.RandomUtils;
24import java.util.Collections;
25import java.util.LinkedList;
27import java.util.function.Consumer;
28import java.util.function.Predicate;
30import static com.osroyale.game.world.items.containers.equipment.Equipment.WEAPON_SLOT;
32public class PlayerMagicStrategy
extends MagicStrategy<Player> {
35 private final CombatSpell spell;
38 public PlayerMagicStrategy(CombatSpell spell) {
43 public boolean canAttack(Player attacker, Mob defender) {
44 if (defender.isPlayer() && defender.getPlayer().isBot && !PlayerRight.isOwner(defender.getPlayer())) {
45 attacker.message(
"You can't attack bots with magic.");
49 if (spell == CombatSpell.TELE_BLOCK) {
50 if (defender.isPlayer()) {
51 if (defender.getPlayer().isTeleblocked()) {
52 attacker.message(
"This player is already affected by this spell!");
55 }
else if (defender.isNpc()) {
56 attacker.message(
"You can't teleblock a npc!");
61 if (spell == CombatSpell.CRUMBLE_UNDEAD) {
62 if (defender.isPlayer()) {
63 attacker.message(
"You can not use the crumble undead spell on a player!");
67 if (defender.isNpc()) {
68 String name = defender.getName().toLowerCase();
70 if (!(name.contains(
"zombified") || name.contains(
"undead") || name.contains(
"zombie") || name.contains(
"skeleton") || name.contains(
"ghost") || name.contains(
"shade"))) {
71 attacker.message(
"This spell only affects skeletons, zombies, ghosts and shades");
77 if ( spell.canCast(attacker, defender)) {
81 attacker.send(
new SendMessage(
"You need some runes to cast this spell."));
82 attacker.getCombat().reset();
87 public void start(Player attacker, Mob defender, Hit[] hits) {
88 if (attacker.getCombat().getDefender() == defender) {
89 attacker.animate(getAttackAnimation(attacker, defender),
true);
90 spell.getStart().ifPresent(attacker::graphic);
92 int projectileDuration = spell.sendProjectile(attacker, defender);
93 if (projectileDuration == 0) {
94 final int distance = attacker.getPosition().getChebyshevDistance(defender.getPosition());
95 final int duration = distance * 10;
96 projectileDuration = 51 + duration;
99 final Graphic endGraphic = getEndGraphic(spell.getEnd(), missed(hits),
SPLASH, projectileDuration);
100 if (endGraphic !=
null) {
101 defender.graphic(endGraphic);
104 if (spell.getEffect().isPresent()) {
105 List<Hit> extra =
new LinkedList<>();
106 for (Hit hit : hits) {
107 Predicate<CombatImpact> filter = effect -> effect.canAffect(attacker, defender, hit);
108 Consumer<CombatImpact> execute = effect -> effect.impact(attacker, defender, hit, extra);
109 spell.getEffect().filter(filter).ifPresent(execute);
112 if (!defender.isPlayer() || !PlayerRight.isIronman(attacker)) {
113 if (extra.isEmpty()) {
114 Collections.addAll(extra, hits);
115 addCombatExperience(attacker, spell.getBaseExperience(), extra.toArray(
new Hit[0]));
117 addCombatExperience(attacker, spell.getBaseExperience(), hits);
120 attacker.skills.addExperience(Skill.MAGIC, spell.getBaseExperience());
122 }
else if (!defender.isPlayer() || !PlayerRight.isIronman(attacker)) {
123 addCombatExperience(attacker, spell.getBaseExperience(), hits);
125 attacker.skills.addExperience(Skill.MAGIC, spell.getBaseExperience());
128 if ((!attacker.equipment.containsAny(11791, 12904) || !RandomUtils.success(0.125))) {
129 MagicRune.remove(attacker, spell.getRunes());
132 if (attacker.isSingleCast()) {
133 attacker.setSingleCast(
null);
134 attacker.getCombat().reset();
135 attacker.interact(defender);
138 Item weapon = attacker.equipment.get(Equipment.WEAPON_SLOT);
140 switch(weapon.getId()) {
141 case ThammaronsSceptre.THAMMARONS_SCEPTRE_CHARGED_ID -> {
142 attacker.thammoranSceptreCharges--;
150 public void hit(Player attacker, Mob defender, Hit hit) {
151 if (!attacker.isSingleCast() && !attacker.isAutocast()) {
152 attacker.resetFace();
155 if (hit.isAccurate()) {
156 if (attacker.equipment.retrieve(WEAPON_SLOT).filter(item -> item.getId() == 12904).isPresent() && RandomUtils.success(0.25)) {
163 public void hitsplat(Player attacker, Mob defender, Hit hit) {
167 public CombatHit[] getHits(Player attacker, Mob defender) {
168 CombatHit combatHit = nextMagicHit(attacker, defender, spell.getCombatProjectile());
170 if (spell == CombatSpell.CRUMBLE_UNDEAD && defender.getName().equalsIgnoreCase(
"zombified spawn")) {
171 combatHit.setDamage(defender.getCurrentHealth());
174 return new CombatHit[]{combatHit};
178 public int getAttackDelay(Player attacker, Mob defender, FightType fightType) {
183 public int getAttackDistance(Player attacker, FightType fightType) {
188 public Animation getAttackAnimation(Player attacker, Mob defender) {
189 if (spell.getAnimation().isPresent()) {
190 return spell.getAnimation().get();
193 FightType fightType = attacker.getCombat().getFightType();
194 int animation = fightType.getAnimation();
196 if (attacker.equipment.hasShield()) {
197 Item weapon = attacker.equipment.getShield();
198 animation = weapon.getAttackAnimation(fightType).orElse(animation);
201 if (attacker.equipment.hasWeapon()) {
202 Item weapon = attacker.equipment.getWeapon();
203 animation = weapon.getAttackAnimation(fightType).orElse(animation);
206 return new Animation(animation, UpdatePriority.HIGH);
210 public CombatType getCombatType() {
211 return CombatType.MAGIC;
214 public CombatSpell getSpell() {
static final Graphic SPLASH