RuneHive-Game
Loading...
Searching...
No Matches
RangedStrategy.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.basic;
2
3import com.runehive.content.activity.Activity;
4import com.runehive.content.activity.impl.kraken.KrakenActivity;
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 RangedStrategy<T extends Mob> extends CombatStrategy<T> {
18
19 @Override
20 public boolean withinDistance(T attacker, Mob defender) {
21 if (attacker.isPlayer() && Activity.evaluate(attacker.getPlayer(), it -> it instanceof KrakenActivity)) {
22 return true;
23 }
24
25 FightType fightType = attacker.getCombat().getFightType();
26
27 int distance = getAttackDistance(attacker, fightType);
28
29 return Utility.inRange(attacker, defender, distance)
30 && (SimplePathChecker.checkProjectile(attacker, defender)
31 || SimplePathChecker.checkProjectile(defender, attacker));
32 }
33
34 protected static void addCombatExperience(Player player, Hit... hits) {
35 int exp = 0;
36 for (Hit hit : hits) {
37 if (hit.getDamage() <= 0) continue;
38 exp += hit.getDamage();
39 }
40
41 exp *= player.experienceRate;
42 if (player.getCombat().getFightType() == FightType.FLARE) {
43 exp *= 4;
44 player.skills.addExperience(Skill.HITPOINTS, exp / 3);
45 player.skills.addExperience(Skill.RANGED, exp);
46 } else if (player.getCombat().getFightType() == FightType.SCORCH) {
47 exp *= 4;
48 player.skills.addExperience(Skill.HITPOINTS, exp / 3);
49 player.skills.addExperience(Skill.STRENGTH, exp);
50 } else if (player.getCombat().getFightType() == FightType.BLAZE) {
51 exp *= 2;
52 player.skills.addExperience(Skill.HITPOINTS, exp / 3);
53 player.skills.addExperience(Skill.MAGIC, exp);
54 } else {
55 player.skills.addExperience(Skill.HITPOINTS, exp / 3);
56
57 switch (player.getCombat().getFightType().getStyle()) {
58 case DEFENSIVE:
59 exp /= 2;
60 player.skills.addExperience(Skill.RANGED, exp);
61 player.skills.addExperience(Skill.DEFENCE, exp);
62 break;
63 default:
64 player.skills.addExperience(Skill.RANGED, exp);
65 break;
66 }
67 }
68 }
69
70}
A Activity object constructs an in-game activity and sequences it through the start() and finish() me...
Definition Activity.java:31
static boolean evaluate(Mob mob, Predicate< Activity > predicate)
Definition Activity.java:74
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.
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 RANGED
The ranged skill id.
Definition Skill.java:33
static final int DEFENCE
The defence skill id.
Definition Skill.java:24
static final int MAGIC
The magic skill id.
Definition Skill.java:39
static final int STRENGTH
The strength skill id.
Definition Skill.java:27
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.