Implement basic lineup switching

This commit is contained in:
memetrollsXD 2022-08-02 04:07:11 +02:00
parent ad1b43ba3e
commit 936c6611bf
No known key found for this signature in database
GPG Key ID: 105C2F3417AC32CD
5 changed files with 44 additions and 6 deletions

View File

@ -28,9 +28,10 @@ export default class Avatar {
}
public static async fromUID(ownerUid: UID, baseAvatarId?: number): Promise<Avatar[]> {
const query = { ownerUid } as { ownerUid: UID, baseAvatarId?: number };
if (baseAvatarId) query.baseAvatarId = baseAvatarId;
const query = { ownerUid } as { ownerUid: UID, "data.baseAvatarId"?: number };
if (baseAvatarId) query['data.baseAvatarId'] = baseAvatarId;
const db = Database.getInstance();
console.debug(query)
return await db.getAll("avatars", query) as unknown as Avatar[];
}

View File

@ -51,6 +51,15 @@ export default class Player {
return new Player(plr);
}
public getCurLineup() {
return this.db.lineup.lineups[this.db.lineup.curIndex];
}
public setCurLineup(lineup: LineupInfo, curIndex: number = this.db.lineup.curIndex) {
this.db.lineup.lineups[curIndex] = lineup;
this.db.lineup.curIndex = curIndex;
}
public static async create(uid: number | string): Promise<Player | undefined> {
if (typeof uid == "string") uid = Number(uid);
const acc = await Account.fromUID(uid);

View File

@ -3,8 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) {
const _lineup = session.player.db.lineup;
const lineup = _lineup.lineups[_lineup.curIndex];
const lineup = session.player.getCurLineup();
session.send("GetCurBattleInfoScRsp", {
retcode: 0,

View File

@ -3,8 +3,7 @@ import Packet from "../kcp/Packet";
import Session from "../kcp/Session";
export default async function handle(session: Session, packet: Packet) {
const _lineup = session.player.db.lineup;
const lineup = _lineup.lineups[_lineup.curIndex];
const lineup = session.player.getCurLineup();
session.send("GetCurLineupDataScRsp", {
retcode: 0,
lineup

View File

@ -0,0 +1,30 @@
import { AvatarType, JoinLineupCsReq, SyncLineupNotify, SyncLineupReason } from "../../data/proto/StarRail";
import Avatar from "../../db/Avatar";
import Packet from "../kcp/Packet";
import Session from "../kcp/Session";
// JoinLineupCsReq { baseAvatarId: 1002, slot: 1 }
export default async function handle(session: Session, packet: Packet) {
const body = packet.body as JoinLineupCsReq;
session.send("JoinLineupScRsp", { retcode: 0 });
let lineup = session.player.getCurLineup();
const slot = body.slot || 0;
const avatar = await Avatar.fromUID(session.player.db._id, body.baseAvatarId);
if (avatar.length === 0) return session.c.warn(`Avatar ${body.baseAvatarId} not found`);
lineup.avatarList[slot] = {
avatarType: AvatarType.AVATAR_FORMAL_TYPE,
hp: 10000,
id: body.baseAvatarId,
satiety: 100,
slot,
sp: 10000
};
session.player.setCurLineup(lineup);
session.player.save();
session.send("SyncLineupNotify", {
lineup: lineup,
reasonList: [SyncLineupReason.SYNC_REASON_NONE]
} as SyncLineupNotify);
}