Fix & implement some lineup stuff (#53)

* fix: add avatar for each lineup

* feat: switch lineup
This commit is contained in:
Dang Hoang Phuc 2022-08-07 02:36:41 +07:00 committed by GitHub
parent 27557a0bbd
commit 5e1209deba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -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);
}

View File

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