diff --git a/src/db/Avatar.ts b/src/db/Avatar.ts index 363ebe0..d68a772 100644 --- a/src/db/Avatar.ts +++ b/src/db/Avatar.ts @@ -144,6 +144,11 @@ export default class Avatar { return res; } + public async save() { + const db = Database.getInstance(); + await db.update("avatars", { ownerUid: this.player.uid, baseAvatarId: this.db.baseAvatarId }, this.db); + } + /******************************************************************************** Get avatar info. ********************************************************************************/ 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/RankUpAvatarCsReq.ts b/src/server/packets/RankUpAvatarCsReq.ts new file mode 100644 index 0000000..0aac5f6 --- /dev/null +++ b/src/server/packets/RankUpAvatarCsReq.ts @@ -0,0 +1,39 @@ +import { RankUpAvatarCsReq, RankUpAvatarScRsp } from "../../data/proto/StarRail"; +import Avatar from "../../db/Avatar"; +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; + + let retcode = 0; + if (body.costData) { + const inv = await session.player.getInventory(); + + for (const item of body.costData.itemList) { + if (!item.pileItem) return; + + const succ = await inv.payItems([{ + count: item.pileItem.itemNum, + id: item.pileItem.itemId, + }]); + + if (!succ) { + retcode = 1301; + c.debug(`failed to pay item ${item.pileItem.itemId}`, item.pileItem); + break; + } + } + } + + if (retcode === 0) { + const avatar = await Avatar.loadAvatarForPlayer(session.player, body.baseAvatarId); + avatar.db.rank = body.rank // gidra moment: ez hack + await avatar.save(); + } + + session.send(RankUpAvatarScRsp, { retcode }); + session.sync(); +} \ No newline at end of file