RuneHive-Game
Loading...
Searching...
No Matches
NpcAssistant.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.mob.npc;
2
3import com.runehive.game.task.impl.ForceChatEvent;
4import com.runehive.game.world.World;
5import com.runehive.game.world.entity.combat.Combat;
6import com.runehive.game.world.entity.combat.CombatType;
7import com.runehive.game.world.entity.combat.attack.listener.CombatListener;
8import com.runehive.game.world.entity.combat.attack.listener.CombatListenerManager;
9import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
10import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
11import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
12import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
13import com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
14import com.runehive.game.world.entity.mob.Mob;
15import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
16import com.runehive.util.parser.impl.NpcForceChatParser;
17
18import java.util.Optional;
19
20/**
21 * Method handles small methods for npcs that do not have any parent class.
22 *
23 * @author Daniel
24 */
25public class NpcAssistant {
26
27 /** The npc. */
28 private Npc npc;
29
30 /** Creates a new <code>NpcAssistant<code> */
32 this.npc = npc;
33 }
34
35 /** Handles initializing all the npc assistant methods on login. */
36 public void login() {
37 Combat<Npc> combat = npc.getCombat();
40 npc.pathfinderProjectiles = Mob.pathfinderProjectiles(npc);
41
42 npc.setWidth(definition.getSize());
43 npc.setLength(definition.getSize());
44 npc.setBonuses(definition.getBonuses());
45 npc.mobAnimation.setNpcAnimations(definition);
47
49 if (listener != null) {
50 combat.addListener(listener);
51 }
52
53 npc.setStrategy(NpcUtility.STRATEGIES.getOrDefault(npc.id, () -> loadStrategy(npc).orElse(NpcMeleeStrategy.get())).get());
54 setEvent();
55 }
56
57 public void reloadSkills() {
58 for (int index = 0; index < npc.definition.getSkills().length; index++) {
59 npc.skills.setNpcMaxLevel(index, npc.definition.getSkills()[index]);
60 }
61 }
62
63 public static boolean isDragon(int id) {
64 for (int dragon : NpcUtility.DRAGONS) if (id == dragon) return true;
65 return false;
66 }
67
68 public static Optional<CombatStrategy<Npc>> loadStrategy(Npc npc) {
69 if (!npc.definition.getCombatAttackData().isPresent()) {
70 return Optional.empty();
71 }
72
73 NpcDefinition.CombatAttackData data = npc.definition.getCombatAttackData().get();
74 CombatType type = data.type;
75
76 switch (type) {
77 case RANGED: {
78 CombatProjectile definition = data.getDefinition();
79 if (definition == null) {
80 throw new AssertionError("Could not find ranged projectile for Mob[id=" + npc.id + ", name=" + npc.getName() + "]");
81 }
82 return Optional.of(new NpcRangedStrategy(definition));
83 }
84 case MAGIC: {
85 CombatProjectile definition = data.getDefinition();
86 if (definition == null) {
87 throw new AssertionError("Could not find magic projectile for Mob[id=" + npc.id + ", name=" + npc.getName() + "]");
88 }
89 return Optional.of(new NpcMagicStrategy(definition));
90 }
91 case MELEE:
92 return Optional.of(NpcMeleeStrategy.get());
93 }
94 return Optional.empty();
95 }
96
97 /** Handles the npc respawning. */
98 void respawn() {
99 npc.setVisible(true);
100 npc.skills.restoreAll();
101 npc.getCombat().reset();
102 }
103
104 /** Handles setting all the events for the npc. */
105 private void setEvent() {
106 if (NpcForceChatParser.FORCED_MESSAGES.containsKey(npc.spawnPosition)) {
108 if (forcedMessage.getId() == npc.id) {
109 World.schedule(new ForceChatEvent(npc, forcedMessage));
110 }
111 }
112 }
113
114 public boolean isBoss() {
115 for (int id : NpcUtility.BOSSES) {
116 if (npc.id == id)
117 return true;
118 }
119 return false;
120 }
121
122 public boolean isBandos() {
123 for (int id : NpcUtility.BANDOS) {
124 if (npc.id == id)
125 return true;
126 }
127 return false;
128 }
129
130 public boolean isArmadyl() {
131 for (int id : NpcUtility.ARMADYL) {
132 if (npc.id == id)
133 return true;
134 }
135 return false;
136 }
137
138 public boolean isSaradomin() {
139 for (int id : NpcUtility.SARADOMIN) {
140 if (npc.id == id)
141 return true;
142 }
143 return false;
144 }
145
146 public boolean isZamorak() {
147 for (int id : NpcUtility.ZAMORAK) {
148 if (npc.id == id)
149 return true;
150 }
151 return false;
152 }
153}
An randomevent which starts the forced message randomevent.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
Handles the mob class.
Definition Mob.java:66
NpcAssistant(Npc npc)
Creates a new NpcAssistant
void setEvent()
Handles setting all the events for the npc.
static Optional< CombatStrategy< Npc > > loadStrategy(Npc npc)
void login()
Handles initializing all the npc assistant methods on login.
Represents a non-player character in the in-game world.
Definition Npc.java:29
static final Map< Integer, Supplier< CombatStrategy< Npc > > > STRATEGIES
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
Parses through the npc spawn file and creates Npcs on startup.
static final Map< Position, ForcedMessage > FORCED_MESSAGES
The map containing all the forced messages.
A combat attack is used to describe what the attacking and defending mobs should do in each stage of ...