Initial commit

This commit is contained in:
2026-08-24 22:20:36 +02:00
commit 62f7b1278a
251 changed files with 16670 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
const EntityNewPacket = require("../Packets/EntityNew");
const EntityDiePacket = require("../Packets/EntityDie");
const constants = require("../Data/constants");
const { TYPES, EVENTS } = constants;
const { ENTITY_TYPE_COLLECTABLE } = TYPES;
const { EVENT_DIE } = EVENTS;
const queries = require("../Data/queries");
const { QUERY_FETCH_COLLECTABLE_SPAWN } = queries;
const Collectable = require("../Game/Collectable");
module.exports = async function (map, globalDieCallback, globalRewardCallback) {
const databaseSpawn = await execute(QUERY_FETCH_COLLECTABLE_SPAWN, [map.id, ENTITY_TYPE_COLLECTABLE]);
if (databaseSpawn.error) return process.exit();
const spawns = databaseSpawn.data.reduce((spawns, spawn) => {
if (!spawns[spawn.id]) {
spawns[spawn.id] = {
id: spawn.id,
amount: spawn.amount,
respawnTime: spawn.respawnTime,
reward: []
};
};
if (spawn.categoryId) spawns[spawn.id].reward.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.registerCollectable(convertedSpawn, collectablesData => {
collectablesData.forEach(data => {
const { collectable, collectableSpawnProperties } = data;
const packet = EntityNewPacket.collectable(collectableSpawnProperties);
map.registerNetworkPacket(collectable.id, packet);
collectable.on(EVENT_DIE, function (data, author) {
const packet = EntityDiePacket(data);
map.registerNetworkPacket(author, packet, [1]);
});
});
}, globalDieCallback, globalRewardCallback, Collectable);
};
+26
View File
@@ -0,0 +1,26 @@
const AdmiralSpawnedPacket = require("../Packets/AdmiralSpawned");
const Game = require("../Game/Game");
const { maps } = Game;
const nonPlayerCharacterHandler = require("./NPC");
const monsterHandler = require("./Monster");
const collectableHandler = require("./Collectable");
const towerHandler = require("./Tower");
const die = require("../Callbacks/die");
const reward = require("../Callbacks/reward");
const attack = require("../Callbacks/attack");
maps.forEach(map => {
nonPlayerCharacterHandler(map, die, reward, attack);
collectableHandler(map, die, reward);
monsterHandler(map, die, reward, attack);
towerHandler(map, die, reward, attack);
map.on("admiralSpawnNotification", function (data, emittingTo) {
const packet = AdmiralSpawnedPacket(data);
emittingTo.forEach(mapID => app.publish(mapID.toString(), packet, true, true));
});
});
+72
View File
@@ -0,0 +1,72 @@
const EntityNewPacket = require("../Packets/EntityNew");
const AttackInformationPacket = require("../Packets/AttackInformation");
const AttackerInformationPacket = require("../Packets/AttackerInformation");
const EntityDiePacket = require("../Packets/EntityDie");
const constants = require("../Data/constants");
const { TYPES, EVENTS } = constants;
const { ENTITY_TYPE_MONSTER } = TYPES;
const { EVENT_ATTACK_STARTED, EVENT_DIE, EVENT_ATTACK_BAR } = EVENTS;
const queries = require("../Data/queries");
const { QUERY_FETCH_MONSTER_SPAWN } = queries;
const Monster = require("../Game/Monster");
module.exports = async function (map, globalDieCallback, globalRewardCallback, globalAttackCallback) {
const databaseSpawn = await execute(QUERY_FETCH_MONSTER_SPAWN, [map.id, ENTITY_TYPE_MONSTER]);
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,
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.setupMonsterSpawn(convertedSpawn,
function monsterNetworkListeners (data) {
const { monster, monsterSpawnProperties } = data;
const packet = EntityNewPacket.monster(monsterSpawnProperties);
map.registerNetworkPacket(monster.id, packet);
monster.on(EVENT_ATTACK_STARTED, function (data, author) {
const packet = AttackInformationPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
});
monster.on(EVENT_ATTACK_BAR, function (data, author) {
const packet = AttackerInformationPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
});
monster.on(EVENT_DIE, function (data, author) {
const packet = EntityDiePacket(data);
this.map.registerNetworkPacket(author, packet, [1]);
});
}, globalDieCallback, globalRewardCallback, globalAttackCallback, Monster);
};
+78
View File
@@ -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);
};
+93
View File
@@ -0,0 +1,93 @@
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();
};
+364
View File
@@ -0,0 +1,364 @@
const MainPlayerPacket = require("../Packets/MainPlayer");
const QuestRemovalPacket = require("../Packets/QuestRemoval");
const EntityOldPacket = require("../Packets/EntityOld");
const EntityNewPacket = require("../Packets/EntityNew");
const AmmunitionUsedPacket = require("../Packets/AmmunitionUsed");
const LogoutCancelledPacket = require("../Packets/LogoutCancelled");
const PropertyChangedPacket = require("../Packets/PropertyChanged")
const AttackInformationPacket = require("../Packets/AttackInformation");
const AttackingPacket = require("../Packets/Attacking");
const AttackAbortedPacket = require("../Packets/AttackAborted");
const AttackerInformationPacket = require("../Packets/AttackerInformation");
const EntityDiePacket = require("../Packets/EntityDie");
const RespawnConfirmationPacket = require("../Packets/RespawnConfirmation");
const EffectAddPacket = require("../Packets/EffectAdd");
const EntitySpeedChangedPacket = require("../Packets/EntitySpeedChanged");
const MapChangeStatePacket = require("../Packets/MapChangeState");
const MapChangedPacket = require("../Packets/MapChanged");
const LevelUpPacket = require("../Packets/LevelUp");
const LevelIsLowPacket = require("../Packets/LevelIsLow");
const HealthChangedAuthorlessPacket = require("../Packets/HealthChangedAuthorless");
const HealthChangedPacket = require("../Packets/HealthChanged");
const ItemUsedPacket = require("../Packets/ItemUsed");
const NewDestinationNodePacket = require("../Packets/NewDestinationNode");
const GuildMemberNewPacket = require("../Packets/GuildMemberNew");
const GuildDataMemberChangedPacket = require("../Packets/GuildDataMemberChanged");
const quests = require("../Data/quests");
const constants = require("../Data/constants");
const Game = require("../Game/Game");
const { players } = Game;
const { TYPES } = constants;
const { ENTITY_TYPE_PLAYER, ENTITY_TYPE_NPC, ENTITY_TYPE_MONSTER, ENTITY_TYPE_TOWER, ENTITY_TYPE_COLLECTABLE } = TYPES;
const [playerEconomy] = require("../Data/batchSave");
// just to add "lag"
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
};
global.PlayerWorker.on("message", data => {
const player = players[data.id];
if (!player) return;
if (player.map.id !== data.mapId) return;
if (player.movementRequestTracker !== data.movementRequestTracker) return;
player.startingPosition = data.startingPosition;
const { path } = data;
if (!player.isMoving) player.initializeMovement(path, data);
else player.emit("scheduledPathReady", path, data);
});
module.exports.scheduledPathReady = function (path, data) {
if (path.length) {
this.data = data;
this.scheduledPath = path;
this.isNewPathReady = true;
} else this.isLastNodeFinished = true;
if (this.isNewPathReady && this.isLastNodeFinished) {
this.isNewPathReady = false;
this.isLastNodeFinished = false;
this.initializeMovement(this.scheduledPath, this.data);
this.scheduledPath = [];
};
};
module.exports.updateVisibility = function (entityProps) {
const { type, data } = entityProps;
let packet = null;
if (type) {
switch (data.typeID) {
case ENTITY_TYPE_PLAYER: packet = EntityNewPacket.player(data); break;
case ENTITY_TYPE_NPC: packet = EntityNewPacket.npc(data); break;
case ENTITY_TYPE_MONSTER: packet = EntityNewPacket.monster(data); break;
case ENTITY_TYPE_TOWER: packet = EntityNewPacket.tower(data); break;
case ENTITY_TYPE_COLLECTABLE: packet = EntityNewPacket.collectable(data); break;
};
} else packet = EntityOldPacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet.buffer ? packet.buffer : packet, [packet.metadata]);
};
module.exports.disconnect = async function (data) {
const { map, position, hp, inventory, textureID } = this;
const playerID = this.id;
const oldEntityID = {
typeID: this.typeID,
id: playerID
};
const packet = EntityOldPacket(oldEntityID);
this.map.registerNetworkPacket(this.id, packet, [1]);
if (this.guild.id) {
const guildDataMemberChanged = {
id: playerID,
isOnline: false
};
const packet = GuildDataMemberChangedPacket(guildDataMemberChanged);
const topic = Game.getTopic(this.guild.topic);
topic.push(packet);
};
this.isUnderDisconnect = true;
if (!this.hasUnexpectedlyLeft) {
socket.sockets[this.sessionID].end();
delete socket.sockets[this.sessionID];
console.info("player handler end socket", performance.now());
};
const ammunition = inventory.getAmmunitions();
const harpoon = inventory.getHarpoons();
const economy = inventory.getEconomy();
const items = inventory.getItems();
const designs = inventory.getDesignIDs();
const cannons = inventory.getCannons();
const harpooners = inventory.getHarpooners();
const resources = [];
const equipments = [];
economy.forEach(e => {
playerEconomy.removeItem(`${playerID}-1-${e.id}`);
resources.push([playerID, 1, e.id, e.amount])
});
items.forEach(i => {
playerEconomy.removeItem(`${playerID}-2-${i.id}`);
resources.push([playerID, 2, i.id, i.amount])
});
ammunition.forEach(a => {
playerEconomy.removeItem(`${playerID}-3-${a.id}`);
resources.push([playerID, 3, a.id, a.amount])
});
harpoon.forEach(h => {
playerEconomy.removeItem(`${playerID}-4-${h.id}`);
resources.push([playerID, 4, h.id, h.amount])
});
designs.forEach(id => {
playerEconomy.removeItem(`${playerID}-5-${id}`);
resources.push([playerID, 5, id, 1])
});
this.statusPoints.forEach(s => {
playerEconomy.removeItem(`${playerID}-6-${s.id}`);
resources.push([playerID, 6, s.id, s.amount])
});
cannons.forEach(c => {
playerEconomy.removeItem(`${playerID}-7-${c.id}`);
resources.push([playerID, 7, c.id, c.amount]);
equipments.push([playerID, 7, c.id, c.amountEquipped]);
});
harpooners.forEach(h => {
playerEconomy.removeItem(`${playerID}-8-${h.id}`);
resources.push([playerID, 8, h.id, h.amount]);
equipments.push([playerID, 8, h.id, h.amountEquipped])
});
// await delay(20000)
Object.entries(this.quests.completedQuestsAmount).forEach(async q => {
const [questID, amount] = q;
const questScheme = quests[questID - 1];
const isQuestAccepted = this.quests.has(questID);
let questState = 0;
if (questScheme.maximumComplete && amount >= questScheme.maximumComplete) questState = 2;
else if (!isQuestAccepted) questState = 1;
else questState = 0;
await execute("INSERT INTO quests (playerID, questID, state, completedAmount) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE state = ?, completedAmount = ?", [playerID, questID, questState, amount, questState, amount]);
if (isQuestAccepted) {
const quest = this.quests.list[questID];
const questProgression = quest.getProgression();
questProgression.forEach(async progression => {
const { amount, index, type } = progression;
await execute("INSERT INTO questprogression (playerID, questID, amount, taskIndex, taskType) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE amount = ?", [playerID, quest.id, amount, index, type, amount]);
});
};
});
const finishedQuestsID = Object.keys(this.quests.finishedQuests);
if (finishedQuestsID.length) await execute("UPDATE questprogression SET amount = 0 WHERE questID IN (?)", finishedQuestsID);
await execute("UPDATE playerdata SET mapID = ?, x = ?, y = ?, currentHitpoints = ?, maximumHitpoints = ?, selectedAmmunitionID = ?, selectedHarpoonID = ?, designID = ? WHERE playerID = ?", [map.id, position.x, position.y, hp.current, hp.maximum, inventory.selectedAmmunition, inventory.selectedHarpoon, textureID, playerID]);
if (resources.length) await query(`INSERT INTO resources (playerID, categoryID, itemID, amount) VALUES ? ON DUPLICATE KEY UPDATE amount = VALUES(amount)`, [resources]);
const activeStatusEffects = this.activeStatusEffects.length ? this.activeStatusEffects : [0];
const activeStatusEffectsFormatted = this.activeStatusEffects.map(e => [playerID, e, 1]);
if (this.activeStatusEffects.length) await query(`INSERT INTO status (playerID, statusID, isActive) VALUES ? ON DUPLICATE KEY UPDATE isActive = ?`, [activeStatusEffectsFormatted, 1]);
await query(`UPDATE status SET isActive = ? WHERE statusID NOT IN (?) AND playerID = ?`, [0, activeStatusEffects, playerID]);
if (equipments.length) await query("INSERT INTO equipments (playerID, categoryID, itemID, amountEquipped) VALUES ? ON DUPLICATE KEY UPDATE amountEquipped = VALUES(amountEquipped)", [equipments]);
if (this.isUnderDisconnect) {
console.info("player handler disconnect finished", performance.now());
delete players[playerID];
}
};
module.exports.disconnectCancel = function() {
const packet = LogoutCancelledPacket();
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.healthChangedAuthorless = function (data, author) {
const packet = HealthChangedAuthorlessPacket(data);
this.map.registerNetworkPacket(author, packet);
};
module.exports.attackBar = function (data, author) {
const packet = AttackerInformationPacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.attackStarted = function (data, author) {
const packet = AttackInformationPacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.attacking = function (data, author) {
const packet = AttackingPacket(data[1]);
const packett = HealthChangedPacket(data[0]);
this.map.registerNetworkPacket(author, [packet, packett], [1, 1]);
};
module.exports.attackAbortedByUser = function (data, author) {
const packet = AttackAbortedPacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.die = function (data, author) {
const packet = EntityDiePacket(data);
this.map.registerNetworkPacket(author, packet, [19]);
};
module.exports.propertyChanged = function (data, author) {
const packet = PropertyChangedPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
};
module.exports.ableToJump = function (data) {
const packet = MapChangeStatePacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.unableToJump = function (data) {
const packet = MapChangeStatePacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.mapChanged = function (data, author) {
const selfSwitchPacket = MapChangedPacket(data.newMap);
this.map.registerIndividualNetworkPacket(this.id, selfSwitchPacket);
const socketInstance = socket.sockets[this.sessionID];
socketInstance.unsubscribe(data.oldMap.id.toString());
socketInstance.subscribe(data.newMap.mapID.toString());
};
module.exports.levelUp = function (data) {
if (this.guild.id) {
const guildDataMemberChanged = {
id: this.id,
level: data.level
};
const guildDataMemberChangedPacket = GuildDataMemberChangedPacket(guildDataMemberChanged);
const topic = Game.getTopic(this.guild.topic);
topic.push(guildDataMemberChangedPacket);
}
const packet = LevelUpPacket(data);
this.map.registerNetworkPacket(this.id, packet);
};
module.exports.levelIsLow = function() {
const packet = LevelIsLowPacket();
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.questDone = async function (data) {
await execute("INSERT INTO quests (playerID, questID, state, completedAmount) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE state = ?, completedAmount = completedAmount + 1", [this.id, data.questID, 1, 1, 1]);
const packet = QuestRemovalPacket(data);
this.map.registerIndividualNetworkPacket(this.id, packet);
};
module.exports.testOvertimeDamage = function (data, author) {
const packet = HealthChangedPacket(data);
this.map.registerNetworkPacket(author, packet);
};
module.exports.itemUsed = function (data, author) {
const packet = ItemUsedPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
};
module.exports.cannonsUsed = function (data, author) {
const packet = AmmunitionUsedPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
};
module.exports.harpoonersUsed = function (data, author) {
const packet = AmmunitionUsedPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
};
module.exports.newDestination = function (data) {
const packet = NewDestinationNodePacket(data);
this.map.registerNetworkPacket(this.id, packet);
};
module.exports.effectAdd = function (data) {
const packet = EffectAddPacket(data);
this.map.registerNetworkPacket(this.id, packet);
};
module.exports.speedUpdate = function (data) {
const packet = EntitySpeedChangedPacket(data);
this.map.registerNetworkPacket(this.id, packet);
};
module.exports.respawn = async function() {
const respawnPacket = RespawnConfirmationPacket();
this.map.registerIndividualNetworkPacket(this.id, respawnPacket);
const respawningPlayerProperties = this.getProperties();
const respawningPlayerPacket = MainPlayerPacket(respawningPlayerProperties);
const packetsToSend = [respawningPlayerPacket];
if (this.guild && this.guild.id) {
const guildProperties = {
playerID: this.id,
tag: this.guild.tag
};
const guildPacket = GuildMemberNewPacket(guildProperties);
packetsToSend.push(guildPacket);
};
this.map.registerIndividualNetworkPacket(this.id, packetsToSend);
};
+184
View File
@@ -0,0 +1,184 @@
const EntityNewPacket = require("../Packets/EntityNew");
const EntityDiePacket = require("../Packets/EntityDie");
const GuildIslandCapturedPacket = require("../Packets/GuildIslandCaptured");
const AttackInformationPacket = require("../Packets/AttackInformation");
const AttackerInformationPacket = require("../Packets/AttackerInformation");
const AttackingPacket = require("../Packets/Attacking");
const HealthChangedPacket = require("../Packets/HealthChanged");
const HealthChangedAuthorlessPacket = require("../Packets/HealthChangedAuthorless");
const GuildDataIslandTowerDestroyedPacket = require("../Packets/GuildDataIslandTowerDestroyed");
const GuildDataIslandTowerHealthChangedPacket = require("../Packets/GuildDataIslandTowerHealthChanged");
const GuildDataIslandCapturedPacket = require("../Packets/GuildDataIslandCaptured");
const GuildDataIslandTowerBuiltPacket = require("../Packets/GuildDataIslandTowerBuilt");
const WorldMapGuildEntryPacket = require("../Packets/WorldMapGuildEntry");
const GuildDataIslandPacket = require("../Packets/GuildDataIsland");
const GuildDataIslandTowerPacket = require("../Packets/GuildDataIslandTower");
const schemeTower = require("../Data/schemeTower");
const queries = require("../Data/queries");
const { QUERY_FETCH_GUILD_TOWERS, QUERY_UPDATE_GUILD_ISLAND_TOWER_DEAD, QUERY_UPDATE_GUILD_ISLAND_TOWER_UPGRADE, QUERY_UPDATE_GUILD_ISLAND_TOWER_DEFAULT, QUERY_DELETE_GUILD_ISLAND_DAMAGES, QUERY_UPDATE_GUILD_ISLAND_AUTHOR, QUERY_UPDATE_GUILD_ISLAND_DAMAGES } = queries;
const constants = require("../Data/constants");
const { EVENTS } = constants;
const { EVENT_ATTACK_STARTED, EVENT_HEALTH_CHANGED_AUTHORLESS, EVENT_ATTACKING, EVENT_ATTACK_BAR, EVENT_DIE, EVENT_GUILD_ISLAND_CAPTURE, EVENT_GUILD_ISLAND_TOWER_BUILT, EVENT_GUILD_ISLAND_TOWER_HEALTH_CHANGED } = EVENTS;
const Tower = require("../Game/Tower");
const Game = require("../Game/Game");
const { guildIslands } = Game;
module.exports = async function (map, globalDieCallback, globalRewardCallback, globalAttackCallback) {
const towers = await execute(QUERY_FETCH_GUILD_TOWERS, [map.id]);
if (towers.error) return process.exit();
const allTowersMap = towers.data;
if (!allTowersMap) return;
let order = 0;
let previousIslandID = 0;
for (let i = 0, length = allTowersMap.length; i < length; i++) {
const tower = allTowersMap[i];
const scheme = schemeTower[tower.entityTypeID];
if (!scheme) continue;
const island = guildIslands.find(island => island.id === tower.guildIslandID);
if (previousIslandID !== island.id) order = 0;
previousIslandID = island.id;
const towerInstance = new Tower({
id: tower.id,
order: ++order,
entityTypeID: tower.entityTypeID,
island,
map,
maximumHitpoint: scheme.maximumHitpoints,
currentHitpoint: tower.currentHitpoints,
position: {
x: tower.positionX,
y: tower.positionY
},
attackCallback: globalAttackCallback,
dieCallback: globalDieCallback
});
const packet = EntityNewPacket.tower(towerInstance.getProperties());
map.registerNetworkPacket(towerInstance.id, packet);
towerInstance.on(EVENT_DIE, function (data, id) {
const packet = EntityDiePacket(data[0]);
this.map.registerNetworkPacket(id, [packet], [1]);
const packet_2 = GuildDataIslandTowerDestroyedPacket(data[1]);
const topic = Game.getTopic(this.island.guild.topic);
topic.push(packet_2);
execute(QUERY_UPDATE_GUILD_ISLAND_TOWER_DEAD, [0, Tower.getID(this.id)]);
});
towerInstance.on(EVENT_ATTACK_STARTED, function (data, author) {
const packet = AttackInformationPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
});
towerInstance.on(EVENT_HEALTH_CHANGED_AUTHORLESS, function (data, author) {
const packet = HealthChangedAuthorlessPacket(data);
this.map.registerNetworkPacket(this.id, packet, [1]);
});
towerInstance.on(EVENT_ATTACK_BAR, function (data, author) {
const packet = AttackerInformationPacket(data);
this.map.registerIndividualNetworkPacket(author, packet);
});
towerInstance.on(EVENT_ATTACKING, function (data, author) {
const packet = AttackingPacket(data[1]);
const packet_2 = HealthChangedPacket(data[0]);
this.map.registerNetworkPacket(author, [packet, packet_2], [1, 1]);
});
towerInstance.on("_", function (data) {
execute(QUERY_UPDATE_GUILD_ISLAND_DAMAGES, [data.damage, data.guildIslandID, data.guildID, data.damage]);
});
towerInstance.on(EVENT_GUILD_ISLAND_TOWER_HEALTH_CHANGED, function (data, author) {
const topic = Game.getTopic(this.island.guild.topic);
const packet = GuildDataIslandTowerHealthChangedPacket(data);
topic.push(packet);
});
towerInstance.on(EVENT_GUILD_ISLAND_TOWER_BUILT, async function (data, author) {
await execute(QUERY_UPDATE_GUILD_ISLAND_TOWER_UPGRADE, [this.entityTypeID, this.hp.maximum, Tower.getID(this.id)]);
const topic = Game.getTopic(this.island.guild.topic);
const packet = GuildDataIslandTowerBuiltPacket(data);
topic.push(packet);
});
towerInstance.on(EVENT_GUILD_ISLAND_CAPTURE, async function (data, author) {
const packet = GuildIslandCapturedPacket(data.packet);
app.publish(this.map.id.toString(), packet, true, true);
if (data.database.oldID !== data.database.newID) {
const packet_2 = GuildDataIslandCapturedPacket({
guildIslandID: this.island.id
});
const topicOld = Game.getTopic(data.topicOld);
topicOld.push(packet_2);
const islandProperties = {
id: this.island.id,
mapID: this.map.id,
position: this.island.position,
};
const guildDataIslandPacket = GuildDataIslandPacket(islandProperties);
const topicNew = Game.getTopic(data.topicNew);
topicNew.push(guildDataIslandPacket);
this.island.towers.forEach(tower => {
const towerProperties = {
entityTypeID: tower.entityTypeID,
id: tower.id,
guildIslandID: island.id,
order: tower.order,
hp: {
current: tower.hp.current
},
isRepairing: tower.isRepairing()
};
const guildDataIslandTowerPacket = GuildDataIslandTowerPacket(towerProperties);
topicNew.push(guildDataIslandTowerPacket);
});
};
const packet_3 = WorldMapGuildEntryPacket({
locationMapID: this.map.id,
index: this.island.index,
bufferTag: this.island.guild.tag
});
Game.maps.forEach(map => app.publish(map.id.toString(), packet_3, true, true));
let dbConnection = null;
try {
dbConnection = await db.getConnection();
await dbConnection.beginTransaction();
await execute(QUERY_UPDATE_GUILD_ISLAND_TOWER_DEFAULT, [5000, this.island.id]);
await execute(QUERY_DELETE_GUILD_ISLAND_DAMAGES, [this.island.id]);
await execute(QUERY_UPDATE_GUILD_ISLAND_AUTHOR, [data.database.newID, this.island.id]);
await dbConnection.commit();
} catch {
await dbConnection.rollback();
} finally {
dbConnection.release();
};
});
};
};