1package com.runehive.game.world.entity.combat.attack.listener;
3import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
4import com.runehive.game.world.entity.mob.npc.Npc;
5import com.runehive.game.world.entity.mob.player.Player;
6import io.github.classgraph.*;
7import org.apache.logging.log4j.LogManager;
8import org.apache.logging.log4j.Logger;
10import java.lang.annotation.Annotation;
11import java.lang.reflect.Constructor;
21 private static final Map<Integer, Set<CombatListenerSet>>
ITEM_LISTENERS =
new HashMap<>();
22 public static final Map<Integer, CombatListener<Npc>>
NPC_LISTENERS =
new HashMap<>();
23 public static final Map<Integer, CombatStrategy<Npc>>
NPC_STRATEGIES =
new HashMap<>();
25 public static void load() {
26 loadItems(
"com.runehive.game.world.entity.combat.attack.listener.item");
27 loadNpcs(
"com.runehive.game.world.entity.combat.attack.listener.npc");
31 try (
final ScanResult scanResult =
35 .enableAnnotationInfo()
40 final MethodInfoList constructorInfos = classInfo.getDeclaredConstructorInfo();
41 final MethodInfo constructorInfo = constructorInfos.get(0);
42 final Constructor<?> constructor = constructorInfo.loadClassAndGetConstructor();
44 final Object instance = constructor.newInstance();
48 final Annotation annotation = annotationInfo.loadClassAndInstantiate();
56 }
catch (Exception ex) {
57 logger.error(String.format(
"Error loading item set combat listener=%s", classInfo.getSimpleName()), ex);
64 private static void loadNpcs(
final String pkg) {
65 try (
final ScanResult scanResult =
69 .enableAnnotationInfo()
74 final MethodInfoList constructorInfos = classInfo.getDeclaredConstructorInfo();
75 final MethodInfo constructorInfo = constructorInfos.get(0);
76 final Constructor<?> constructor = constructorInfo.loadClassAndGetConstructor();
78 final Object instance = constructor.newInstance();
82 final Annotation annotation = annotationInfo.loadClassAndInstantiate();
88 }
catch (Exception ex) {
89 logger.error(String.format(
"Error loading npc combat listener=%s", classInfo.getSimpleName()), ex);
137 private final int[]
set;
153 return Arrays.equals(
other.set,
set) && other.requireAll ==
requireAll;
165 return "ItemSet[set=" + Arrays.toString(
set) +
", requireAll=" +
requireAll +
"]";
boolean equals(Object obj)
final CombatListener< Player > listener
CombatListenerSet(int[] set, boolean requireAll, CombatListener< Player > listener)
static void addListener(Player player, int id)
static void loadNpcs(final String pkg)
static final Map< Integer, Set< CombatListenerSet > > ITEM_LISTENERS
static void removeListener(Player player, int id)
static final Logger logger
static final Map< Integer, CombatStrategy< Npc > > NPC_STRATEGIES
static final Map< Integer, CombatListener< Npc > > NPC_LISTENERS
static void loadItems(final String pkg)
This class represents a character controlled by a player.
final Equipment equipment
Combat< Player > getCombat()
The combat of the mob.
final boolean containsAny(int... identifiers)
Determines if this container contains any identifiers.
final boolean containsAll(int... identifiers)
Determines if this container contains all identifiers.
A combat attack is used to describe what the attacking and defending mobs should do in each stage of ...
boolean requireAll()
Checks if all items are required.
int[] items()
The item ids to attach this listener to.
int[] npcs()
The NPC ids to attach this listener to.