[add] slot系列API Class化

This commit is contained in:
建喵 2024-08-30 11:20:52 +08:00
parent 735a0a6bb3
commit acd1cb7337
8 changed files with 129 additions and 71 deletions

View File

@ -0,0 +1,22 @@
import { INetRequest } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetRequest";
import { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { ClientData } from "../../shared/protocols/define/interface";
import { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocols/Slot1Request";
export default abstract class SlotFgSpinBase {
public *fgspin(clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data
const { count, freeData } = clientData.free;
const slotData: any = freeData[count];
const response: INetResponse<RpcSlot1SpinResponse> = {
Status: 0,
Method: req.Method,
Data: slotData,
IsValid: true
};
clientData.free.count++;
return response;
}
}

View File

@ -0,0 +1,25 @@
import { INetRequest } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetRequest";
import { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { ClientData } from "../../shared/protocols/define/interface";
import { RpcSlotInRequest, RpcSlotInResponse } from "../../shared/protocols/SlotRequest";
export default abstract class SlotInBase {
protected ver: string = "";
protected abstract db: number;
protected abstract br: number[];
protected abstract jp: { [key: string]: number; };
public *in(clientData: ClientData, req: INetRequest<RpcSlotInRequest>): IterableIterator<any> {
const data: RpcSlotInRequest = req.Data;
const { id } = data;
const { ver, db, br, jp } = this;
const response: INetResponse<RpcSlotInResponse> = {
Status: 0,
Method: req.Method,
Data: { ver, db, br, jp },
IsValid: true
};
return response;
}
}

View File

@ -2,15 +2,21 @@ import { INetRequest } from "../../script/Engine/CatanEngine/NetManagerV2/Core/I
import { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { ClientData } from "../../shared/protocols/define/interface";
import { RpcSlotInRequest, RpcSlotInResponse } from "../../shared/protocols/SlotRequest";
import SlotIn1 from "../slot1/in";
export default function* (clientData: ClientData, req: INetRequest<RpcSlotInRequest>): IterableIterator<any> {
const data: RpcSlotInRequest = req.Data
const data: RpcSlotInRequest = req.Data;
const { id } = data;
const response: INetResponse<RpcSlotInResponse> = {
Status: 0,
Method: req.Method,
Data: { ver: "", db: 4, br: [4, 10, 20, 40, 80, 100, 120, 160, 200, 400, 600, 800, 1000, 1200, 1600, 2000, 4000, 10000, 20000, 30000], jp: { "1": 1500000, "3": 3000000, "5": 30000000 } },
IsValid: true
let moduleClass: SlotIn1;
let AsyncFunction = async function () {
const module = await import(`../slot${id}/in`);
moduleClass = new module.default();
};
AsyncFunction();
while (!moduleClass) {
yield;
}
const response: INetResponse<RpcSlotInResponse> = yield* moduleClass.in(clientData, req);
return response;
}

View File

@ -5,15 +5,20 @@ import { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocol
import { RandomEx } from "../../Utils/Number/RandomEx";
export default class SlotBase {
protected temps: string[];
protected freeTemps: string[];
export default abstract class SlotSpinBase {
protected abstract ID: number;
protected IsHaveFreeSpin: boolean = false;
protected IsHaveReSpin: boolean = false;
protected IsHaveRetriggerFreeSpin: boolean = false;
protected FreeMax: number = 50;
protected abstract Temps: string[];
protected abstract FreeTemps: string[];
public *spin(clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data
clientData.free = null;
const slotData: any = JSON.parse(this.temps[RandomEx.GetInt(0, this.temps.length)]);
const slotData: any = JSON.parse(this.Temps[RandomEx.GetInt(0, this.Temps.length)]);
let totalGet: number = 0;
if (slotData.line) {
@ -22,7 +27,7 @@ export default class SlotBase {
if (slotData.scatter) {
totalGet += this.getScatterGet(slotData.scatter);
}
if (slotData.free) {
if (this.IsHaveFreeSpin && slotData.free) {
const count = slotData.free[1];
const { freeData, totalFreeGet } = this.getFree(count);
totalGet += totalFreeGet;
@ -49,14 +54,25 @@ export default class SlotBase {
}
protected getFree(count: number) {
const freeData = [];
let freeData = [];
let totalFreeGet = 0;
for (let i: number = 0; i < count; i++) {
const slotData: any = JSON.parse(this.freeTemps[RandomEx.GetInt(0, this.freeTemps.length)]);
const slotData: any = JSON.parse(this.FreeTemps[RandomEx.GetInt(0, this.FreeTemps.length)]);
freeData.push(slotData);
if (slotData.line) {
totalFreeGet += this.getLineGet(slotData.line);
}
if (slotData.scatter) {
totalFreeGet += this.getScatterGet(slotData.scatter);
if (this.IsHaveRetriggerFreeSpin && slotData.free && freeData.length < this.FreeMax) {
const count = slotData.free[1] + freeData.length > this.FreeMax
? slotData.free[1] + freeData.length - this.FreeMax
: slotData.free[1];
const { freeData: reFreeData, totalFreeGet: reTotalFreeGet } = this.getFree(count);
freeData = freeData.concat(reFreeData);
totalFreeGet += reTotalFreeGet;
}
}
}
return { freeData, totalFreeGet }
}

View File

@ -1,33 +1,4 @@
import { INetRequest } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetRequest";
import { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { ClientData } from "../../shared/protocols/define/interface";
import { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocols/Slot1Request";
import SlotFgSpinBase from "../slot/SlotFgSpinBase";
export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data
// const freeTemps: string[] = [
// `{"slot":[13,9,5,14,4,9,4,12,12,11,4,14,8,7,6],"line":[[[10,6],195,300],[[10,6],213,300]]}`,
// `{"slot":[9,9,10,13,4,5,4,3,4,11,10,14,14,14,5]}`,
// `{"slot":[12,6,8,12,11,7,12,11,5,5,11,5,3,10,9]}`,
// `{"slot":[4,6,11,13,8,12,12,3,4,10,7,5,14,14,4]}`,
// `{"slot":[5,9,9,3,11,10,4,5,12,5,4,14,12,5,9],"line":[[[10,6],195,300],[[10,6],213,300]]}`,
// `{"slot":[14,4,10,3,11,5,14,3,12,6,10,6,14,5,12],"line":[[[0,6,12],49,750]],"scatter":[[[3,7],3000]]}`,
// `{"slot":[9,14,13,4,11,4,7,6,14,6,12,13,9,12,12]}`,
// `{"slot":[10,3,12,13,5,6,4,8,4,9,13,14,11,14,4]}`,
// `{"slot":[10,14,13,9,8,6,6,6,4,13,13,12,9,14,4],"line":[[[5,6,7],122,3000]]}`,
// `{"slot":[11,13,9,8,5,8,5,5,13,9,14,9,12,4,7]}`,
// ];
// const Data: any = JSON.parse(freeTemps[RandomEx.GetInt(0, freeTemps.length)]);
const { count, freeData } = clientData.free;
const slotData: any = freeData[count];
const response: INetResponse<RpcSlot1SpinResponse> = {
Status: 0,
Method: req.Method,
Data: slotData,
IsValid: true
};
clientData.free.count++;
return response;
}
export default class SlotFgSpin1 extends SlotFgSpinBase { }

7
src/api/slot1/in.ts Normal file
View File

@ -0,0 +1,7 @@
import SlotInBase from "../slot/SlotInBase";
export default class SlotIn1 extends SlotInBase {
protected db: number = 4;
protected br: number[] = [4, 10, 20, 40, 80, 100, 120, 160, 200, 400, 600, 800, 1000, 1200, 1600, 2000, 4000, 10000, 20000, 30000];
protected jp: { [key: string]: number; } = { "1": 1500000, "3": 3000000, "5": 30000000 };
}

View File

@ -1,24 +1,32 @@
import SlotBase from "../slot/spin";
import SlotSpinBase from "../slot/spin";
export default class Slot1 extends SlotBase {
protected temps: string[] = [
`{"slot":[11,4,8,9,5,2,13,10,7,9,10,6,6,12,4],"line":[[[5,11,12],161,2000]]}`,
export default class SlotSpin1 extends SlotSpinBase {
protected ID: number = 1;
protected IsHaveFreeSpin: boolean = true;
protected IsHaveRetriggerFreeSpin: boolean = true;
protected Temps: string[] = [
`{"slot":[11,4,8,9,5,2,13,10,7,9,10,6,6,12,4],"line":[[[5,11,12],161,200]]}`,
`{"slot":[9,6,2,5,4,14,10,9,13,10,4,5,5,2,2]}`,
`{"slot":[4,3,3,3,9,10,14,14,9,4,7,8,8,5,10],"free":[[1,2,3],3],"scatter":[[[1,2,3],3000]]}`,
`{"slot":[4,3,3,3,9,10,14,14,9,4,7,8,8,5,10],"free":[[1,2,3],3],"scatter":[[[1,2,3],300]]}`,
`{"slot":[1,2,4,5,6,7,3,3,3,8,9,10,11,12,13],"free":[[6,7,8],10],"scatter":[[[6,7,8],300]]}`,
];
protected freeTemps: string[] = [
`{"slot":[13,9,5,14,4,9,4,12,12,11,4,14,8,7,6],"line":[[[10,6],195,300],[[10,6],213,300]]}`,
protected FreeTemps: string[] = [
`{"slot":[9,9,10,13,4,5,4,3,4,11,10,14,14,14,5]}`,
`{"slot":[12,6,8,12,11,7,12,11,5,5,11,5,3,10,9]}`,
`{"slot":[4,6,11,13,8,12,12,3,4,10,7,5,14,14,4]}`,
`{"slot":[5,9,9,3,11,10,4,5,12,5,4,14,12,5,9],"line":[[[10,6],195,300],[[10,6],213,300]]}`,
`{"slot":[14,4,10,3,11,5,14,3,12,6,10,6,14,5,12],"line":[[[0,6,12],49,750]],"scatter":[[[3,7],3000]]}`,
`{"slot":[12,11,9,14,6,7,2,3,8,8,11,10,10,7,14]}`,
`{"slot":[9,14,13,4,11,4,7,6,14,6,12,13,9,12,12]}`,
`{"slot":[10,3,12,13,5,6,4,8,4,9,13,14,11,14,4]}`,
`{"slot":[10,14,13,9,8,6,6,6,4,13,13,12,9,14,4],"line":[[[5,6,7],122,3000]]}`,
`{"slot":[11,13,9,8,5,8,5,5,13,9,14,9,12,4,7]}`,
// `{"slot":[10,14,13,9,8,6,6,6,4,13,13,12,9,14,4],"line":[[[5,6,7],122,300]]}`,
// `{"slot":[13,9,5,14,4,9,4,12,12,11,4,14,8,7,6],"line":[[[10,6],195,300],[[10,6],213,300]]}`,
// `{"slot":[5,9,9,3,11,10,4,5,12,5,4,14,12,5,9],"line":[[[10,6],195,300],[[10,6],213,300]]}`,
// `{"slot":[2,8,13,2,10,9,12,5,11,4,5,2,12,5,8],"line":[[[0,6,12],49,150],[[0,11,2],61,150],[[0,11,7,13],70,3000],[[0,11,12],79,150],[[10,11,7,13],234,3000]]}`,
// `{"slot":[5,12,13,3,4,10,2,5,8,8,2,9,12,10,9],"line":[[[10,1,12],183,150],[[10,6,2],195,150],[[10,6,12],213,150]]}`,
`{"slot":[14,4,10,3,11,5,14,3,12,6,10,6,14,5,12],"line":[[[0,6,12],49,750]],"scatter":[[[3,7],300]]}`,
`{"slot":[6,3,12,4,8,14,10,3,7,9,10,4,10,6,7],"line":[[[10,6,12],213,75]],"scatter":[[[1,7],300]]}`,
`{"slot":[9,12,3,7,2,6,13,11,3,11,13,3,8,6,6],"free":[[2,8,11],10],"scatter":[[[2,8,11],900]]}`,
];
}

View File

@ -5,7 +5,8 @@ import "module-alias/register";
// // 必載入
// import "../Utils/catan.ts";
import WebSocket, { WebSocketServer } from 'ws';
import { WebSocketServer } from 'ws';
import { NetConnector } from "../script/Engine/CatanEngine/NetManagerV2/NetConnector";
/*
http://119.77.165.60/MyWeb/SD2/slot1/index.html?token=test&slotid=1&v=1724652287&host=127.0.0.1&language=zh-tw&logo=2&pl=1
@ -14,26 +15,28 @@ ws://192.168.5.36:9005
ws://127.0.0.1:9005
*/
const port: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080; // 默认端口为 8080
const server = new WebSocketServer({ port: 8080 });
server.on('connection', (socket: WebSocket) => {
console.log('客户端已连接');
// server.on('connection', (socket: WebSocket) => {
// console.log('客户端已连接');
// 发送消息到客户端
socket.send('欢迎连接到WebSocket服务器');
// // 发送消息到客户端
// socket.send('欢迎连接到WebSocket服务器');
// 接收来自客户端的消息
socket.on('message', (message: string) => {
console.log(`收到客户端消息: ${message}`);
// // 接收来自客户端的消息
// socket.on('message', (message: string) => {
// console.log(`收到客户端消息: ${message}`);
// 回应消息
socket.send(`服务器收到你的消息: ${message}`);
});
// // 回应消息
// socket.send(`服务器收到你的消息: ${message}`);
// });
// 处理客户端断开连接
socket.on('close', () => {
console.log('客户端已断开连接');
});
});
// // 处理客户端断开连接
// socket.on('close', () => {
// console.log('客户端已断开连接');
// });
// });
server.on('connection', NetConnector.OnWebSocketConnection);
console.log('WebSocket服务器运行在 ws://localhost:8080');