implement eidolon levelup

This commit is contained in:
memetrollsXD 2022-08-04 11:55:00 +02:00
parent 7577f0e273
commit 38b5d51be2
No known key found for this signature in database
GPG Key ID: 105C2F3417AC32CD
3 changed files with 45 additions and 1 deletions

View File

@ -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.
********************************************************************************/

View File

@ -16,7 +16,7 @@ export default async function handle(session: Session, packet: Packet) {
if (!success) {
session.send(DoGachaScRsp, {
retcode: 1
retcode: 1301
} as DoGachaScRsp);
}

View File

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