From 5e1209deba109368967ac4464150b570dee3c854 Mon Sep 17 00:00:00 2001 From: Dang Hoang Phuc <13364457+phuchptty@users.noreply.github.com> Date: Sun, 7 Aug 2022 02:36:41 +0700 Subject: [PATCH] Fix & implement some lineup stuff (#53) * fix: add avatar for each lineup * feat: switch lineup --- src/server/packets/JoinLineupCsReq.ts | 18 ++++++++++++------ src/server/packets/SwitchLineupIndexCsReq.ts | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/server/packets/SwitchLineupIndexCsReq.ts diff --git a/src/server/packets/JoinLineupCsReq.ts b/src/server/packets/JoinLineupCsReq.ts index c394b50..7ecdf26 100644 --- a/src/server/packets/JoinLineupCsReq.ts +++ b/src/server/packets/JoinLineupCsReq.ts @@ -1,20 +1,26 @@ -import { AvatarType, JoinLineupCsReq, JoinLineupScRsp, SyncLineupNotify, SyncLineupReason } from "../../data/proto/StarRail"; -import Avatar from "../../db/Avatar"; +import { + JoinLineupCsReq, + JoinLineupScRsp, + SyncLineupNotify, + SyncLineupReason +} from "../../data/proto/StarRail"; 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 }); + session.send(JoinLineupScRsp, {retcode: 0}); // Replace avatar in the player's lineup. const slot = body.slot ?? 0; - session.player.db.lineup.lineups[session.player.db.lineup.curIndex].avatarList[slot] = body.baseAvatarId; + const index = body.index ?? 1; + + session.player.db.lineup.lineups[index].avatarList[slot] = body.baseAvatarId; await session.player.save(); session.send(SyncLineupNotify, { - lineup: await session.player.getLineup(), + lineup: await session.player.getLineup(index), reasonList: [SyncLineupReason.SYNC_REASON_NONE] } as SyncLineupNotify); -} \ No newline at end of file +} diff --git a/src/server/packets/SwitchLineupIndexCsReq.ts b/src/server/packets/SwitchLineupIndexCsReq.ts new file mode 100644 index 0000000..2aca878 --- /dev/null +++ b/src/server/packets/SwitchLineupIndexCsReq.ts @@ -0,0 +1,19 @@ +import Session from "../kcp/Session"; +import Packet from "../kcp/Packet"; +import {SwitchLineupIndexCsReq, SwitchLineupIndexScRsp} from "../../data/proto/StarRail"; + +// SwitchLineupIndexCsReq { index: 0 } +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as SwitchLineupIndexCsReq + const index = body.index ?? 0 + + session.send(SwitchLineupIndexScRsp, { + retcode: 0, + index: index + }) + + session.player.db.lineup.curIndex = index + await session.player.save() + + // Todo: figure need to send SyncLineupNotify again ? +}