feat: gacha

This commit is contained in:
labalityowo 2022-08-03 12:46:52 +07:00
parent 465e0e44c8
commit 80d2763efa
2 changed files with 37 additions and 2 deletions

View File

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

View File

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