RuneHive-Game
Loading...
Searching...
No Matches
Venenatis.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.UpdatePriority;
6import com.runehive.game.task.TickableTask;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.combat.CombatType;
9import com.runehive.game.world.entity.combat.attack.FightType;
10import com.runehive.game.world.entity.combat.hit.CombatHit;
11import com.runehive.game.world.entity.combat.hit.Hit;
12import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
13import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
14import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
15import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
16import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
17import com.runehive.game.world.entity.mob.Mob;
18import com.runehive.game.world.entity.mob.data.LockType;
19import com.runehive.game.world.entity.mob.npc.Npc;
20import com.runehive.game.world.entity.mob.prayer.Prayer;
21import com.runehive.game.world.entity.skill.Skill;
22import com.runehive.game.world.position.Area;
23import com.runehive.util.RandomUtils;
24
25import static com.runehive.game.world.entity.combat.CombatUtil.*;
26
27/** @author Daniel */
28public class Venenatis extends MultiStrategy {
29 private static final PrayerDrain PRAYER_DRAIN = new PrayerDrain();
30 private static final Magic MAGIC = new Magic();
31 private static final Web WEB = new Web();
32
34 private static final CombatStrategy<Npc>[] NON_MELEE = createStrategyArray(MAGIC, MAGIC, PRAYER_DRAIN, WEB);
35
36 public Venenatis() {
38 }
39
40 @Override
41 public boolean withinDistance(Npc attacker, Mob defender) {
42 if (currentStrategy == NpcMeleeStrategy.get() && !currentStrategy.withinDistance(attacker, defender) && !defender.prayer.isActive(Prayer.PROTECT_FROM_MAGIC)) {
43 currentStrategy = randomStrategy(NON_MELEE);
44 }
45 return currentStrategy.withinDistance(attacker, defender);
46 }
47
48 @Override
49 public boolean canAttack(Npc attacker, Mob defender) {
50 if (!currentStrategy.canAttack(attacker, defender)) {
51 currentStrategy = randomStrategy(FULL_STRATEGIES);
52 }
53 return currentStrategy.canAttack(attacker, defender);
54 }
55
56 @Override
57 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
58// if (hit.isAccurate() && !Area.inMulti(defender)) { TODO: Gotta make the area multi first
59// hit.modifyDamage(damage -> RandomUtils.inclusive(1, 6));
60// }
61
62 currentStrategy.block(attacker, defender, hit, combatType);
63 defender.getCombat().attack(attacker);
64 }
65
66 @Override
67 public void finishOutgoing(Npc attacker, Mob defender) {
69 currentStrategy.finishOutgoing(attacker, defender);
70
72 return;
73
74 if (!NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
75 currentStrategy = randomStrategy(NON_MELEE);
76 } else {
77 currentStrategy = randomStrategy(FULL_STRATEGIES);
78 }
79 }
80
81 private static final class Magic extends NpcMagicStrategy {
82 private static final Animation ANIMATION = new Animation(5322, UpdatePriority.HIGH);
83
85 super(CombatProjectile.getDefinition("Earth Wave"));
86 }
87
88 @Override
89 public Animation getAttackAnimation(Npc attacker, Mob defender) {
90 return ANIMATION;
91 }
92
93 @Override
94 public CombatHit[] getHits(Npc attacker, Mob defender) {
95 return new CombatHit[]{nextMagicHit(attacker, defender)};
96 }
97 }
98
99 private static final class Web extends NpcMagicStrategy {
100 private static final Animation ANIMATION = new Animation(5322, UpdatePriority.HIGH);
101 private static final Graphic GRAPHIC = new Graphic(80, true, UpdatePriority.HIGH);
102
103 Web() {
104 super(CombatProjectile.getDefinition("EMPTY"));
105 }
106
107 @Override
108 public boolean canAttack(Npc attacker, Mob defender) {
109 return !defender.locking.locked() && super.canAttack(attacker, defender);
110 }
111
112 @Override
113 public void hit(Npc attacker, Mob defender, Hit hit) {
114 super.hit(attacker, defender, hit);
115 if (!hit.isAccurate())
116 return;
117 if (defender.isPlayer())
118 defender.getPlayer().message("Venenatis hurls her web at you, sticking you to the ground.");
119 defender.graphic(GRAPHIC);
120 defender.locking.lock(5, LockType.WALKING);
121 }
122
123 @Override
124 public void finishOutgoing(Npc attacker, Mob defender) {
125 attacker.getCombat().setCooldown(0);
126 ((Venenatis) attacker.getStrategy()).currentStrategy = RandomUtils.randomExclude(FULL_STRATEGIES, WEB);
127 }
128
129 @Override
130 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
131 return 0;
132 }
133
134 @Override
135 public Animation getAttackAnimation(Npc attacker, Mob defender) {
136 return ANIMATION;
137 }
138
139 @Override
140 public CombatHit[] getHits(Npc attacker, Mob defender) {
141 return new CombatHit[]{nextMagicHit(attacker, defender, 50)};
142 }
143 }
144
145 private static final class PrayerDrain extends NpcMagicStrategy {
147 super(CombatProjectile.getDefinition("EMPTY"));
148 }
149
150 @Override
151 public void hit(Npc attacker, Mob defender, Hit hit) {
152 if (!hit.isAccurate()) return;
153 World.schedule(new TickableTask(true, 1) {
154 @Override
155 protected void tick() {
156 defender.graphic(new Graphic(172, true, UpdatePriority.HIGH));
157 Skill prayer = defender.skills.get(Skill.PRAYER);
158 prayer.modifyLevel(level -> level * 2 / 3);
159 defender.skills.refresh(Skill.PRAYER);
160
161 if (defender.isPlayer())
162 defender.getPlayer().message("Your prayer has been drained!");
163
164 if (tick == ((CombatHit) hit).getHitsplatDelay() - 1)
165 cancel();
166 }
167 });
168 }
169
170 @Override
171 public CombatHit[] getHits(Npc attacker, Mob defender) {
172 int hitDelay = getHitDelay(attacker, defender, CombatType.MAGIC);
173 return new CombatHit[]{nextMagicHit(attacker, defender, 50, hitDelay, RandomUtils.inclusive(1, 3))};
174 }
175 }
176
177}
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
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
final CombatHit nextMagicHit(T attacker, Mob defender)
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
boolean locked()
Checks if the mob is locked.
Definition Locking.java:52
Handles the mob class.
Definition Mob.java:66
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Optional< Graphic > graphic
Definition Mob.java:91
Represents a non-player character in the in-game world.
Definition Npc.java:29
CombatStrategy< Npc > getStrategy()
The combat strategy of the mob.
Definition Npc.java:161
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
boolean isActive(Prayer... prayers)
Checks if all given prayers are active.
Represents a trainable and usable skill.
Definition Skill.java:18
void modifyLevel(Function< Integer, Integer > function)
Modifies the current level with a given function.
Definition Skill.java:281
static final int PRAYER
The prayer skill id.
Definition Skill.java:36
Skill get(int id)
Gets the skill for an id.
void refresh()
Refreshes all the skills for the mob.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static< T > T randomExclude(T[] array, T exclude)
Returns a pseudo-random int value between inclusive min and inclusive max excluding the specified num...
static int inclusive(int min, int max)
Returns a pseudo-random int value between inclusive min and inclusive max.
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.