Initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
const getFixedDate = require("../Utility/getFixedDate");
|
||||
|
||||
const Game = require("../Game/Game");
|
||||
const { maps } = Game;
|
||||
|
||||
const constants = require("../Data/constants");
|
||||
const { TYPES } = constants;
|
||||
const { ENTITY_TYPE_NPC } = TYPES;
|
||||
|
||||
const queries = require("../Data/queries");
|
||||
const { QUERY_FETCH_NPC_SPAWN } = queries;
|
||||
|
||||
const NPCWorker = global.NPCWorker;
|
||||
|
||||
const NPC = require("../Game/NPC");
|
||||
|
||||
const nonPlayerCharacterNetworkListeners = require("./NPCTest");
|
||||
|
||||
const messages = {
|
||||
1: function (data) {
|
||||
const { path, id, mapID } = data;
|
||||
const map = maps[mapID - 1];
|
||||
const npc = map.npcs.get(id);
|
||||
if (!npc) return;
|
||||
|
||||
npc.startMovement(path);
|
||||
}
|
||||
};
|
||||
|
||||
NPCWorker.on("message", data => {
|
||||
const { messageId } = data;
|
||||
const event = messages[messageId];
|
||||
if (event) event(data);
|
||||
});
|
||||
|
||||
module.exports = async function (map, globalDieCallback, globalRewardCallback, globalAttackCallback) {
|
||||
const databaseSpawn = await execute(QUERY_FETCH_NPC_SPAWN, [map.id, ENTITY_TYPE_NPC]);
|
||||
if (databaseSpawn.error) return process.exit();
|
||||
|
||||
const spawns = databaseSpawn.data.reduce((spawns, spawn) => {
|
||||
if (!spawns[spawn.id]) {
|
||||
spawns[spawn.id] = {
|
||||
id: spawn.id,
|
||||
parentEntityTypeId: spawn.parentEntityTypeId,
|
||||
name: spawn.name,
|
||||
speed: spawn.speed,
|
||||
minHealth: spawn.minHealth,
|
||||
maxHealth: spawn.maxHealth,
|
||||
amount: spawn.amount,
|
||||
respawnTime: spawn.respawnTime,
|
||||
rewardEntries: []
|
||||
};
|
||||
};
|
||||
|
||||
if (spawn.categoryId) spawns[spawn.id].rewardEntries.push({
|
||||
categoryId: spawn.categoryId,
|
||||
itemId: spawn.itemId,
|
||||
min: spawn.min,
|
||||
max: spawn.max,
|
||||
chance: spawn.chance,
|
||||
isLastShot: spawn.isLastShot
|
||||
});
|
||||
|
||||
return spawns;
|
||||
}, {});
|
||||
|
||||
const convertedSpawn = Object.values(spawns);
|
||||
map.setupNonPlayerCharacterSpawn(convertedSpawn, nonPlayerCharacterNetworkListeners, globalDieCallback, globalRewardCallback, globalAttackCallback, NPC);
|
||||
|
||||
const event = {
|
||||
fn: map.spawnEntityGroups.bind(map),
|
||||
arguments: [nonPlayerCharacterNetworkListeners, NPC, globalAttackCallback, globalDieCallback],
|
||||
next: Game.eventsFixed.add.bind(Game.eventsFixed)
|
||||
};
|
||||
|
||||
const nextRunDate = getFixedDate(30);
|
||||
Game.eventsFixed.add(nextRunDate, event);
|
||||
};
|
||||
Reference in New Issue
Block a user