[add] 自己計算get

This commit is contained in:
建喵 2024-08-29 17:35:40 +08:00
parent 04789455a3
commit e741029939
5 changed files with 258 additions and 170 deletions

View File

@ -3,167 +3,166 @@ import { BaseEnumerator } from "./BaseEnumerator";
import { SingleEnumerator } from "./SingleEnumerator";
export class EnumeratorExecutor implements IEnumeratorV2Started {
public Current: any;
public Current: any;
public target: any;
public pauseFlag: boolean;
public doneFlag: boolean;
public childFlag: boolean;
public asyncFlag: boolean;
public error: any;
public target: any;
public pauseFlag: boolean;
public doneFlag: boolean;
public childFlag: boolean;
public asyncFlag: boolean;
public error: any;
private _executor: EnumeratorExecutor;
private _enumerator: BaseEnumerator;
private _executor: EnumeratorExecutor;
private _enumerator: BaseEnumerator;
constructor(enumerator: BaseEnumerator, target: any) {
this.target = target;
this._enumerator = enumerator;
}
constructor(enumerator: BaseEnumerator, target: any) {
this.target = target;
this._enumerator = enumerator;
}
next(delta?: any): IteratorResult<any> {
if (this._executor && this._executor.doneFlag) {
this._executor = null;
}
next(delta?: any): IteratorResult<any> {
if (this._executor && this._executor.doneFlag) {
this._executor = null;
}
if (this.doneFlag || (!this._enumerator && !this._executor)) {
this.doneFlag = true;
return { done: true, value: undefined };
}
if (this.doneFlag || (!this._enumerator && !this._executor)) {
this.doneFlag = true;
return { done: true, value: undefined };
}
if (this.asyncFlag || this.pauseFlag) return { done: false, value: undefined };
if (this.asyncFlag || this.pauseFlag) return { done: false, value: undefined };
let result: IteratorResult<any>;
let result: IteratorResult<any>;
if (this._executor) {
result = this._executor.next(delta);
this.Current = this._executor.Current;
if (this._executor.doneFlag) {
this._executor = null;
} else {
result.done = false;
return result;
}
}
if (!this._enumerator) {
this.doneFlag = true;
return { done: true, value: undefined };
}
if (this._executor) {
result = this._executor.next(delta);
this.Current = this._executor.Current;
if (this._executor.doneFlag) {
this._executor = null;
} else {
result.done = false;
return result;
}
}
try {
result = this._enumerator.next(delta);
let value = result.value;
let done = result.done;
if (!this._enumerator) {
this.doneFlag = true;
return { done: true, value: undefined };
}
if (value) {
// Iterator
if (typeof value[Symbol.iterator] === 'function') {
value = new SingleEnumerator(<Iterator<any>>value);
}
try {
result = this._enumerator.next(delta);
let value = result.value;
let done = result.done;
if (value instanceof BaseEnumerator) {
if (!done) {
BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator;
}
this._enumerator = value;
result = this._enumerator.next(delta);
value = result.value;
done = result.done;
if (value) {
// Iterator again
if (typeof value[Symbol.iterator] === 'function') {
value = new SingleEnumerator(<Iterator<any>>value);
}
if (value instanceof BaseEnumerator) {
if (!done) {
BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator;
}
this._enumerator = value;
result.done = false;
done = false;
}
}
}
if (value instanceof EnumeratorExecutor) {
if (done) {
this._enumerator = this._enumerator.nextEnumerator;
}
value.childFlag = true;
result.done = false;
done = false;
this._executor = value;
} else if (Promise.resolve(value) === value) {
this.asyncFlag = true;
result.done = false;
done = false;
(<Promise<any>>value)
.then(v => {
this.asyncFlag = false;
this.Current = v;
if (done) {
this._enumerator = this._enumerator.nextEnumerator;
}
})
.catch(e => {
this.asyncFlag = false;
this.doneFlag = true;
this._enumerator = null;
this.error = e;
if (e instanceof Error) {
cc.error(e.stack);
} else {
cc.error(`Error: ${JSON.stringify(e)}`);
}
});
}
if (value) {
// Iterator
if (typeof value[Symbol.iterator] === 'function') {
value = new SingleEnumerator(<Iterator<any>>value);
}
this.Current = value;
}
if (done) {
this._enumerator = this._enumerator.nextEnumerator;
if (this._enumerator) {
result.done = false;
}
}
}
catch (e)
{
this.doneFlag = true;
this.error = e;
if (e instanceof Error) {
cc.error(e.stack);
} else {
cc.error(`Error: ${JSON.stringify(e)}`);
}
result = { done: true, value: e };
}
if (value instanceof BaseEnumerator) {
if (!done) {
BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator;
}
this._enumerator = value;
result = this._enumerator.next(delta);
value = result.value;
done = result.done;
return result;
}
if (value) {
// Iterator again
if (typeof value[Symbol.iterator] === 'function') {
value = new SingleEnumerator(<Iterator<any>>value);
}
Stop(): void {
this.doneFlag = true;
if (this._executor) {
this._executor.Stop();
}
}
if (value instanceof BaseEnumerator) {
if (!done) {
BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator;
}
this._enumerator = value;
result.done = false;
done = false;
}
}
}
Pause(): void {
this.pauseFlag = true;
if (this._executor) {
this._executor.Pause();
}
}
if (value instanceof EnumeratorExecutor) {
if (done) {
this._enumerator = this._enumerator.nextEnumerator;
}
value.childFlag = true;
result.done = false;
done = false;
this._executor = value;
} else if (Promise.resolve(value) === value) {
this.asyncFlag = true;
result.done = false;
done = false;
(<Promise<any>>value)
.then(v => {
this.asyncFlag = false;
this.Current = v;
if (done) {
this._enumerator = this._enumerator.nextEnumerator;
}
})
.catch(e => {
this.asyncFlag = false;
this.doneFlag = true;
this._enumerator = null;
this.error = e;
if (e instanceof Error) {
console.error(e.stack);
} else {
console.error(`Error: ${JSON.stringify(e)}`);
}
});
}
Resume(): void {
this.pauseFlag = false;
if (this._executor) {
this._executor.Resume();
}
}
this.Current = value;
}
if (done) {
this._enumerator = this._enumerator.nextEnumerator;
if (this._enumerator) {
result.done = false;
}
}
}
catch (e) {
this.doneFlag = true;
this.error = e;
if (e instanceof Error) {
console.error(e.stack);
} else {
console.error(`Error: ${JSON.stringify(e)}`);
}
result = { done: true, value: e };
}
return result;
}
Stop(): void {
this.doneFlag = true;
if (this._executor) {
this._executor.Stop();
}
}
Pause(): void {
this.pauseFlag = true;
if (this._executor) {
this._executor.Pause();
}
}
Resume(): void {
this.pauseFlag = false;
if (this._executor) {
this._executor.Resume();
}
}
}

View File

@ -2,30 +2,32 @@ 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 { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocols/Slot1Request";
import { RandomEx } from "../../Utils/Number/RandomEx";
export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data
const temps: 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(temps[RandomEx.GetInt(0, temps.length)]);
// 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,
Data: slotData,
IsValid: true
};
clientData.free.count++;
return response;
}

View File

@ -6,27 +6,112 @@ import { RandomEx } from "../../Utils/Number/RandomEx";
export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data
clientData.free = null;
// // 原始的编码字符串
// // // {"slot":[4,4,1,12,14,9,10,1,6,4,8,9,1,14,10],"scatter":[[[2,7,12],100]],"pay":[[1,-100]],"get":[[1,100]],"money":9990624}
// // const encodedStr = 'H4sIAAAAAAAAA1WOMQ+CMBCF/0vnG9paRdkcSRwMjoahQjE1hZIWooTw371TSLS54d3ru7tvYpylE4vO97mJg+uztvbkNNq2WcVSAax2/rnIe/BDR5qj7UNDUipgtq3M62Rjz9KrUrBNgMMGSxbw2b1+gQIBQoJQcADBsdmhtaeGPMGLGZhutRujjbkxLq50Zz0uaJh4dJexuXm3wlY2mJIiX16kOdI5CQkeo5Wx/B/oKMp/oshZB2PQnPG9ARdrnfUWAQAA';
// // {"slot":[5,6,14,6,5,11,12,3,14,11,6,2,11,2,12],"line":[[[5,11,12,13,9],161,1500]],"pay":[[1,-100]],"get":[[1,1500]],"money":9991524}
// const encodedStr = 'H4sIAAAAAAAAA11Pu27DMAz8F84cQjlSEG9FpwAdinQMMqi2XKiQJcOykRqB/72kH0OrQTreEXenJxygfEIOabi6PIbhEpskTGt9vNRQEkIT0mODX30aO8EHplPfClRHBB9r9/Pm8wDlrdBIZ6QjFoSk77iYb5pGI4pB3mFVYSEjQ4NKHr7UfUaw0YYp+3x1LuS94Lud9nZkaGGn9jMFbsbVqjRGjtAIDx/q13VSCMFHt7Q3JMNWY02nAs9csLMT63rm4O/uY/Hcg2rfu0qS1y/zP1/EQDrm6u9q93/pxNZN7xyzM59fbBqv0msBAAA=';
// // 解码 Base64
// const decodedBytes = Buffer.from(encodedStr, 'base64');
// // 解压缩 zlib 数据
// gunzip(decodedBytes, (err, decompressedBytes) => {
// if (err) {
// console.error('解压缩失败:', err);
// return;
// }
// // 解析 JSON 数据
// try {
// const jsonData = JSON.parse(decompressedBytes.toString());
// console.log(JSON.stringify(jsonData, null, 4));
// } catch (parseErr) {
// console.error('JSON 解析失败:', parseErr);
// }
// });
const temps: string[] = [
`{"slot":[11,4,8,9,5,2,13,10,7,9,10,6,6,12,4],"line":[[[5,11,12],161,2000]],"get":[[1,2000]]}`,
`{"slot":[11,4,8,9,5,2,13,10,7,9,10,6,6,12,4],"line":[[[5,11,12],161,2000]]}`,
`{"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]],"get":[[1,2000]]}`,
`{"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]]}`,
];
const Data: any = JSON.parse(temps[RandomEx.GetInt(0, temps.length)]);
clientData.money -= data.pay;
if (Data.get) {
clientData.money += Data.get[0][1];
const slotData: any = JSON.parse(temps[RandomEx.GetInt(0, temps.length)]);
let totalGet: number = 0;
if (slotData.line) {
totalGet += getLineGet(slotData.line);
}
Data["pay"] = [[1, -data.pay]];
Data["money"] = clientData.money;
if (slotData.scatter) {
totalGet += getScatterGet(slotData.scatter);
}
if (slotData.free) {
const count = slotData.free[1];
const { freeData, totalFreeGet } = getFree(count);
totalGet += totalFreeGet;
clientData.free = { count: 0, freeData };
}
if (totalGet) {
slotData.get = [[1, totalGet]];
}
clientData.money -= data.pay;
if (slotData.get) {
clientData.money += slotData.get[0][1];
}
slotData["pay"] = [[1, -data.pay]];
slotData["money"] = clientData.money;
const response: INetResponse<RpcSlot1SpinResponse> = {
Status: 0,
Method: req.Method,
Data,
Data: slotData,
IsValid: true
};
return response;
}
function getFree(count: number) {
const freeData = [];
let totalFreeGet = 0;
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]}`,
];
for (let i: number = 0; i < count; i++) {
const slotData: any = JSON.parse(freeTemps[RandomEx.GetInt(0, freeTemps.length)]);
freeData.push(slotData);
if (slotData.line) {
totalFreeGet += getLineGet(slotData.line);
}
}
return { freeData, totalFreeGet }
}
function getLineGet(lines: number[][]): number {
let totalGet: number = 0;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
totalGet += line[2]
}
return totalGet;
}
function getScatterGet(scatter: number[][]): number {
let totalGet: number = scatter[0][1];
return totalGet;
}

View File

@ -8,6 +8,7 @@ import "module-alias/register";
import WebSocket, { WebSocketServer } from 'ws';
/*
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
http://entry.lybobet.com/casino_sd_2/resource-internal/_Debug/slot1/index.html?token=test&slotid=1&v=1724652287&host=127.0.0.1&language=zh-tw&logo=2&pl=1
ws://192.168.5.36:9005
ws://127.0.0.1:9005

View File

@ -6,4 +6,5 @@ export interface ClientData {
id: number;
name: string;
money: number;
free?: { count: number, freeData: any[] };
}