RuneHive-Game
Loading...
Searching...
No Matches
DragonfireShieldStrategy.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.player.custom;
2
3import com.runehive.Config;
4import com.runehive.game.Animation;
5import com.runehive.game.UpdatePriority;
6import com.runehive.game.world.entity.combat.CombatType;
7import com.runehive.game.world.entity.combat.CombatUtil;
8import com.runehive.game.world.entity.combat.attack.FightType;
9import com.runehive.game.world.entity.combat.hit.CombatHit;
10import com.runehive.game.world.entity.combat.hit.Hit;
11import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
12import com.runehive.game.world.entity.combat.strategy.basic.MagicStrategy;
13import com.runehive.game.world.entity.mob.Mob;
14import com.runehive.game.world.entity.mob.player.Player;
15import com.runehive.game.world.entity.skill.Skill;
16
17import static com.runehive.game.world.entity.combat.CombatUtil.getHitDelay;
18
19public class DragonfireShieldStrategy extends MagicStrategy<Player> {
22
23 static {
24 try {
25 PROJECTILE = CombatProjectile.getDefinition("Dragonfire Shield");
26 } catch (Exception e) {
27 e.printStackTrace();
28 }
29 }
30
31 @Override
32 public CombatHit[] getHits(Player attacker, Mob defender) {
33 int hitDelay = getHitDelay(attacker, defender, CombatType.MAGIC) + 2;
34 int hitsplatDelay = 1;
35 return new CombatHit[] { CombatUtil.generateDragonfire(attacker, defender, 25, hitDelay, hitsplatDelay, false) };
36 }
37
38 @Override
39 public boolean canAttack(Player attacker, Mob defender) {
40 if (attacker.dragonfireCharges == 0) {
41 attacker.message("You have no charges to do this!");
42 return false;
43 }
44 return true;
45 }
46
47 @Override
48 public void start(Player attacker, Mob defender, Hit[] hits) {
49 PROJECTILE.getAnimation().ifPresent(animation -> attacker.animate(animation, true));
50 PROJECTILE.getStart().ifPresent(attacker::graphic);
51
52 int damage = 0;
53 for (Hit hit : hits) {
54 damage += hit.getDamage();
55 }
56
57 if (damage > 0) {
59 attacker.skills.addExperience(Skill.DEFENCE, damage / 2);
60 if (defender.isNpc()) {
61 attacker.skills.addExperience(Skill.HITPOINTS, damage / 3);
62 attacker.skills.addExperience(Skill.MAGIC, damage / 2);
63 }
64 }
65 attacker.interact(defender);
66 }
67
68 @Override
69 public void attack(Player attacker, Mob defender, Hit hit) {
70 PROJECTILE.sendProjectile(attacker, defender);
71 attacker.dragonfireCharges--;
72 }
73
74 @Override
75 public void hit(Player attacker, Mob defender, Hit hit) {
76 PROJECTILE.getEnd().ifPresent(defender::graphic);
77 attacker.resetFace();
78 }
79
80 @Override
81 public void hitsplat(Player attacker, Mob defender, Hit hit) {
82 }
83
84 @Override
85 public Animation getAttackAnimation(Player attacker, Mob defender) {
86 return new Animation(6696, UpdatePriority.HIGH);
87 }
88
89 @Override
90 public int getAttackDelay(Player attacker, Mob defender, FightType fightType) {
91 return 5;
92 }
93
94 @Override
95 public int getAttackDistance(Player attacker, FightType fightType) {
96 return 10;
97 }
98
99 @Override
101 return CombatType.MAGIC;
102 }
103
104 public static DragonfireShieldStrategy get() {
105 return INSTANCE;
106 }
107
108}
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
Class that models a single animation used by an entity.
A collection of util methods and constants related to combat.
static CombatHit generateDragonfire(Mob attacker, Mob defender, int max, boolean prayer)
A wrapper for a Hit object, adding additional variables for hit and hitsplat delays.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Handles the mob class.
Definition Mob.java:66
void interact(Mob mob)
Sets the mob interacting with another mob.
Definition Mob.java:278
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
void resetFace()
Resets the mob's face location.
Definition Mob.java:330
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 DEFENCE
The defence skill id.
Definition Skill.java:24
static final int MAGIC
The magic skill id.
Definition Skill.java:39
static final int HITPOINTS
The hitpoints skill id.
Definition Skill.java:30
void addExperience(int id, double experience)
Adds experience to a given skill.
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.