Merge pull request #41 from thomeval/stable

Persist secret music and rewards
This commit is contained in:
Freddie Wang
2022-05-01 22:43:40 +08:00
committed by GitHub
4 changed files with 84 additions and 13 deletions
+9 -2
View File
@@ -1,6 +1,6 @@
GITADORA Plugin for Asphyxia-Core GITADORA Plugin for Asphyxia-Core
================================= =================================
![Version: v1.2.0](https://img.shields.io/badge/version-v1.2.0-blue) ![Version: v1.2.1](https://img.shields.io/badge/version-v1.2.1-blue)
This plugin is based on converted from public-exported Asphyxia's Routes. This plugin is based on converted from public-exported Asphyxia's Routes.
@@ -23,13 +23,20 @@ The folder structure between v1.0 and v1.1 is quite different. Do not overwrite
Known Issues Known Issues
============ ============
* Information dialog keep showing as plugin doesn't store item data currently. * ~Information dialog keep showing as plugin doesn't store item data currently.~ (Fixed as of version 1.2.1)
* Special Premium Encore on Nextage * Special Premium Encore on Nextage
- Bandage solution is implemented. Try it. - Bandage solution is implemented. Try it.
Release Notes Release Notes
============= =============
v1.2.1
----------------
* Secret Music (unlocked songs) are now saved and loaded correctly. Partially fixes Github issue #34. Note that all songs are already marked as unlocked by the server - there is no need to unlock them manually. If you would like to lock them, consider using a custom MDB.
* Rewards field is now saved and loaded correctly. Fixes Github issue #34
NOTE: Rewards and secret music is saved at the end of each session, so you will see the unlock notifications one last time after updating the plugin to this version.
v1.2.0 v1.2.0
---------------- ----------------
* Fixed server error when saving profiles for two Guitar Freaks players at the end of a session. Fixes Github issue #39. * Fixed server error when saving profiles for two Guitar Freaks players at the end of a session. Fixes Github issue #39.
+65 -11
View File
@@ -8,6 +8,7 @@ import { Scores } from "../models/scores";
import { PLUGIN_VER } from "../const"; import { PLUGIN_VER } from "../const";
import Logger from "../utils/logger" import Logger from "../utils/logger"
import { isAsphyxiaDebugMode } from "../Utils/index"; import { isAsphyxiaDebugMode } from "../Utils/index";
import { SecretMusicEntry } from "../models/secretmusicentry";
const logger = new Logger("profiles") const logger = new Logger("profiles")
@@ -374,15 +375,13 @@ export const getPlayer: EPR = async (info, data, send) => {
} }
} }
const innerSecretMusic = getSecretMusicResponse(profile)
const response = { const response = {
player: K.ATTR({ 'no': `${no}` }, { player: K.ATTR({ 'no': `${no}` }, {
now_date: K.ITEM('u64', time), now_date: K.ITEM('u64', time),
secretmusic: { // TODO: FIX THIS secretmusic: {
music: { music: innerSecretMusic
musicid: K.ITEM('s32', 0),
seq: K.ITEM('u16', 255),
kind: K.ITEM('s32', 40),
}
}, },
chara_list: {}, chara_list: {},
title_parts: {}, title_parts: {},
@@ -390,7 +389,7 @@ export const getPlayer: EPR = async (info, data, send) => {
info: K.ARRAY('u32', Array(50).fill(0)), info: K.ARRAY('u32', Array(50).fill(0)),
}, },
reward: { reward: {
status: K.ARRAY('u32', Array(50).fill(0)), status: K.ARRAY('u32', extra.reward_status ?? Array(50).fill(0)),
}, },
rivaldata: {}, rivaldata: {},
frienddata: {}, frienddata: {},
@@ -615,7 +614,10 @@ async function registerUser(refid: string, version: string, id = _.random(0, 999
full_music_num: 0, full_music_num: 0,
exce_music_num: 0, exce_music_num: 0,
clear_seq_num: 0, clear_seq_num: 0,
classic_all_skill: 0 classic_all_skill: 0,
secretmusic: {
music: []
}
} }
}; };
@@ -842,6 +844,11 @@ async function saveSinglePlayer(dataplayer: KDataReader, refid: string, no: numb
} }
}; };
let newSecretMusic = parseSecretMusic(dataplayer)
profile.secretmusic = {
music: newSecretMusic
}
autoSet('max_skill', 'record.max.skill'); autoSet('max_skill', 'record.max.skill');
autoSet('max_all_skill', 'record.max.all_skill'); autoSet('max_all_skill', 'record.max.all_skill');
autoSet('clear_diff', 'record.max.clear_diff'); autoSet('clear_diff', 'record.max.clear_diff');
@@ -939,14 +946,20 @@ async function saveSinglePlayer(dataplayer: KDataReader, refid: string, no: numb
autoExtra('playstyle', 'customdata.playstyle', true); autoExtra('playstyle', 'customdata.playstyle', true);
autoExtra('custom', 'customdata.custom', true); autoExtra('custom', 'customdata.custom', true);
autoExtra('reward_status', 'reward.status', true)
await DB.Upsert(refid, { collection: 'profile', game, version }, profile) await DB.Upsert(refid, { collection: 'profile', game, version }, profile)
await DB.Upsert(refid, { collection: 'record', game, version }, rec) await DB.Upsert(refid, { collection: 'record', game, version }, rec)
await DB.Upsert(refid, { collection: 'extra', game, version }, extra) await DB.Upsert(refid, { collection: 'extra', game, version }, extra)
const stages = dataplayer.elements('stage'); const playedStages = dataplayer.elements('stage');
const scores = await updatePlayerScoreCollection(refid, playedStages, version, game)
await saveScore(refid, version, game, scores);
}
async function updatePlayerScoreCollection(refid, playedStages, version, game) {
const scores = (await getScore(refid, version, game)).scores; const scores = (await getScore(refid, version, game)).scores;
for (const stage of stages) { for (const stage of playedStages) {
const mid = stage.number('musicid', -1); const mid = stage.number('musicid', -1);
const seq = stage.number('seq', -1); const seq = stage.number('seq', -1);
@@ -986,8 +999,9 @@ async function saveSinglePlayer(dataplayer: KDataReader, refid: string, no: numb
}; };
} }
await saveScore(refid, version, game, scores); return scores
} }
async function getPlayerRanking(refid: string, version: string, game: 'gf' | 'dm') : Promise<PlayerRanking> { async function getPlayerRanking(refid: string, version: string, game: 'gf' | 'dm') : Promise<PlayerRanking> {
let profiles = await getAllProfiles(version, game) let profiles = await getAllProfiles(version, game)
let playerCount = profiles.length let playerCount = profiles.length
@@ -1086,3 +1100,43 @@ async function saveScore(refid: string, version: string, game: 'gf' | 'dm', scor
scores scores
}) })
} }
function parseSecretMusic(playerData: KDataReader) : SecretMusicEntry[]
{
let response : SecretMusicEntry[] = []
let elements = playerData.element('secretmusic')?.elements('music')
if (!elements) {
return response
}
for (let el of elements) {
let item : SecretMusicEntry = {
musicid: el.number('musicid'),
seq: el.number('seq'),
kind: el.number('kind')
}
response.push(item)
}
return response
}
function getSecretMusicResponse(profile: Profile) {
let response = []
if (!profile.secretmusic?.music ) {
return response
}
for (let music of profile.secretmusic.music) {
response.push({
musicid: K.ITEM('s32', music.musicid),
seq: K.ITEM('u16', music.seq),
kind: K.ITEM('s32', music.kind)
})
}
return response
}
+5
View File
@@ -1,3 +1,5 @@
import { SecretMusicEntry } from "./secretmusicentry";
export interface Profile { export interface Profile {
collection: 'profile'; collection: 'profile';
@@ -54,4 +56,7 @@ export interface Profile {
exce_music_num: number; exce_music_num: number;
clear_seq_num: number; clear_seq_num: number;
classic_all_skill: number; classic_all_skill: number;
secretmusic: {
music: SecretMusicEntry[];
}
} }
@@ -0,0 +1,5 @@
export interface SecretMusicEntry {
musicid: number;
seq: number;
kind: number;
}