RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
NpcAssistant.java
1package com.osroyale.game.world.entity.mob.npc;
2
3import com.osroyale.game.task.impl.ForceChatEvent;
4import com.osroyale.game.world.World;
5import com.osroyale.game.world.entity.combat.Combat;
6import com.osroyale.game.world.entity.combat.CombatType;
7import com.osroyale.game.world.entity.combat.attack.listener.CombatListener;
8import com.osroyale.game.world.entity.combat.attack.listener.CombatListenerManager;
9import com.osroyale.game.world.entity.combat.projectile.CombatProjectile;
10import com.osroyale.game.world.entity.combat.strategy.CombatStrategy;
11import com.osroyale.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
12import com.osroyale.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
13import com.osroyale.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
14import com.osroyale.game.world.entity.mob.Mob;
15import com.osroyale.game.world.entity.mob.npc.definition.NpcDefinition;
16import com.osroyale.util.parser.impl.NpcForceChatParser;
17
18import java.util.Optional;
19
58
59public class NpcAssistant {
60
62 private Npc npc;
63
65 NpcAssistant(Npc npc) {
66 this.npc = npc;
67 }
68
70 public void login() {
71 Combat<Npc> combat = npc.getCombat();
72 NpcDefinition definition = NpcDefinition.get(npc.id);
73 npc.definition = definition;
74 npc.pathfinderProjectiles = Mob.pathfinderProjectiles(npc);
75
76 npc.setWidth(definition.getSize());
77 npc.setLength(definition.getSize());
78 npc.setBonuses(definition.getBonuses());
79 npc.mobAnimation.setNpcAnimations(definition);
80 reloadSkills();
81
82 CombatListener<Npc> listener = CombatListenerManager.NPC_LISTENERS.get(npc.id);
83 if (listener != null) {
84 combat.addListener(listener);
85 }
86
87 npc.setStrategy(NpcUtility.STRATEGIES.getOrDefault(npc.id, () -> loadStrategy(npc).orElse(NpcMeleeStrategy.get())).get());
88 setEvent();
89 }
90
91 public void reloadSkills() {
92 for (int index = 0; index < npc.definition.getSkills().length; index++) {
93 npc.skills.setNpcMaxLevel(index, npc.definition.getSkills()[index]);
94 }
95 }
96
97 public static boolean isDragon(int id) {
98 for (int dragon : NpcUtility.DRAGONS) if (id == dragon) return true;
99 return false;
100 }
101
102 public static Optional<CombatStrategy<Npc>> loadStrategy(Npc npc) {
103 if (!npc.definition.getCombatAttackData().isPresent()) {
104 return Optional.empty();
105 }
106
107 NpcDefinition.CombatAttackData data = npc.definition.getCombatAttackData().get();
108 CombatType type = data.type;
109
110 switch (type) {
111 case RANGED: {
112 CombatProjectile definition = data.getDefinition();
113 if (definition == null) {
114 throw new AssertionError("Could not find ranged projectile for Mob[id=" + npc.id + ", name=" + npc.getName() + "]");
115 }
116 return Optional.of(new NpcRangedStrategy(definition));
117 }
118 case MAGIC: {
119 CombatProjectile definition = data.getDefinition();
120 if (definition == null) {
121 throw new AssertionError("Could not find magic projectile for Mob[id=" + npc.id + ", name=" + npc.getName() + "]");
122 }
123 return Optional.of(new NpcMagicStrategy(definition));
124 }
125 case MELEE:
126 return Optional.of(NpcMeleeStrategy.get());
127 }
128 return Optional.empty();
129 }
130
132 void respawn() {
133 npc.setVisible(true);
134 npc.skills.restoreAll();
135 npc.getCombat().reset();
136 }
137
139 private void setEvent() {
140 if (NpcForceChatParser.FORCED_MESSAGES.containsKey(npc.spawnPosition)) {
141 NpcForceChatParser.ForcedMessage forcedMessage = NpcForceChatParser.FORCED_MESSAGES.get(npc.spawnPosition);
142 if (forcedMessage.getId() == npc.id) {
143 World.schedule(new ForceChatEvent(npc, forcedMessage));
144 }
145 }
146 }
147
148 public boolean isBoss() {
149 for (int id : NpcUtility.BOSSES) {
150 if (npc.id == id)
151 return true;
152 }
153 return false;
154 }
155
156 public boolean isBandos() {
157 for (int id : NpcUtility.BANDOS) {
158 if (npc.id == id)
159 return true;
160 }
161 return false;
162 }
163
164 public boolean isArmadyl() {
165 for (int id : NpcUtility.ARMADYL) {
166 if (npc.id == id)
167 return true;
168 }
169 return false;
170 }
171
172 public boolean isSaradomin() {
173 for (int id : NpcUtility.SARADOMIN) {
174 if (npc.id == id)
175 return true;
176 }
177 return false;
178 }
179
180 public boolean isZamorak() {
181 for (int id : NpcUtility.ZAMORAK) {
182 if (npc.id == id)
183 return true;
184 }
185 return false;
186 }
187}