93 lines
3.9 KiB
JavaScript
93 lines
3.9 KiB
JavaScript
const EntityNewPacket = require("../Packets/EntityNew");
|
|
const AttackInformationPacket = require("../Packets/AttackInformation");
|
|
const AttackerInformationPacket = require("../Packets/AttackerInformation");
|
|
const AttackingPacket = require("../Packets/Attacking");
|
|
const AttackAbortedPacket = require("../Packets/AttackAborted");
|
|
const EntityDiePacket = require("../Packets/EntityDie");
|
|
const EffectAddPacket = require("../Packets/EffectAdd");
|
|
const EntitySpeedChangedPacket = require("../Packets/EntitySpeedChanged");
|
|
const HealthChangedPacket = require("../Packets/HealthChanged");
|
|
const HealthChangedAuthorlessPacket = require("../Packets/HealthChangedAuthorless");
|
|
const MiniMapEntryMovePacket = require("../Packets/MiniMapEntryMove");
|
|
const MiniMapEntryRemovePacket = require("../Packets/MiniMapEntryRemove");
|
|
|
|
const NewDestinationNodePacket = require("../Packets/NewDestinationNode");
|
|
|
|
const constants = require("../Data/constants");
|
|
const { EVENTS } = constants;
|
|
const { EVENT_DESTINATION_REACHED, EVENT_ATTACK_STARTED, EVENT_HEALTH_CHANGED, EVENT_ATTACKING, EVENT_ATTACK_ABORTED_BY_USER, EVENT_DIE, EVENT_SPEED_UPDATE, EVENT_DESTINATION_NEW, EVENT_EFFECT_ADD, EVENT_ATTACK_BAR } = EVENTS;
|
|
|
|
module.exports = function nonPlayerCharacterNetworkListeners(map, data) {
|
|
const { npc, npcSpawnProperties } = data;
|
|
|
|
const packet = EntityNewPacket.npc(npcSpawnProperties);
|
|
map.registerNetworkPacket(npc.id, packet.buffer ? packet.buffer : packet);
|
|
|
|
npc.on(EVENT_DESTINATION_REACHED, function (data) {
|
|
NPCWorker.postMessage({
|
|
position: npc.position,
|
|
mapID: map.id,
|
|
id: npc.id,
|
|
preSelectedDestinationNode: data.destination,
|
|
predefinedArea: data.predefinedArea
|
|
});
|
|
});
|
|
|
|
npc.on(EVENT_ATTACK_STARTED, function (data, author) {
|
|
const packet = AttackInformationPacket(data);
|
|
this.map.registerIndividualNetworkPacket(author, packet);
|
|
});
|
|
|
|
npc.on(EVENT_ATTACK_BAR, function (data, author) {
|
|
const packet = AttackerInformationPacket(data);
|
|
this.map.registerIndividualNetworkPacket(author, packet);
|
|
});
|
|
|
|
npc.on(EVENT_HEALTH_CHANGED, function (data, author) {
|
|
const packet = HealthChangedAuthorlessPacket(data);
|
|
this.map.registerNetworkPacket(this.id, packet);
|
|
});
|
|
|
|
npc.on(EVENT_ATTACKING, function (data, author) {
|
|
const _packet = AttackingPacket(data);
|
|
const packet = HealthChangedPacket(data);
|
|
this.map.registerNetworkPacket(this.id, [_packet, packet], [1, 1]);
|
|
});
|
|
|
|
npc.on(EVENT_ATTACK_ABORTED_BY_USER, function (data, author) {
|
|
const packet = AttackAbortedPacket(data);
|
|
this.map.registerNetworkPacket(this.id, packet);
|
|
});
|
|
|
|
npc.on(EVENT_DIE, function (data, author) {
|
|
const packet = EntityDiePacket(data);
|
|
this.map.registerNetworkPacket(this.id, packet, [1]);
|
|
});
|
|
|
|
npc.on(EVENT_SPEED_UPDATE, function (data, author) {
|
|
const packet = EntitySpeedChangedPacket(data);
|
|
this.map.registerNetworkPacket(this.id, packet);
|
|
});
|
|
|
|
npc.on(EVENT_DESTINATION_NEW, function (data, author) {
|
|
const packet = NewDestinationNodePacket(data);
|
|
this.map.registerNetworkPacket(this.id, packet, [59]);
|
|
});
|
|
|
|
npc.on(EVENT_EFFECT_ADD, function (data, author) {
|
|
const packet = EffectAddPacket(data);
|
|
this.map.registerNetworkPacket(this.id, packet);
|
|
});
|
|
|
|
npc.on("miniMapDotRemoveTest", function (data, author) {
|
|
const packet = MiniMapEntryRemovePacket(data);
|
|
this.map.registerGlobalNetworkPacket(this.id, packet);
|
|
});
|
|
|
|
npc.on("miniMapMove", function (data, author) {
|
|
const packet = MiniMapEntryMovePacket(data);
|
|
this.map.registerGlobalNetworkPacket(this.id, packet);
|
|
});
|
|
|
|
npc.determineMovementState();
|
|
}; |