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 ? +}