[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"; import { SingleEnumerator } from "./SingleEnumerator";
export class EnumeratorExecutor implements IEnumeratorV2Started { export class EnumeratorExecutor implements IEnumeratorV2Started {
public Current: any; public Current: any;
public target: any; public target: any;
public pauseFlag: boolean; public pauseFlag: boolean;
public doneFlag: boolean; public doneFlag: boolean;
public childFlag: boolean; public childFlag: boolean;
public asyncFlag: boolean; public asyncFlag: boolean;
public error: any; public error: any;
private _executor: EnumeratorExecutor; private _executor: EnumeratorExecutor;
private _enumerator: BaseEnumerator; private _enumerator: BaseEnumerator;
constructor(enumerator: BaseEnumerator, target: any) { constructor(enumerator: BaseEnumerator, target: any) {
this.target = target; this.target = target;
this._enumerator = enumerator; this._enumerator = enumerator;
} }
next(delta?: any): IteratorResult<any> { next(delta?: any): IteratorResult<any> {
if (this._executor && this._executor.doneFlag) { if (this._executor && this._executor.doneFlag) {
this._executor = null; this._executor = null;
} }
if (this.doneFlag || (!this._enumerator && !this._executor)) { if (this.doneFlag || (!this._enumerator && !this._executor)) {
this.doneFlag = true; this.doneFlag = true;
return { done: true, value: undefined }; 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) { if (this._executor) {
result = this._executor.next(delta); result = this._executor.next(delta);
this.Current = this._executor.Current; this.Current = this._executor.Current;
if (this._executor.doneFlag) { if (this._executor.doneFlag) {
this._executor = null; this._executor = null;
} else { } else {
result.done = false; result.done = false;
return result; return result;
} }
} }
if (!this._enumerator) {
this.doneFlag = true;
return { done: true, value: undefined };
}
try { if (!this._enumerator) {
result = this._enumerator.next(delta); this.doneFlag = true;
let value = result.value; return { done: true, value: undefined };
let done = result.done; }
if (value) { try {
// Iterator result = this._enumerator.next(delta);
if (typeof value[Symbol.iterator] === 'function') { let value = result.value;
value = new SingleEnumerator(<Iterator<any>>value); let done = result.done;
}
if (value instanceof BaseEnumerator) { if (value) {
if (!done) { // Iterator
BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator; if (typeof value[Symbol.iterator] === 'function') {
} value = new SingleEnumerator(<Iterator<any>>value);
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)}`);
}
});
}
this.Current = value; if (value instanceof BaseEnumerator) {
} if (!done) {
BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator;
if (done) { }
this._enumerator = this._enumerator.nextEnumerator; this._enumerator = value;
if (this._enumerator) { result = this._enumerator.next(delta);
result.done = false; value = result.value;
} done = result.done;
}
}
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 };
}
return result; if (value) {
} // Iterator again
if (typeof value[Symbol.iterator] === 'function') {
value = new SingleEnumerator(<Iterator<any>>value);
}
Stop(): void { if (value instanceof BaseEnumerator) {
this.doneFlag = true; if (!done) {
if (this._executor) { BaseEnumerator.getLastEnumerator(value).nextEnumerator = this._enumerator;
this._executor.Stop(); }
} this._enumerator = value;
} result.done = false;
done = false;
}
}
}
Pause(): void { if (value instanceof EnumeratorExecutor) {
this.pauseFlag = true; if (done) {
if (this._executor) { this._enumerator = this._enumerator.nextEnumerator;
this._executor.Pause(); }
} 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.Current = value;
this.pauseFlag = false; }
if (this._executor) {
this._executor.Resume(); 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 { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { ClientData } from "../../shared/protocols/define/interface"; import { ClientData } from "../../shared/protocols/define/interface";
import { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocols/Slot1Request"; import { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocols/Slot1Request";
import { RandomEx } from "../../Utils/Number/RandomEx";
export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> { export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data const data: RpcSlot1SpinRequest = req.Data
const temps: string[] = [ // 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":[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":[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":[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":[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":[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":[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":[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,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":[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":[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 Data: any = JSON.parse(freeTemps[RandomEx.GetInt(0, freeTemps.length)]);
const { count, freeData } = clientData.free;
const slotData: any = freeData[count];
const response: INetResponse<RpcSlot1SpinResponse> = { const response: INetResponse<RpcSlot1SpinResponse> = {
Status: 0, Status: 0,
Method: req.Method, Method: req.Method,
Data, Data: slotData,
IsValid: true IsValid: true
}; };
clientData.free.count++;
return response; return response;
} }

View File

@ -6,27 +6,112 @@ import { RandomEx } from "../../Utils/Number/RandomEx";
export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> { export default function* (clientData: ClientData, req: INetRequest<RpcSlot1SpinRequest>): IterableIterator<any> {
const data: RpcSlot1SpinRequest = req.Data 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[] = [ 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":[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)]); const slotData: any = JSON.parse(temps[RandomEx.GetInt(0, temps.length)]);
clientData.money -= data.pay;
if (Data.get) { let totalGet: number = 0;
clientData.money += Data.get[0][1]; if (slotData.line) {
totalGet += getLineGet(slotData.line);
} }
Data["pay"] = [[1, -data.pay]]; if (slotData.scatter) {
Data["money"] = clientData.money; 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> = { const response: INetResponse<RpcSlot1SpinResponse> = {
Status: 0, Status: 0,
Method: req.Method, Method: req.Method,
Data, Data: slotData,
IsValid: true IsValid: true
}; };
return response; 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'; 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 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://192.168.5.36:9005
ws://127.0.0.1:9005 ws://127.0.0.1:9005

View File

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