RuneHive-Game
Loading...
Searching...
No Matches
Porazdir.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss.magearena;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.Projectile;
6import com.runehive.game.UpdatePriority;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.combat.CombatType;
9import com.runehive.game.world.entity.combat.CombatUtil;
10import com.runehive.game.world.entity.combat.attack.FightType;
11import com.runehive.game.world.entity.combat.hit.CombatHit;
12import com.runehive.game.world.entity.combat.hit.Hit;
13import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
14import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
15import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
16import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
17import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
18import com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
19import com.runehive.game.world.entity.mob.Mob;
20import com.runehive.game.world.entity.mob.npc.Npc;
21import com.runehive.game.world.entity.mob.prayer.Prayer;
22import com.runehive.game.world.position.Position;
23import com.runehive.net.packet.out.SendMessage;
24import com.runehive.util.RandomUtils;
25import com.runehive.util.Utility;
26
27import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
28import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
29
30/**
31 * Handles Porazdir Combat Strategy
32 *
33 * @author TJ#5762
34 */
35public class Porazdir extends MultiStrategy {
36 private static Magic MAGIC = new Magic();
37 private static Melee MELEE = new Melee();
38
39 private static final CombatStrategy<Npc>[] FULL_STRATEGIES = createStrategyArray(NpcMeleeStrategy.get(), MAGIC);
40 private static final CombatStrategy<Npc>[] MAGIC_STRATEGIES = createStrategyArray(MAGIC, MAGIC, MAGIC);
41 private static final CombatStrategy<Npc>[] NON_MELEE = createStrategyArray(MAGIC, MELEE, MELEE, MAGIC, MAGIC);
42
43 /** Constructs a new <code>Porazdir</code>. */
44 public Porazdir() {
47 }
48
49 @Override
50 public boolean canAttack(Npc attacker, Mob defender) {
51 if (!currentStrategy.canAttack(attacker, defender)) {
52 currentStrategy = randomStrategy(MAGIC_STRATEGIES);
53 currentStrategy = randomStrategy(NON_MELEE);
54 }
55 return currentStrategy.canAttack(attacker, defender);
56 }
57
58 @Override
59 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
60 currentStrategy.block(attacker, defender, hit, combatType);
61 defender.getCombat().attack(attacker);
62
63 if (!defender.getCombat().isAttacking()) {
64 defender.animate(new Animation(7843, UpdatePriority.VERY_HIGH));
65 defender.graphic(1196);
66 defender.graphic(481);
67 if (Utility.random(1, 25) == 2) {
70 defender.getPlayer().send(new SendMessage("Your overhead prayers have been disabled!"));
71 }
72 CombatUtil.areaAction(attacker, 64, 18, mob -> {
73 if (RandomUtils.success(.65))
74 return;
75
76 World.schedule(2, () -> {
77 Position destination = Utility.randomElement(defender.boundaries);
78 World.sendGraphic(new Graphic(481), destination);
79 attacker.move(destination);
80
81 });
82 });
83 }
84 }
85
86 @Override
87 public void finishOutgoing(Npc attacker, Mob defender) {
88 currentStrategy.finishOutgoing(attacker, defender);
89 if (NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
90 currentStrategy = randomStrategy(FULL_STRATEGIES);
91 } else {
92 currentStrategy = randomStrategy(MAGIC_STRATEGIES);
93 }
94 }
95
96 @Override
97 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
98 return attacker.definition.getAttackDelay();
99 }
100
101 private static class Melee extends NpcRangedStrategy {
102
103 public Melee() {
104 super(CombatProjectile.getDefinition("EMPTY"));
105 }
106
107 @Override
108 public void hit(Npc attacker, Mob defender, Hit hit) {
109 }
110
111 @Override
112 public void attack(Npc attacker, Mob defender, Hit hit) {
113 }
114
115 @Override
116 public void start(Npc attacker, Mob defender, Hit[] hits) {
117
118 attacker.animate(new Animation(7840, UpdatePriority.VERY_HIGH));
119 CombatHit hit = nextMeleeHit(attacker, defender, 21);
120 defender.graphic(1176);
121 CombatUtil.areaAction(attacker, 64, 18, mob -> {
122 mob.damage(nextMagicHit(attacker, defender, 38));
123 });
124
125 }
126
127 @Override
128 public CombatHit[] getHits(Npc attacker, Mob defender) {
129 CombatHit hit = nextRangedHit(attacker, defender, 38);
130 hit.setAccurate(false);
131 return new CombatHit[] { hit };
132 }
133
134 @Override
135 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
136 return roll + 50_000;
137 }
138
139 }
140
141 /** Jisticiar magic strategy. */
142 private static class Magic extends NpcMagicStrategy {
143 public Magic() {
144 super(CombatProjectile.getDefinition("EMPTY"));
145 }
146
147 @Override
148 public void hit(Npc attacker, Mob defender, Hit hit) {
149 }
150
151 @Override
152 public void attack(Npc attacker, Mob defender, Hit hit) {
153 }
154
155 @Override
156 public void start(Npc attacker, Mob defender, Hit[] hits) {
157 Projectile projectile = new Projectile(1378, 50, 80, 85, 25);
158 attacker.animate(new Animation(7841, UpdatePriority.VERY_HIGH));
159 CombatUtil.areaAction(attacker, 64, 18, mob -> {
160 projectile.send(attacker, defender);
161 defender.graphic(157);
162 mob.damage(nextMagicHit(attacker, defender, 35));
163
164 });
165
166 if (Utility.random(0, 10) == 1) {
167 attacker.animate(new Animation(7849, UpdatePriority.VERY_HIGH));
168 attacker.graphic(new Graphic(1296, UpdatePriority.VERY_HIGH));
169 attacker.heal(130);
170 attacker.speak("Time To HEAL!");
171 defender.getPlayer().send(new SendMessage("Porazdir heals himself!"));
172
173 }
174
175 }
176
177 @Override
178 public CombatHit[] getHits(Npc attacker, Mob defender) {
179 CombatHit hit = nextMagicHit(attacker, defender, 38);
180 hit.setAccurate(false);
181 return new CombatHit[] { hit };
182 }
183
184 @Override
185 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
186 return roll + 50_000;
187 }
188 }
189
190}
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
static void sendGraphic(Graphic graphic, Position position, int instance)
Sends a graphic to the world.
Definition World.java:268
A collection of util methods and constants related to combat.
static void areaAction(Mob mob, Consumer< Mob > action)
Executes an action for mobs within a 3x3 square, including the source mob.
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 nextRangedHit(T attacker, Mob defender)
final CombatHit nextMagicHit(T attacker, Mob defender)
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Definition Porazdir.java:97
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
Definition Porazdir.java:59
Handles the mob class.
Definition Mob.java:66
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
Optional< Graphic > graphic
Definition Mob.java:91
Represents a non-player character in the in-game world.
Definition Npc.java:29
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
void deactivate(Prayer... prayers)
Sends the dectivate prayer packet to the client.
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.