Fix & implement some lineup stuff (#53)
* fix: add avatar for each lineup * feat: switch lineup
This commit is contained in:
parent
27557a0bbd
commit
5e1209deba
@ -1,20 +1,26 @@
|
|||||||
import { AvatarType, JoinLineupCsReq, JoinLineupScRsp, SyncLineupNotify, SyncLineupReason } from "../../data/proto/StarRail";
|
import {
|
||||||
import Avatar from "../../db/Avatar";
|
JoinLineupCsReq,
|
||||||
|
JoinLineupScRsp,
|
||||||
|
SyncLineupNotify,
|
||||||
|
SyncLineupReason
|
||||||
|
} from "../../data/proto/StarRail";
|
||||||
import Packet from "../kcp/Packet";
|
import Packet from "../kcp/Packet";
|
||||||
import Session from "../kcp/Session";
|
import Session from "../kcp/Session";
|
||||||
|
|
||||||
// JoinLineupCsReq { baseAvatarId: 1002, slot: 1 }
|
// JoinLineupCsReq { baseAvatarId: 1002, slot: 1 }
|
||||||
export default async function handle(session: Session, packet: Packet) {
|
export default async function handle(session: Session, packet: Packet) {
|
||||||
const body = packet.body as JoinLineupCsReq;
|
const body = packet.body as JoinLineupCsReq;
|
||||||
session.send(JoinLineupScRsp, { retcode: 0 });
|
session.send(JoinLineupScRsp, {retcode: 0});
|
||||||
|
|
||||||
// Replace avatar in the player's lineup.
|
// Replace avatar in the player's lineup.
|
||||||
const slot = body.slot ?? 0;
|
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();
|
await session.player.save();
|
||||||
|
|
||||||
session.send(SyncLineupNotify, {
|
session.send(SyncLineupNotify, {
|
||||||
lineup: await session.player.getLineup(),
|
lineup: await session.player.getLineup(index),
|
||||||
reasonList: [SyncLineupReason.SYNC_REASON_NONE]
|
reasonList: [SyncLineupReason.SYNC_REASON_NONE]
|
||||||
} as SyncLineupNotify);
|
} as SyncLineupNotify);
|
||||||
}
|
}
|
||||||
|
19
src/server/packets/SwitchLineupIndexCsReq.ts
Normal file
19
src/server/packets/SwitchLineupIndexCsReq.ts
Normal 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 ?
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user