Implement basic lineup switching
This commit is contained in:
parent
ad1b43ba3e
commit
936c6611bf
@ -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[];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
30
src/server/packets/JoinLineupCsReq.ts
Normal file
30
src/server/packets/JoinLineupCsReq.ts
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user