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
+23
View File
@@ -0,0 +1,23 @@
const { TASK_TYPES } = require("../Data/constants");
const { TASK_TYPE_DEAL_DAMAGE } = TASK_TYPES;
const Game = require("../Game/Game");
const { players } = Game;
function globalAttackCallback(data) {
const { typeID, entityTypeID, authorID, damage } = data;
const player = players[authorID];
if (!player) return;
/*
* only quest is updated here
* if player is unavailable, it means that they have logged out: damage without player being online???
* conclusion: only overtime damage can cause this issue
*/
const toBeAdjusted = [{ taskCategoryID: TASK_TYPE_DEAL_DAMAGE, typeID, entityTypeID }];
Object.values(player.quests.list).forEach(quest => quest.adjustTask(toBeAdjusted, damage));
};
module.exports = globalAttackCallback;
+253
View File
@@ -0,0 +1,253 @@
const Reward = require("../Game/Reward");
const DoubleLinkedList = require("../Utility/DoubleLinkedList");
const admiralTable = require("../Data/admiralTable");
const leaderboards = require("../Data/leaderboard");
const { TASK_TYPES, TYPES } = require("../Data/constants");
const rewardCallback = require("./reward");
const { TASK_TYPE_DESTROY } = TASK_TYPES;
const { ENTITY_TYPE_PLAYER, ENTITY_TYPE_NPC, ENTITY_TYPE_MONSTER } = TYPES;
const Game = require("../Game/Game");
const { players } = Game;
const percentages = [0.40, 0.25, 0.15, 0.10, 0.07, 0.03];
const amounts = [1, 3, 5, 10, 20, 25, 35];
const totalAmount = amounts.reduce((acc, cur) => acc + cur, 0);
let aa = new Array(amounts.length);
setTimeout(async () => {
const q = await execute("SELECT * FROM leaderboard_1 ORDER BY amount DESC LIMIT 1099");
const batches = [];
const values = q.data;
let totalSize = 0;
for (let i = 0; i < percentages.length; i++) { // this loop is for slicing based on percentages
if (values.length - totalAmount < 0) {
batches.push([]);
continue;
};
const batchSize = (values.length - totalAmount) * percentages[i];
const batch = values.slice(totalSize, totalSize + batchSize);
batches.push(batch);
totalSize += batchSize;
};
let rest = values.slice(totalSize, totalSize + totalAmount);
//require("../Miscellaneous/winston").error(`Total length: ${values.length} (these are from DB, raw)`)
// require("../Miscellaneous/winston").error(`Rest length: ${rest.length} (these are based on fixed amounts instead of percentages)`)
let x = 0;
for (let i = 0; i < amounts.length; i++) {
const batchSize = amounts[i];
const batch = rest.slice(totalAmount - (totalAmount - x), totalAmount - (totalAmount - x - batchSize));
// require("../Miscellaneous/winston").error(`amounts array index: ${i} | slicing between: ${totalAmount - (totalAmount - x)} - ${totalAmount - (totalAmount - x - batchSize)}`)
aa[amounts.length - 1 - i] = batch;
x += batchSize;
};
batches.push(...aa);
const thresholds = new Array(batches.length);
for (let j = 0; j < batches.length; j++) {
const batch = batches[j];
const lastElemWithValue = batch.filter(e => e.id);
// require("../Miscellaneous/winston").error(`Batch ${j}: length is ${batch.length}, last elem with value: ${lastElemWithValue[lastElemWithValue.length - 1]?.id} ${lastElemWithValue[lastElemWithValue.length - 1]?.amount}`)
thresholds[j] = lastElemWithValue[lastElemWithValue.length - 1] ? lastElemWithValue[lastElemWithValue.length - 1].amount : 0;
for (let k = 0; k < batch.length; k++)
db.execute("UPDATE playerdata SET globalrank = ? WHERE playerID = ?", [j, batch[k].id]);
};
global.thresholds = thresholds;
// require("../Miscellaneous/winston").error(thresholds);
}, 2000)
const tracker = new DoubleLinkedList();
function globalDieCallback(source) {
const { typeID, entityTypeID, parentEntityTypeID, isAdmiral, authorID, authorTypeID } = source;
const id = `${typeID}_${isAdmiral ? entityTypeID : parentEntityTypeID}`;
const ids = {
typeID,
parentEntityTypeID
};
console.trace("death", source);
const player = players[authorID];
switch (typeID) {
case 1:
leaderboards[4].updatePosition(authorID, 1);
break;
case 2:
leaderboards[5].updatePosition(authorID, 1);
break;
case 3:
leaderboards[6].updatePosition(authorID, 1);
break;
};
if (authorTypeID === ENTITY_TYPE_PLAYER && typeID === ENTITY_TYPE_PLAYER) {
const targetPlayer = players[source.id];
const keyAuthor = `${player.id}-${targetPlayer.id}`;
const killCountAuthor = tracker.getElement(keyAuthor);
if (killCountAuthor === 2) return console.info("reached threshold");
const keyTarget = `${targetPlayer.id}-${player.id}`;
const killCountTarget = tracker.getElement(keyTarget);
if (killCountTarget) tracker.accumulateItem(keyTarget, -1);
tracker.accumulateItem(keyAuthor, 1);
const amount = 10;
const reward = new Reward({
distributionType: 3,
baseReward: [
{
categoryID: 6,
id: 4,
amountMinimum: amount
}
]
});
reward.dynamic(rewards => rewardCallback({ isRegular: true, authorID, source, rewards }));
const battlePointsTarget = targetPlayer.statusPoints[3] && targetPlayer.statusPoints[3].amount;
console.info(battlePointsTarget, amount, "sp")
if (battlePointsTarget >= amount) {
const reward_2 = new Reward({
distributionType: 3,
baseReward: [
{
categoryID: 6,
id: 4,
amountMinimum: amount * -1
}
]
});
reward_2.dynamic(rewards => rewardCallback({ isRegular: true, authorID: source.id, source, rewards }));
};
};
if (typeID === ENTITY_TYPE_NPC) {
} else if (typeID === ENTITY_TYPE_MONSTER) {
};
const toBeAdjusted = [{
taskCategoryID: TASK_TYPE_DESTROY,
typeID,
entityTypeID
}];
for (questID in player.quests.list) player.quests.list[questID].adjustTask(toBeAdjusted, 1);
if (this.reward) {
const playerInventory = player.inventory.getPosessions();
switch (this.reward.distributionType) {
case 1:
this.reward.multiple({
playerInventory,
damage: this.damageReceived,
maximum: this.totalDamageReceived,
lastShotAuthorID: authorID
}, (ids, rewards) => this.rewardCallback({ isRegular: true, authorID: ids.id, source, rewards }));
break;
case 2:
this.reward.single(1, playerInventory, rewards => this.rewardCallback({ isRegular: true, authorID, source, rewards }));
break;
};
};
const playerInventory = player.inventory.getPosessions();
if (isAdmiral) return admiralTable.descreaseAdmiralCount(id);
const isAdmiralSpawnReady = parentEntityTypeID ? admiralTable.increaseCounter(ids) : false;
return isAdmiralSpawnReady;
};
module.exports = globalDieCallback;
//const globalPoints = Math.floor(player.statusPoints[0] / 10000 + player.statusPoints[1] / 2000 + player.statusPoints[2] / 2000);
//if (globalPoints) leaderboards[0].updatePosition(authorID, globalPoints, true);
/*
let aa = new Array(amounts.length);
setTimeout(async () => {
const q = await execute("SELECT * FROM leaderboard_1 ORDER BY amount DESC");
const batches = [];
const values = q.data;
let totalSize = 0;
for (let i = 0; i < percentages.length; i++) { // this loop is for slicing based on percentages
if (values.length - totalAmount < 0) {
batches.push([]);
continue;
};
const batchSize = (values.length - totalAmount) * percentages[i];
const batch = values.slice(totalSize, totalSize + batchSize);
batches.push(batch);
totalSize += batchSize;
};
let rest = values.slice(totalSize, totalSize + totalAmount);
require("../Miscellaneous/winston").error(`Total length: ${values.length} (these are from DB, raw)`)
require("../Miscellaneous/winston").error(`Rest length: ${rest.length} (these are based on fixed amounts instead of percentages)`)
let x = 0;
for (let i = 0; i < amounts.length; i++) {
const batchSize = amounts[i];
const batch = rest.slice(totalAmount - (totalAmount - x), totalAmount - (totalAmount - x - batchSize));
require("../Miscellaneous/winston").error(`amounts array index: ${i} | slicing between: ${totalAmount - (totalAmount - x)} - ${totalAmount - (totalAmount - x - batchSize)}`)
aa[amounts.length - 1 - i] = batch;
x += batchSize;
};
batches.push(...aa);
const thresholds = new Array(batches.length);
for (let j = 0; j < batches.length; j++) {
const batch = batches[j];
const lastElemWithValue = batch.filter(e => e.id);
require("../Miscellaneous/winston").error(`Batch ${j}: length is ${batch.length}, last elem with value: ${lastElemWithValue[lastElemWithValue.length - 1]?.id} ${lastElemWithValue[lastElemWithValue.length - 1]?.amount}`)
thresholds[j] = lastElemWithValue[lastElemWithValue.length - 1] ? lastElemWithValue[lastElemWithValue.length - 1].amount : 0;
for (let k = 0; k < batch.length; k++)
db.execute("UPDATE playerdata SET globalrank = ? WHERE playerID = ?", [j, batch[k].id]);
};
global.thresholds = thresholds;
require("../Miscellaneous/winston").error(thresholds);
}, 2000)
*/
+183
View File
@@ -0,0 +1,183 @@
const RewardPacket = require("../Packets/Reward");
const DesignChangedPacket = require("../Packets/DesignChanged");
const LevelUpPacket = require("../Packets/LevelUp");
const GuildDataEconomyDonatedPacket = require("../Packets/GuildDataEconomyDonated");
const StatisticsWorker = global.StatisticsWorker;
const Game = require("../Game/Game");
const { players } = Game;
const constants = require("../Data/constants");
const leaderboards = require("../Data/leaderboard");
const eliteRewards = require("../Data/eliteRewards");
const [playerEconomy, guildEconomy] = require("../Data/batchSave");
const { CATEGORIES } = constants;
const { CATEGORY_ECONOMY, CATEGORY_DESIGN, CATEGORY_STATUS, CATEGORY_RANKING_POINTS } = CATEGORIES;
const statusMappedToLeaderboard = {
1: 1,
2: 2,
3: 3
};
const EXP_GUILD_ALLOWED_SOURCES = {
2: true,
3: true
};
async function rewardCallback(reward) {
if (!reward) return;
const player = players[reward.authorID];
if (!player) return;
const initializedPacket = RewardPacket.init(reward.isRegular, reward.rewards.length);
const initializedGuildPacket = RewardPacket.init(true, 1);
let designRewardID = 0;
reward.rewards.forEach(r => {
if (r.categoryID === CATEGORY_STATUS) {
if (player.guild.id && r.id === 1 && EXP_GUILD_ALLOWED_SOURCES[reward.source.typeID]) {
const newLevel = player.guild.levelUpdate(r.amount);
guildEconomy.accumulateItem(`${player.guild.id}-${r.categoryID}-${r.id}`, r.amount);
const guildExperienceReward = {
categoryID: 9,
id: r.id,
amount: r.amount
};
initializedGuildPacket.update(guildExperienceReward);
const guildRewardPacket = initializedGuildPacket.get();
const topic = Game.getTopic(player.guild.topic);
topic.push(guildRewardPacket);
if (newLevel !== -1) {
const levelUp = {
level: newLevel,
statusLevelID: 4,
id: player.id
};
const levelUpPacket = LevelUpPacket(levelUp);
topic.push(levelUpPacket);
/*player.emit("levelUp", {
level: newLevel,
statusLevelID: 4,
id: player.id
});*/
};
};
const leaderboardID = statusMappedToLeaderboard[r.id];
const leaderboard = leaderboards[leaderboardID];
if (leaderboard) leaderboard.updatePosition(player.id, r.amount);
player.updateLevels(r.id, r.amount);
}// else if (r.categoryID === CATEGORY_RANKING_POINTS) player.updateRankingPoints(r.id, r.amount);
else player.inventory.refreshSingle(r);
if (r.categoryID === CATEGORY_ECONOMY) {
if (player.guild.id) {
let guildTax = 0;
switch (r.id) {
case 1:
guildTax = player.guild.taxRates[0];
break;
case 2:
guildTax = player.guild.taxRates[1];
break;
};
const guildTaxAmount = Math.floor(r.amount * guildTax);
const playerRewardAmount = r.amount - guildTaxAmount;
console.info("guild tax reward", guildTaxAmount, r.categoryID, r.id);
player.guild.bank.depositTax({
categoryID: r.categoryID,
id: r.id,
amount: guildTaxAmount
});
const guildEconomyDonated = {
id: r.id,
amount: guildTaxAmount
};
const guildEconomyDonatedPacket = GuildDataEconomyDonatedPacket(guildEconomyDonated);
const topic = Game.getTopic(player.guild.topic);
topic.push(guildEconomyDonatedPacket);
if (guildTax) guildEconomy.accumulateItem(`${player.guild.id}-${r.categoryID}-${r.id}`, guildTaxAmount);
r.amount -= guildTaxAmount;
};
};
if (r.categoryID === CATEGORY_DESIGN && !designRewardID) designRewardID = r.id;
console.info("reward amount", r.amount)
playerEconomy.accumulateItem(`${player.id}-${r.categoryID}-${r.id}`, r.amount);
initializedPacket.update(r);
const now = new Date();
StatisticsWorker.postMessage({
id: 1,
data: {
timestamp: now,
playerID: player.id,
categoryID: r.categoryID,
id: r.id,
amount: r.amount,
source: {
typeID: reward.source.typeID,
entityTypeID: reward.source.entityTypeID,
}
}
});
});
const packet = initializedPacket.get();
player.map.registerIndividualNetworkPacket(player.id, packet);
if (designRewardID) {
player.textureID = designRewardID;
const designReward = {
typeID: player.typeID,
id: player.id,
designID: designRewardID
};
const packet = DesignChangedPacket(designReward);
player.map.registerNetworkPacket(player.id, packet);
if (designRewardID === 5) {
for (let i = 1, length = player.eliteLevel; i < length; i++) {
const currentEliteLevelRewards = eliteRewards[i];
if (currentEliteLevelRewards) {
currentEliteLevelRewards.single(0, player.inventory.getPosessions(), rewards => player.rewardCallback({ isRegular: true, authorID: player.id, source: {}, rewards }));
player.inventory.resourceSharedLimiter.cannon.quantity.maximum += 2;
};
};
const ePropertyChanged = {
typeID: 5,
value: player.inventory.resourceSharedLimiter.cannon.quantity.maximum
};
player.emit("propertyChanged", ePropertyChanged, player.id);
};
};
};
module.exports = rewardCallback;