diff --git a/src/server/packets/DoGachaCsReq.ts b/src/server/packets/DoGachaCsReq.ts new file mode 100644 index 0000000..3dff2bf --- /dev/null +++ b/src/server/packets/DoGachaCsReq.ts @@ -0,0 +1,35 @@ +import { DoGachaCsReq, DoGachaScRsp, GachaItem, Item, ItemList } from "../../data/proto/StarRail"; +import Banners from "../../util/Banner"; +import Packet from "../kcp/Packet"; +import Session from "../kcp/Session"; + +export default async function handle(session: Session, packet: Packet) { + const gachaItemList: GachaItem[] = []; + const body = packet.body as DoGachaCsReq; + const banner = Banners.config.find(banner => banner.gachaId === body.gachaId)!; + const combined = banner.rateUpItems4.concat(banner.rateUpItems5) + //bad gachaing but whatever.... + //TODO: pity system, proper logic + for(let i = 0; i < body.gachaNum; i++){ + const result = combined[Math.floor(Math.random() * combined.length)]; + gachaItemList.push({ + gachaItem: { + itemId: result, + num: 1 + } as Item, + tokenItem: {}, + transferItemList: {}, + isNew: true //TODO: avatar checking + } as GachaItem); + } + session.send("DoGachaScRsp", { + retcode: 0, + gachaId: body.gachaId!, + gachaNum: body.gachaNum!, + newGachaRandom: body.gachaRandom!, + newbieGachaCnt: 0, + todayGachaCnt: 0, + todayTotalGachaCnt: 0, //todo find out what are THESE + gachaItemList: gachaItemList + } as DoGachaScRsp); +} \ No newline at end of file diff --git a/src/util/Banner.ts b/src/util/Banner.ts index 18491e3..91e6454 100644 --- a/src/util/Banner.ts +++ b/src/util/Banner.ts @@ -23,7 +23,7 @@ export default class Banners { private static readConfig(){ let config: Banner[]; - let defaultConfig: Banner[] = [ + const defaultConfig: Banner[] = [ { gachaId: 1001, detailWebview: "", @@ -40,7 +40,7 @@ export default class Banners { try { config = JSON.parse(r('../../banners.json')); - for(let [index, gachaBanner] of Object.entries(config)){ + for(const [index, gachaBanner] of Object.entries(config)){ const missing = Object.keys(defaultConfig[0]).filter(key => !gachaBanner.hasOwnProperty(key)); if (missing.length > 0) { console.log(`Missing ${missing.join(', ')}, using default values. Backup of your older config: ${JSON.stringify(gachaBanner, null, 2)}`);