Skip to content

Commit

Permalink
Attach initiator to nodes + prevent sync NPC by moveType
Browse files Browse the repository at this point in the history
  • Loading branch information
Andaroth committed Jun 5, 2021
1 parent 1f983da commit 5f3112c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/core/gameworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ world.makeNode = (object) => {
actionUniqueId,
assetUniqueId,
};
if (!playerId) {
Object.assign(_node, {
initiator: object.initiator || 'server'
});
}
if (playerId || npcUniqueId) {
Object.assign(_node, {
mapId: object.mapId || 1,
Expand Down Expand Up @@ -235,7 +240,7 @@ world.fetchConnectedNpcs = (map) => {
if (!map || !world.isMapInstanced(map.mapId)) return;
for (let npc of world.getInstanceByMapId(map.mapId).events.filter(event => JSON.stringify(event).includes('<Sync>'))) {
const _generatedNpc = world.makeConnectedNpc(npc,map);
if (_generatedNpc) {
if (_generatedNpc && world.isConnectableNpc( _generatedNpc )) {
world.getConnectedNpcs(map.mapId).push( _generatedNpc );
world.attachNode( _generatedNpc );
console.log('[WORLD] Added synced NPC ' + _generatedNpc.uniqueId + ' on map ' + map.mapId);
Expand All @@ -258,6 +263,10 @@ world.getAllEntitiesByMapId = (mapId) => {
return [].concat(world.getAllPlayersByMapId(mapId)).concat(world.getAllNpcsByMapId(mapId));
}

world.isConnectableNpc = (npc) => {
return JSON.stringify(npc).includes('<Sync>') && npc._moveType === 1;
}

world.makeConnectedNpc = (npc,instance,pageIndex,initiator) => {
if (!npc || !instance) return;
// Target selected or first page to assign helpers :
Expand Down Expand Up @@ -328,7 +337,7 @@ world.spawnNpc = (npcSummonId, coords, pageIndex, initiator) => {
}
world.disableNpc = (npc) => {
world.npcMoveTo(npc,-1,-1); // visually hide npc
Object.assign(world.getNpcByUniqueId(npc.uniqueId), { disabled: true }); // Prevent turn execution
Object.assign(world.getNpcByUniqueId(npc.uniqueId), { busy: true }); // Prevent turn execution
}
world.removeSpawnedNpcByIndex = (index) => {
if (!world.spawnedUniqueIds[index]) return;
Expand Down Expand Up @@ -422,7 +431,7 @@ world.toggleNpcBusyStatus = (uniqueId,status) => {
world.handleNpcTurn = (npc,_currentTime,_cooldown) => {
// This function will read basic NPC behavior and mock it on
// server-side then replicate it on every concerned player
if (!npc || npc.disabled || npc.busy
if (!npc || npc.busy
|| !npc.uniqueId
|| !world.getNpcByUniqueId(npc.uniqueId)
) return;
Expand Down

0 comments on commit 5f3112c

Please sign in to comment.