Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded task generation and misc tidy up #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
Node v22.4.0 required

To generate League tasks and Combat Tasks, with the above Node version installed run;

npm run cli tasks combat -- --legacy --json

npm run cli tasks leagues4 -- --legacy --json

Ensuring you have an "out" directory alongside /src/ this will generate 2 corresponding .JSONs for use.

Examples below;


{
"id": "1622",
"name": "Equip a Corrupted Bow of Faerdhinen",
"description": "Obtain and Equip a Corrupted Bow of Faerdhinen.",
"category": "Combat",
"tier": "Master",
"clientSortId": "1471"
},



{
"structId": 3453,
"sortId": 393,
"id": "3594",
"monster": "12",
"name": "Undying Raider",
"description": "Complete a Chambers of Xeric solo raid without dying.",
"category": "Combat",
"tier": "Master",
"clientSortId": "393"
},
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@abextm/cache2": "^0.1.1",
"@abextm/cache2": "^0.1.2",
"@inquirer/prompts": "^5.5.0",
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
Expand Down
138 changes: 76 additions & 62 deletions src/cli/commands/tasks/tasks-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,101 +39,115 @@ export class TasksCommand {

public async handleCombatTasks(options: any): Promise<ITask[]> {
const orderedStructIds: number[] = [];

const categoryEnum = await this.enumService.getEnum(3413); // Preload category enum

const difficultyEnums: number[] = [3981, 3982, 3983, 3984, 3985, 3986];
for (let enumId of difficultyEnums) {
const orderedDifficultyStructIds: Map<number, string | number> = (await this.enumService.getEnum(enumId)).map;
for (const structId of orderedDifficultyStructIds.values()) {
orderedStructIds.push(structId as number);
}
}

const allTaskStructs: Struct[] = [];
for (let structId of orderedStructIds) {
const taskStruct: Struct = await this.structService.getStruct(structId);
allTaskStructs.push(taskStruct);
}

let allTasksFormatted: any[] = [];

if (options.legacy) {
allTasksFormatted = allTaskStructs.map((s, i) => {
const out = {
id: '' + (s.params.get(PARAM_ID.CA_VARBIT_INDEX) as number),
monster: '' + (s.params.get(PARAM_ID.CA_MONSTER_ID) as number),
name: s.params.get(PARAM_ID.CA_NAME) as string,
description: s.params.get(PARAM_ID.CA_DESCRIPTION) as string,
category: '',
tier: this.getLegacyTier(s.params.get(PARAM_ID.CA_TIER_ID) as number),
clientSortId: '' + i,
};
return out;
});
} else {
allTasksFormatted = allTaskStructs.map((s, i) => {
const out: ITask = {
structId: s.id,
sortId: i,
};
return out;
});
}


const allTasksFormatted: ITask[] = allTaskStructs.map((s, i) => {
const categoryValue = s.params.get(PARAM_ID.CA_CATEGORY_ID) as number;

return {
structId: s.id,
sortId: i,
id: '' + (s.params.get(PARAM_ID.CA_VARBIT_INDEX) as number),
monster: '' + (s.params.get(PARAM_ID.CA_MONSTER_ID) as number),
name: s.params.get(PARAM_ID.CA_NAME) as string,
description: s.params.get(PARAM_ID.CA_DESCRIPTION) as string,
category: categoryEnum.map.get(categoryValue) || 'Unknown',
tier: this.getLegacyTier(s.params.get(PARAM_ID.CA_TIER_ID) as number),
clientSortId: '' + i,
};
});

if (options.json) {
this.writeToFile(allTasksFormatted, 'combat.json');
} else {
console.log(JSON.stringify(allTasksFormatted, replacer));
}
return allTasksFormatted;

return allTasksFormatted;
}



public async handleLeagues4(options: any): Promise<ITask[]> {
const structId: ParamID = 873 as ParamID;
// console.log('handleLeagues4 invoked with options:', options);
SonderAu marked this conversation as resolved.
Show resolved Hide resolved

const structId: ParamID = PARAM_ID.LEAGUE_VARBIT_INDEX;
const categoryParamId: ParamID = PARAM_ID.LEAGUE_CATEGORY_ID;
const tierParamId: ParamID = PARAM_ID.LEAGUE_TIER_ID;

// Define tierMap (could probably move this not here)
const tierMap = {
SonderAu marked this conversation as resolved.
Show resolved Hide resolved
1: 'Easy',
2: 'Medium',
3: 'Hard',
4: 'Elite',
5: 'Master',
6: 'Grandmaster',
};

// Fetch category enum (3413)
const categoryEnum = await this.enumService.getEnum(3413);

// Ensure the categories are read and still valid from previous year.
console.log('Loaded categoryEnum:', Array.from(categoryEnum.map.entries()));


// Sort function for tasks
const sortFunction = (a: Struct, b: Struct) => {
const aSort = a.params.get(structId) as number;
const bSort = b.params.get(structId) as number;
return aSort - bSort;
};
const tierParamId: ParamID = 1852 as ParamID;
const easy: Struct[] = (await this.structService.findByParam(tierParamId, 1)).sort(sortFunction);
const medium: Struct[] = (await this.structService.findByParam(tierParamId, 2)).sort(sortFunction);
const hard: Struct[] = (await this.structService.findByParam(tierParamId, 3)).sort(sortFunction);
const elite: Struct[] = (await this.structService.findByParam(tierParamId, 4)).sort(sortFunction);
const master: Struct[] = (await this.structService.findByParam(tierParamId, 5)).sort(sortFunction);

const easy = (await this.structService.findByParam(tierParamId, 1)).sort(sortFunction);
const medium = (await this.structService.findByParam(tierParamId, 2)).sort(sortFunction);
const hard = (await this.structService.findByParam(tierParamId, 3)).sort(sortFunction);
const elite = (await this.structService.findByParam(tierParamId, 4)).sort(sortFunction);
const master = (await this.structService.findByParam(tierParamId, 5)).sort(sortFunction);

const all = [...easy, ...medium, ...hard, ...elite, ...master];
let allAsTasks: any[] = [];

if (options.legacy) {
allAsTasks = all.map((s, i) => {
const out = {
id: '' + (s.params.get(structId) as number),
monster: '',
name: s.params.get(874 as ParamID) as string,
description: s.params.get(875 as ParamID) as string,
category: '',
tier: '',
clientSortId: '' + i,
};
return out;
});
} else {
allAsTasks = all.map((s, i) => {
const out: ITask = {
structId: s.params.get(structId) as number,
sortId: i,
};
return out;
});
}


allAsTasks = all.map((s, i) => {
const categoryValue = s.params.get(categoryParamId) as number;
SonderAu marked this conversation as resolved.
Show resolved Hide resolved
const tierValue = s.params.get(tierParamId) as number;

return {
id: '' + (s.params.get(structId) as number),
name: s.params.get(PARAM_ID.LEAGUE_NAME) as string,
description: s.params.get(PARAM_ID.LEAGUE_DESCRIPTION) as string,
category: categoryEnum.map.get(categoryValue) || 'Unknown',
tier: tierMap[tierValue] || 'Unknown',
clientSortId: '' + i,
};
});


if (options.json) {
this.writeToFile(allAsTasks, 'leagues_4.json');
} else {
console.log(JSON.stringify(allAsTasks, replacer));
console.log(JSON.stringify(allAsTasks, replacer, 2));
}

return allAsTasks;
}

SonderAu marked this conversation as resolved.
Show resolved Hide resolved



private writeToFile(obj: any, fileNameAndPath: string): void {
writeFileSync('./out/' + fileNameAndPath, JSON.stringify(obj, null, 2));
Expand Down
3 changes: 3 additions & 0 deletions src/core/data/param-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ export class PARAM_ID {
static LEAGUE_NAME: ParamID = 874 as ParamID;
static LEAGUE_DESCRIPTION: ParamID = 875 as ParamID;
static LEAGUE_TIER_ID: ParamID = 1852 as ParamID;
static LEAGUE_CATEGORY_ID: ParamID = 1016 as ParamID; // Leagues IV category

// Combat achievements
static CA_VARBIT_INDEX: ParamID = 1307 as ParamID;
static CA_NAME: ParamID = 1308 as ParamID;
static CA_DESCRIPTION: ParamID = 1309 as ParamID;
static CA_MONSTER_ID: ParamID = 1312 as ParamID;
static CA_TIER_ID: ParamID = 1310 as ParamID;
static CA_CATEGORY_ID: ParamID = 1311 as ParamID; // Combat Achievements category
}
21 changes: 21 additions & 0 deletions src/core/services/enum/enum.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,26 @@ export class EnumService {
const structEnums: Enum[] = allEnums.filter((e) => e.valueTypeChar === ScriptVarType.struct.char);
return structEnums;
}

// Add this method for getting category names
public async getCategoryName(enumId: number, categoryId: number): Promise<string> {
SonderAu marked this conversation as resolved.
Show resolved Hide resolved
if (!enumId || !categoryId) {
return 'Unknown';
}

// Load the enum map using the enum ID
const categoryEnum = await this.getEnum(enumId);
if (!categoryEnum || !categoryEnum.map) {
return 'Unknown';
}

// Retrieve the category name
const categoryValue = categoryEnum.map.get(categoryId);

// Always return a string
return categoryValue ? String(categoryValue) : 'Unknown';
}


}