66public class Npc
extends Mob {
67 private static final Logger logger = LogManager.getLogger(Npc.class);
70 public boolean canAttack;
75 private CombatStrategy<Npc> strategy;
77 private final Combat<Npc> combat =
new Combat<>(
this);
78 private int walkCooldown;
80 public int walkingRadius;
81 public final AtomicInteger atomicPlayerCount =
new AtomicInteger(0);
83 public Npc(
int id,
Position position) {
84 this(id, position, 0,
Mob.DEFAULT_INSTANCE,
Direction.SOUTH);
87 public Npc(
int id,
int instance,
Position position) {
90 this.instance = instance;
92 this.spawnPosition = position;
93 this.walkingRadius = 0;
96 public Npc(
int id,
Position position,
int walkingRadius,
int instance,
Direction direction) {
99 this.instance = instance;
100 this.faceDirection = direction;
101 this.spawnPosition = position.copy();
102 this.walkingRadius = walkingRadius;
108 this.faceDirection = direction;
109 this.spawnPosition = position.copy();
110 this.walkingRadius = walkingRadius;
119 if (sequence % 110 == 0) {
120 for (
int index = 0; index <= 6; index++) {
121 skills.regress(index);
125 if (definition.isAttackable() && (definition.isAggressive() ||
Area.inWilderness(
this))) {
126 getCombat().checkAggression(spawnPosition);
129 if (!isDead() && !locking.locked(
PacketType.MOVEMENT) && combat.getDefender() ==
null && !combat.inCombat() && walk) {
130 if (walkCooldown > 0) {
135 walkCooldown = RandomUtils.inclusive(10, 30);
139 if (definition.isAttackable()) {
142 }
catch (Exception ex) {
143 logger.error(String.format(
"error npc.sequence(): %s",
this), ex);
150 if (!isRegistered() && !
World.getNpcs().contains(
this)) {
151 int w = walkingRadius *
width();
152 int l = walkingRadius *
length();
154 walk = walkingRadius != 0;
155 boundaries =
Utility.getInnerBoundaries(spawnPosition.transform(-w, -l), w * 2, l * 2);
156 setRegistered(
World.getNpcs().add(
this));
158 npcAssistant.login();
164 if (isRegistered()) {
176 region.removeNpc(
this);
180 public void onStep() {
186 Activity.forActivity(
this, activity -> activity.onDeath(
this));
204 return definition ==
null ?
"Unknown" : definition.getName();
208 public int getBonus(
int index) {
209 return definition.getBonuses()[index];
213 public int[] getBonuses() {
223 public int hashCode() {
224 return Objects.hash(getIndex(), definition);
228 public boolean equals(Object obj) {
229 if (obj instanceof
Npc) {
231 return id == other.id && getIndex() == other.getIndex() && spawnPosition.equals(other.spawnPosition);
237 public String toString() {
238 return String.format(
"Npc[name=" +
getName() +
" index=%d id=%d registered=%s instance=%s %s]", getIndex(),
id, isRegistered(), instance,
getPosition());
242 return definition.getDeathTimer();
246 return definition.isRetaliate();
249 public void setStrategy(CombatStrategy<Npc> strategy) {
250 this.strategy = strategy;
254 public int getPriorityIndex() {
255 return -getListIndex();
262 public boolean pyroSnowAttack;