gacha: implementation (#25)
Co-authored-by: labalityowo <56186498+labalityowo@users.noreply.github.com>
This commit is contained in:
parent
0c62eff9d6
commit
8f53466970
3
.gitignore
vendored
3
.gitignore
vendored
@ -109,4 +109,5 @@ dist
|
|||||||
|
|
||||||
# CrepeSR
|
# CrepeSR
|
||||||
config.json
|
config.json
|
||||||
src/data/*
|
src/data/*
|
||||||
|
banners.json
|
@ -6,11 +6,13 @@
|
|||||||
import Interface from "./commands/Interface";
|
import Interface from "./commands/Interface";
|
||||||
import HttpServer from "./http/HttpServer";
|
import HttpServer from "./http/HttpServer";
|
||||||
import SRServer from "./server/kcp/SRServer";
|
import SRServer from "./server/kcp/SRServer";
|
||||||
|
import Banners from "./util/Banner";
|
||||||
import Logger from "./util/Logger";
|
import Logger from "./util/Logger";
|
||||||
import ProtoFactory from "./util/ProtoFactory"
|
import ProtoFactory from "./util/ProtoFactory"
|
||||||
|
|
||||||
const c = new Logger("CrepeSR");
|
const c = new Logger("CrepeSR");
|
||||||
c.log(`Starting CrepeSR...`);
|
c.log(`Starting CrepeSR...`);
|
||||||
|
Banners.init();
|
||||||
ProtoFactory.init();
|
ProtoFactory.init();
|
||||||
Interface.start();
|
Interface.start();
|
||||||
HttpServer.getInstance().start();
|
HttpServer.getInstance().start();
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
import { GetGachaInfoScRsp } from "../../data/proto/StarRail";
|
import { GachaInfo, GetGachaInfoCsReq, GetGachaInfoScRsp } from "../../data/proto/StarRail";
|
||||||
import Packet from "../kcp/Packet";
|
import Packet from "../kcp/Packet";
|
||||||
import Session from "../kcp/Session";
|
import Session from "../kcp/Session";
|
||||||
|
import Banner from './../../util/Banner';
|
||||||
const unix = () => Math.floor(Date.now() / 1000);
|
|
||||||
|
|
||||||
export default async function handle(session: Session, packet: Packet) {
|
export default async function handle(session: Session, packet: Packet) {
|
||||||
session.send("GetGachaInfoScRsp", {
|
session.send("GetGachaInfoScRsp", {
|
||||||
gachaRandom: 2503,
|
gachaRandom: 0,
|
||||||
retcode: 0,
|
retcode: 0,
|
||||||
gachaInfoList: [{
|
gachaInfoList: Banner.config.map(banner => {
|
||||||
beginTime: unix(),
|
return {
|
||||||
endTime: unix() * 2,
|
beginTime: 0,
|
||||||
newbieGachaCnt: 10,
|
endTime: 1924992000,
|
||||||
todayGachaCnt: 10,
|
gachaId: banner.gachaId,
|
||||||
gachaId: 1001, // TODO: Figure out gachaIDs
|
detailWebview: banner.detailWebview,
|
||||||
detailWebview: "https://omfgdogs.com/"
|
newbieGachaCnt: 0,
|
||||||
}],
|
todayGachaCnt: 0
|
||||||
|
} as GachaInfo
|
||||||
|
}),
|
||||||
todaySingleGachaMaxCnt: 10,
|
todaySingleGachaMaxCnt: 10,
|
||||||
todayTotalGachaCnt: 10,
|
todayTotalGachaCnt: 10,
|
||||||
} as GetGachaInfoScRsp);
|
} as GetGachaInfoScRsp);
|
||||||
|
61
src/util/Banner.ts
Normal file
61
src/util/Banner.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { VerboseLevel } from './Logger';
|
||||||
|
|
||||||
|
type Banner = {
|
||||||
|
gachaId: number,
|
||||||
|
detailWebview: string,
|
||||||
|
rateUpItems4: number[],
|
||||||
|
rateUpItems5: number[],
|
||||||
|
costItemId: number
|
||||||
|
}
|
||||||
|
|
||||||
|
function r(...args: string[]) {
|
||||||
|
return fs.readFileSync(resolve(__dirname, ...args)).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Banners {
|
||||||
|
public static config: Banner[];
|
||||||
|
|
||||||
|
public static init(){
|
||||||
|
Banners.readConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readConfig(){
|
||||||
|
let config: Banner[];
|
||||||
|
let defaultConfig: Banner[] = [
|
||||||
|
{
|
||||||
|
gachaId: 1001,
|
||||||
|
detailWebview: "",
|
||||||
|
rateUpItems4: [
|
||||||
|
1001, 1103
|
||||||
|
],
|
||||||
|
rateUpItems5: [
|
||||||
|
1102
|
||||||
|
],
|
||||||
|
costItemId: -1 //unused for now
|
||||||
|
} as Banner
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
config = JSON.parse(r('../../banners.json'));
|
||||||
|
|
||||||
|
for(let [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)}`);
|
||||||
|
config[parseInt(index)] = defaultConfig[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Banners.updateConfig(config);
|
||||||
|
} catch {
|
||||||
|
console.error("Could not read banners file. Creating one for you...");
|
||||||
|
Banners.updateConfig(defaultConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static updateConfig(config: Banner[]) {
|
||||||
|
this.config = config;
|
||||||
|
fs.writeFileSync('./banners.json', JSON.stringify(config, null, 2));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user