mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-10-11 00:28:16 +03:00
Add rivals support for Lapistoria-peace
Fix stamp not properly initialized on usaneko
This commit is contained in:
@@ -11,6 +11,7 @@ export const setRoutes = () => {
|
||||
R.Route(`player23.read_score`, readScore);
|
||||
R.Route(`player23.write_music`, writeScore);
|
||||
R.Route(`player23.write`, write);
|
||||
R.Route(`player23.friend`, friend);
|
||||
}
|
||||
|
||||
const getInfoCommon = (req: EamuseInfo) => {
|
||||
@@ -130,16 +131,31 @@ const readScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
|
||||
const refid = $(data).str('ref_id');
|
||||
if (!refid) return send.deny();
|
||||
|
||||
send.object({ music: await getScores(refid, version) });
|
||||
};
|
||||
|
||||
const getScores = async (refid: string, version: string, forFriend: boolean = false) => {
|
||||
const scoresData = await utils.readScores(refid, version);
|
||||
const result: any = {
|
||||
music: [],
|
||||
};
|
||||
const result = [];
|
||||
|
||||
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);
|
||||
const clearType = {
|
||||
100: 1,
|
||||
200: 2,
|
||||
300: 3,
|
||||
400: 4,
|
||||
500: 5,
|
||||
600: 6,
|
||||
700: 7,
|
||||
800: 8,
|
||||
900: 9,
|
||||
1000: 10,
|
||||
1100: 11,
|
||||
}[score.clear_type];
|
||||
|
||||
if (music > GAME_MAX_MUSIC_ID) {
|
||||
continue;
|
||||
@@ -148,28 +164,24 @@ const readScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
|
||||
continue;
|
||||
}
|
||||
|
||||
result.music.push({
|
||||
music_num: K.ITEM('s16', music),
|
||||
sheet_num: K.ITEM('u8', sheet),
|
||||
score: K.ITEM('s32', score.score),
|
||||
clear_type: K.ITEM('u8', {
|
||||
100: 1,
|
||||
200: 2,
|
||||
300: 3,
|
||||
400: 4,
|
||||
500: 5,
|
||||
600: 6,
|
||||
700: 7,
|
||||
800: 8,
|
||||
900: 9,
|
||||
1000: 10,
|
||||
1100: 11,
|
||||
}[score.clear_type]),
|
||||
cnt: K.ITEM('s16', score.cnt),
|
||||
});
|
||||
if(forFriend) {
|
||||
result.push(K.ATTR({
|
||||
music_num: music.toString(),
|
||||
sheet_num: sheet.toString(),
|
||||
score: score.score.toString(),
|
||||
clearmedal: clearType.toString()
|
||||
}));
|
||||
} else {
|
||||
result.push({
|
||||
music_num: K.ITEM('s16', music),
|
||||
sheet_num: K.ITEM('u8', sheet),
|
||||
score: K.ITEM('s32', score.score),
|
||||
clear_type: K.ITEM('u8', clearType),
|
||||
cnt: K.ITEM('s16', score.cnt),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
send.object(result);
|
||||
return result;
|
||||
};
|
||||
|
||||
const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any> => {
|
||||
@@ -223,6 +235,7 @@ const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise
|
||||
*/
|
||||
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;
|
||||
@@ -261,6 +274,7 @@ const getProfile = async (refid: string, name?: string) => {
|
||||
is_conv: K.ITEM('s8', 0),
|
||||
meteor_flg: K.ITEM('bool', true),
|
||||
license_data: K.ARRAY('s16', Array(20).fill(-1)),
|
||||
active_fr_num: K.ITEM('u8', rivals.rivals.length),
|
||||
|
||||
// TODO: replace with real data
|
||||
total_play_cnt: K.ITEM('s16', 100),
|
||||
@@ -270,7 +284,6 @@ const getProfile = async (refid: string, name?: string) => {
|
||||
interval_day: K.ITEM('s16', 1),
|
||||
my_best: K.ARRAY('s16', myBest),
|
||||
latest_music: K.ARRAY('s16', [-1, -1, -1, -1, -1]),
|
||||
active_fr_num: K.ITEM('u8', 0),
|
||||
},
|
||||
netvs: {
|
||||
record: K.ARRAY('s16', [0, 0, 0, 0, 0, 0]),
|
||||
@@ -424,6 +437,34 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
|
||||
send.success();
|
||||
};
|
||||
|
||||
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)});
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = await utils.readProfile(rivals.rivals[no]);
|
||||
const params = await utils.readParams(rivals.rivals[no], version);
|
||||
|
||||
const friend = {
|
||||
friend: {
|
||||
no: K.ITEM('s16', no),
|
||||
g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'),
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
send.object(friend);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const version: string = 'v23';
|
||||
|
||||
@@ -8,6 +8,7 @@ export const setRoutes = () => {
|
||||
R.Route(`player22.read`, read);
|
||||
R.Route(`player22.write_music`, writeScore);
|
||||
R.Route(`player22.write`, write);
|
||||
R.Route(`player22.friend`, friend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +111,7 @@ const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise
|
||||
*/
|
||||
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;
|
||||
@@ -126,6 +128,7 @@ const getProfile = async (refid: string, name?: string) => {
|
||||
item_type: K.ITEM('s16', 0),
|
||||
item_id: K.ITEM('s16', 0),
|
||||
license_data: K.ARRAY('s16', [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]),
|
||||
active_fr_num: K.ITEM('u8', rivals.rivals.length),
|
||||
|
||||
// TODO: replace with real data
|
||||
total_play_cnt: K.ITEM('s16', 100),
|
||||
@@ -134,7 +137,6 @@ const getProfile = async (refid: string, name?: string) => {
|
||||
total_days: K.ITEM('s16', 366),
|
||||
interval_day: K.ITEM('s16', 1),
|
||||
latest_music: K.ARRAY('s16', [-1, -1, -1, -1, -1]),
|
||||
active_fr_num: K.ITEM('u8', 0),
|
||||
},
|
||||
netvs: {
|
||||
rank_point: K.ITEM('s32', 0),
|
||||
@@ -372,6 +374,70 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
|
||||
send.success();
|
||||
};
|
||||
|
||||
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)});
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = await utils.readProfile(rivals.rivals[no]);
|
||||
const params = await utils.readParams(rivals.rivals[no], version);
|
||||
|
||||
// Add Score
|
||||
const scoresData = await utils.readScores(rivals.rivals[no], version);
|
||||
const scores = [];
|
||||
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;
|
||||
}
|
||||
|
||||
scores.push(K.ATTR({
|
||||
music_num: music.toString(),
|
||||
sheet_num: sheet.toString(),
|
||||
score: score.score.toString(),
|
||||
clearmedal: {
|
||||
100: 1,
|
||||
200: 2,
|
||||
300: 3,
|
||||
400: 4,
|
||||
500: 5,
|
||||
600: 6,
|
||||
700: 7,
|
||||
800: 8,
|
||||
900: 9,
|
||||
1000: 10,
|
||||
1100: 11,
|
||||
}[score.clear_type].toString(),
|
||||
}));
|
||||
}
|
||||
|
||||
const friend = {
|
||||
friend: {
|
||||
no: K.ITEM('s16', no),
|
||||
g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'),
|
||||
name: K.ITEM('str', profile.name),
|
||||
chara: K.ITEM('s16', params.params.chara || -1),
|
||||
is_open: K.ITEM('s8', 1),
|
||||
music: scores,
|
||||
}
|
||||
}
|
||||
|
||||
send.object(friend);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const version: string = 'v22';
|
||||
|
||||
@@ -11,6 +11,7 @@ export const setRoutes = () => {
|
||||
R.Route(`player24.read_score`, readScore);
|
||||
R.Route(`player24.write_music`, writeScore);
|
||||
R.Route(`player24.write`, write);
|
||||
R.Route(`player24.friend`, friend);
|
||||
}
|
||||
|
||||
const getInfoCommon = (req: EamuseInfo) => {
|
||||
@@ -148,7 +149,7 @@ const readScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<
|
||||
send.object({ music: await getScores(refid, version) });
|
||||
};
|
||||
|
||||
const getScores = async (refid: string, version: string) => {
|
||||
const getScores = async (refid: string, version: string, forFriend: boolean = false) => {
|
||||
const scoresData = await utils.readScores(refid, version);
|
||||
const result = [];
|
||||
|
||||
@@ -157,6 +158,19 @@ const getScores = async (refid: string, version: string) => {
|
||||
const score = scoresData.scores[key];
|
||||
const music = parseInt(keyData[0], 10);
|
||||
const sheet = parseInt(keyData[1], 10);
|
||||
const clearType = {
|
||||
100: 1,
|
||||
200: 2,
|
||||
300: 3,
|
||||
400: 4,
|
||||
500: 5,
|
||||
600: 6,
|
||||
700: 7,
|
||||
800: 8,
|
||||
900: 9,
|
||||
1000: 10,
|
||||
1100: 11,
|
||||
}[score.clear_type];
|
||||
|
||||
if (music > GAME_MAX_MUSIC_ID[version]) {
|
||||
continue;
|
||||
@@ -165,26 +179,24 @@ const getScores = async (refid: string, version: string) => {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push({
|
||||
music_num: K.ITEM('s16', music),
|
||||
sheet_num: K.ITEM('u8', sheet),
|
||||
score: K.ITEM('s32', score.score),
|
||||
clear_type: K.ITEM('u8', {
|
||||
100: 1,
|
||||
200: 2,
|
||||
300: 3,
|
||||
400: 4,
|
||||
500: 5,
|
||||
600: 6,
|
||||
700: 7,
|
||||
800: 8,
|
||||
900: 9,
|
||||
1000: 10,
|
||||
1100: 11,
|
||||
}[score.clear_type]),
|
||||
clear_rank: K.ITEM('u8', getRank(score.score)),
|
||||
cnt: K.ITEM('s16', score.cnt),
|
||||
});
|
||||
if(forFriend) {
|
||||
result.push(K.ATTR({
|
||||
music_num: music.toString(),
|
||||
sheet_num: sheet.toString(),
|
||||
score: score.score.toString(),
|
||||
cleartype: clearType.toString(),
|
||||
clearrank: getRank(score.score).toString()
|
||||
}));
|
||||
} else {
|
||||
result.push({
|
||||
music_num: K.ITEM('s16', music),
|
||||
sheet_num: K.ITEM('u8', sheet),
|
||||
score: K.ITEM('s32', score.score),
|
||||
clear_type: K.ITEM('u8', clearType),
|
||||
clear_rank: K.ITEM('u8', getRank(score.score)),
|
||||
cnt: K.ITEM('s16', score.cnt),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -261,6 +273,7 @@ const writeScore = async (req: EamuseInfo, data: any, send: EamuseSend): Promise
|
||||
*/
|
||||
const getProfile = async (refid: string, version: string, name?: string) => {
|
||||
const profile = await utils.readProfile(refid);
|
||||
const rivals = await utils.readRivals(refid);
|
||||
|
||||
if (name && name.length > 0) {
|
||||
profile.name = name;
|
||||
@@ -299,6 +312,7 @@ const getProfile = async (refid: string, version: string, name?: string) => {
|
||||
is_conv: K.ITEM('s8', 0),
|
||||
license_data: K.ARRAY('s16', Array(20).fill(-1)),
|
||||
my_best: K.ARRAY('s16', myBest),
|
||||
active_fr_num: K.ITEM('u8', rivals.rivals.length),
|
||||
|
||||
// TODO: replace with real data
|
||||
total_play_cnt: K.ITEM('s16', 100),
|
||||
@@ -307,7 +321,6 @@ const getProfile = async (refid: string, version: string, name?: string) => {
|
||||
total_days: K.ITEM('s16', 366),
|
||||
interval_day: K.ITEM('s16', 1),
|
||||
latest_music: K.ARRAY('s16', [-1, -1, -1, -1, -1]),
|
||||
active_fr_num: K.ITEM('u8', 0),
|
||||
},
|
||||
netvs: {
|
||||
record: K.ARRAY('s16', [0, 0, 0, 0, 0, 0]),
|
||||
@@ -381,7 +394,10 @@ const getProfile = async (refid: string, version: string, name?: string) => {
|
||||
});
|
||||
}
|
||||
|
||||
const profileStamps = achievements.stamps || { '0': 0 };
|
||||
let profileStamps = achievements.stamps;
|
||||
if(Object.entries(profileStamps).length == 0) {
|
||||
profileStamps = {"0": 0 };
|
||||
}
|
||||
for (const stamp_id in profileStamps) {
|
||||
player.stamp.push({
|
||||
stamp_id: K.ITEM('s16', parseInt(stamp_id, 10)),
|
||||
@@ -595,6 +611,35 @@ const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promise<any>
|
||||
send.success();
|
||||
};
|
||||
|
||||
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 version = getVersion(req);
|
||||
|
||||
const rivals = await utils.readRivals(refid);
|
||||
|
||||
if(no < 0 || no >= rivals.rivals.length) {
|
||||
send.object({result : K.ITEM('s8', 2)});
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = await utils.readProfile(rivals.rivals[no]);
|
||||
const params = await utils.readParams(rivals.rivals[no], version);
|
||||
|
||||
const friend = {
|
||||
friend: {
|
||||
no: K.ITEM('s16', no),
|
||||
g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'),
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
send.object(friend);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const getVersion = (req: EamuseInfo): string => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Achievements } from "../models/achievements";
|
||||
import { Profile, Scores, ExtraData, Params } from "../models/common";
|
||||
import { Profile, Scores, ExtraData, Params, Rivals } from "../models/common";
|
||||
|
||||
const CURRENT_DATA_VERSION = 2;
|
||||
|
||||
@@ -68,6 +68,11 @@ export const writeProfile = async (refid: string, profile: Profile) => {
|
||||
await DB.Upsert<Profile>(refid, { collection: 'profile' }, profile);
|
||||
}
|
||||
|
||||
export const readRivals = async (refid: string): Promise<Rivals> => {
|
||||
const rivals = await DB.FindOne<Rivals>(refid, { collection: 'rivals' });
|
||||
return rivals || { collection: 'rivals', rivals: [] };
|
||||
}
|
||||
|
||||
export const readParams = async (refid: string, version: string): Promise<Params> => {
|
||||
const params = await DB.FindOne<Params>(refid, { collection: 'params', version });
|
||||
return params || { collection: 'params', version, params: {} };
|
||||
|
||||
Reference in New Issue
Block a user