feat: gacha
This commit is contained in:
parent
465e0e44c8
commit
80d2763efa
35
src/server/packets/DoGachaCsReq.ts
Normal file
35
src/server/packets/DoGachaCsReq.ts
Normal 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);
|
||||||
|
}
|
@ -23,7 +23,7 @@ export default class Banners {
|
|||||||
|
|
||||||
private static readConfig(){
|
private static readConfig(){
|
||||||
let config: Banner[];
|
let config: Banner[];
|
||||||
let defaultConfig: Banner[] = [
|
const defaultConfig: Banner[] = [
|
||||||
{
|
{
|
||||||
gachaId: 1001,
|
gachaId: 1001,
|
||||||
detailWebview: "",
|
detailWebview: "",
|
||||||
@ -40,7 +40,7 @@ export default class Banners {
|
|||||||
try {
|
try {
|
||||||
config = JSON.parse(r('../../banners.json'));
|
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));
|
const missing = Object.keys(defaultConfig[0]).filter(key => !gachaBanner.hasOwnProperty(key));
|
||||||
if (missing.length > 0) {
|
if (missing.length > 0) {
|
||||||
console.log(`Missing ${missing.join(', ')}, using default values. Backup of your older config: ${JSON.stringify(gachaBanner, null, 2)}`);
|
console.log(`Missing ${missing.join(', ')}, using default values. Backup of your older config: ${JSON.stringify(gachaBanner, null, 2)}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user