From 4e0b5a3064411ab1c4c8060cfff4c3a170df3427 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Fri, 5 Aug 2022 07:35:10 +0200 Subject: [PATCH] Implement some packets for character screen (#44) * implement eidolon levelup * implement changing weapons --- src/server/packets/DoGachaCsReq.ts | 2 +- src/server/packets/DressAvatarCsReq.ts | 16 +++++++++ src/server/packets/RankUpAvatarCsReq.ts | 44 +++++++++++++++++++++++ src/server/packets/StartChallengeCsReq.ts | 4 +-- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/server/packets/DressAvatarCsReq.ts create mode 100644 src/server/packets/RankUpAvatarCsReq.ts diff --git a/src/server/packets/DoGachaCsReq.ts b/src/server/packets/DoGachaCsReq.ts index 2798719..eb0dbb0 100644 --- a/src/server/packets/DoGachaCsReq.ts +++ b/src/server/packets/DoGachaCsReq.ts @@ -16,7 +16,7 @@ export default async function handle(session: Session, packet: Packet) { if (!success) { session.send(DoGachaScRsp, { - retcode: 1 + retcode: 1301 } as DoGachaScRsp); } diff --git a/src/server/packets/DressAvatarCsReq.ts b/src/server/packets/DressAvatarCsReq.ts new file mode 100644 index 0000000..7d72746 --- /dev/null +++ b/src/server/packets/DressAvatarCsReq.ts @@ -0,0 +1,16 @@ +import { DressAvatarCsReq, DressAvatarScRsp } from "../../data/proto/StarRail"; +import Avatar from "../../db/Avatar"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as DressAvatarCsReq; + + const avatar = await Avatar.loadAvatarForPlayer(session.player, body.baseAvatarId); + + avatar.db.equipmentUniqueId = body.equipmentUniqueId; + await avatar.save(); + + session.send(DressAvatarScRsp, { retcode: 0 }); + session.sync(); +} \ No newline at end of file diff --git a/src/server/packets/RankUpAvatarCsReq.ts b/src/server/packets/RankUpAvatarCsReq.ts new file mode 100644 index 0000000..d6093c9 --- /dev/null +++ b/src/server/packets/RankUpAvatarCsReq.ts @@ -0,0 +1,44 @@ +import { RankUpAvatarCsReq, RankUpAvatarScRsp } from "../../data/proto/StarRail"; +import Avatar from "../../db/Avatar"; +import { PayItemData } from "../../db/Inventory"; +import Logger from "../../util/Logger"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; +const c = new Logger("RankUpAvatarCsReq"); + +export default async function handle(session: Session, packet: Packet) { + const body = packet.body as RankUpAvatarCsReq; + const dataObj: RankUpAvatarScRsp = { + retcode: 0 + }; + + try { + const inv = await session.player.getInventory(); + if (!body.costData) return; + const list = body.costData.itemList; + const arr: Array = []; + + for (let i = 0; i < list.length; i++) { + const item = list[i]; + if (!item.pileItem) continue; + arr.push({ + count: item.pileItem.itemNum, + id: item.pileItem.itemId + }); + } + + if (await inv.payItems(arr)) { + const avatar = await Avatar.loadAvatarForPlayer(session.player, body.baseAvatarId); + avatar.db.rank = body.rank // gidra moment: ez hack + await avatar.save(); + } else { + dataObj.retcode = 1301; + } + } catch (e) { + c.error(e as Error); + dataObj.retcode = 2; + } finally { + session.send(RankUpAvatarScRsp, dataObj); + session.sync(); + } +} \ No newline at end of file diff --git a/src/server/packets/StartChallengeCsReq.ts b/src/server/packets/StartChallengeCsReq.ts index 7c8c5d7..5b7bb92 100644 --- a/src/server/packets/StartChallengeCsReq.ts +++ b/src/server/packets/StartChallengeCsReq.ts @@ -17,14 +17,14 @@ export default async function handle(session: Session, packet: Packet) { rounds: 1, status: ChallengeStatus.CHALLENGE_DOING, killMonsterList: [{ - monsterId: 1001010, + monsterId: 8013010, killNum: 1, }] }, maze: { // ? Data from MappingInfoExcelTable id: 30101, - mapEntryId: 1000, + mapEntryId: 10001, floor: { floorId: 20121001, scene: {