From afec59e8a6731429283985605f50c3ec86385bf2 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 27 Apr 2025 12:38:55 -0700 Subject: [PATCH] feat: skipClanKeyCrafting cheat (#1883) Closes #1843 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1883 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- config.json.example | 1 + .../api/confirmGuildInvitationController.ts | 28 ++++++++----------- src/controllers/api/createGuildController.ts | 24 +++++----------- src/services/configService.ts | 1 + src/services/guildService.ts | 28 ++++++++++++++++++- static/webui/index.html | 4 +++ static/webui/translations/de.js | 1 + static/webui/translations/en.js | 1 + static/webui/translations/es.js | 1 + static/webui/translations/fr.js | 1 + static/webui/translations/ru.js | 1 + static/webui/translations/zh.js | 1 + 12 files changed, 57 insertions(+), 35 deletions(-) diff --git a/config.json.example b/config.json.example index 4eb30783..e8c32ed1 100644 --- a/config.json.example +++ b/config.json.example @@ -38,6 +38,7 @@ "noKimCooldowns": false, "instantResourceExtractorDrones": false, "noResourceExtractorDronesDamage": false, + "skipClanKeyCrafting": false, "noDojoRoomBuildStage": false, "noDecoBuildStage": false, "fastDojoRoomDestruction": false, diff --git a/src/controllers/api/confirmGuildInvitationController.ts b/src/controllers/api/confirmGuildInvitationController.ts index 9f43b893..b4a10b98 100644 --- a/src/controllers/api/confirmGuildInvitationController.ts +++ b/src/controllers/api/confirmGuildInvitationController.ts @@ -1,8 +1,14 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { Guild, GuildMember } from "@/src/models/guildModel"; import { Account } from "@/src/models/loginModel"; -import { deleteGuild, getGuildClient, hasGuildPermission, removeDojoKeyItems } from "@/src/services/guildService"; -import { addRecipes, combineInventoryChanges, getInventory } from "@/src/services/inventoryService"; +import { + deleteGuild, + getGuildClient, + giveClanKey, + hasGuildPermission, + removeDojoKeyItems +} from "@/src/services/guildService"; +import { getInventory } from "@/src/services/inventoryService"; import { getAccountForRequest, getAccountIdForRequest, getSuffixedName } from "@/src/services/loginService"; import { GuildPermission } from "@/src/types/guildTypes"; import { IInventoryChanges } from "@/src/types/purchaseTypes"; @@ -41,14 +47,7 @@ export const confirmGuildInvitationGetController: RequestHandler = async (req, r // Update inventory of new member const inventory = await getInventory(account._id.toString(), "GuildId LevelKeys Recipes"); inventory.GuildId = new Types.ObjectId(req.query.clanId as string); - const recipeChanges = [ - { - ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", - ItemCount: 1 - } - ]; - addRecipes(inventory, recipeChanges); - combineInventoryChanges(inventoryChanges, { Recipes: recipeChanges }); + giveClanKey(inventory, inventoryChanges); await inventory.save(); const guild = (await Guild.findById(req.query.clanId as string))!; @@ -96,14 +95,9 @@ export const confirmGuildInvitationPostController: RequestHandler = async (req, await GuildMember.deleteMany({ accountId: guildMember.accountId, status: 1 }); // Update inventory of new member - const inventory = await getInventory(guildMember.accountId.toString(), "GuildId Recipes"); + const inventory = await getInventory(guildMember.accountId.toString(), "GuildId LevelKeys Recipes"); inventory.GuildId = new Types.ObjectId(req.query.clanId as string); - addRecipes(inventory, [ - { - ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", - ItemCount: 1 - } - ]); + giveClanKey(inventory); await inventory.save(); // Add join to clan log diff --git a/src/controllers/api/createGuildController.ts b/src/controllers/api/createGuildController.ts index 9b5bc768..bbaecc19 100644 --- a/src/controllers/api/createGuildController.ts +++ b/src/controllers/api/createGuildController.ts @@ -2,8 +2,9 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { Guild, GuildMember } from "@/src/models/guildModel"; -import { createUniqueClanName, getGuildClient } from "@/src/services/guildService"; -import { addRecipes, getInventory } from "@/src/services/inventoryService"; +import { createUniqueClanName, getGuildClient, giveClanKey } from "@/src/services/guildService"; +import { getInventory } from "@/src/services/inventoryService"; +import { IInventoryChanges } from "@/src/types/purchaseTypes"; export const createGuildController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); @@ -26,26 +27,15 @@ export const createGuildController: RequestHandler = async (req, res) => { rank: 0 }); - const inventory = await getInventory(accountId, "GuildId Recipes"); + const inventory = await getInventory(accountId, "GuildId LevelKeys Recipes"); inventory.GuildId = guild._id; - addRecipes(inventory, [ - { - ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", - ItemCount: 1 - } - ]); + const inventoryChanges: IInventoryChanges = {}; + giveClanKey(inventory, inventoryChanges); await inventory.save(); res.json({ ...(await getGuildClient(guild, accountId)), - InventoryChanges: { - Recipes: [ - { - ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", - ItemCount: 1 - } - ] - } + InventoryChanges: inventoryChanges }); }; diff --git a/src/services/configService.ts b/src/services/configService.ts index 3fe35bcb..26a5008d 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -44,6 +44,7 @@ interface IConfig { noKimCooldowns?: boolean; instantResourceExtractorDrones?: boolean; noResourceExtractorDronesDamage?: boolean; + skipClanKeyCrafting?: boolean; noDojoRoomBuildStage?: boolean; noDojoDecoBuildStage?: boolean; fastDojoRoomDestruction?: boolean; diff --git a/src/services/guildService.ts b/src/services/guildService.ts index 80efc7b5..61e64465 100644 --- a/src/services/guildService.ts +++ b/src/services/guildService.ts @@ -1,6 +1,6 @@ import { Request } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; -import { getInventory } from "@/src/services/inventoryService"; +import { addLevelKeys, addRecipes, combineInventoryChanges, getInventory } from "@/src/services/inventoryService"; import { Alliance, AllianceMember, Guild, GuildAd, GuildMember, TGuildDatabaseDocument } from "@/src/models/guildModel"; import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; import { @@ -657,6 +657,32 @@ export const checkClanAscensionHasRequiredContributors = async (guild: TGuildDat } }; +export const giveClanKey = (inventory: TInventoryDatabaseDocument, inventoryChanges?: IInventoryChanges): void => { + if (config.skipClanKeyCrafting) { + const levelKeyChanges = [ + { + ItemType: "/Lotus/Types/Keys/DojoKey", + ItemCount: 1 + } + ]; + addLevelKeys(inventory, levelKeyChanges); + if (inventoryChanges) { + combineInventoryChanges(inventoryChanges, { LevelKeys: levelKeyChanges }); + } + } else { + const recipeChanges = [ + { + ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", + ItemCount: 1 + } + ]; + addRecipes(inventory, recipeChanges); + if (inventoryChanges) { + combineInventoryChanges(inventoryChanges, { Recipes: recipeChanges }); + } + } +}; + export const removeDojoKeyItems = (inventory: TInventoryDatabaseDocument): IInventoryChanges => { const inventoryChanges: IInventoryChanges = {}; diff --git a/static/webui/index.html b/static/webui/index.html index 5210cd66..2297c8e6 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -674,6 +674,10 @@ +