Add rivals support for fantasia and sunny park

Add comments
This commit is contained in:
cracrayol 2021-04-17 00:13:02 +02:00
parent af7128e327
commit 84113ca2e2
8 changed files with 309 additions and 149 deletions

View File

@ -16,8 +16,8 @@ Important : require minimum Asphyxia Core **v1.31**
## Changelog
### 2.1.0
* Add rivals support
* Various fixes
* Add rivals support (except for Tune Street)
* Some fixes
### 2.0.0
* Big rewrite/reorganization of the code

View File

@ -14,6 +14,9 @@ export const setRoutes = () => {
R.Route(`player23.friend`, friend);
}
/**
* Return current state of the game (phase, good prices, etc...)
*/
const getInfoCommon = (req: EamuseInfo) => {
const result: any = {
phase: [],
@ -80,7 +83,7 @@ const start = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
};
/**
* Create a new profile and send it.
* Handler for new profile
*/
const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -92,7 +95,7 @@ const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
};
/**
* Read a profile and send it.
* Handler for existing profile
*/
const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -101,6 +104,9 @@ const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
send.object(await getProfile(refid));
};
/**
* Handler fo buying goods with lumina
*/
const buy = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -127,14 +133,22 @@ const buy = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> =
send.success();
};
/**
* Handler for getting the user scores
*/
const readScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
send.object({ music: await getScores(refid, version) });
send.object({ music: await getScores(refid) });
};
const getScores = async (refid: string, version: string, forFriend: boolean = false) => {
/**
* Read the user scores and format them (profile/friend)
* @param refid ID of the user
* @param forFriend If true, format the output for friend request.
*/
const getScores = async (refid: string, forFriend: boolean = false) => {
const scoresData = await utils.readScores(refid, version);
const result = [];
@ -164,7 +178,7 @@ const getScores = async (refid: string, version: string, forFriend: boolean = fa
continue;
}
if(forFriend) {
if (forFriend) {
result.push(K.ATTR({
music_num: music.toString(),
sheet_num: sheet.toString(),
@ -184,6 +198,9 @@ const getScores = async (refid: string, version: string, forFriend: boolean = fa
return result;
};
/**
* Handler for saving the scores
*/
const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -231,7 +248,6 @@ const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise
* Get/create the profile based on refid
* @param refid the profile refid
* @param name if defined, create/update the profile with the given name
* @returns
*/
const getProfile = async (refid: string, name?: string) => {
const profile = await utils.readProfile(refid);
@ -244,9 +260,9 @@ const getProfile = async (refid: string, name?: string) => {
let myBest = Array(10).fill(-1);
const scores = await utils.readScores(refid, version, true);
if(Object.entries(scores.scores).length > 0) {
if (Object.entries(scores.scores).length > 0) {
const playCount = new Map();
for(const key in scores.scores) {
for (const key in scores.scores) {
const keyData = key.split(':');
const music = parseInt(keyData[0], 10);
playCount.set(music, (playCount.get(music) || 0) + scores.scores[key].cnt);
@ -255,7 +271,7 @@ const getProfile = async (refid: string, name?: string) => {
const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1]));
let i = 0;
for (const value of sortedPlayCount.keys()) {
if(i >= 10) {
if (i >= 10) {
break;
}
myBest[i] = value;
@ -360,6 +376,9 @@ const getProfile = async (refid: string, name?: string) => {
return player;
}
/**
* Handler for saving the profile
*/
const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -437,14 +456,17 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
send.success();
};
/**
* Handler for sending rivals
*/
const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
const no = parseInt($(data).attr()['no'], -1);
const rivals = await utils.readRivals(refid);
if(no < 0 || no >= rivals.rivals.length) {
send.object({result : K.ITEM('s8', 2)});
if (no < 0 || no >= rivals.rivals.length) {
send.object({ result: K.ITEM('s8', 2) });
return;
}
@ -458,7 +480,7 @@ const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any
name: K.ITEM('str', profile.name),
chara: K.ITEM('s16', params.params.chara || -1),
is_open: K.ITEM('s8', 1),
music : await getScores(rivals.rivals[no], version, true),
music: await getScores(rivals.rivals[no], true),
}
}

View File

@ -2,7 +2,7 @@ import { ExtraData } from "../models/common";
import * as utils from "./utils";
/**
* Return the current phases of the game.
* Handler for getting the current state of the game.
*/
export const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const result = {
@ -31,7 +31,7 @@ export const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Pro
};
/**
* Create a new profile and send it.
* Handler for new profile
*/
export const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -43,7 +43,7 @@ export const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): P
};
/**
* Read a profile and send it.
* Handler for existing profile
*/
export const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -59,6 +59,7 @@ export const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promis
*/
export const getProfile = async (refid: string, name?: string) => {
const profile = await utils.readProfile(refid);
const rivals = await utils.readRivals(refid);
if (name && name.length > 0) {
profile.name = name;
@ -66,53 +67,11 @@ export const getProfile = async (refid: string, name?: string) => {
}
// Get Score
let hiscore_array = Array(Math.floor((((GAME_MAX_MUSIC_ID * 4) * 17) + 7) / 8)).fill(0);
let clear_medal = Array(GAME_MAX_MUSIC_ID).fill(0);
const scores = await getScores(refid);
let clear_medal_sub = Array(GAME_MAX_MUSIC_ID).fill(0);
const scoresData = await utils.readScores(refid, version);
const playCount = new Map();
for (const key in scoresData.scores) {
const keyData = key.split(':');
const score = scoresData.scores[key];
const music = parseInt(keyData[0], 10);
const sheet = parseInt(keyData[1], 10);
if (music > GAME_MAX_MUSIC_ID) {
continue;
}
if ([0, 1, 2, 3].indexOf(sheet) == -1) {
continue;
}
const medal = {
100: 1,
200: 2,
300: 3,
400: 5,
500: 5,
600: 6,
700: 7,
800: 9,
900: 10,
1000: 11,
1100: 15,
}[score.clear_type];
clear_medal[music] = clear_medal[music] | (medal << (sheet * 4));
const hiscore_index = (music * 4) + sheet;
const hiscore_byte_pos = Math.floor((hiscore_index * 17) / 8);
const hiscore_bit_pos = ((hiscore_index * 17) % 8);
const hiscore_value = score.score << hiscore_bit_pos;
hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF);
hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF);
hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF);
playCount.set(music, (playCount.get(music) || 0) + score.cnt);
}
let myBest = Array(20).fill(-1);
const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1]));
const sortedPlayCount = new Map([...scores.playCount.entries()].sort((a, b) => b[1] - a[1]));
let i = 0;
for (const value of sortedPlayCount.keys()) {
if (i >= 20) {
@ -129,15 +88,15 @@ export const getProfile = async (refid: string, name?: string) => {
staff: K.ITEM('s8', 0),
is_conv: K.ITEM('s8', -1),
my_best: K.ARRAY('s16', myBest),
clear_medal: K.ARRAY('u16', clear_medal),
clear_medal: K.ARRAY('u16', scores.clear_medal),
clear_medal_sub: K.ARRAY('u8', clear_medal_sub),
active_fr_num: K.ITEM('u8', rivals.rivals.length),
// TODO: replace with real data
total_play_cnt: K.ITEM('s32', 100),
today_play_cnt: K.ITEM('s16', 50),
consecutive_days: K.ITEM('s16', 365),
latest_music: K.ARRAY('s16', [-1, -1, -1]),
active_fr_num: K.ITEM('u8', 0),
},
player_card: {
// TODO: replace with real data
@ -162,7 +121,7 @@ export const getProfile = async (refid: string, name?: string) => {
set_recommend: K.ARRAY('s8', [0, 0, 0]),
jewelry: K.ARRAY('s8', Array(15).fill(0)),
},
hiscore: K.ITEM('bin', Buffer.from(hiscore_array))
hiscore: K.ITEM('bin', Buffer.from(scores.hiscore_array))
};
// Add version specific datas
@ -175,7 +134,7 @@ export const getProfile = async (refid: string, name?: string) => {
}
/**
* Unformat and write the end game data into DB
* Handler for saving profile ans scores
*/
export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
@ -238,6 +197,91 @@ export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promi
send.object(result);
};
/**
* Handler for sending rivals
*/
export const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
const rivals = await utils.readRivals(refid);
let result = {
friend: []
}
for (const rival of rivals.rivals.slice(0, 2)) {
const profile = await utils.readProfile(rival);
const params = await utils.readParams(rival, version);
const scores = await getScores(refid);
result.friend.push({
open: K.ITEM('s8', 1),
g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'),
name: K.ITEM('str', profile.name),
chara: K.ITEM('s16', params.params.chara || -1),
clear_medal: K.ARRAY('u16', scores.clear_medal),
hiscore: K.ITEM('bin', Buffer.from(scores.hiscore_array))
});
}
send.object(result);
}
/**
* Read the user scores and format them
* @param refid ID of the user
*/
const getScores = async (refid: string) => {
let hiscore_array = Array(Math.floor((((GAME_MAX_MUSIC_ID * 4) * 17) + 7) / 8)).fill(0);
let clear_medal = Array(GAME_MAX_MUSIC_ID).fill(0);
const scoresData = await utils.readScores(refid, version);
const playCount = new Map();
for (const key in scoresData.scores) {
const keyData = key.split(':');
const score = scoresData.scores[key];
const music = parseInt(keyData[0], 10);
const sheet = parseInt(keyData[1], 10);
if (music > GAME_MAX_MUSIC_ID) {
continue;
}
if ([0, 1, 2, 3].indexOf(sheet) == -1) {
continue;
}
const medal = {
100: 1,
200: 2,
300: 3,
400: 5,
500: 5,
600: 6,
700: 7,
800: 9,
900: 10,
1000: 11,
1100: 15,
}[score.clear_type];
clear_medal[music] = clear_medal[music] | (medal << (sheet * 4));
const hiscore_index = (music * 4) + sheet;
const hiscore_byte_pos = Math.floor((hiscore_index * 17) / 8);
const hiscore_bit_pos = ((hiscore_index * 17) % 8);
const hiscore_value = score.score << hiscore_bit_pos;
hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF);
hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF);
hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF);
playCount.set(music, (playCount.get(music) || 0) + score.cnt);
}
return {
hiscore_array,
clear_medal,
playCount
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const version: string = 'v20';

View File

@ -12,7 +12,7 @@ export const setRoutes = () => {
}
/**
* Return info22.common informations (phase, etc...)
* Handler for getting current state of the game.
*/
const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const result: any = {
@ -39,7 +39,7 @@ const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<an
};
/**
* Create a new profile and send it.
* Handler for new profile
*/
const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -51,7 +51,7 @@ const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
};
/**
* Read a profile and send it.
* Handler for existing profile
*/
const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -60,6 +60,9 @@ const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
send.object(await getProfile(refid));
};
/**
* Handler for saving the scores
*/
const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -107,7 +110,6 @@ const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise
* Get/create the profile based on refid
* @param refid the profile refid
* @param name if defined, create/update the profile with the given name
* @returns
*/
const getProfile = async (refid: string, name?: string) => {
const profile = await utils.readProfile(refid);
@ -280,6 +282,9 @@ const getProfile = async (refid: string, name?: string) => {
return player;
}
/**
* Handler for saving the profile
*/
const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -374,14 +379,17 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
send.success();
};
/**
* Handler for sending rivals
*/
const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
const no = parseInt($(data).attr()['no'], -1);
const rivals = await utils.readRivals(refid);
if(no < 0 || no >= rivals.rivals.length) {
send.object({result : K.ITEM('s8', 2)});
if (no < 0 || no >= rivals.rivals.length) {
send.object({ result: K.ITEM('s8', 2) });
return;
}

View File

@ -2,7 +2,7 @@ import { ExtraData } from "../models/common";
import * as utils from "./utils";
/**
* Return the current phases of the game.
* Handler for getting the current state of the game (phase, good prices, etc...)
*/
export const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const result = {
@ -19,15 +19,15 @@ export const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Pro
l_matching_sec: K.ITEM('s32', 60),
is_check_cpu: K.ITEM('s32', 0),
week_no: K.ITEM('s32', 0),
sel_ranking: K.ARRAY('s16', [-1, -1, -1, -1, -1]),
up_ranking: K.ARRAY('s16', [-1, -1, -1, -1, -1]),
sel_ranking: K.ARRAY('s16', Array(10).fill(-1)),
up_ranking: K.ARRAY('s16', Array(10).fill(-1)),
};
return send.object(result);
};
/**
* Create a new profile and send it.
* Handler for new profile
*/
export const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -39,7 +39,7 @@ export const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): P
};
/**
* Read a profile and send it.
* Handler for existing profile
*/
export const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -55,6 +55,7 @@ export const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promis
*/
export const getProfile = async (refid: string, name?: string) => {
const profile = await utils.readProfile(refid);
const rivals = await utils.readRivals(refid);
if (name && name.length > 0) {
profile.name = name;
@ -62,53 +63,11 @@ export const getProfile = async (refid: string, name?: string) => {
}
// Get Score
let hiscore_array = Array(Math.floor((((GAME_MAX_MUSIC_ID * 4) * 17) + 7) / 8)).fill(0);
let clear_medal = Array(GAME_MAX_MUSIC_ID).fill(0);
const scores = await getScores(refid);
let clear_medal_sub = Array(GAME_MAX_MUSIC_ID).fill(0);
const scoresData = await utils.readScores(refid, version);
const playCount = new Map();
for (const key in scoresData.scores) {
const keyData = key.split(':');
const score = scoresData.scores[key];
const music = parseInt(keyData[0], 10);
const sheet = parseInt(keyData[1], 10);
if (music > GAME_MAX_MUSIC_ID) {
continue;
}
if ([0, 1, 2, 3].indexOf(sheet) == -1) {
continue;
}
const medal = {
100: 1,
200: 2,
300: 3,
400: 5,
500: 5,
600: 6,
700: 7,
800: 9,
900: 10,
1000: 11,
1100: 15,
}[score.clear_type];
clear_medal[music] = clear_medal[music] | (medal << (sheet * 4));
const hiscore_index = (music * 4) + sheet;
const hiscore_byte_pos = Math.floor((hiscore_index * 17) / 8);
const hiscore_bit_pos = ((hiscore_index * 17) % 8);
const hiscore_value = score.score << hiscore_bit_pos;
hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF);
hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF);
hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF);
playCount.set(music, (playCount.get(music) || 0) + score.cnt);
}
let myBest = Array(20).fill(-1);
const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1]));
const sortedPlayCount = new Map([...scores.playCount.entries()].sort((a, b) => b[1] - a[1]));
let i = 0;
for (const value of sortedPlayCount.keys()) {
if (i >= 20) {
@ -126,15 +85,15 @@ export const getProfile = async (refid: string, name?: string) => {
is_conv: K.ITEM('s8', -1),
collabo: K.ITEM('u8', 255),
my_best: K.ARRAY('s16', myBest),
clear_medal: K.ARRAY('u16', clear_medal),
clear_medal: K.ARRAY('u16', scores.clear_medal),
clear_medal_sub: K.ARRAY('u8', clear_medal_sub),
active_fr_num: K.ITEM('u8', rivals.rivals.length),
// TODO: replace with real data
total_play_cnt: K.ITEM('s32', 100),
today_play_cnt: K.ITEM('s16', 50),
consecutive_days: K.ITEM('s16', 365),
latest_music: K.ARRAY('s16', [-1, -1, -1]),
active_fr_num: K.ITEM('u8', 0),
},
netvs: {
rank_point: K.ITEM('s32', 0),
@ -154,7 +113,7 @@ export const getProfile = async (refid: string, name?: string) => {
set_recommend: K.ARRAY('s8', [0, 0, 0]),
netvs_play_cnt: K.ITEM('u8', 0),
},
hiscore: K.ITEM('bin', Buffer.from(hiscore_array)),
hiscore: K.ITEM('bin', Buffer.from(scores.hiscore_array)),
gakuen_data: {
music_list: K.ITEM('s32', -1),
},
@ -215,7 +174,7 @@ export const getProfile = async (refid: string, name?: string) => {
}
/**
* Unformat and write the end game data into DB
* Handler for saving profile and scores
*/
export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
@ -273,6 +232,97 @@ export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promi
send.object(result);
};
/**
* Handler for sending rivals
*/
export const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
const rivals = await utils.readRivals(refid);
let result = {
friend: []
}
for (const rival of rivals.rivals.slice(0, 2)) {
const profile = await utils.readProfile(rival);
const params = await utils.readParams(rival, version);
const scores = await getScores(rival);
result.friend.push({
open: K.ITEM('s8', 1),
g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'),
name: K.ITEM('str', profile.name),
chara: K.ITEM('s16', params.params.chara || -1),
hair: K.ITEM('u8', params.params.hair || 0),
face: K.ITEM('u8', params.params.face || 0),
body: K.ITEM('u8', params.params.body || 0),
effect: K.ITEM('u8', params.params.effect || 0),
object: K.ITEM('u8', params.params.object || 0),
comment: K.ARRAY('u8', params.params.comment || [0, 0]),
clear_medal: K.ARRAY('u16', scores.clear_medal),
hiscore: K.ITEM('bin', Buffer.from(scores.hiscore_array))
});
}
send.object(result);
}
/**
* Read the user scores and format them
* @param refid ID of the user
*/
const getScores = async (refid: string) => {
let hiscore_array = Array(Math.floor((((GAME_MAX_MUSIC_ID * 4) * 17) + 7) / 8)).fill(0);
let clear_medal = Array(GAME_MAX_MUSIC_ID).fill(0);
const scoresData = await utils.readScores(refid, version);
const playCount = new Map();
for (const key in scoresData.scores) {
const keyData = key.split(':');
const score = scoresData.scores[key];
const music = parseInt(keyData[0], 10);
const sheet = parseInt(keyData[1], 10);
if (music > GAME_MAX_MUSIC_ID) {
continue;
}
if ([0, 1, 2, 3].indexOf(sheet) == -1) {
continue;
}
const medal = {
100: 1,
200: 2,
300: 3,
400: 5,
500: 5,
600: 6,
700: 7,
800: 9,
900: 10,
1000: 11,
1100: 15,
}[score.clear_type];
clear_medal[music] = clear_medal[music] | (medal << (sheet * 4));
const hiscore_index = (music * 4) + sheet;
const hiscore_byte_pos = Math.floor((hiscore_index * 17) / 8);
const hiscore_bit_pos = ((hiscore_index * 17) % 8);
const hiscore_value = score.score << hiscore_bit_pos;
hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF);
hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF);
hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF);
playCount.set(music, (playCount.get(music) || 0) + score.cnt);
}
return {
hiscore_array,
clear_medal,
playCount
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const version: string = 'v21';

View File

@ -1,5 +1,8 @@
import * as utils from "./utils";
/**
* Handler for getting the current state of the game (phase, good prices, etc...)
*/
export const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const result = K.ATTR({ game_phase: "2", psp_phase: "2" });
@ -7,7 +10,7 @@ export const getInfo = async (req: EamuseInfo, data: any, send: EamuseSend): Pro
};
/**
* Create a new profile and send it.
* Handler for new profile
*/
export const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
@ -19,7 +22,7 @@ export const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): P
};
/**
* Read a profile and send it.
* Handler for existing profile
*/
export const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
@ -29,10 +32,9 @@ export const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promis
};
/**
* Get/create the profile based on refid
* Get/create the profile and scores based on refid
* @param refid the profile refid
* @param name if defined, create/update the profile with the given name
* @returns
*/
export const getProfile = async (refid: string, name?: string) => {
const profile = await utils.readProfile(refid);
@ -185,6 +187,9 @@ const __format_flags_for_score = (sheet: number, clear_type: number) => {
return (flags << shift) | playedflag
}
/**
* Handler for saving profile and scores
*/
export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
if (!refid) return send.deny();
@ -288,6 +293,11 @@ export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promi
send.object(result);
};
export const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
// No rivals support for Tune street :(
send.deny();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const version: string = 'v19';

View File

@ -14,6 +14,9 @@ export const setRoutes = () => {
R.Route(`player24.friend`, friend);
}
/**
* Return current state of the game (phase, good prices, etc...)
*/
const getInfoCommon = (req: EamuseInfo) => {
const result: any = {
phase: [],
@ -92,7 +95,7 @@ const start = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
};
/**
* Create a new profile and send it.
* Handler for new profile
*/
const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -104,7 +107,7 @@ const newPlayer = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
};
/**
* Read a profile and send it.
* Handler for existing profile
*/
const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
@ -113,6 +116,9 @@ const read = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
send.object(await getProfile(refid, getVersion(req)));
};
/**
* Handler fo buying goods with lumina
*/
const buy = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -134,13 +140,16 @@ const buy = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> =
params.params.player_point = lumina - price;
await utils.writeParams(refid, version, params);
const achievements = <AchievementsUsaneko>await utils.readAchievements(refid, version, {...defaultAchievements, version});
const achievements = <AchievementsUsaneko>await utils.readAchievements(refid, version, { ...defaultAchievements, version });
achievements.items[`${type}:${id}`] = param;
await utils.writeAchievements(refid, version, achievements);
}
send.success();
};
/**
* Handler for getting the user scores
*/
const readScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
const version = getVersion(req);
@ -149,6 +158,11 @@ const readScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
send.object({ music: await getScores(refid, version) });
};
/**
* Read the user scores and format them (profile/friend)
* @param refid ID of the user
* @param forFriend If true, format the output for friend request.
*/
const getScores = async (refid: string, version: string, forFriend: boolean = false) => {
const scoresData = await utils.readScores(refid, version);
const result = [];
@ -179,7 +193,7 @@ const getScores = async (refid: string, version: string, forFriend: boolean = fa
continue;
}
if(forFriend) {
if (forFriend) {
result.push(K.ATTR({
music_num: music.toString(),
sheet_num: sheet.toString(),
@ -202,6 +216,9 @@ const getScores = async (refid: string, version: string, forFriend: boolean = fa
return result;
};
/**
* Return the rank based on the given score
*/
const getRank = (score: number): number => {
if (score < 50000) {
return 1
@ -221,6 +238,9 @@ const getRank = (score: number): number => {
return 8
}
/**
* Handler for saving the scores
*/
const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const version = getVersion(req);
const refid = $(data).str('ref_id');
@ -269,7 +289,6 @@ const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise
* Get/create the profile based on refid
* @param refid the profile refid
* @param name if defined, create/update the profile with the given name
* @returns
*/
const getProfile = async (refid: string, version: string, name?: string) => {
const profile = await utils.readProfile(refid);
@ -282,9 +301,9 @@ const getProfile = async (refid: string, version: string, name?: string) => {
let myBest = Array(10).fill(-1);
const scores = await utils.readScores(refid, version, true);
if(Object.entries(scores.scores).length > 0) {
if (Object.entries(scores.scores).length > 0) {
const playCount = new Map();
for(const key in scores.scores) {
for (const key in scores.scores) {
const keyData = key.split(':');
const music = parseInt(keyData[0], 10);
playCount.set(music, (playCount.get(music) || 0) + scores.scores[key].cnt);
@ -293,7 +312,7 @@ const getProfile = async (refid: string, version: string, name?: string) => {
const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1]));
let i = 0;
for (const value of sortedPlayCount.keys()) {
if(i >= 10) {
if (i >= 10) {
break;
}
myBest[i] = value;
@ -384,7 +403,7 @@ const getProfile = async (refid: string, version: string, name?: string) => {
stamp: [],
};
const achievements = <AchievementsUsaneko>await utils.readAchievements(refid, version, {...defaultAchievements, version});
const achievements = <AchievementsUsaneko>await utils.readAchievements(refid, version, { ...defaultAchievements, version });
const profileCharas = achievements.charas || {};
for (const chara_id in profileCharas) {
@ -395,8 +414,8 @@ const getProfile = async (refid: string, version: string, name?: string) => {
}
let profileStamps = achievements.stamps;
if(Object.entries(profileStamps).length == 0) {
profileStamps = {"0": 0 };
if (Object.entries(profileStamps).length == 0) {
profileStamps = { "0": 0 };
}
for (const stamp_id in profileStamps) {
player.stamp.push({
@ -465,6 +484,9 @@ const getProfile = async (refid: string, version: string, name?: string) => {
return player;
}
/**
* Handler for saving the profile
*/
const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).str('ref_id');
if (!refid) return send.deny();
@ -472,7 +494,7 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
const version = getVersion(req);
const params = await utils.readParams(refid, version);
const achievements = <AchievementsUsaneko>await utils.readAchievements(refid, version, {...defaultAchievements, version});
const achievements = <AchievementsUsaneko>await utils.readAchievements(refid, version, { ...defaultAchievements, version });
utils.getExtraData(data, params, EXTRA_DATA);
@ -611,6 +633,9 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
send.success();
};
/**
* Handler for sending rivals
*/
const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
const refid = $(data).attr()['ref_id'];
const no = parseInt($(data).attr()['no'], -1);
@ -618,8 +643,8 @@ const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any
const rivals = await utils.readRivals(refid);
if(no < 0 || no >= rivals.rivals.length) {
send.object({result : K.ITEM('s8', 2)});
if (no < 0 || no >= rivals.rivals.length) {
send.object({ result: K.ITEM('s8', 2) });
return;
}
@ -633,7 +658,7 @@ const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any
name: K.ITEM('str', profile.name),
chara: K.ITEM('s16', params.params.chara || -1),
is_open: K.ITEM('s8', 1),
music : await getScores(rivals.rivals[no], version, true),
music: await getScores(rivals.rivals[no], version, true),
}
}

View File

@ -38,9 +38,9 @@ export function register() {
// Rivals UI management
R.WebUIEvent('deleteRival', async (data: any) => {
const rivals = await DB.FindOne<Rivals>(data.refid, { collection: 'rivals' }) || {collection: 'rivals', rivals: []};
const rivals = await DB.FindOne<Rivals>(data.refid, { collection: 'rivals' }) || { collection: 'rivals', rivals: [] };
const idx = rivals.rivals.indexOf(data.rivalid);
if(idx >= 0) {
if (idx >= 0) {
rivals.rivals.splice(idx, 1);
await DB.Update(data.refid, { collection: 'rivals' }, rivals);
}
@ -48,10 +48,10 @@ export function register() {
R.WebUIEvent('addRival', async (data: any) => {
const refid = data.refid.trim();
const profile = await DB.FindOne(data.rivalid, { collection: 'profile'});
if(profile != undefined && profile != null) {
const rivals = await DB.FindOne<Rivals>(refid, { collection: 'rivals' }) || {collection: 'rivals', rivals: []};
if(rivals.rivals.length < 4) {
const profile = await DB.FindOne(data.rivalid, { collection: 'profile' });
if (profile != undefined && profile != null) {
const rivals = await DB.FindOne<Rivals>(refid, { collection: 'rivals' }) || { collection: 'rivals', rivals: [] };
if (rivals.rivals.length < 4) {
rivals.rivals.push(data.rivalid);
await DB.Upsert(refid, { collection: 'rivals' }, rivals);
}
@ -64,6 +64,7 @@ export function register() {
R.Route(`playerdata.conversion`, async (req, data, send) => getVersion(req).newPlayer(req, data, send));
R.Route(`playerdata.get`, async (req, data, send) => getVersion(req).read(req, data, send));
R.Route(`playerdata.set`, async (req, data, send) => getVersion(req).write(req, data, send));
R.Route(`playerdata.friend`, async (req, data, send) => getVersion(req).friend(req, data, send));
// For Pnm >= 22, each game set his own route
lapistoria.setRoutes();