RuneHive-Game
Loading...
Searching...
No Matches
MagicStrategy.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.basic;
2
3import com.runehive.Config;
4import com.runehive.game.Graphic;
5import com.runehive.game.world.entity.combat.attack.FightType;
6import com.runehive.game.world.entity.combat.hit.Hit;
7import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
8import com.runehive.game.world.entity.mob.Mob;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.game.world.entity.skill.Skill;
11import com.runehive.game.world.pathfinding.path.SimplePathChecker;
12import com.runehive.util.Utility;
13
14/**
15 * @author Michael | Chex
16 */
17public abstract class MagicStrategy<T extends Mob> extends CombatStrategy<T> {
18
19 /** The spell splash graphic. */
20 public static final Graphic SPLASH = new Graphic(85, 0, Graphic.HIGH_HEIGHT/*96*/);
21
22 @Override
23 public boolean withinDistance(T attacker, Mob defender) {
24 FightType fightType = attacker.getCombat().getFightType();
25 int distance = getAttackDistance(attacker, fightType);
26
27 return Utility.inRange(attacker, defender, distance)
28 && (SimplePathChecker.checkProjectile(attacker, defender)
29 || SimplePathChecker.checkProjectile(defender, attacker));
30 }
31
32 protected static void addCombatExperience(Player player, double base, Hit... hits) {
33 int exp = 0;
34 for (Hit hit : hits) {
35 if (hit.getDamage() <= 0) continue;
36 exp += hit.getDamage();
37 }
38
40 exp += base;
41 player.skills.addExperience(Skill.MAGIC, exp);
42 player.skills.addExperience(Skill.HITPOINTS, exp / 3);
43 }
44
45}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double COMBAT_MODIFICATION
The experience modification for combat.
Definition Config.java:244
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
static final int HIGH_HEIGHT
Definition Graphic.java:12
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
abstract int getAttackDistance(T attacker, FightType fightType)
void hit(T attacker, Mob defender, Hit hit)
Called when the attacking mob performs an attack on the defender.
static final Graphic SPLASH
The spell splash graphic.
static void addCombatExperience(Player player, double base, Hit... hits)
Handles the mob class.
Definition Mob.java:66
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int MAGIC
The magic skill id.
Definition Skill.java:39
static final int HITPOINTS
The hitpoints skill id.
Definition Skill.java:30
Represents a PathFinder which is meant to be used to check projectiles passage in a straight line.
static boolean checkProjectile(Interactable source, Interactable target)
Handles miscellaneous methods.
Definition Utility.java:27
static boolean inRange(int absX, int absY, int size, int targetX, int targetY, int targetSize, int distance)
Definition Utility.java:910
The enumerated type whose elements represent the fighting types.