RuneHive-Game
Loading...
Searching...
No Matches
MagicSpell.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.magic;
2
3import com.runehive.net.packet.out.SendMessage;
4import com.runehive.game.world.entity.mob.Mob;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.entity.skill.Skill;
7import com.runehive.game.world.items.Item;
8
9import java.util.Optional;
10
11/**
12 * Represents a combat spell.
13 * Created by mmaks on 8/24/2017.
14 */
15public abstract class MagicSpell {
16
17 public final int level;
18
19 final double baseExperience;
20
21 public final RequiredRune[] runes;
22
24 this.level = level;
25 this.baseExperience = baseExperience;
26 this.runes = runes;
27 }
28
29 public Optional<Item[]> equipmentRequired() {
30 return Optional.empty();
31 }
32
33 boolean canCast(Mob attacker, Optional<Mob> defender) {
34 if(attacker.isNpc()) {
35 return true;
36 }
37
38 Player player = attacker.getPlayer();
39
40 if(player.skills.getLevel(Skill.MAGIC) < level) {
41 player.send(new SendMessage("You need a Magic level of " + level + " to cast this spell."));
42 player.getCombat().reset();
43 return false;
44 }
45
46 if(equipmentRequired().isPresent() && !player.equipment.containsAll(equipmentRequired().get())) {
47 player.send(new SendMessage("You do not have the required equipment to cast this spell."));
48 player.getCombat().reset();
49 return false;
50 }
51
52 return MagicRune.hasRunes(player, runes);
53 }
54
55}
MagicSpell(int level, double baseExperience, RequiredRune... runes)
boolean canCast(Mob attacker, Optional< Mob > defender)
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
This class represents a character controlled by a player.
Definition Player.java:125
Combat< Player > getCombat()
The combat of the mob.
Definition Player.java:759
Represents a trainable and usable skill.
Definition Skill.java:18
static final int MAGIC
The magic skill id.
Definition Skill.java:39
int getLevel(int id)
Gets the level of a skill.
final boolean containsAll(int... identifiers)
Determines if this container contains all identifiers.
The OutgoingPacket that sends a message to a Players chatbox in the client.
static boolean hasRunes(Player player, Item[] required)